| 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/x/selection_utils.h" | 15 #include "ui/base/x/selection_utils.h" |
| 16 #include "ui/base/x/x11_util.h" | 16 #include "ui/base/x/x11_util.h" |
| 17 | 17 |
| 18 // Note: the GetBlah() methods are used immediately by the | 18 // Note: the GetBlah() methods are used immediately by the |
| 19 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a | 19 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a |
| 20 // little more discriminating and calls HasBlah() before trying to get the | 20 // little more discriminating and calls HasBlah() before trying to get the |
| 21 // information. | 21 // information. |
| 22 | 22 |
| 23 namespace ui { | 23 namespace ui { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kDndSelection[] = "XdndSelection"; | 27 const char kDndSelection[] = "XdndSelection"; |
| 28 const char kRendererTaint[] = "chromium/x-renderer-taint"; |
| 28 | 29 |
| 29 const char* kAtomsToCache[] = { | 30 const char* kAtomsToCache[] = { |
| 30 kString, | 31 kString, |
| 31 kText, | 32 kText, |
| 32 kUtf8String, | 33 kUtf8String, |
| 33 kDndSelection, | 34 kDndSelection, |
| 34 Clipboard::kMimeTypeURIList, | 35 Clipboard::kMimeTypeURIList, |
| 35 kMimeTypeMozillaURL, | 36 kMimeTypeMozillaURL, |
| 36 Clipboard::kMimeTypeText, | 37 Clipboard::kMimeTypeText, |
| 38 kRendererTaint, |
| 37 NULL | 39 NULL |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 } // namespace | 42 } // namespace |
| 41 | 43 |
| 42 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11( | 44 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11( |
| 43 ::Window x_window, | 45 ::Window x_window, |
| 44 const SelectionFormatMap& selection) | 46 const SelectionFormatMap& selection) |
| 45 : x_display_(gfx::GetXDisplay()), | 47 : x_display_(gfx::GetXDisplay()), |
| 46 x_root_window_(DefaultRootWindow(x_display_)), | 48 x_root_window_(DefaultRootWindow(x_display_)), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // ours has been modified since TakeOwnershipOfSelection() was called. | 103 // ours has been modified since TakeOwnershipOfSelection() was called. |
| 102 return selection_owner_.selection_format_map(); | 104 return selection_owner_.selection_format_map(); |
| 103 } | 105 } |
| 104 | 106 |
| 105 OSExchangeData::Provider* OSExchangeDataProviderAuraX11::Clone() const { | 107 OSExchangeData::Provider* OSExchangeDataProviderAuraX11::Clone() const { |
| 106 OSExchangeDataProviderAuraX11* ret = new OSExchangeDataProviderAuraX11(); | 108 OSExchangeDataProviderAuraX11* ret = new OSExchangeDataProviderAuraX11(); |
| 107 ret->format_map_ = format_map_; | 109 ret->format_map_ = format_map_; |
| 108 return ret; | 110 return ret; |
| 109 } | 111 } |
| 110 | 112 |
| 113 void OSExchangeDataProviderAuraX11::MarkOriginatedFromRenderer() { |
| 114 std::string empty; |
| 115 format_map_.Insert(atom_cache_.GetAtom(kRendererTaint), |
| 116 scoped_refptr<base::RefCountedMemory>( |
| 117 base::RefCountedString::TakeString(&empty))); |
| 118 } |
| 119 |
| 120 bool OSExchangeDataProviderAuraX11::DidOriginateFromRenderer() const { |
| 121 return format_map_.find(atom_cache_.GetAtom(kRendererTaint)) != |
| 122 format_map_.end(); |
| 123 } |
| 124 |
| 111 void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) { | 125 void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) { |
| 112 std::string utf8 = base::UTF16ToUTF8(text_data); | 126 std::string utf8 = base::UTF16ToUTF8(text_data); |
| 113 scoped_refptr<base::RefCountedMemory> mem( | 127 scoped_refptr<base::RefCountedMemory> mem( |
| 114 base::RefCountedString::TakeString(&utf8)); | 128 base::RefCountedString::TakeString(&utf8)); |
| 115 | 129 |
| 116 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); | 130 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeText), mem); |
| 117 format_map_.Insert(atom_cache_.GetAtom(kText), mem); | 131 format_map_.Insert(atom_cache_.GetAtom(kText), mem); |
| 118 format_map_.Insert(atom_cache_.GetAtom(kString), mem); | 132 format_map_.Insert(atom_cache_.GetAtom(kString), mem); |
| 119 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); | 133 format_map_.Insert(atom_cache_.GetAtom(kUtf8String), mem); |
| 120 } | 134 } |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 473 |
| 460 /////////////////////////////////////////////////////////////////////////////// | 474 /////////////////////////////////////////////////////////////////////////////// |
| 461 // OSExchangeData, public: | 475 // OSExchangeData, public: |
| 462 | 476 |
| 463 // static | 477 // static |
| 464 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 478 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 465 return new OSExchangeDataProviderAuraX11(); | 479 return new OSExchangeDataProviderAuraX11(); |
| 466 } | 480 } |
| 467 | 481 |
| 468 } // namespace ui | 482 } // namespace ui |
| OLD | NEW |