| OLD | NEW |
| (Empty) |
| 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 | |
| 5 #include "ui/base/dragdrop/os_exchange_data_provider_chromeos.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "net/base/net_util.h" | |
| 10 #include "ui/base/clipboard/clipboard.h" | |
| 11 #include "ui/base/clipboard/scoped_clipboard_writer.h" | |
| 12 | |
| 13 namespace ui { | |
| 14 | |
| 15 OSExchangeDataProviderChromeos::OSExchangeDataProviderChromeos() | |
| 16 : formats_(0) { | |
| 17 } | |
| 18 | |
| 19 OSExchangeDataProviderChromeos::~OSExchangeDataProviderChromeos() {} | |
| 20 | |
| 21 void OSExchangeDataProviderChromeos::SetString(const string16& data) { | |
| 22 string_ = data; | |
| 23 formats_ |= OSExchangeData::STRING; | |
| 24 } | |
| 25 | |
| 26 void OSExchangeDataProviderChromeos::SetURL(const GURL& url, | |
| 27 const string16& title) { | |
| 28 url_ = url; | |
| 29 title_ = title; | |
| 30 formats_ |= OSExchangeData::URL; | |
| 31 } | |
| 32 | |
| 33 void OSExchangeDataProviderChromeos::SetFilename(const base::FilePath& path) { | |
| 34 filenames_.clear(); | |
| 35 filenames_.push_back(OSExchangeData::FileInfo(path, base::FilePath())); | |
| 36 formats_ |= OSExchangeData::FILE_NAME; | |
| 37 } | |
| 38 | |
| 39 void OSExchangeDataProviderChromeos::SetFilenames( | |
| 40 const std::vector<OSExchangeData::FileInfo>& filenames) { | |
| 41 filenames_ = filenames; | |
| 42 formats_ |= OSExchangeData::FILE_NAME; | |
| 43 } | |
| 44 | |
| 45 void OSExchangeDataProviderChromeos::SetPickledData( | |
| 46 OSExchangeData::CustomFormat format, | |
| 47 const Pickle& data) { | |
| 48 pickle_data_[format] = data; | |
| 49 formats_ |= OSExchangeData::PICKLED_DATA; | |
| 50 } | |
| 51 | |
| 52 bool OSExchangeDataProviderChromeos::GetString(string16* data) const { | |
| 53 if ((formats_ & OSExchangeData::STRING) == 0) | |
| 54 return false; | |
| 55 *data = string_; | |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 bool OSExchangeDataProviderChromeos::GetURLAndTitle(GURL* url, | |
| 60 string16* title) const { | |
| 61 if ((formats_ & OSExchangeData::URL) == 0) { | |
| 62 title->clear(); | |
| 63 return GetPlainTextURL(url); | |
| 64 } | |
| 65 | |
| 66 if (!url_.is_valid()) | |
| 67 return false; | |
| 68 | |
| 69 *url = url_; | |
| 70 *title = title_; | |
| 71 return true; | |
| 72 } | |
| 73 | |
| 74 bool OSExchangeDataProviderChromeos::GetFilename(base::FilePath* path) const { | |
| 75 if ((formats_ & OSExchangeData::FILE_NAME) == 0) | |
| 76 return false; | |
| 77 DCHECK(!filenames_.empty()); | |
| 78 *path = filenames_[0].path; | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 bool OSExchangeDataProviderChromeos::GetFilenames( | |
| 83 std::vector<OSExchangeData::FileInfo>* filenames) const { | |
| 84 if ((formats_ & OSExchangeData::FILE_NAME) == 0) | |
| 85 return false; | |
| 86 *filenames = filenames_; | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 bool OSExchangeDataProviderChromeos::GetPickledData( | |
| 91 OSExchangeData::CustomFormat format, | |
| 92 Pickle* data) const { | |
| 93 PickleData::const_iterator i = pickle_data_.find(format); | |
| 94 if (i == pickle_data_.end()) | |
| 95 return false; | |
| 96 | |
| 97 *data = i->second; | |
| 98 return true; | |
| 99 } | |
| 100 | |
| 101 bool OSExchangeDataProviderChromeos::HasString() const { | |
| 102 return (formats_ & OSExchangeData::STRING) != 0; | |
| 103 } | |
| 104 | |
| 105 bool OSExchangeDataProviderChromeos::HasURL() const { | |
| 106 if ((formats_ & OSExchangeData::URL) != 0) { | |
| 107 return true; | |
| 108 } | |
| 109 // No URL, see if we have plain text that can be parsed as a URL. | |
| 110 return GetPlainTextURL(NULL); | |
| 111 } | |
| 112 | |
| 113 bool OSExchangeDataProviderChromeos::HasFile() const { | |
| 114 return (formats_ & OSExchangeData::FILE_NAME) != 0; | |
| 115 } | |
| 116 | |
| 117 bool OSExchangeDataProviderChromeos::HasCustomFormat( | |
| 118 OSExchangeData::CustomFormat format) const { | |
| 119 return pickle_data_.find(format) != pickle_data_.end(); | |
| 120 } | |
| 121 | |
| 122 void OSExchangeDataProviderChromeos::SetHtml(const string16& html, | |
| 123 const GURL& base_url) { | |
| 124 formats_ |= OSExchangeData::HTML; | |
| 125 html_ = html; | |
| 126 base_url_ = base_url; | |
| 127 } | |
| 128 | |
| 129 bool OSExchangeDataProviderChromeos::GetHtml(string16* html, | |
| 130 GURL* base_url) const { | |
| 131 if ((formats_ & OSExchangeData::HTML) == 0) | |
| 132 return false; | |
| 133 *html = html_; | |
| 134 *base_url = base_url_; | |
| 135 return true; | |
| 136 } | |
| 137 | |
| 138 bool OSExchangeDataProviderChromeos::HasHtml() const { | |
| 139 return ((formats_ & OSExchangeData::HTML) != 0); | |
| 140 } | |
| 141 | |
| 142 void OSExchangeDataProviderChromeos::SetDragImage( | |
| 143 const gfx::ImageSkia& image, | |
| 144 const gfx::Vector2d& cursor_offset) { | |
| 145 drag_image_ = image; | |
| 146 drag_image_offset_ = cursor_offset; | |
| 147 } | |
| 148 | |
| 149 const gfx::ImageSkia& OSExchangeDataProviderChromeos::GetDragImage() const { | |
| 150 return drag_image_; | |
| 151 } | |
| 152 | |
| 153 const gfx::Vector2d& | |
| 154 OSExchangeDataProviderChromeos::GetDragImageOffset() const { | |
| 155 return drag_image_offset_; | |
| 156 } | |
| 157 | |
| 158 bool OSExchangeDataProviderChromeos::GetPlainTextURL(GURL* url) const { | |
| 159 if ((formats_ & OSExchangeData::STRING) == 0) | |
| 160 return false; | |
| 161 | |
| 162 GURL test_url(string_); | |
| 163 if (!test_url.is_valid()) | |
| 164 return false; | |
| 165 | |
| 166 if (url) | |
| 167 *url = test_url; | |
| 168 return true; | |
| 169 } | |
| 170 | |
| 171 /////////////////////////////////////////////////////////////////////////////// | |
| 172 // OSExchangeData, public: | |
| 173 | |
| 174 // static | |
| 175 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | |
| 176 return new OSExchangeDataProviderChromeos(); | |
| 177 } | |
| 178 | |
| 179 // static | |
| 180 OSExchangeData::CustomFormat | |
| 181 OSExchangeData::RegisterCustomFormat(const std::string& type) { | |
| 182 // On Aura you probably want to just use the Clipboard::Get*FormatType APIs | |
| 183 // instead. But we can also dynamically generate new CustomFormat objects | |
| 184 // here too if really necessary. | |
| 185 return Clipboard::FormatType::Deserialize(type); | |
| 186 } | |
| 187 | |
| 188 | |
| 189 } // namespace ui | |
| OLD | NEW |