| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 | |
| 5 #ifndef UI_VIEWS_MUS_OS_EXCHANGE_DATA_PROVIDER_MUS_H_ | |
| 6 #define UI_VIEWS_MUS_OS_EXCHANGE_DATA_PROVIDER_MUS_H_ | |
| 7 | |
| 8 #include "ui/base/dragdrop/os_exchange_data.h" | |
| 9 | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <utility> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "mojo/public/cpp/bindings/map.h" | |
| 17 #include "ui/gfx/geometry/vector2d.h" | |
| 18 #include "ui/gfx/image/image_skia.h" | |
| 19 #include "ui/views/mus/mus_export.h" | |
| 20 | |
| 21 namespace views { | |
| 22 | |
| 23 // Translates chrome's requests for various data types to a platform specific | |
| 24 // type. In the case of mus, this is a mapping of MIME types to byte arrays. | |
| 25 // | |
| 26 // TODO(erg): In the long run, there's a lot of optimizations that we can do | |
| 27 // once everything targets mus. The entire model of OSExchangeDataProvider | |
| 28 // shoves all data across the wire at once whether it is needed or not. | |
| 29 class VIEWS_MUS_EXPORT OSExchangeDataProviderMus | |
| 30 : public ui::OSExchangeData::Provider { | |
| 31 public: | |
| 32 using Data = std::map<std::string, std::vector<uint8_t>>; | |
| 33 | |
| 34 OSExchangeDataProviderMus(); | |
| 35 explicit OSExchangeDataProviderMus(Data data); | |
| 36 ~OSExchangeDataProviderMus() override; | |
| 37 | |
| 38 // Returns the raw MIME type to data mapping. | |
| 39 Data GetData() const; | |
| 40 | |
| 41 // Overridden from OSExchangeData::Provider: | |
| 42 std::unique_ptr<Provider> Clone() const override; | |
| 43 | |
| 44 void MarkOriginatedFromRenderer() override; | |
| 45 bool DidOriginateFromRenderer() const override; | |
| 46 | |
| 47 void SetString(const base::string16& data) override; | |
| 48 void SetURL(const GURL& url, const base::string16& title) override; | |
| 49 void SetFilename(const base::FilePath& path) override; | |
| 50 void SetFilenames(const std::vector<ui::FileInfo>& file_names) override; | |
| 51 void SetPickledData(const ui::Clipboard::FormatType& format, | |
| 52 const base::Pickle& data) override; | |
| 53 | |
| 54 bool GetString(base::string16* data) const override; | |
| 55 bool GetURLAndTitle(ui::OSExchangeData::FilenameToURLPolicy policy, | |
| 56 GURL* url, | |
| 57 base::string16* title) const override; | |
| 58 bool GetFilename(base::FilePath* path) const override; | |
| 59 bool GetFilenames(std::vector<ui::FileInfo>* file_names) const override; | |
| 60 bool GetPickledData(const ui::Clipboard::FormatType& format, | |
| 61 base::Pickle* data) const override; | |
| 62 | |
| 63 bool HasString() const override; | |
| 64 bool HasURL(ui::OSExchangeData::FilenameToURLPolicy policy) const override; | |
| 65 bool HasFile() const override; | |
| 66 bool HasCustomFormat(const ui::Clipboard::FormatType& format) const override; | |
| 67 | |
| 68 // Provider doesn't have a consistent interface between operating systems; | |
| 69 // this wasn't seen as a problem when there was a single Provider subclass | |
| 70 // per operating system. Now we have to have at least two providers per OS, | |
| 71 // leading to the following warts, which will remain until we clean all the | |
| 72 // callsites up. | |
| 73 #if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN) | |
| 74 void SetFileContents(const base::FilePath& filename, | |
| 75 const std::string& file_contents) override; | |
| 76 #endif | |
| 77 #if defined(OS_WIN) | |
| 78 bool GetFileContents(base::FilePath* filename, | |
| 79 std::string* file_contents) const override; | |
| 80 bool HasFileContents() const override; | |
| 81 void SetDownloadFileInfo( | |
| 82 const ui::OSExchangeData::DownloadFileInfo& download) override; | |
| 83 #endif | |
| 84 | |
| 85 #if defined(USE_AURA) | |
| 86 void SetHtml(const base::string16& html, const GURL& base_url) override; | |
| 87 bool GetHtml(base::string16* html, GURL* base_url) const override; | |
| 88 bool HasHtml() const override; | |
| 89 #endif | |
| 90 | |
| 91 #if defined(USE_AURA) || defined(OS_MACOSX) | |
| 92 void SetDragImage(const gfx::ImageSkia& image, | |
| 93 const gfx::Vector2d& cursor_offset) override; | |
| 94 const gfx::ImageSkia& GetDragImage() const override; | |
| 95 const gfx::Vector2d& GetDragImageOffset() const override; | |
| 96 #endif | |
| 97 | |
| 98 private: | |
| 99 // Returns true if |formats_| contains a file format and the file name can be | |
| 100 // parsed as a URL. | |
| 101 bool GetFileURL(GURL* url) const; | |
| 102 | |
| 103 // Returns true if |formats_| contains a string format and the string can be | |
| 104 // parsed as a URL. | |
| 105 bool GetPlainTextURL(GURL* url) const; | |
| 106 | |
| 107 // Drag image and offset data. | |
| 108 gfx::ImageSkia drag_image_; | |
| 109 gfx::Vector2d drag_image_offset_; | |
| 110 | |
| 111 Data mime_data_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderMus); | |
| 114 }; | |
| 115 | |
| 116 } // namespace views | |
| 117 | |
| 118 #endif // UI_VIEWS_MUS_OS_EXCHANGE_DATA_PROVIDER_MUS_H_ | |
| OLD | NEW |