Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: ui/base/dragdrop/os_exchange_data_provider_aura.cc

Issue 14189002: linux_aura: Implement dropping in chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add HTML type to prefetch list to fix crashes. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_aura.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 OSExchangeDataProviderAura::OSExchangeDataProviderAura() : formats_(0) {}
16
17 OSExchangeDataProviderAura::~OSExchangeDataProviderAura() {}
18
19 void OSExchangeDataProviderAura::SetString(const string16& data) {
20 string_ = data;
21 formats_ |= OSExchangeData::STRING;
22 }
23
24 void OSExchangeDataProviderAura::SetURL(const GURL& url,
25 const string16& title) {
26 url_ = url;
27 title_ = title;
28 formats_ |= OSExchangeData::URL;
29 }
30
31 void OSExchangeDataProviderAura::SetFilename(const base::FilePath& path) {
32 filenames_.clear();
33 filenames_.push_back(OSExchangeData::FileInfo(path, base::FilePath()));
34 formats_ |= OSExchangeData::FILE_NAME;
35 }
36
37 void OSExchangeDataProviderAura::SetFilenames(
38 const std::vector<OSExchangeData::FileInfo>& filenames) {
39 filenames_ = filenames;
40 formats_ |= OSExchangeData::FILE_NAME;
41 }
42
43 void OSExchangeDataProviderAura::SetPickledData(
44 OSExchangeData::CustomFormat format,
45 const Pickle& data) {
46 pickle_data_[format] = data;
47 formats_ |= OSExchangeData::PICKLED_DATA;
48 }
49
50 bool OSExchangeDataProviderAura::GetString(string16* data) const {
51 if ((formats_ & OSExchangeData::STRING) == 0)
52 return false;
53 *data = string_;
54 return true;
55 }
56
57 bool OSExchangeDataProviderAura::GetURLAndTitle(GURL* url,
58 string16* title) const {
59 if ((formats_ & OSExchangeData::URL) == 0) {
60 title->clear();
61 return GetPlainTextURL(url);
62 }
63
64 if (!url_.is_valid())
65 return false;
66
67 *url = url_;
68 *title = title_;
69 return true;
70 }
71
72 bool OSExchangeDataProviderAura::GetFilename(base::FilePath* path) const {
73 if ((formats_ & OSExchangeData::FILE_NAME) == 0)
74 return false;
75 DCHECK(!filenames_.empty());
76 *path = filenames_[0].path;
77 return true;
78 }
79
80 bool OSExchangeDataProviderAura::GetFilenames(
81 std::vector<OSExchangeData::FileInfo>* filenames) const {
82 if ((formats_ & OSExchangeData::FILE_NAME) == 0)
83 return false;
84 *filenames = filenames_;
85 return true;
86 }
87
88 bool OSExchangeDataProviderAura::GetPickledData(
89 OSExchangeData::CustomFormat format,
90 Pickle* data) const {
91 PickleData::const_iterator i = pickle_data_.find(format);
92 if (i == pickle_data_.end())
93 return false;
94
95 *data = i->second;
96 return true;
97 }
98
99 bool OSExchangeDataProviderAura::HasString() const {
100 return (formats_ & OSExchangeData::STRING) != 0;
101 }
102
103 bool OSExchangeDataProviderAura::HasURL() const {
104 if ((formats_ & OSExchangeData::URL) != 0) {
105 return true;
106 }
107 // No URL, see if we have plain text that can be parsed as a URL.
108 return GetPlainTextURL(NULL);
109 }
110
111 bool OSExchangeDataProviderAura::HasFile() const {
112 return (formats_ & OSExchangeData::FILE_NAME) != 0;
113 }
114
115 bool OSExchangeDataProviderAura::HasCustomFormat(
116 OSExchangeData::CustomFormat format) const {
117 return pickle_data_.find(format) != pickle_data_.end();
118 }
119
120 #if defined(OS_WIN)
121 void OSExchangeDataProviderAura::SetFileContents(
122 const base::FilePath& filename,
123 const std::string& file_contents) {
124 NOTIMPLEMENTED();
125 }
126
127 bool OSExchangeDataProviderAura::GetFileContents(
128 base::FilePath* filename,
129 std::string* file_contents) const {
130 NOTIMPLEMENTED();
131 return false;
132 }
133
134 bool OSExchangeDataProviderAura::HasFileContents() const {
135 NOTIMPLEMENTED();
136 return false;
137 }
138
139 void OSExchangeDataProviderAura::SetDownloadFileInfo(
140 const OSExchangeData::DownloadFileInfo& download) {
141 NOTIMPLEMENTED();
142 }
143 #endif
144
145 void OSExchangeDataProviderAura::SetHtml(const string16& html,
146 const GURL& base_url) {
147 formats_ |= OSExchangeData::HTML;
148 html_ = html;
149 base_url_ = base_url;
150 }
151
152 bool OSExchangeDataProviderAura::GetHtml(string16* html,
153 GURL* base_url) const {
154 if ((formats_ & OSExchangeData::HTML) == 0)
155 return false;
156 *html = html_;
157 *base_url = base_url_;
158 return true;
159 }
160
161 bool OSExchangeDataProviderAura::HasHtml() const {
162 return ((formats_ & OSExchangeData::HTML) != 0);
163 }
164
165 void OSExchangeDataProviderAura::SetDragImage(
166 const gfx::ImageSkia& image,
167 const gfx::Vector2d& cursor_offset) {
168 drag_image_ = image;
169 drag_image_offset_ = cursor_offset;
170 }
171
172 const gfx::ImageSkia& OSExchangeDataProviderAura::GetDragImage() const {
173 return drag_image_;
174 }
175
176 const gfx::Vector2d& OSExchangeDataProviderAura::GetDragImageOffset() const {
177 return drag_image_offset_;
178 }
179
180 bool OSExchangeDataProviderAura::GetPlainTextURL(GURL* url) const {
181 if ((formats_ & OSExchangeData::STRING) == 0)
182 return false;
183
184 GURL test_url(string_);
185 if (!test_url.is_valid())
186 return false;
187
188 if (url)
189 *url = test_url;
190 return true;
191 }
192
193 ///////////////////////////////////////////////////////////////////////////////
194 // OSExchangeData, public:
195
196 // static
197 OSExchangeData::Provider* OSExchangeData::CreateProvider() {
198 return new OSExchangeDataProviderAura();
199 }
200
201 // static
202 OSExchangeData::CustomFormat
203 OSExchangeData::RegisterCustomFormat(const std::string& type) {
204 // On Aura you probably want to just use the Clipboard::Get*FormatType APIs
205 // instead. But we can also dynamically generate new CustomFormat objects
206 // here too if really necessary.
207 return Clipboard::FormatType::Deserialize(type);
208 }
209
210
211 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698