| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
| 11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "net/base/filename_util.h" | 14 #include "net/base/filename_util.h" |
| 15 #include "ui/base/clipboard/clipboard.h" | 15 #include "ui/base/clipboard/clipboard.h" |
| 16 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 16 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 17 #include "ui/base/dragdrop/file_info.h" | 17 #include "ui/base/dragdrop/file_info.h" |
| 18 #include "ui/base/x/selection_utils.h" | 18 #include "ui/base/x/selection_utils.h" |
| 19 #include "ui/base/x/x11_util.h" | |
| 20 #include "ui/events/platform/platform_event_source.h" | 19 #include "ui/events/platform/platform_event_source.h" |
| 20 #include "ui/gfx/x/x11_atom_cache.h" |
| 21 | 21 |
| 22 // Note: the GetBlah() methods are used immediately by the | 22 // Note: the GetBlah() methods are used immediately by the |
| 23 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a | 23 // web_contents_view_aura.cc:PrepareDropData(), while the omnibox is a |
| 24 // little more discriminating and calls HasBlah() before trying to get the | 24 // little more discriminating and calls HasBlah() before trying to get the |
| 25 // information. | 25 // information. |
| 26 | 26 |
| 27 namespace ui { | 27 namespace ui { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kDndSelection[] = "XdndSelection"; | 31 const char kDndSelection[] = "XdndSelection"; |
| 32 const char kRendererTaint[] = "chromium/x-renderer-taint"; | 32 const char kRendererTaint[] = "chromium/x-renderer-taint"; |
| 33 | 33 |
| 34 const char kNetscapeURL[] = "_NETSCAPE_URL"; | 34 const char kNetscapeURL[] = "_NETSCAPE_URL"; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11( | 38 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11( |
| 39 ::Window x_window, | 39 ::Window x_window, |
| 40 const SelectionFormatMap& selection) | 40 const SelectionFormatMap& selection) |
| 41 : x_display_(gfx::GetXDisplay()), | 41 : x_display_(gfx::GetXDisplay()), |
| 42 x_root_window_(DefaultRootWindow(x_display_)), | 42 x_root_window_(DefaultRootWindow(x_display_)), |
| 43 own_window_(false), | 43 own_window_(false), |
| 44 x_window_(x_window), | 44 x_window_(x_window), |
| 45 format_map_(selection), | 45 format_map_(selection), |
| 46 selection_owner_(x_display_, x_window_, GetAtom(kDndSelection)) {} | 46 selection_owner_(x_display_, x_window_, gfx::GetAtom(kDndSelection)) {} |
| 47 | 47 |
| 48 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11() | 48 OSExchangeDataProviderAuraX11::OSExchangeDataProviderAuraX11() |
| 49 : x_display_(gfx::GetXDisplay()), | 49 : x_display_(gfx::GetXDisplay()), |
| 50 x_root_window_(DefaultRootWindow(x_display_)), | 50 x_root_window_(DefaultRootWindow(x_display_)), |
| 51 own_window_(true), | 51 own_window_(true), |
| 52 x_window_(XCreateWindow(x_display_, | 52 x_window_(XCreateWindow(x_display_, |
| 53 x_root_window_, | 53 x_root_window_, |
| 54 -100, | 54 -100, |
| 55 -100, | 55 -100, |
| 56 10, | 56 10, |
| 57 10, // x, y, width, height | 57 10, // x, y, width, height |
| 58 0, // border width | 58 0, // border width |
| 59 CopyFromParent, // depth | 59 CopyFromParent, // depth |
| 60 InputOnly, | 60 InputOnly, |
| 61 CopyFromParent, // visual | 61 CopyFromParent, // visual |
| 62 0, | 62 0, |
| 63 NULL)), | 63 NULL)), |
| 64 format_map_(), | 64 format_map_(), |
| 65 selection_owner_(x_display_, x_window_, GetAtom(kDndSelection)) { | 65 selection_owner_(x_display_, x_window_, gfx::GetAtom(kDndSelection)) { |
| 66 XStoreName(x_display_, x_window_, "Chromium Drag & Drop Window"); | 66 XStoreName(x_display_, x_window_, "Chromium Drag & Drop Window"); |
| 67 | 67 |
| 68 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | 68 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 OSExchangeDataProviderAuraX11::~OSExchangeDataProviderAuraX11() { | 71 OSExchangeDataProviderAuraX11::~OSExchangeDataProviderAuraX11() { |
| 72 if (own_window_) { | 72 if (own_window_) { |
| 73 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 73 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
| 74 XDestroyWindow(x_display_, x_window_); | 74 XDestroyWindow(x_display_, x_window_); |
| 75 } | 75 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 93 std::unique_ptr<OSExchangeData::Provider> | 93 std::unique_ptr<OSExchangeData::Provider> |
| 94 OSExchangeDataProviderAuraX11::Clone() const { | 94 OSExchangeDataProviderAuraX11::Clone() const { |
| 95 std::unique_ptr<OSExchangeDataProviderAuraX11> ret( | 95 std::unique_ptr<OSExchangeDataProviderAuraX11> ret( |
| 96 new OSExchangeDataProviderAuraX11()); | 96 new OSExchangeDataProviderAuraX11()); |
| 97 ret->format_map_ = format_map_; | 97 ret->format_map_ = format_map_; |
| 98 return std::move(ret); | 98 return std::move(ret); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void OSExchangeDataProviderAuraX11::MarkOriginatedFromRenderer() { | 101 void OSExchangeDataProviderAuraX11::MarkOriginatedFromRenderer() { |
| 102 std::string empty; | 102 std::string empty; |
| 103 format_map_.Insert(GetAtom(kRendererTaint), | 103 format_map_.Insert(gfx::GetAtom(kRendererTaint), |
| 104 scoped_refptr<base::RefCountedMemory>( | 104 scoped_refptr<base::RefCountedMemory>( |
| 105 base::RefCountedString::TakeString(&empty))); | 105 base::RefCountedString::TakeString(&empty))); |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool OSExchangeDataProviderAuraX11::DidOriginateFromRenderer() const { | 108 bool OSExchangeDataProviderAuraX11::DidOriginateFromRenderer() const { |
| 109 return format_map_.find(GetAtom(kRendererTaint)) != format_map_.end(); | 109 return format_map_.find(gfx::GetAtom(kRendererTaint)) != format_map_.end(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) { | 112 void OSExchangeDataProviderAuraX11::SetString(const base::string16& text_data) { |
| 113 if (HasString()) | 113 if (HasString()) |
| 114 return; | 114 return; |
| 115 | 115 |
| 116 std::string utf8 = base::UTF16ToUTF8(text_data); | 116 std::string utf8 = base::UTF16ToUTF8(text_data); |
| 117 scoped_refptr<base::RefCountedMemory> mem( | 117 scoped_refptr<base::RefCountedMemory> mem( |
| 118 base::RefCountedString::TakeString(&utf8)); | 118 base::RefCountedString::TakeString(&utf8)); |
| 119 | 119 |
| 120 format_map_.Insert(GetAtom(Clipboard::kMimeTypeText), mem); | 120 format_map_.Insert(gfx::GetAtom(Clipboard::kMimeTypeText), mem); |
| 121 format_map_.Insert(GetAtom(kText), mem); | 121 format_map_.Insert(gfx::GetAtom(kText), mem); |
| 122 format_map_.Insert(GetAtom(kString), mem); | 122 format_map_.Insert(gfx::GetAtom(kString), mem); |
| 123 format_map_.Insert(GetAtom(kUtf8String), mem); | 123 format_map_.Insert(gfx::GetAtom(kUtf8String), mem); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, | 126 void OSExchangeDataProviderAuraX11::SetURL(const GURL& url, |
| 127 const base::string16& title) { | 127 const base::string16& title) { |
| 128 // TODO(dcheng): The original GTK code tries very hard to avoid writing out an | 128 // TODO(dcheng): The original GTK code tries very hard to avoid writing out an |
| 129 // empty title. Is this necessary? | 129 // empty title. Is this necessary? |
| 130 if (url.is_valid()) { | 130 if (url.is_valid()) { |
| 131 // Mozilla's URL format: (UTF16: URL, newline, title) | 131 // Mozilla's URL format: (UTF16: URL, newline, title) |
| 132 base::string16 spec = base::UTF8ToUTF16(url.spec()); | 132 base::string16 spec = base::UTF8ToUTF16(url.spec()); |
| 133 | 133 |
| 134 std::vector<unsigned char> data; | 134 std::vector<unsigned char> data; |
| 135 ui::AddString16ToVector(spec, &data); | 135 ui::AddString16ToVector(spec, &data); |
| 136 ui::AddString16ToVector(base::ASCIIToUTF16("\n"), &data); | 136 ui::AddString16ToVector(base::ASCIIToUTF16("\n"), &data); |
| 137 ui::AddString16ToVector(title, &data); | 137 ui::AddString16ToVector(title, &data); |
| 138 scoped_refptr<base::RefCountedMemory> mem( | 138 scoped_refptr<base::RefCountedMemory> mem( |
| 139 base::RefCountedBytes::TakeVector(&data)); | 139 base::RefCountedBytes::TakeVector(&data)); |
| 140 | 140 |
| 141 format_map_.Insert(GetAtom(Clipboard::kMimeTypeMozillaURL), mem); | 141 format_map_.Insert(gfx::GetAtom(Clipboard::kMimeTypeMozillaURL), mem); |
| 142 | 142 |
| 143 // Set a string fallback as well. | 143 // Set a string fallback as well. |
| 144 SetString(spec); | 144 SetString(spec); |
| 145 | 145 |
| 146 // Return early if this drag already contains file contents (this implies | 146 // Return early if this drag already contains file contents (this implies |
| 147 // that file contents must be populated before URLs). Nautilus (and possibly | 147 // that file contents must be populated before URLs). Nautilus (and possibly |
| 148 // other file managers) prefer _NETSCAPE_URL over the X Direct Save | 148 // other file managers) prefer _NETSCAPE_URL over the X Direct Save |
| 149 // protocol, but we want to prioritize XDS in this case. | 149 // protocol, but we want to prioritize XDS in this case. |
| 150 if (!file_contents_name_.empty()) | 150 if (!file_contents_name_.empty()) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 // Set _NETSCAPE_URL for file managers like Nautilus that use it as a hint | 153 // Set _NETSCAPE_URL for file managers like Nautilus that use it as a hint |
| 154 // to create a link to the URL. Setting text/uri-list doesn't work because | 154 // to create a link to the URL. Setting text/uri-list doesn't work because |
| 155 // Nautilus will fetch and copy the contents of the URL to the drop target | 155 // Nautilus will fetch and copy the contents of the URL to the drop target |
| 156 // instead of linking... | 156 // instead of linking... |
| 157 // Format is UTF8: URL + "\n" + title. | 157 // Format is UTF8: URL + "\n" + title. |
| 158 std::string netscape_url = url.spec(); | 158 std::string netscape_url = url.spec(); |
| 159 netscape_url += "\n"; | 159 netscape_url += "\n"; |
| 160 netscape_url += base::UTF16ToUTF8(title); | 160 netscape_url += base::UTF16ToUTF8(title); |
| 161 format_map_.Insert(GetAtom(kNetscapeURL), | 161 format_map_.Insert(gfx::GetAtom(kNetscapeURL), |
| 162 scoped_refptr<base::RefCountedMemory>( | 162 scoped_refptr<base::RefCountedMemory>( |
| 163 base::RefCountedString::TakeString(&netscape_url))); | 163 base::RefCountedString::TakeString(&netscape_url))); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { | 167 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { |
| 168 std::vector<FileInfo> data; | 168 std::vector<FileInfo> data; |
| 169 data.push_back(FileInfo(path, base::FilePath())); | 169 data.push_back(FileInfo(path, base::FilePath())); |
| 170 SetFilenames(data); | 170 SetFilenames(data); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void OSExchangeDataProviderAuraX11::SetFilenames( | 173 void OSExchangeDataProviderAuraX11::SetFilenames( |
| 174 const std::vector<FileInfo>& filenames) { | 174 const std::vector<FileInfo>& filenames) { |
| 175 std::vector<std::string> paths; | 175 std::vector<std::string> paths; |
| 176 for (std::vector<FileInfo>::const_iterator it = filenames.begin(); | 176 for (std::vector<FileInfo>::const_iterator it = filenames.begin(); |
| 177 it != filenames.end(); | 177 it != filenames.end(); |
| 178 ++it) { | 178 ++it) { |
| 179 std::string url_spec = net::FilePathToFileURL(it->path).spec(); | 179 std::string url_spec = net::FilePathToFileURL(it->path).spec(); |
| 180 if (!url_spec.empty()) | 180 if (!url_spec.empty()) |
| 181 paths.push_back(url_spec); | 181 paths.push_back(url_spec); |
| 182 } | 182 } |
| 183 | 183 |
| 184 std::string joined_data = base::JoinString(paths, "\n"); | 184 std::string joined_data = base::JoinString(paths, "\n"); |
| 185 scoped_refptr<base::RefCountedMemory> mem( | 185 scoped_refptr<base::RefCountedMemory> mem( |
| 186 base::RefCountedString::TakeString(&joined_data)); | 186 base::RefCountedString::TakeString(&joined_data)); |
| 187 format_map_.Insert(GetAtom(Clipboard::kMimeTypeURIList), mem); | 187 format_map_.Insert(gfx::GetAtom(Clipboard::kMimeTypeURIList), mem); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void OSExchangeDataProviderAuraX11::SetPickledData( | 190 void OSExchangeDataProviderAuraX11::SetPickledData( |
| 191 const Clipboard::FormatType& format, | 191 const Clipboard::FormatType& format, |
| 192 const base::Pickle& pickle) { | 192 const base::Pickle& pickle) { |
| 193 const unsigned char* data = | 193 const unsigned char* data = |
| 194 reinterpret_cast<const unsigned char*>(pickle.data()); | 194 reinterpret_cast<const unsigned char*>(pickle.data()); |
| 195 | 195 |
| 196 std::vector<unsigned char> bytes; | 196 std::vector<unsigned char> bytes; |
| 197 bytes.insert(bytes.end(), data, data + pickle.size()); | 197 bytes.insert(bytes.end(), data, data + pickle.size()); |
| 198 scoped_refptr<base::RefCountedMemory> mem( | 198 scoped_refptr<base::RefCountedMemory> mem( |
| 199 base::RefCountedBytes::TakeVector(&bytes)); | 199 base::RefCountedBytes::TakeVector(&bytes)); |
| 200 | 200 |
| 201 format_map_.Insert(GetAtom(format.ToString().c_str()), mem); | 201 format_map_.Insert(gfx::GetAtom(format.ToString().c_str()), mem); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool OSExchangeDataProviderAuraX11::GetString(base::string16* result) const { | 204 bool OSExchangeDataProviderAuraX11::GetString(base::string16* result) const { |
| 205 if (HasFile()) { | 205 if (HasFile()) { |
| 206 // Various Linux file managers both pass a list of file:// URIs and set the | 206 // Various Linux file managers both pass a list of file:// URIs and set the |
| 207 // string representation to the URI. We explicitly don't want to return use | 207 // string representation to the URI. We explicitly don't want to return use |
| 208 // this representation. | 208 // this representation. |
| 209 return false; | 209 return false; |
| 210 } | 210 } |
| 211 | 211 |
| 212 std::vector<::Atom> text_atoms = ui::GetTextAtomsFrom(); | 212 std::vector<::Atom> text_atoms = ui::GetTextAtomsFrom(); |
| 213 std::vector< ::Atom> requested_types; | 213 std::vector< ::Atom> requested_types; |
| 214 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); | 214 GetAtomIntersection(text_atoms, GetTargets(), &requested_types); |
| 215 | 215 |
| 216 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 216 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 217 if (data.IsValid()) { | 217 if (data.IsValid()) { |
| 218 std::string text = data.GetText(); | 218 std::string text = data.GetText(); |
| 219 *result = base::UTF8ToUTF16(text); | 219 *result = base::UTF8ToUTF16(text); |
| 220 return true; | 220 return true; |
| 221 } | 221 } |
| 222 | 222 |
| 223 return false; | 223 return false; |
| 224 } | 224 } |
| 225 | 225 |
| 226 bool OSExchangeDataProviderAuraX11::GetURLAndTitle( | 226 bool OSExchangeDataProviderAuraX11::GetURLAndTitle( |
| 227 OSExchangeData::FilenameToURLPolicy policy, | 227 OSExchangeData::FilenameToURLPolicy policy, |
| 228 GURL* url, | 228 GURL* url, |
| 229 base::string16* title) const { | 229 base::string16* title) const { |
| 230 std::vector<::Atom> url_atoms = ui::GetURLAtomsFrom(); | 230 std::vector<::Atom> url_atoms = ui::GetURLAtomsFrom(); |
| 231 std::vector< ::Atom> requested_types; | 231 std::vector< ::Atom> requested_types; |
| 232 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 232 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 233 | 233 |
| 234 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 234 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 235 if (data.IsValid()) { | 235 if (data.IsValid()) { |
| 236 // TODO(erg): Technically, both of these forms can accept multiple URLs, | 236 // TODO(erg): Technically, both of these forms can accept multiple URLs, |
| 237 // but that doesn't match the assumptions of the rest of the system which | 237 // but that doesn't match the assumptions of the rest of the system which |
| 238 // expect single types. | 238 // expect single types. |
| 239 | 239 |
| 240 if (data.GetType() == GetAtom(Clipboard::kMimeTypeMozillaURL)) { | 240 if (data.GetType() == gfx::GetAtom(Clipboard::kMimeTypeMozillaURL)) { |
| 241 // Mozilla URLs are (UTF16: URL, newline, title). | 241 // Mozilla URLs are (UTF16: URL, newline, title). |
| 242 base::string16 unparsed; | 242 base::string16 unparsed; |
| 243 data.AssignTo(&unparsed); | 243 data.AssignTo(&unparsed); |
| 244 | 244 |
| 245 std::vector<base::string16> tokens = base::SplitString( | 245 std::vector<base::string16> tokens = base::SplitString( |
| 246 unparsed, base::ASCIIToUTF16("\n"), | 246 unparsed, base::ASCIIToUTF16("\n"), |
| 247 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 247 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 248 if (tokens.size() > 0) { | 248 if (tokens.size() > 0) { |
| 249 if (tokens.size() > 1) | 249 if (tokens.size() > 1) |
| 250 *title = tokens[1]; | 250 *title = tokens[1]; |
| 251 else | 251 else |
| 252 *title = base::string16(); | 252 *title = base::string16(); |
| 253 | 253 |
| 254 *url = GURL(tokens[0]); | 254 *url = GURL(tokens[0]); |
| 255 return true; | 255 return true; |
| 256 } | 256 } |
| 257 } else if (data.GetType() == GetAtom(Clipboard::kMimeTypeURIList)) { | 257 } else if (data.GetType() == gfx::GetAtom(Clipboard::kMimeTypeURIList)) { |
| 258 std::vector<std::string> tokens = ui::ParseURIList(data); | 258 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 259 for (std::vector<std::string>::const_iterator it = tokens.begin(); | 259 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 260 it != tokens.end(); ++it) { | 260 it != tokens.end(); ++it) { |
| 261 GURL test_url(*it); | 261 GURL test_url(*it); |
| 262 if (!test_url.SchemeIsFile() || | 262 if (!test_url.SchemeIsFile() || |
| 263 policy == OSExchangeData::CONVERT_FILENAMES) { | 263 policy == OSExchangeData::CONVERT_FILENAMES) { |
| 264 *url = test_url; | 264 *url = test_url; |
| 265 *title = base::string16(); | 265 *title = base::string16(); |
| 266 return true; | 266 return true; |
| 267 } | 267 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 279 return true; | 279 return true; |
| 280 } | 280 } |
| 281 | 281 |
| 282 return false; | 282 return false; |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool OSExchangeDataProviderAuraX11::GetFilenames( | 285 bool OSExchangeDataProviderAuraX11::GetFilenames( |
| 286 std::vector<FileInfo>* filenames) const { | 286 std::vector<FileInfo>* filenames) const { |
| 287 std::vector<::Atom> url_atoms = ui::GetURIListAtomsFrom(); | 287 std::vector<::Atom> url_atoms = ui::GetURIListAtomsFrom(); |
| 288 std::vector< ::Atom> requested_types; | 288 std::vector< ::Atom> requested_types; |
| 289 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 289 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 290 | 290 |
| 291 filenames->clear(); | 291 filenames->clear(); |
| 292 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 292 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 293 if (data.IsValid()) { | 293 if (data.IsValid()) { |
| 294 std::vector<std::string> tokens = ui::ParseURIList(data); | 294 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 295 for (std::vector<std::string>::const_iterator it = tokens.begin(); | 295 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 296 it != tokens.end(); ++it) { | 296 it != tokens.end(); ++it) { |
| 297 GURL url(*it); | 297 GURL url(*it); |
| 298 base::FilePath file_path; | 298 base::FilePath file_path; |
| 299 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) { | 299 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) { |
| 300 filenames->push_back(FileInfo(file_path, base::FilePath())); | 300 filenames->push_back(FileInfo(file_path, base::FilePath())); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 return !filenames->empty(); | 305 return !filenames->empty(); |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool OSExchangeDataProviderAuraX11::GetPickledData( | 308 bool OSExchangeDataProviderAuraX11::GetPickledData( |
| 309 const Clipboard::FormatType& format, | 309 const Clipboard::FormatType& format, |
| 310 base::Pickle* pickle) const { | 310 base::Pickle* pickle) const { |
| 311 std::vector< ::Atom> requested_types; | 311 std::vector< ::Atom> requested_types; |
| 312 requested_types.push_back(GetAtom(format.ToString().c_str())); | 312 requested_types.push_back(gfx::GetAtom(format.ToString().c_str())); |
| 313 | 313 |
| 314 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 314 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 315 if (data.IsValid()) { | 315 if (data.IsValid()) { |
| 316 // Note that the pickle object on the right hand side of the assignment | 316 // Note that the pickle object on the right hand side of the assignment |
| 317 // only refers to the bytes in |data|. The assignment copies the data. | 317 // only refers to the bytes in |data|. The assignment copies the data. |
| 318 *pickle = base::Pickle(reinterpret_cast<const char*>(data.GetData()), | 318 *pickle = base::Pickle(reinterpret_cast<const char*>(data.GetData()), |
| 319 static_cast<int>(data.GetSize())); | 319 static_cast<int>(data.GetSize())); |
| 320 return true; | 320 return true; |
| 321 } | 321 } |
| 322 | 322 |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool OSExchangeDataProviderAuraX11::HasString() const { | 326 bool OSExchangeDataProviderAuraX11::HasString() const { |
| 327 std::vector<::Atom> text_atoms = ui::GetTextAtomsFrom(); | 327 std::vector<::Atom> text_atoms = ui::GetTextAtomsFrom(); |
| 328 std::vector< ::Atom> requested_types; | 328 std::vector< ::Atom> requested_types; |
| 329 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); | 329 GetAtomIntersection(text_atoms, GetTargets(), &requested_types); |
| 330 return !requested_types.empty() && !HasFile(); | 330 return !requested_types.empty() && !HasFile(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 bool OSExchangeDataProviderAuraX11::HasURL( | 333 bool OSExchangeDataProviderAuraX11::HasURL( |
| 334 OSExchangeData::FilenameToURLPolicy policy) const { | 334 OSExchangeData::FilenameToURLPolicy policy) const { |
| 335 std::vector<::Atom> url_atoms = ui::GetURLAtomsFrom(); | 335 std::vector<::Atom> url_atoms = ui::GetURLAtomsFrom(); |
| 336 std::vector< ::Atom> requested_types; | 336 std::vector< ::Atom> requested_types; |
| 337 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 337 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 338 | 338 |
| 339 if (requested_types.empty()) | 339 if (requested_types.empty()) |
| 340 return false; | 340 return false; |
| 341 | 341 |
| 342 // The Linux desktop doesn't differentiate between files and URLs like | 342 // The Linux desktop doesn't differentiate between files and URLs like |
| 343 // Windows does and stuffs all the data into one mime type. | 343 // Windows does and stuffs all the data into one mime type. |
| 344 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 344 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 345 if (data.IsValid()) { | 345 if (data.IsValid()) { |
| 346 if (data.GetType() == GetAtom(Clipboard::kMimeTypeMozillaURL)) { | 346 if (data.GetType() == gfx::GetAtom(Clipboard::kMimeTypeMozillaURL)) { |
| 347 // File managers shouldn't be using this type, so this is a URL. | 347 // File managers shouldn't be using this type, so this is a URL. |
| 348 return true; | 348 return true; |
| 349 } else if (data.GetType() == GetAtom(ui::Clipboard::kMimeTypeURIList)) { | 349 } else if (data.GetType() == |
| 350 gfx::GetAtom(ui::Clipboard::kMimeTypeURIList)) { |
| 350 std::vector<std::string> tokens = ui::ParseURIList(data); | 351 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 351 for (std::vector<std::string>::const_iterator it = tokens.begin(); | 352 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 352 it != tokens.end(); ++it) { | 353 it != tokens.end(); ++it) { |
| 353 if (!GURL(*it).SchemeIsFile() || | 354 if (!GURL(*it).SchemeIsFile() || |
| 354 policy == OSExchangeData::CONVERT_FILENAMES) | 355 policy == OSExchangeData::CONVERT_FILENAMES) |
| 355 return true; | 356 return true; |
| 356 } | 357 } |
| 357 | 358 |
| 358 return false; | 359 return false; |
| 359 } | 360 } |
| 360 } | 361 } |
| 361 | 362 |
| 362 return false; | 363 return false; |
| 363 } | 364 } |
| 364 | 365 |
| 365 bool OSExchangeDataProviderAuraX11::HasFile() const { | 366 bool OSExchangeDataProviderAuraX11::HasFile() const { |
| 366 std::vector<::Atom> url_atoms = ui::GetURIListAtomsFrom(); | 367 std::vector<::Atom> url_atoms = ui::GetURIListAtomsFrom(); |
| 367 std::vector< ::Atom> requested_types; | 368 std::vector< ::Atom> requested_types; |
| 368 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 369 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 369 | 370 |
| 370 if (requested_types.empty()) | 371 if (requested_types.empty()) |
| 371 return false; | 372 return false; |
| 372 | 373 |
| 373 // To actually answer whether we have a file, we need to look through the | 374 // To actually answer whether we have a file, we need to look through the |
| 374 // contents of the kMimeTypeURIList type, and see if any of them are file:// | 375 // contents of the kMimeTypeURIList type, and see if any of them are file:// |
| 375 // URIs. | 376 // URIs. |
| 376 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 377 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 377 if (data.IsValid()) { | 378 if (data.IsValid()) { |
| 378 std::vector<std::string> tokens = ui::ParseURIList(data); | 379 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 379 for (std::vector<std::string>::const_iterator it = tokens.begin(); | 380 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 380 it != tokens.end(); ++it) { | 381 it != tokens.end(); ++it) { |
| 381 GURL url(*it); | 382 GURL url(*it); |
| 382 base::FilePath file_path; | 383 base::FilePath file_path; |
| 383 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) | 384 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) |
| 384 return true; | 385 return true; |
| 385 } | 386 } |
| 386 } | 387 } |
| 387 | 388 |
| 388 return false; | 389 return false; |
| 389 } | 390 } |
| 390 | 391 |
| 391 bool OSExchangeDataProviderAuraX11::HasCustomFormat( | 392 bool OSExchangeDataProviderAuraX11::HasCustomFormat( |
| 392 const Clipboard::FormatType& format) const { | 393 const Clipboard::FormatType& format) const { |
| 393 std::vector< ::Atom> url_atoms; | 394 std::vector< ::Atom> url_atoms; |
| 394 url_atoms.push_back(GetAtom(format.ToString().c_str())); | 395 url_atoms.push_back(gfx::GetAtom(format.ToString().c_str())); |
| 395 std::vector< ::Atom> requested_types; | 396 std::vector< ::Atom> requested_types; |
| 396 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 397 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 397 | 398 |
| 398 return !requested_types.empty(); | 399 return !requested_types.empty(); |
| 399 } | 400 } |
| 400 | 401 |
| 401 void OSExchangeDataProviderAuraX11::SetFileContents( | 402 void OSExchangeDataProviderAuraX11::SetFileContents( |
| 402 const base::FilePath& filename, | 403 const base::FilePath& filename, |
| 403 const std::string& file_contents) { | 404 const std::string& file_contents) { |
| 404 DCHECK(!filename.empty()); | 405 DCHECK(!filename.empty()); |
| 405 DCHECK(format_map_.end() == | 406 DCHECK(format_map_.end() == |
| 406 format_map_.find(GetAtom(Clipboard::kMimeTypeMozillaURL))); | 407 format_map_.find(gfx::GetAtom(Clipboard::kMimeTypeMozillaURL))); |
| 407 | 408 |
| 408 file_contents_name_ = filename; | 409 file_contents_name_ = filename; |
| 409 | 410 |
| 410 // Direct save handling is a complicated juggling affair between this class, | 411 // Direct save handling is a complicated juggling affair between this class, |
| 411 // SelectionFormat, and DesktopDragDropClientAuraX11. The general idea behind | 412 // SelectionFormat, and DesktopDragDropClientAuraX11. The general idea behind |
| 412 // the protocol is this: | 413 // the protocol is this: |
| 413 // - The source window sets its XdndDirectSave0 window property to the | 414 // - The source window sets its XdndDirectSave0 window property to the |
| 414 // proposed filename. | 415 // proposed filename. |
| 415 // - When a target window receives the drop, it updates the XdndDirectSave0 | 416 // - When a target window receives the drop, it updates the XdndDirectSave0 |
| 416 // property on the source window to the filename it would like the contents | 417 // property on the source window to the filename it would like the contents |
| 417 // to be saved to and then requests the XdndDirectSave0 type from the | 418 // to be saved to and then requests the XdndDirectSave0 type from the |
| 418 // source. | 419 // source. |
| 419 // - The source is supposed to copy the file here and return success (S), | 420 // - The source is supposed to copy the file here and return success (S), |
| 420 // failure (F), or error (E). | 421 // failure (F), or error (E). |
| 421 // - In this case, failure means the destination should try to populate the | 422 // - In this case, failure means the destination should try to populate the |
| 422 // file itself by copying the data from application/octet-stream. To make | 423 // file itself by copying the data from application/octet-stream. To make |
| 423 // things simpler for Chrome, we always 'fail' and let the destination do | 424 // things simpler for Chrome, we always 'fail' and let the destination do |
| 424 // the work. | 425 // the work. |
| 425 std::string failure("F"); | 426 std::string failure("F"); |
| 426 format_map_.Insert(GetAtom("XdndDirectSave0"), | 427 format_map_.Insert(gfx::GetAtom("XdndDirectSave0"), |
| 427 scoped_refptr<base::RefCountedMemory>( | 428 scoped_refptr<base::RefCountedMemory>( |
| 428 base::RefCountedString::TakeString(&failure))); | 429 base::RefCountedString::TakeString(&failure))); |
| 429 std::string file_contents_copy = file_contents; | 430 std::string file_contents_copy = file_contents; |
| 430 format_map_.Insert( | 431 format_map_.Insert( |
| 431 GetAtom("application/octet-stream"), | 432 gfx::GetAtom("application/octet-stream"), |
| 432 scoped_refptr<base::RefCountedMemory>( | 433 scoped_refptr<base::RefCountedMemory>( |
| 433 base::RefCountedString::TakeString(&file_contents_copy))); | 434 base::RefCountedString::TakeString(&file_contents_copy))); |
| 434 } | 435 } |
| 435 | 436 |
| 436 void OSExchangeDataProviderAuraX11::SetHtml(const base::string16& html, | 437 void OSExchangeDataProviderAuraX11::SetHtml(const base::string16& html, |
| 437 const GURL& base_url) { | 438 const GURL& base_url) { |
| 438 std::vector<unsigned char> bytes; | 439 std::vector<unsigned char> bytes; |
| 439 // Manually jam a UTF16 BOM into bytes because otherwise, other programs will | 440 // Manually jam a UTF16 BOM into bytes because otherwise, other programs will |
| 440 // assume UTF-8. | 441 // assume UTF-8. |
| 441 bytes.push_back(0xFF); | 442 bytes.push_back(0xFF); |
| 442 bytes.push_back(0xFE); | 443 bytes.push_back(0xFE); |
| 443 ui::AddString16ToVector(html, &bytes); | 444 ui::AddString16ToVector(html, &bytes); |
| 444 scoped_refptr<base::RefCountedMemory> mem( | 445 scoped_refptr<base::RefCountedMemory> mem( |
| 445 base::RefCountedBytes::TakeVector(&bytes)); | 446 base::RefCountedBytes::TakeVector(&bytes)); |
| 446 | 447 |
| 447 format_map_.Insert(GetAtom(Clipboard::kMimeTypeHTML), mem); | 448 format_map_.Insert(gfx::GetAtom(Clipboard::kMimeTypeHTML), mem); |
| 448 } | 449 } |
| 449 | 450 |
| 450 bool OSExchangeDataProviderAuraX11::GetHtml(base::string16* html, | 451 bool OSExchangeDataProviderAuraX11::GetHtml(base::string16* html, |
| 451 GURL* base_url) const { | 452 GURL* base_url) const { |
| 452 std::vector< ::Atom> url_atoms; | 453 std::vector< ::Atom> url_atoms; |
| 453 url_atoms.push_back(GetAtom(Clipboard::kMimeTypeHTML)); | 454 url_atoms.push_back(gfx::GetAtom(Clipboard::kMimeTypeHTML)); |
| 454 std::vector< ::Atom> requested_types; | 455 std::vector< ::Atom> requested_types; |
| 455 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 456 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 456 | 457 |
| 457 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 458 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 458 if (data.IsValid()) { | 459 if (data.IsValid()) { |
| 459 *html = data.GetHtml(); | 460 *html = data.GetHtml(); |
| 460 *base_url = GURL(); | 461 *base_url = GURL(); |
| 461 return true; | 462 return true; |
| 462 } | 463 } |
| 463 | 464 |
| 464 return false; | 465 return false; |
| 465 } | 466 } |
| 466 | 467 |
| 467 bool OSExchangeDataProviderAuraX11::HasHtml() const { | 468 bool OSExchangeDataProviderAuraX11::HasHtml() const { |
| 468 std::vector< ::Atom> url_atoms; | 469 std::vector< ::Atom> url_atoms; |
| 469 url_atoms.push_back(GetAtom(Clipboard::kMimeTypeHTML)); | 470 url_atoms.push_back(gfx::GetAtom(Clipboard::kMimeTypeHTML)); |
| 470 std::vector< ::Atom> requested_types; | 471 std::vector< ::Atom> requested_types; |
| 471 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 472 GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 472 | 473 |
| 473 return !requested_types.empty(); | 474 return !requested_types.empty(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 void OSExchangeDataProviderAuraX11::SetDragImage( | 477 void OSExchangeDataProviderAuraX11::SetDragImage( |
| 477 const gfx::ImageSkia& image, | 478 const gfx::ImageSkia& image, |
| 478 const gfx::Vector2d& cursor_offset) { | 479 const gfx::Vector2d& cursor_offset) { |
| 479 drag_image_ = image; | 480 drag_image_ = image; |
| 480 drag_image_offset_ = cursor_offset; | 481 drag_image_offset_ = cursor_offset; |
| 481 } | 482 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 518 } |
| 518 | 519 |
| 519 return false; | 520 return false; |
| 520 } | 521 } |
| 521 | 522 |
| 522 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { | 523 std::vector< ::Atom> OSExchangeDataProviderAuraX11::GetTargets() const { |
| 523 return format_map_.GetTypes(); | 524 return format_map_.GetTypes(); |
| 524 } | 525 } |
| 525 | 526 |
| 526 } // namespace ui | 527 } // namespace ui |
| OLD | NEW |