File: share_operation.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (112 lines) | stat: -rw-r--r-- 3,948 bytes parent folder | download | duplicates (4)
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
106
107
108
109
110
111
112
// 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_WIN_SHARE_OPERATION_H_
#define CHROME_BROWSER_WEBSHARE_WIN_SHARE_OPERATION_H_

#include <memory>
#include <string>
#include <vector>

#include "base/memory/weak_ptr.h"
#include "base/win/core_winrt_util.h"
#include "third_party/blink/public/mojom/webshare/webshare.mojom.h"
#include "url/gurl.h"

#include <wrl/client.h>

namespace ABI::Windows {
namespace ApplicationModel::DataTransfer {
struct IDataPackage;
class IDataRequest;
class IDataRequestDeferral;
class IDataRequestedEventArgs;
}  // namespace ApplicationModel::DataTransfer
namespace Storage {
class IStorageFile;
class IStorageItem;
}  // namespace Storage
}  // namespace ABI::Windows

namespace base::win {
template <typename T>
class Vector;
}  // namespace base::win

namespace content {
class WebContents;
}  // namespace content

namespace webshare {

class ShowShareUIForWindowOperation;

class ShareOperation final {
 public:
  using SharedFiles = std::vector<blink::mojom::SharedFilePtr>;
  static void SetMaxFileBytesForTesting(uint64_t max_file_bytes);

  // Test hook for overriding the base RoGetActivationFactory function
  static void SetRoGetActivationFactoryFunctionForTesting(
      decltype(&base::win::RoGetActivationFactory) value);

  ShareOperation(const std::string& title,
                 const std::string& text,
                 const GURL& url,
                 content::WebContents* web_contents);
  ShareOperation(const ShareOperation&) = delete;
  ShareOperation& operator=(const ShareOperation&) = delete;
  ~ShareOperation();

  base::WeakPtr<ShareOperation> AsWeakPtr();
  // Starts this Windows Share operation for the previously provided content
  // and a set of files. The |callback| will be invoked upon completion of the
  // operation with a value indicating the success of the operation, or if the
  // returned instance is destroyed before the operation is completed the
  // |callback| will be invoked with a CANCELLED value and the underlying
  // Windows operation will be aborted.
  void Run(SharedFiles files,
           blink::mojom::ShareService::ShareCallback callback);

 private:
  void OnDataRequested(
      SharedFiles files,
      ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs* e);
  bool PutShareContentInDataPackage(
      SharedFiles files,
      ABI::Windows::ApplicationModel::DataTransfer::IDataRequest* data_request);
  bool PutShareContentInEventArgs(
      SharedFiles files,
      ABI::Windows::ApplicationModel::DataTransfer::IDataRequestedEventArgs* e);
  void OnStreamedFileCreated(
      uint32_t expected_file_count,
      Microsoft::WRL::ComPtr<ABI::Windows::Storage::IStorageFile> storage_file);
  void Complete(const blink::mojom::ShareError share_error);

  const base::WeakPtr<content::WebContents> web_contents_;
  const std::string title_;
  const std::string text_;
  const GURL url_;

  std::vector<Microsoft::WRL::ComPtr<IUnknown>> async_operations_;
  blink::mojom::ShareService::ShareCallback callback_;
  Microsoft::WRL::ComPtr<
      ABI::Windows::ApplicationModel::DataTransfer::IDataPackage>
      data_package_;
  Microsoft::WRL::ComPtr<
      ABI::Windows::ApplicationModel::DataTransfer::IDataRequestDeferral>
      data_request_deferral_;
  std::unique_ptr<ShowShareUIForWindowOperation>
      show_share_ui_for_window_operation_;
  // Though this Vector is declared as using a raw IStorageItem*, because
  // IStorageItem implements IUnknown it will be stored internally with
  // ComPtrs, so does not need to be specially handled.
  Microsoft::WRL::ComPtr<
      base::win::Vector<ABI::Windows::Storage::IStorageItem*>>
      storage_items_;
  base::WeakPtrFactory<ShareOperation> weak_factory_{this};
};

}  // namespace webshare

#endif  // CHROME_BROWSER_WEBSHARE_WIN_SHARE_OPERATION_H_