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

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

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