| 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" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); | 116 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); |
| 117 format_map_.Insert(atom_cache_.GetAtom(kText), mem); | 117 format_map_.Insert(atom_cache_.GetAtom(kText), mem); |
| 118 format_map_.Insert(atom_cache_.GetAtom(kString), mem); | 118 format_map_.Insert(atom_cache_.GetAtom(kString), mem); |
| 119 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); | 119 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, | 122 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, |
| 123 const base::string16& title) { | 123 const base::string16& title) { |
| 124 // Mozilla's URL format: (UTF16: URL, newline, title) | 124 // Mozilla's URL format: (UTF16: URL, newline, title) |
| 125 if (url.is_valid()) { | 125 if (url.is_valid()) { |
| 126 string16 spec = UTF8ToUTF16(url.spec()); | 126 base::string16 spec = UTF8ToUTF16(url.spec()); |
| 127 | 127 |
| 128 std::vector<unsigned char> data; | 128 std::vector<unsigned char> data; |
| 129 ui::AddString16ToVector(spec, &data); | 129 ui::AddString16ToVector(spec, &data); |
| 130 ui::AddString16ToVector(ASCIIToUTF16("\n"), &data); | 130 ui::AddString16ToVector(ASCIIToUTF16("\n"), &data); |
| 131 ui::AddString16ToVector(title, &data); | 131 ui::AddString16ToVector(title, &data); |
| 132 scoped_refptr<base::RefCountedMemory> mem( | 132 scoped_refptr<base::RefCountedMemory> mem( |
| 133 base::RefCountedBytes::TakeVector(&data)); | 133 base::RefCountedBytes::TakeVector(&data)); |
| 134 | 134 |
| 135 format_map_.Insert(atom_cache_.GetAtom(kMimeTypeMozillaURL), mem); | 135 format_map_.Insert(atom_cache_.GetAtom(kMimeTypeMozillaURL), mem); |
| 136 | 136 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // Mozilla URLs are (UTF16: URL, newline, title). | 193 // Mozilla URLs are (UTF16: URL, newline, title). |
| 194 base::string16 unparsed; | 194 base::string16 unparsed; |
| 195 data.AssignTo(&unparsed); | 195 data.AssignTo(&unparsed); |
| 196 | 196 |
| 197 std::vector<base::string16> tokens; | 197 std::vector<base::string16> tokens; |
| 198 size_t num_tokens = Tokenize(unparsed, ASCIIToUTF16("\n"), &tokens); | 198 size_t num_tokens = Tokenize(unparsed, ASCIIToUTF16("\n"), &tokens); |
| 199 if (num_tokens > 0) { | 199 if (num_tokens > 0) { |
| 200 if (num_tokens > 1) | 200 if (num_tokens > 1) |
| 201 *title = tokens[1]; | 201 *title = tokens[1]; |
| 202 else | 202 else |
| 203 *title = string16(); | 203 *title = base::string16(); |
| 204 | 204 |
| 205 *url = GURL(tokens[0]); | 205 *url = GURL(tokens[0]); |
| 206 return true; | 206 return true; |
| 207 } | 207 } |
| 208 } else if (data.GetType() == atom_cache_.GetAtom( | 208 } else if (data.GetType() == atom_cache_.GetAtom( |
| 209 Clipboard::kMimeTypeURIList)) { | 209 Clipboard::kMimeTypeURIList)) { |
| 210 // uri-lists are newline separated file lists in URL encoding. | 210 // uri-lists are newline separated file lists in URL encoding. |
| 211 std::string unparsed; | 211 std::string unparsed; |
| 212 data.AssignTo(&unparsed); | 212 data.AssignTo(&unparsed); |
| 213 | 213 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 selection_owner_.OnSelectionRequest(xev->xselectionrequest); | 348 selection_owner_.OnSelectionRequest(xev->xselectionrequest); |
| 349 break; | 349 break; |
| 350 default: | 350 default: |
| 351 NOTIMPLEMENTED(); | 351 NOTIMPLEMENTED(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 return true; | 354 return true; |
| 355 } | 355 } |
| 356 | 356 |
| 357 bool OSExchangeDataProviderAuraX11::GetPlainTextURL(GURL* url) const { | 357 bool OSExchangeDataProviderAuraX11::GetPlainTextURL(GURL* url) const { |
| 358 string16 text; | 358 base::string16 text; |
| 359 if (GetString(&text)) { | 359 if (GetString(&text)) { |
| 360 GURL test_url(text); | 360 GURL test_url(text); |
| 361 if (test_url.is_valid()) { | 361 if (test_url.is_valid()) { |
| 362 *url = test_url; | 362 *url = test_url; |
| 363 return true; | 363 return true; |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 return false; | 367 return false; |
| 368 } | 368 } |
| 369 | 369 |
| 370 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { | 370 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { |
| 371 return format_map_.GetTypes(); | 371 return format_map_.GetTypes(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 /////////////////////////////////////////////////////////////////////////////// | 374 /////////////////////////////////////////////////////////////////////////////// |
| 375 // OSExchangeData, public: | 375 // OSExchangeData, public: |
| 376 | 376 |
| 377 // static | 377 // static |
| 378 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 378 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 379 return new OSExchangeDataProviderAuraX11(); | 379 return new OSExchangeDataProviderAuraX11(); |
| 380 } | 380 } |
| 381 | 381 |
| 382 } // namespace ui | 382 } // namespace ui |
| OLD | NEW |