os_exchange_data_provider.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_
  5. #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "build/build_config.h"
  10. #include "base/component_export.h"
  11. #include "base/files/file_path.h"
  12. #include "ui/base/clipboard/clipboard_format_type.h"
  13. #include "ui/base/clipboard/file_info.h"
  14. #include "ui/base/dragdrop/download_file_info.h"
  15. #include "ui/base/dragdrop/download_file_interface.h"
  16. #include "url/gurl.h"
  17. #if BUILDFLAG(IS_WIN)
  18. #include "base/callback_forward.h"
  19. #endif
  20. #if defined(USE_AURA) || BUILDFLAG(IS_APPLE)
  21. #include "ui/gfx/geometry/vector2d.h"
  22. #include "ui/gfx/image/image_skia.h"
  23. #endif
  24. namespace ui {
  25. class DataTransferEndpoint;
  26. // Controls whether or not filenames should be converted to file: URLs when
  27. // getting a URL.
  28. enum class FilenameToURLPolicy {
  29. CONVERT_FILENAMES,
  30. DO_NOT_CONVERT_FILENAMES,
  31. };
  32. // Provider defines the platform specific part of OSExchangeData that
  33. // interacts with the native system.
  34. class COMPONENT_EXPORT(UI_BASE_DATA_EXCHANGE) OSExchangeDataProvider {
  35. public:
  36. OSExchangeDataProvider() = default;
  37. virtual ~OSExchangeDataProvider() = default;
  38. virtual std::unique_ptr<OSExchangeDataProvider> Clone() const = 0;
  39. virtual void MarkOriginatedFromRenderer() = 0;
  40. virtual bool DidOriginateFromRenderer() const = 0;
  41. virtual void MarkAsFromPrivileged() = 0;
  42. virtual bool IsFromPrivileged() const = 0;
  43. virtual void SetString(const std::u16string& data) = 0;
  44. virtual void SetURL(const GURL& url, const std::u16string& title) = 0;
  45. virtual void SetFilename(const base::FilePath& path) = 0;
  46. virtual void SetFilenames(const std::vector<FileInfo>& file_names) = 0;
  47. virtual void SetPickledData(const ClipboardFormatType& format,
  48. const base::Pickle& data) = 0;
  49. virtual bool GetString(std::u16string* data) const = 0;
  50. virtual bool GetURLAndTitle(FilenameToURLPolicy policy,
  51. GURL* url,
  52. std::u16string* title) const = 0;
  53. virtual bool GetFilename(base::FilePath* path) const = 0;
  54. virtual bool GetFilenames(std::vector<FileInfo>* file_names) const = 0;
  55. virtual bool GetPickledData(const ClipboardFormatType& format,
  56. base::Pickle* data) const = 0;
  57. virtual bool HasString() const = 0;
  58. virtual bool HasURL(FilenameToURLPolicy policy) const = 0;
  59. virtual bool HasFile() const = 0;
  60. virtual bool HasCustomFormat(const ClipboardFormatType& format) const = 0;
  61. virtual void SetFileContents(const base::FilePath& filename,
  62. const std::string& file_contents) = 0;
  63. virtual bool GetFileContents(base::FilePath* filename,
  64. std::string* file_contents) const = 0;
  65. virtual bool HasFileContents() const = 0;
  66. #if BUILDFLAG(IS_WIN)
  67. virtual bool HasVirtualFilenames() const = 0;
  68. virtual bool GetVirtualFilenames(std::vector<FileInfo>* file_names) const = 0;
  69. virtual bool GetVirtualFilesAsTempFiles(
  70. base::OnceCallback<
  71. void(const std::vector<std::pair</*temp path*/ base::FilePath,
  72. /*display name*/ base::FilePath>>&)>
  73. callback) const = 0;
  74. virtual void SetVirtualFileContentsForTesting(
  75. const std::vector<std::pair<base::FilePath, std::string>>&
  76. filenames_and_contents,
  77. DWORD tymed) = 0;
  78. virtual void SetDownloadFileInfo(DownloadFileInfo* download) = 0;
  79. #endif
  80. #if defined(USE_AURA)
  81. virtual void SetHtml(const std::u16string& html, const GURL& base_url) = 0;
  82. virtual bool GetHtml(std::u16string* html, GURL* base_url) const = 0;
  83. virtual bool HasHtml() const = 0;
  84. #endif
  85. #if defined(USE_AURA) || BUILDFLAG(IS_APPLE)
  86. virtual void SetDragImage(const gfx::ImageSkia& image,
  87. const gfx::Vector2d& cursor_offset) = 0;
  88. virtual gfx::ImageSkia GetDragImage() const = 0;
  89. virtual gfx::Vector2d GetDragImageOffset() const = 0;
  90. #endif
  91. // These functions are only implemented on Chrome OS currently.
  92. virtual void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) = 0;
  93. virtual DataTransferEndpoint* GetSource() const = 0;
  94. };
  95. } // namespace ui
  96. #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_H_