| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 137 SetString(spec); | 137 SetString(spec); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { | 141 void OSExchangeDataProviderAuraX11::SetFilename(const base::FilePath& path) { |
| 142 NOTIMPLEMENTED(); | 142 std::vector<OSExchangeData::FileInfo> data; |
| 143 data.push_back(OSExchangeData::FileInfo(path, base::FilePath())); |
| 144 SetFilenames(data); |
| 143 } | 145 } |
| 144 | 146 |
| 145 void OSExchangeDataProviderAuraX11::SetFilenames( | 147 void OSExchangeDataProviderAuraX11::SetFilenames( |
| 146 const std::vector<OSExchangeData::FileInfo>& filenames) { | 148 const std::vector<OSExchangeData::FileInfo>& filenames) { |
| 147 NOTIMPLEMENTED(); | 149 std::vector<std::string> paths; |
| 150 for (std::vector<OSExchangeData::FileInfo>::const_iterator it = |
| 151 filenames.begin(); it != filenames.end(); ++it) { |
| 152 std::string url_spec = net::FilePathToFileURL(it->path).spec(); |
| 153 if (!url_spec.empty()) |
| 154 paths.push_back(url_spec); |
| 155 } |
| 156 |
| 157 std::string joined_data = JoinString(paths, '\n'); |
| 158 scoped_refptr<base::RefCountedMemory> mem( |
| 159 base::RefCountedString::TakeString(&joined_data)); |
| 160 format_map_.Insert(atom_cache_.GetAtom(Clipboard::kMimeTypeURIList), mem); |
| 148 } | 161 } |
| 149 | 162 |
| 150 void OSExchangeDataProviderAuraX11::SetPickledData( | 163 void OSExchangeDataProviderAuraX11::SetPickledData( |
| 151 const OSExchangeData::CustomFormat& format, | 164 const OSExchangeData::CustomFormat& format, |
| 152 const Pickle& pickle) { | 165 const Pickle& pickle) { |
| 153 const unsigned char* data = | 166 const unsigned char* data = |
| 154 reinterpret_cast<const unsigned char*>(pickle.data()); | 167 reinterpret_cast<const unsigned char*>(pickle.data()); |
| 155 | 168 |
| 156 std::vector<unsigned char> bytes; | 169 std::vector<unsigned char> bytes; |
| 157 bytes.insert(bytes.end(), data, data + pickle.size()); | 170 bytes.insert(bytes.end(), data, data + pickle.size()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if (num_tokens > 1) | 213 if (num_tokens > 1) |
| 201 *title = tokens[1]; | 214 *title = tokens[1]; |
| 202 else | 215 else |
| 203 *title = base::string16(); | 216 *title = base::string16(); |
| 204 | 217 |
| 205 *url = GURL(tokens[0]); | 218 *url = GURL(tokens[0]); |
| 206 return true; | 219 return true; |
| 207 } | 220 } |
| 208 } else if (data.GetType() == atom_cache_.GetAtom( | 221 } else if (data.GetType() == atom_cache_.GetAtom( |
| 209 Clipboard::kMimeTypeURIList)) { | 222 Clipboard::kMimeTypeURIList)) { |
| 210 // uri-lists are newline separated file lists in URL encoding. | 223 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 211 std::string unparsed; | 224 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 212 data.AssignTo(&unparsed); | 225 it != tokens.end(); ++it) { |
| 213 | 226 GURL test_url(*it); |
| 214 std::vector<std::string> tokens; | 227 if (!test_url.SchemeIsFile()) { |
| 215 size_t num_tokens = Tokenize(unparsed, "\n", &tokens); | 228 *url = test_url; |
| 216 if (!num_tokens) { | 229 *title = base::string16(); |
| 217 NOTREACHED() << "Empty URI list"; | 230 return true; |
| 218 return false; | 231 } |
| 219 } | 232 } |
| 220 | |
| 221 *url = GURL(tokens[0]); | |
| 222 *title = base::string16(); | |
| 223 | |
| 224 return true; | |
| 225 } | 233 } |
| 226 } | 234 } |
| 227 | 235 |
| 228 return false; | 236 return false; |
| 229 } | 237 } |
| 230 | 238 |
| 231 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { | 239 bool OSExchangeDataProviderAuraX11::GetFilename(base::FilePath* path) const { |
| 232 // On X11, files are passed by URL and aren't separate. | 240 std::vector<OSExchangeData::FileInfo> filenames; |
| 241 if (GetFilenames(&filenames)) { |
| 242 *path = filenames.front().path; |
| 243 return true; |
| 244 } |
| 245 |
| 233 return false; | 246 return false; |
| 234 } | 247 } |
| 235 | 248 |
| 236 bool OSExchangeDataProviderAuraX11::GetFilenames( | 249 bool OSExchangeDataProviderAuraX11::GetFilenames( |
| 237 std::vector<OSExchangeData::FileInfo>* filenames) const { | 250 std::vector<OSExchangeData::FileInfo>* filenames) const { |
| 238 // On X11, files are passed by URL and aren't separate. | 251 std::vector< ::Atom> url_atoms = ui::GetURIListAtomsFrom(&atom_cache_); |
| 239 return false; | 252 std::vector< ::Atom> requested_types; |
| 253 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 254 |
| 255 filenames->clear(); |
| 256 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 257 if (data.IsValid()) { |
| 258 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 259 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 260 it != tokens.end(); ++it) { |
| 261 GURL url(*it); |
| 262 base::FilePath file_path; |
| 263 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) { |
| 264 filenames->push_back(OSExchangeData::FileInfo(file_path, |
| 265 base::FilePath())); |
| 266 } |
| 267 } |
| 268 } |
| 269 |
| 270 return !filenames->empty(); |
| 240 } | 271 } |
| 241 | 272 |
| 242 bool OSExchangeDataProviderAuraX11::GetPickledData( | 273 bool OSExchangeDataProviderAuraX11::GetPickledData( |
| 243 const OSExchangeData::CustomFormat& format, | 274 const OSExchangeData::CustomFormat& format, |
| 244 Pickle* pickle) const { | 275 Pickle* pickle) const { |
| 245 std::vector< ::Atom> requested_types; | 276 std::vector< ::Atom> requested_types; |
| 246 requested_types.push_back(atom_cache_.GetAtom(format.ToString().c_str())); | 277 requested_types.push_back(atom_cache_.GetAtom(format.ToString().c_str())); |
| 247 | 278 |
| 248 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); | 279 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 249 if (data.IsValid()) { | 280 if (data.IsValid()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 261 std::vector< ::Atom> text_atoms = ui::GetTextAtomsFrom(&atom_cache_); | 292 std::vector< ::Atom> text_atoms = ui::GetTextAtomsFrom(&atom_cache_); |
| 262 std::vector< ::Atom> requested_types; | 293 std::vector< ::Atom> requested_types; |
| 263 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); | 294 ui::GetAtomIntersection(text_atoms, GetTargets(), &requested_types); |
| 264 return !requested_types.empty(); | 295 return !requested_types.empty(); |
| 265 } | 296 } |
| 266 | 297 |
| 267 bool OSExchangeDataProviderAuraX11::HasURL() const { | 298 bool OSExchangeDataProviderAuraX11::HasURL() const { |
| 268 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_); | 299 std::vector< ::Atom> url_atoms = ui::GetURLAtomsFrom(&atom_cache_); |
| 269 std::vector< ::Atom> requested_types; | 300 std::vector< ::Atom> requested_types; |
| 270 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 301 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 271 return !requested_types.empty(); | 302 |
| 303 if (requested_types.empty()) |
| 304 return false; |
| 305 |
| 306 // The Linux desktop doesn't differentiate between files and URLs like |
| 307 // Windows does and stuffs all the data into one mime type. |
| 308 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 309 if (data.IsValid()) { |
| 310 if (data.GetType() == atom_cache_.GetAtom(kMimeTypeMozillaURL)) { |
| 311 // File managers shouldn't be using this type, so this is a URL. |
| 312 return true; |
| 313 } else if (data.GetType() == atom_cache_.GetAtom( |
| 314 ui::Clipboard::kMimeTypeURIList)) { |
| 315 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 316 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 317 it != tokens.end(); ++it) { |
| 318 if (!GURL(*it).SchemeIsFile()) |
| 319 return true; |
| 320 } |
| 321 |
| 322 return false; |
| 323 } |
| 324 } |
| 325 |
| 326 return false; |
| 272 } | 327 } |
| 273 | 328 |
| 274 bool OSExchangeDataProviderAuraX11::HasFile() const { | 329 bool OSExchangeDataProviderAuraX11::HasFile() const { |
| 275 // On X11, files are passed by URL and aren't separate. | 330 std::vector< ::Atom> url_atoms = ui::GetURIListAtomsFrom(&atom_cache_); |
| 331 std::vector< ::Atom> requested_types; |
| 332 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 333 |
| 334 if (requested_types.empty()) |
| 335 return false; |
| 336 |
| 337 // To actually answer whether we have a file, we need to look through the |
| 338 // contents of the kMimeTypeURIList type, and see if any of them are file:// |
| 339 // URIs. |
| 340 ui::SelectionData data(format_map_.GetFirstOf(requested_types)); |
| 341 if (data.IsValid()) { |
| 342 std::vector<std::string> tokens = ui::ParseURIList(data); |
| 343 for (std::vector<std::string>::const_iterator it = tokens.begin(); |
| 344 it != tokens.end(); ++it) { |
| 345 GURL url(*it); |
| 346 base::FilePath file_path; |
| 347 if (url.SchemeIsFile() && net::FileURLToFilePath(url, &file_path)) |
| 348 return true; |
| 349 } |
| 350 } |
| 351 |
| 276 return false; | 352 return false; |
| 277 } | 353 } |
| 278 | 354 |
| 279 bool OSExchangeDataProviderAuraX11::HasCustomFormat( | 355 bool OSExchangeDataProviderAuraX11::HasCustomFormat( |
| 280 const OSExchangeData::CustomFormat& format) const { | 356 const OSExchangeData::CustomFormat& format) const { |
| 281 std::vector< ::Atom> url_atoms; | 357 std::vector< ::Atom> url_atoms; |
| 282 url_atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); | 358 url_atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); |
| 283 std::vector< ::Atom> requested_types; | 359 std::vector< ::Atom> requested_types; |
| 284 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); | 360 ui::GetAtomIntersection(url_atoms, GetTargets(), &requested_types); |
| 285 | 361 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 449 |
| 374 /////////////////////////////////////////////////////////////////////////////// | 450 /////////////////////////////////////////////////////////////////////////////// |
| 375 // OSExchangeData, public: | 451 // OSExchangeData, public: |
| 376 | 452 |
| 377 // static | 453 // static |
| 378 OSExchangeData::Provider* OSExchangeData::CreateProvider() { | 454 OSExchangeData::Provider* OSExchangeData::CreateProvider() { |
| 379 return new OSExchangeDataProviderAuraX11(); | 455 return new OSExchangeDataProviderAuraX11(); |
| 380 } | 456 } |
| 381 | 457 |
| 382 } // namespace ui | 458 } // namespace ui |
| OLD | NEW |