os_exchange_data_provider_non_backed.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (c) 2012 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_NON_BACKED_H_
  5. #define UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_
  6. #include <map>
  7. #include <memory>
  8. #include "base/component_export.h"
  9. #include "base/pickle.h"
  10. #include "build/build_config.h"
  11. #include "build/chromeos_buildflags.h"
  12. #include "ui/base/clipboard/file_info.h"
  13. #include "ui/base/dragdrop/os_exchange_data_provider.h"
  14. #include "ui/gfx/geometry/vector2d.h"
  15. #include "ui/gfx/image/image_skia.h"
  16. #include "url/gurl.h"
  17. namespace base {
  18. class FilePath;
  19. } // namespace base
  20. namespace ui {
  21. class ClipboardFormatType;
  22. // Simple OSExchangeDataProvider implementation for aura-based ports with no
  23. // actual platform integration. So data managed by this class is exchangeable
  24. // only among Chromium windows and is available only while it is alive.
  25. class COMPONENT_EXPORT(UI_BASE) OSExchangeDataProviderNonBacked
  26. : public OSExchangeDataProvider {
  27. public:
  28. OSExchangeDataProviderNonBacked();
  29. OSExchangeDataProviderNonBacked(const OSExchangeDataProviderNonBacked&) =
  30. delete;
  31. OSExchangeDataProviderNonBacked& operator=(
  32. const OSExchangeDataProviderNonBacked&) = delete;
  33. ~OSExchangeDataProviderNonBacked() override;
  34. // Overridden from OSExchangeDataProvider:
  35. std::unique_ptr<OSExchangeDataProvider> Clone() const override;
  36. void MarkOriginatedFromRenderer() override;
  37. bool DidOriginateFromRenderer() const override;
  38. void MarkAsFromPrivileged() override;
  39. bool IsFromPrivileged() const override;
  40. void SetString(const std::u16string& data) override;
  41. void SetURL(const GURL& url, const std::u16string& title) override;
  42. void SetFilename(const base::FilePath& path) override;
  43. void SetFilenames(const std::vector<FileInfo>& filenames) override;
  44. void SetPickledData(const ClipboardFormatType& format,
  45. const base::Pickle& data) override;
  46. bool GetString(std::u16string* data) const override;
  47. bool GetURLAndTitle(FilenameToURLPolicy policy,
  48. GURL* url,
  49. std::u16string* title) const override;
  50. bool GetFilename(base::FilePath* path) const override;
  51. bool GetFilenames(std::vector<FileInfo>* filenames) const override;
  52. bool GetPickledData(const ClipboardFormatType& format,
  53. base::Pickle* data) const override;
  54. bool HasString() const override;
  55. bool HasURL(FilenameToURLPolicy policy) const override;
  56. bool HasFile() const override;
  57. bool HasCustomFormat(const ClipboardFormatType& format) const override;
  58. void SetFileContents(const base::FilePath& filename,
  59. const std::string& file_contents) override;
  60. bool GetFileContents(base::FilePath* filename,
  61. std::string* file_contents) const override;
  62. bool HasFileContents() const override;
  63. void SetHtml(const std::u16string& html, const GURL& base_url) override;
  64. bool GetHtml(std::u16string* html, GURL* base_url) const override;
  65. bool HasHtml() const override;
  66. void SetDragImage(const gfx::ImageSkia& image,
  67. const gfx::Vector2d& cursor_offset) override;
  68. gfx::ImageSkia GetDragImage() const override;
  69. gfx::Vector2d GetDragImageOffset() const override;
  70. void SetSource(std::unique_ptr<DataTransferEndpoint> data_source) override;
  71. DataTransferEndpoint* GetSource() const override;
  72. protected:
  73. // Copy internal data into |provider| object.
  74. void CopyData(OSExchangeDataProviderNonBacked* provider) const;
  75. const std::map<ClipboardFormatType, base::Pickle>& pickle_data() const {
  76. return pickle_data_;
  77. }
  78. private:
  79. // Returns true if |formats_| contains a file format and the file name can be
  80. // parsed as a URL.
  81. bool GetFileURL(GURL* url) const;
  82. // Returns true if |formats_| contains a string format and the string can be
  83. // parsed as a URL.
  84. bool GetPlainTextURL(GURL* url) const;
  85. // Actual formats that have been set.
  86. // for details.
  87. int formats_ = 0;
  88. // String contents.
  89. std::u16string string_;
  90. // URL contents.
  91. GURL url_;
  92. std::u16string title_;
  93. // File name.
  94. std::vector<FileInfo> filenames_;
  95. // PICKLED_DATA contents.
  96. std::map<ClipboardFormatType, base::Pickle> pickle_data_;
  97. // Drag image and offset data.
  98. gfx::ImageSkia drag_image_;
  99. gfx::Vector2d drag_image_offset_;
  100. // For file contents.
  101. base::FilePath file_contents_filename_;
  102. std::string file_contents_;
  103. // For HTML format
  104. std::u16string html_;
  105. GURL base_url_;
  106. #if !BUILDFLAG(IS_CHROMEOS_ASH)
  107. // For marking data originating from the renderer.
  108. bool originated_from_renderer_ = false;
  109. #endif
  110. // For marking data originating by privileged WebContents.
  111. bool is_from_privileged_ = false;
  112. // Data source.
  113. std::unique_ptr<DataTransferEndpoint> source_;
  114. };
  115. } // namespace ui
  116. #endif // UI_BASE_DRAGDROP_OS_EXCHANGE_DATA_PROVIDER_NON_BACKED_H_