OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" | 5 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/message_loop/message_pump_x11.h" | 9 #include "base/message_loop/message_pump_x11.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
13 #include "ui/base/clipboard/clipboard.h" | 13 #include "ui/base/clipboard/clipboard.h" |
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 14 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 15 #include "ui/base/dragdrop/file_info.h" |
15 #include "ui/base/x/selection_utils.h" | 16 #include "ui/base/x/selection_utils.h" |
16 #include "ui/base/x/x11_util.h" | 17 #include "ui/base/x/x11_util.h" |
17 | 18 |
18 // Note: the GetBlah() methods are used immediately by the | 19 // Note: the GetBlah() methods are used immediately by the |
19 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a | 20 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a |
20 // little more discriminating and calls HasBlah() before trying to get the | 21 // little more discriminating and calls HasBlah() before trying to get the |
21 // information. | 22 // information. |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 format_map_.Insert(atom_cache_.GetAtom(kNetscapeURL), | 164 format_map_.Insert(atom_cache_.GetAtom(kNetscapeURL), |
164 scoped_refptr<base::RefCountedMemory>( | 165 scoped_refptr<base::RefCountedMemory>( |
165 base::RefCountedString::TakeString(&netscape_url))); | 166 base::RefCountedString::TakeString(&netscape_url))); |
166 | 167 |
167 // And finally a string fallback as well. | 168 // And finally a string fallback as well. |
168 SetString(spec); | 169 SetString(spec); |
169 } | 170 } |
170 } | 171 } |
171 | 172 |
172 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { | 173 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { |
173 std::vector<OSExchangeData::FileInfo> data; | 174 std::vector<FileInfo> data; |
174 data.push_back(OSExchangeData::FileInfo(path, base::FilePath())); | 175 data.push_back(FileInfo(path, base::FilePath())); |
175 SetFilenames(data); | 176 SetFilenames(data); |
176 } | 177 } |
177 | 178 |
178 void OSExchangeDataProviderAuraX11::SetFilenames( | 179 void OSExchangeDataProviderAuraX11::SetFilenames( |
179 const std::vector<OSExchangeData::FileInfo>& filenames) { | 180 const std::vector<FileInfo>& filenames) { |
180 std::vector<std::string> paths; | 181 std::vector<std::string> paths; |
181 for (std::vector<OSExchangeData::FileInfo>::const_iterator it = | 182 for (std::vector<FileInfo>::const_iterator it = filenames.begin(); |
182 filenames.begin(); it != filenames.end(); ++it) { | 183 it != filenames.end(); |
| 184 ++it) { |
183 std::string url_spec = net::FilePathToFileURL(it->path).spec(); | 185 std::string url_spec = net::FilePathToFileURL(it->path).spec(); |
184 if (!url_spec.empty()) | 186 if (!url_spec.empty()) |
185 paths.push_back(url_spec); | 187 paths.push_back(url_spec); |
186 } | 188 } |
187 | 189 |
188 std::string joined_data = JoinString(paths, '\n'); | 190 std::string joined_data = JoinString(paths, '\n'); |
189 scoped_refptr<base::RefCountedMemory> mem( | 191 scoped_refptr<base::RefCountedMemory> mem( |
190 base::RefCountedString::TakeString(&joined_data)); | 192 base::RefCountedString::TakeString(&joined_data)); |
191 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeURIList), mem); | 193 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeURIList), mem); |
192 } | 194 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return true; | 272 return true; |
271 } | 273 } |
272 } | 274 } |
273 } | 275 } |
274 } | 276 } |
275 | 277 |
276 return false; | 278 return false; |
277 } | 279 } |
278 | 280 |
279 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { | 281 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { |
280 std::vector<OSExchangeData::FileInfo> filenames; | 282 std::vector<FileInfo> filenames; |
281 if (GetFilenames(&filenames)) { | 283 if (GetFilenames(&filenames)) { |
282 *path = filenames.front().path; | 284 *path = filenames.front().path; |
283 return true; | 285 return true; |
284 } | 286 } |
285 | 287 |
286 return false; | 288 return false; |
287 } | 289 } |
288 | 290 |
289 bool OSExchangeDataProviderAuraX11::GetFilenames( | 291 bool OSExchangeDataProviderAuraX11::GetFilenames( |
290 std::vector<OSExchangeData::FileInfo>* filenames) const { | 292 std::vector<FileInfo>* filenames) const { |
291 std::vector< ::Atom> url_atoms = ui::GetURIListAtomsFrom(&atom_cache_); | 293 std::vector< ::Atom> url_atoms = ui::GetURIListAtomsFrom(&atom_cache_); |
292 std::vector< ::Atom> requested_types; | 294 std::vector< ::Atom> requested_types; |
293 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 295 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
294 | 296 |
295 filenames->clear(); | 297 filenames->clear(); |
296 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 298 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
297 if (data.IsValid()) { | 299 if (data.IsValid()) { |
298 std::vector<std::string> tokens = ui::ParseURIList(data); | 300 std::vector<std::string> tokens = ui::ParseURIList(data); |
299 for (std::vector<std::string>::const_iterator it = tokens.begin(); | 301 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
300 it != tokens.end(); ++it) { | 302 it != tokens.end(); ++it) { |
301 GURL url(*it); | 303 GURL url(*it); |
302 base::FilePath file_path; | 304 base::FilePath file_path; |
303 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) { | 305 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) { |
304 filenames->push_back(OSExchangeData::FileInfo(file_path, | 306 filenames->push_back(FileInfo(file_path, base::FilePath())); |
305 base::FilePath())); | |
306 } | 307 } |
307 } | 308 } |
308 } | 309 } |
309 | 310 |
310 return !filenames->empty(); | 311 return !filenames->empty(); |
311 } | 312 } |
312 | 313 |
313 bool OSExchangeDataProviderAuraX11::GetPickledData( | 314 bool OSExchangeDataProviderAuraX11::GetPickledData( |
314 const OSExchangeData::CustomFormat& format, | 315 const OSExchangeData::CustomFormat& format, |
315 Pickle* pickle) const { | 316 Pickle* pickle) const { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 527 |
527 /////////////////////////////////////////////////////////////////////////////// | 528 /////////////////////////////////////////////////////////////////////////////// |
528 // OSExchangeData, public: | 529 // OSExchangeData, public: |
529 | 530 |
530 // static | 531 // static |
531 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 532 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
532 return new OSExchangeDataProviderAuraX11(); | 533 return new OSExchangeDataProviderAuraX11(); |
533 } | 534 } |
534 | 535 |
535 } // namespace ui | 536 } // namespace ui |
OLD | NEW |