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