File: sharesheet_client.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (105 lines) | stat: -rw-r--r-- 3,600 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEBSHARE_CHROMEOS_SHARESHEET_CLIENT_H_
#define CHROME_BROWSER_WEBSHARE_CHROMEOS_SHARESHEET_CLIENT_H_

#include <optional>
#include <string>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "chrome/browser/sharesheet/sharesheet_types.h"
#include "chromeos/components/sharesheet/constants.h"
#include "content/public/browser/web_contents_observer.h"
#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
#include "url/gurl.h"

namespace content {
class WebContents;
}

namespace webshare {

class PrepareDirectoryTask;
class PrepareSubDirectoryTask;

// Chrome-OS implementation of navigator.share() sharing to
// sharesheet::SharesheetService.
class SharesheetClient : public content::WebContentsObserver {
 public:
  using DeliveredCallback = sharesheet::DeliveredCallback;
  using SharesheetCallback = base::RepeatingCallback<void(
      content::WebContents* web_contents,
      const std::vector<base::FilePath>& file_paths,
      const std::vector<std::string>& content_types,
      const std::vector<uint64_t>& file_sizes,
      const std::string& text,
      const std::string& title,
      DeliveredCallback delivered_callback)>;

  explicit SharesheetClient(content::WebContents* web_contents);
  SharesheetClient(const SharesheetClient&) = delete;
  SharesheetClient& operator=(const SharesheetClient&) = delete;
  ~SharesheetClient() override;

  void Share(const std::string& title,
             const std::string& text,
             const GURL& share_url,
             std::vector<blink::mojom::SharedFilePtr> files,
             blink::mojom::ShareService::ShareCallback callback);

  static void SetSharesheetCallbackForTesting(SharesheetCallback callback);

 private:
  void OnPrepareDirectory(blink::mojom::ShareError);

  void OnPrepareSubdirectory(blink::mojom::ShareError);

  void OnStoreFiles(blink::mojom::ShareError);

  void OnShowSharesheet(sharesheet::SharesheetResult result);

  static void ShowSharesheet(content::WebContents* web_contents,
                             const std::vector<base::FilePath>& file_paths,
                             const std::vector<std::string>& content_types,
                             const std::vector<uint64_t>& file_sizes,
                             const std::string& text,
                             const std::string& title,
                             DeliveredCallback delivered_callback);

  static SharesheetCallback& GetSharesheetCallback();

  // WebContentsObserver:
  void WebContentsDestroyed() override;

  struct CurrentShare {
    CurrentShare();
    CurrentShare(CurrentShare&&);
    CurrentShare& operator=(CurrentShare&&);
    CurrentShare(const CurrentShare&) = delete;
    CurrentShare& operator=(const CurrentShare&) = delete;
    ~CurrentShare();

    std::vector<blink::mojom::SharedFilePtr> files;
    base::FilePath directory;
    std::vector<base::FilePath> file_paths;
    std::vector<std::string> content_types;
    std::vector<uint64_t> file_sizes;
    std::string text;
    std::string title;
    blink::mojom::ShareService::ShareCallback callback;

    std::unique_ptr<PrepareDirectoryTask> prepare_directory_task;
    std::unique_ptr<PrepareSubDirectoryTask> prepare_subdirectory_task;
  };

  std::optional<CurrentShare> current_share_;

  base::WeakPtrFactory<SharesheetClient> weak_ptr_factory_{this};
};

}  // namespace webshare

#endif  // CHROME_BROWSER_WEBSHARE_CHROMEOS_SHARESHEET_CLIENT_H_