File: os_exchange_data_provider.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; 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 (141 lines) | stat: -rw-r--r-- 5,326 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// 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 UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_
#define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_

#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "base/component_export.h"
#include "base/files/file_path.h"
#include "build/build_config.h"
#include "ui/base/clipboard/clipboard_format_type.h"
#include "ui/base/clipboard/file_info.h"
#include "ui/base/dragdrop/download_file_info.h"
#include "ui/base/dragdrop/download_file_interface.h"
#include "url/gurl.h"
#include "url/origin.h"

#if BUILDFLAG(IS_WIN)
#include "base/functional/callback_forward.h"
#endif

#if defined(USE_AURA) || BUILDFLAG(IS_APPLE)
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/image/image_skia.h"
#endif

namespace ui {

class DataTransferEndpoint;

// Controls whether or not filenames are converted to file: URLs when getting a
// URL. Some callers, e.g. when populating the DataTransfer object for the web
// platform, need to suppress this conversion, as this:
// - leaks filesystem paths to the web
// - results in duplicate entries for the same logical entity
// See crbug.com/40078641 for more historical context.
enum class FilenameToURLPolicy {
  CONVERT_FILENAMES,
  DO_NOT_CONVERT_FILENAMES,
};

// Provider defines the platform specific part of OSExchangeData that
// interacts with the native system.
class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider {
 public:
  OSExchangeDataProvider() = default;
  virtual ~OSExchangeDataProvider() = default;

  virtual std::unique_ptr<OSExchangeDataProvider> Clone() const = 0;

  virtual void MarkRendererTaintedFromOrigin(const url::Origin& origin) = 0;
  virtual bool IsRendererTainted() const = 0;
  virtual std::optional<url::Origin> GetRendererTaintedOrigin() const = 0;

  virtual void MarkAsFromPrivileged() = 0;
  virtual bool IsFromPrivileged() const = 0;

  virtual void SetString(std::u16string_view data) = 0;
  virtual void SetURL(const GURL& url, std::u16string_view title) = 0;
  virtual void SetFilename(const base::FilePath& path) = 0;
  virtual void SetFilenames(const std::vector<FileInfo>& file_names) = 0;
  virtual void SetPickledData(const ClipboardFormatType& format,
                              const base::Pickle& data) = 0;

  virtual std::optional<std::u16string> GetString() const = 0;
  struct UrlInfo {
    GURL url;
    std::u16string title;
  };
  // Even if there is no URL data present, many implementations will coerce text
  // content into URLs if the text is a valid URL. This coercion should only
  // happen for HTTP-like URLs (i.e. http or https) if the data originates from
  // a renderer (i.e. `IsRendererTainted()` is true) to avoid bypassing the URL
  // filtering applied when a drag is started.
  virtual std::optional<UrlInfo> GetURLAndTitle(
      FilenameToURLPolicy policy) const = 0;
  virtual std::optional<std::vector<GURL>> GetURLs(
      FilenameToURLPolicy policy) const = 0;
  virtual std::optional<std::vector<FileInfo>> GetFilenames() const = 0;
  virtual std::optional<base::Pickle> GetPickledData(
      const ClipboardFormatType& format) const = 0;

  virtual bool HasString() const = 0;
  virtual bool HasURL(FilenameToURLPolicy policy) const = 0;
  virtual bool HasFile() const = 0;
  virtual bool HasCustomFormat(const ClipboardFormatType& format) const = 0;

  virtual void SetFileContents(const base::FilePath& filename,
                               const std::string& file_contents) = 0;
  struct FileContentsInfo {
    base::FilePath filename;
    std::string file_contents;
  };
  virtual std::optional<FileContentsInfo> GetFileContents() const = 0;
  virtual bool HasFileContents() const = 0;
#if BUILDFLAG(IS_WIN)
  virtual bool HasVirtualFilenames() const = 0;
  virtual std::optional<std::vector<FileInfo>> GetVirtualFilenames() const = 0;
  virtual void GetVirtualFilesAsTempFiles(
      base::OnceCallback<
          void(const std::vector<std::pair</*temp path*/ base::FilePath,
                                           /*display name*/ base::FilePath>>&)>
          callback) const = 0;
  virtual void SetVirtualFileContentsForTesting(
      const std::vector<std::pair<base::FilePath, std::string>>&
          filenames_and_contents,
      DWORD tymed) = 0;
  virtual void SetDownloadFileInfo(DownloadFileInfo* download) = 0;
#endif

#if defined(USE_AURA)
  virtual void SetHtml(const std::u16string& html, const GURL& base_url) = 0;
  struct HtmlInfo {
    std::u16string html;
    GURL base_url;
  };
  virtual std::optional<HtmlInfo> GetHtml() const = 0;
  virtual bool HasHtml() const = 0;
#endif

#if defined(USE_AURA) || BUILDFLAG(IS_APPLE)
  virtual void SetDragImage(const gfx::ImageSkia& image,
                            const gfx::Vector2d& cursor_offset) = 0;
  virtual gfx::ImageSkia GetDragImage() const = 0;
  virtual gfx::Vector2d GetDragImageOffset() const = 0;
#endif

  // These functions are only implemented on Chrome OS currently.
  virtual void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) = 0;
  virtual DataTransferEndpoint* GetSource() const = 0;
};

}  // namespace ui

#endif  // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_