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

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

Issue 2047703003: Revert of Implement ui::ClipboardMus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ui/base/clipboard/custom_data_helper_mac.mm ('k') | ui/base/test/test_clipboard.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 13 matching lines...) Expand all
24 24
25 namespace ui { 25 namespace ui {
26 26
27 namespace { 27 namespace {
28 28
29 const char kDndSelection[] = "XdndSelection"; 29 const char kDndSelection[] = "XdndSelection";
30 const char kRendererTaint[] = "chromium/x-renderer-taint"; 30 const char kRendererTaint[] = "chromium/x-renderer-taint";
31 31
32 const char kNetscapeURL[] = "_NETSCAPE_URL"; 32 const char kNetscapeURL[] = "_NETSCAPE_URL";
33 33
34 const char* kAtomsToCache[] = {kString, 34 const char* kAtomsToCache[] = {
35 kText, 35 kString,
36 kUtf8String, 36 kText,
37 kDndSelection, 37 kUtf8String,
38 Clipboard::kMimeTypeURIList, 38 kDndSelection,
39 Clipboard::kMimeTypeMozillaURL, 39 Clipboard::kMimeTypeURIList,
40 kNetscapeURL, 40 kMimeTypeMozillaURL,
41 Clipboard::kMimeTypeText, 41 kNetscapeURL,
42 kRendererTaint, 42 Clipboard::kMimeTypeText,
43 nullptr}; 43 kRendererTaint,
44 NULL
45 };
44 46
45 } // namespace 47 } // namespace
46 48
47 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11( 49 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11(
48 ::Window x_window, 50 ::Window x_window,
49 const SelectionFormatMap& selection) 51 const SelectionFormatMap& selection)
50 : x_display_(gfx::GetXDisplay()), 52 : x_display_(gfx::GetXDisplay()),
51 x_root_window_(DefaultRootWindow(x_display_)), 53 x_root_window_(DefaultRootWindow(x_display_)),
52 own_window_(false), 54 own_window_(false),
53 x_window_(x_window), 55 x_window_(x_window),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Mozilla's URL format: (UTF16: URL, newline, title) 149 // Mozilla's URL format: (UTF16: URL, newline, title)
148 base::string16 spec = base::UTF8ToUTF16(url.spec()); 150 base::string16 spec = base::UTF8ToUTF16(url.spec());
149 151
150 std::vector<unsigned char> data; 152 std::vector<unsigned char> data;
151 ui::AddString16ToVector(spec, &data); 153 ui::AddString16ToVector(spec, &data);
152 ui::AddString16ToVector(base::ASCIIToUTF16("\n"), &data); 154 ui::AddString16ToVector(base::ASCIIToUTF16("\n"), &data);
153 ui::AddString16ToVector(title, &data); 155 ui::AddString16ToVector(title, &data);
154 scoped_refptr<base::RefCountedMemory> mem( 156 scoped_refptr<base::RefCountedMemory> mem(
155 base::RefCountedBytes::TakeVector(&data)); 157 base::RefCountedBytes::TakeVector(&data));
156 158
157 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeMozillaURL), 159 format_map_.Insert(atom_cache_.GetAtom(kMimeTypeMozillaURL), mem);
158 mem);
159 160
160 // Set a string fallback as well. 161 // Set a string fallback as well.
161 SetString(spec); 162 SetString(spec);
162 163
163 // Return early if this drag already contains file contents (this implies 164 // Return early if this drag already contains file contents (this implies
164 // that file contents must be populated before URLs). Nautilus (and possibly 165 // that file contents must be populated before URLs). Nautilus (and possibly
165 // other file managers) prefer _NETSCAPE_URL over the X Direct Save 166 // other file managers) prefer _NETSCAPE_URL over the X Direct Save
166 // protocol, but we want to prioritize XDS in this case. 167 // protocol, but we want to prioritize XDS in this case.
167 if (!file_contents_name_.empty()) 168 if (!file_contents_name_.empty())
168 return; 169 return;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_); 248 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_);
248 std::vector< ::Atom> requested_types; 249 std::vector< ::Atom> requested_types;
249 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); 250 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types);
250 251
251 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); 252 ui::SelectionData data(format_map_.GetFirstOf(requested_types));
252 if (data.IsValid()) { 253 if (data.IsValid()) {
253 // TODO(erg): Technically, both of these forms can accept multiple URLs, 254 // TODO(erg): Technically, both of these forms can accept multiple URLs,
254 // but that doesn't match the assumptions of the rest of the system which 255 // but that doesn't match the assumptions of the rest of the system which
255 // expect single types. 256 // expect single types.
256 257
257 if (data.GetType() == atom_cache_.GetAtom(Clipboard::kMimeTypeMozillaURL)) { 258 if (data.GetType() == atom_cache_.GetAtom(kMimeTypeMozillaURL)) {
258 // Mozilla URLs are (UTF16: URL, newline, title). 259 // Mozilla URLs are (UTF16: URL, newline, title).
259 base::string16 unparsed; 260 base::string16 unparsed;
260 data.AssignTo(&unparsed); 261 data.AssignTo(&unparsed);
261 262
262 std::vector<base::string16> tokens = base::SplitString( 263 std::vector<base::string16> tokens = base::SplitString(
263 unparsed, base::ASCIIToUTF16("\n"), 264 unparsed, base::ASCIIToUTF16("\n"),
264 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 265 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
265 if (tokens.size() > 0) { 266 if (tokens.size() > 0) {
266 if (tokens.size() > 1) 267 if (tokens.size() > 1)
267 *title = tokens[1]; 268 *title = tokens[1];
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 std::vector< ::Atom> requested_types; 355 std::vector< ::Atom> requested_types;
355 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); 356 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types);
356 357
357 if (requested_types.empty()) 358 if (requested_types.empty())
358 return false; 359 return false;
359 360
360 // The Linux desktop doesn't differentiate between files and URLs like 361 // The Linux desktop doesn't differentiate between files and URLs like
361 // Windows does and stuffs all the data into one mime type. 362 // Windows does and stuffs all the data into one mime type.
362 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); 363 ui::SelectionData data(format_map_.GetFirstOf(requested_types));
363 if (data.IsValid()) { 364 if (data.IsValid()) {
364 if (data.GetType() == atom_cache_.GetAtom(Clipboard::kMimeTypeMozillaURL)) { 365 if (data.GetType() == atom_cache_.GetAtom(kMimeTypeMozillaURL)) {
365 // File managers shouldn't be using this type, so this is a URL. 366 // File managers shouldn't be using this type, so this is a URL.
366 return true; 367 return true;
367 } else if (data.GetType() == atom_cache_.GetAtom( 368 } else if (data.GetType() == atom_cache_.GetAtom(
368 ui::Clipboard::kMimeTypeURIList)) { 369 ui::Clipboard::kMimeTypeURIList)) {
369 std::vector<std::string> tokens = ui::ParseURIList(data); 370 std::vector<std::string> tokens = ui::ParseURIList(data);
370 for (std::vector<std::string>::const_iterator it = tokens.begin(); 371 for (std::vector<std::string>::const_iterator it = tokens.begin();
371 it != tokens.end(); ++it) { 372 it != tokens.end(); ++it) {
372 if (!GURL(*it).SchemeIsFile() || 373 if (!GURL(*it).SchemeIsFile() ||
373 policy == OSExchangeData::CONVERT_FILENAMES) 374 policy == OSExchangeData::CONVERT_FILENAMES)
374 return true; 375 return true;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); 416 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types);
416 417
417 return !requested_types.empty(); 418 return !requested_types.empty();
418 } 419 }
419 420
420 void OSExchangeDataProviderAuraX11::SetFileContents( 421 void OSExchangeDataProviderAuraX11::SetFileContents(
421 const base::FilePath& filename, 422 const base::FilePath& filename,
422 const std::string& file_contents) { 423 const std::string& file_contents) {
423 DCHECK(!filename.empty()); 424 DCHECK(!filename.empty());
424 DCHECK(format_map_.end() == 425 DCHECK(format_map_.end() ==
425 format_map_.find(atom_cache_.GetAtom(Clipboard::kMimeTypeMozillaURL))); 426 format_map_.find(atom_cache_.GetAtom(kMimeTypeMozillaURL)));
426 427
427 file_contents_name_ = filename; 428 file_contents_name_ = filename;
428 429
429 // Direct save handling is a complicated juggling affair between this class, 430 // Direct save handling is a complicated juggling affair between this class,
430 // SelectionFormat, and DesktopDragDropClientAuraX11. The general idea behind 431 // SelectionFormat, and DesktopDragDropClientAuraX11. The general idea behind
431 // the protocol is this: 432 // the protocol is this:
432 // - The source window sets its XdndDirectSave0 window property to the 433 // - The source window sets its XdndDirectSave0 window property to the
433 // proposed filename. 434 // proposed filename.
434 // - When a target window receives the drop, it updates the XdndDirectSave0 435 // - When a target window receives the drop, it updates the XdndDirectSave0
435 // property on the source window to the filename it would like the contents 436 // property on the source window to the filename it would like the contents
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 546
546 /////////////////////////////////////////////////////////////////////////////// 547 ///////////////////////////////////////////////////////////////////////////////
547 // OSExchangeData, public: 548 // OSExchangeData, public:
548 549
549 // static 550 // static
550 OSExchangeData::Provider* OSExchangeData::CreateProvider() { 551 OSExchangeData::Provider* OSExchangeData::CreateProvider() {
551 return new OSExchangeDataProviderAuraX11(); 552 return new OSExchangeDataProviderAuraX11();
552 } 553 }
553 554
554 } // namespace ui 555 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/custom_data_helper_mac.mm ('k') | ui/base/test/test_clipboard.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698