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/clipboard/clipboard.h" | 5 #include "ui/base/clipboard/clipboard_aurax11.h" |
6 | 6 |
7 #include <X11/extensions/Xfixes.h> | 7 #include <X11/extensions/Xfixes.h> |
8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
9 #include <list> | 9 #include <list> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 215 |
216 bool Clipboard::FormatType::operator<(const FormatType& other) const { | 216 bool Clipboard::FormatType::operator<(const FormatType& other) const { |
217 return data_ < other.data_; | 217 return data_ < other.data_; |
218 } | 218 } |
219 | 219 |
220 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 220 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
221 return data_ == other.data_; | 221 return data_ == other.data_; |
222 } | 222 } |
223 | 223 |
224 /////////////////////////////////////////////////////////////////////////////// | 224 /////////////////////////////////////////////////////////////////////////////// |
225 // Clipboard::AuraX11Details | 225 // ClipboardAuraX11::AuraX11Details |
226 | 226 |
227 // Private implementation of our X11 integration. Keeps X11 headers out of the | 227 // Private implementation of our X11 integration. Keeps X11 headers out of the |
228 // majority of chrome, which break badly. | 228 // majority of chrome, which break badly. |
229 class Clipboard::AuraX11Details : public PlatformEventDispatcher { | 229 class ClipboardAuraX11::AuraX11Details : public PlatformEventDispatcher { |
230 public: | 230 public: |
231 AuraX11Details(); | 231 AuraX11Details(); |
232 virtual ~AuraX11Details(); | 232 virtual ~AuraX11Details(); |
233 | 233 |
234 X11AtomCache* atom_cache() { return &atom_cache_; } | 234 X11AtomCache* atom_cache() { return &atom_cache_; } |
235 | 235 |
236 // Returns the X11 type that we pass to various XSelection functions for the | 236 // Returns the X11 type that we pass to various XSelection functions for the |
237 // given type. | 237 // given type. |
238 ::Atom LookupSelectionForClipboardType(ClipboardType type) const; | 238 ::Atom LookupSelectionForClipboardType(ClipboardType type) const; |
239 | 239 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // Temporary target map that we write to during DispatchObects. | 308 // Temporary target map that we write to during DispatchObects. |
309 SelectionFormatMap clipboard_data_; | 309 SelectionFormatMap clipboard_data_; |
310 | 310 |
311 // Objects which offer selection data to other windows. | 311 // Objects which offer selection data to other windows. |
312 SelectionOwner clipboard_owner_; | 312 SelectionOwner clipboard_owner_; |
313 SelectionOwner primary_owner_; | 313 SelectionOwner primary_owner_; |
314 | 314 |
315 DISALLOW_COPY_AND_ASSIGN(AuraX11Details); | 315 DISALLOW_COPY_AND_ASSIGN(AuraX11Details); |
316 }; | 316 }; |
317 | 317 |
318 Clipboard::AuraX11Details::AuraX11Details() | 318 ClipboardAuraX11::AuraX11Details::AuraX11Details() |
319 : x_display_(gfx::GetXDisplay()), | 319 : x_display_(gfx::GetXDisplay()), |
320 x_root_window_(DefaultRootWindow(x_display_)), | 320 x_root_window_(DefaultRootWindow(x_display_)), |
321 x_window_(XCreateWindow( | 321 x_window_(XCreateWindow(x_display_, |
322 x_display_, x_root_window_, | 322 x_root_window_, |
323 -100, -100, 10, 10, // x, y, width, height | 323 -100, |
324 0, // border width | 324 -100, |
325 CopyFromParent, // depth | 325 10, |
326 InputOnly, | 326 10, // x, y, width, height |
327 CopyFromParent, // visual | 327 0, // border width |
328 0, | 328 CopyFromParent, // depth |
329 NULL)), | 329 InputOnly, |
| 330 CopyFromParent, // visual |
| 331 0, |
| 332 NULL)), |
330 atom_cache_(x_display_, kAtomsToCache), | 333 atom_cache_(x_display_, kAtomsToCache), |
331 selection_requestor_(x_display_, x_window_, this), | 334 selection_requestor_(x_display_, x_window_, this), |
332 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)), | 335 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)), |
333 primary_owner_(x_display_, x_window_, XA_PRIMARY) { | 336 primary_owner_(x_display_, x_window_, XA_PRIMARY) { |
334 // We don't know all possible MIME types at compile time. | 337 // We don't know all possible MIME types at compile time. |
335 atom_cache_.allow_uncached_atoms(); | 338 atom_cache_.allow_uncached_atoms(); |
336 | 339 |
337 XStoreName(x_display_, x_window_, "Chromium clipboard"); | 340 XStoreName(x_display_, x_window_, "Chromium clipboard"); |
338 XSelectInput(x_display_, x_window_, PropertyChangeMask); | 341 XSelectInput(x_display_, x_window_, PropertyChangeMask); |
339 | 342 |
340 if (PlatformEventSource::GetInstance()) | 343 if (PlatformEventSource::GetInstance()) |
341 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); | 344 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this); |
342 } | 345 } |
343 | 346 |
344 Clipboard::AuraX11Details::~AuraX11Details() { | 347 ClipboardAuraX11::AuraX11Details::~AuraX11Details() { |
345 if (PlatformEventSource::GetInstance()) | 348 if (PlatformEventSource::GetInstance()) |
346 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); | 349 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this); |
347 | 350 |
348 XDestroyWindow(x_display_, x_window_); | 351 XDestroyWindow(x_display_, x_window_); |
349 } | 352 } |
350 | 353 |
351 ::Atom Clipboard::AuraX11Details::LookupSelectionForClipboardType( | 354 ::Atom ClipboardAuraX11::AuraX11Details::LookupSelectionForClipboardType( |
352 ClipboardType type) const { | 355 ClipboardType type) const { |
353 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 356 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
354 return GetCopyPasteSelection(); | 357 return GetCopyPasteSelection(); |
355 | 358 |
356 return XA_PRIMARY; | 359 return XA_PRIMARY; |
357 } | 360 } |
358 | 361 |
359 ::Atom Clipboard::AuraX11Details::GetCopyPasteSelection() const { | 362 ::Atom ClipboardAuraX11::AuraX11Details::GetCopyPasteSelection() const { |
360 return atom_cache_.GetAtom(kClipboard); | 363 return atom_cache_.GetAtom(kClipboard); |
361 } | 364 } |
362 | 365 |
363 const SelectionFormatMap& Clipboard::AuraX11Details::LookupStorageForAtom( | 366 const SelectionFormatMap& |
364 ::Atom atom) { | 367 ClipboardAuraX11::AuraX11Details::LookupStorageForAtom(::Atom atom) { |
365 if (atom == XA_PRIMARY) | 368 if (atom == XA_PRIMARY) |
366 return primary_owner_.selection_format_map(); | 369 return primary_owner_.selection_format_map(); |
367 | 370 |
368 DCHECK_EQ(GetCopyPasteSelection(), atom); | 371 DCHECK_EQ(GetCopyPasteSelection(), atom); |
369 return clipboard_owner_.selection_format_map(); | 372 return clipboard_owner_.selection_format_map(); |
370 } | 373 } |
371 | 374 |
372 void Clipboard::AuraX11Details::CreateNewClipboardData() { | 375 void ClipboardAuraX11::AuraX11Details::CreateNewClipboardData() { |
373 clipboard_data_ = SelectionFormatMap(); | 376 clipboard_data_ = SelectionFormatMap(); |
374 } | 377 } |
375 | 378 |
376 void Clipboard::AuraX11Details::InsertMapping( | 379 void ClipboardAuraX11::AuraX11Details::InsertMapping( |
377 const std::string& key, | 380 const std::string& key, |
378 const scoped_refptr<base::RefCountedMemory>& memory) { | 381 const scoped_refptr<base::RefCountedMemory>& memory) { |
379 ::Atom atom_key = atom_cache_.GetAtom(key.c_str()); | 382 ::Atom atom_key = atom_cache_.GetAtom(key.c_str()); |
380 clipboard_data_.Insert(atom_key, memory); | 383 clipboard_data_.Insert(atom_key, memory); |
381 } | 384 } |
382 | 385 |
383 void Clipboard::AuraX11Details::TakeOwnershipOfSelection(ClipboardType type) { | 386 void ClipboardAuraX11::AuraX11Details::TakeOwnershipOfSelection( |
| 387 ClipboardType type) { |
384 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 388 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
385 return clipboard_owner_.TakeOwnershipOfSelection(clipboard_data_); | 389 return clipboard_owner_.TakeOwnershipOfSelection(clipboard_data_); |
386 else | 390 else |
387 return primary_owner_.TakeOwnershipOfSelection(clipboard_data_); | 391 return primary_owner_.TakeOwnershipOfSelection(clipboard_data_); |
388 } | 392 } |
389 | 393 |
390 SelectionData Clipboard::AuraX11Details::RequestAndWaitForTypes( | 394 SelectionData ClipboardAuraX11::AuraX11Details::RequestAndWaitForTypes( |
391 ClipboardType type, | 395 ClipboardType type, |
392 const std::vector< ::Atom>& types) { | 396 const std::vector<::Atom>& types) { |
393 ::Atom selection_name = LookupSelectionForClipboardType(type); | 397 ::Atom selection_name = LookupSelectionForClipboardType(type); |
394 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { | 398 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { |
395 // We can local fastpath instead of playing the nested message loop game | 399 // We can local fastpath instead of playing the nested message loop game |
396 // with the X server. | 400 // with the X server. |
397 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); | 401 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); |
398 | 402 |
399 for (std::vector< ::Atom>::const_iterator it = types.begin(); | 403 for (std::vector< ::Atom>::const_iterator it = types.begin(); |
400 it != types.end(); ++it) { | 404 it != types.end(); ++it) { |
401 SelectionFormatMap::const_iterator format_map_it = format_map.find(*it); | 405 SelectionFormatMap::const_iterator format_map_it = format_map.find(*it); |
402 if (format_map_it != format_map.end()) | 406 if (format_map_it != format_map.end()) |
403 return SelectionData(format_map_it->first, format_map_it->second); | 407 return SelectionData(format_map_it->first, format_map_it->second); |
404 } | 408 } |
405 } else { | 409 } else { |
406 TargetList targets = WaitAndGetTargetsList(type); | 410 TargetList targets = WaitAndGetTargetsList(type); |
407 | 411 |
408 ::Atom selection_name = LookupSelectionForClipboardType(type); | 412 ::Atom selection_name = LookupSelectionForClipboardType(type); |
409 std::vector< ::Atom> intersection; | 413 std::vector< ::Atom> intersection; |
410 ui::GetAtomIntersection(types, targets.target_list(), &intersection); | 414 ui::GetAtomIntersection(types, targets.target_list(), &intersection); |
411 return selection_requestor_.RequestAndWaitForTypes(selection_name, | 415 return selection_requestor_.RequestAndWaitForTypes(selection_name, |
412 intersection); | 416 intersection); |
413 } | 417 } |
414 | 418 |
415 return SelectionData(); | 419 return SelectionData(); |
416 } | 420 } |
417 | 421 |
418 TargetList Clipboard::AuraX11Details::WaitAndGetTargetsList( | 422 TargetList ClipboardAuraX11::AuraX11Details::WaitAndGetTargetsList( |
419 ClipboardType type) { | 423 ClipboardType type) { |
420 ::Atom selection_name = LookupSelectionForClipboardType(type); | 424 ::Atom selection_name = LookupSelectionForClipboardType(type); |
421 std::vector< ::Atom> out; | 425 std::vector< ::Atom> out; |
422 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { | 426 if (XGetSelectionOwner(x_display_, selection_name) == x_window_) { |
423 // We can local fastpath and return the list of local targets. | 427 // We can local fastpath and return the list of local targets. |
424 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); | 428 const SelectionFormatMap& format_map = LookupStorageForAtom(selection_name); |
425 | 429 |
426 for (SelectionFormatMap::const_iterator it = format_map.begin(); | 430 for (SelectionFormatMap::const_iterator it = format_map.begin(); |
427 it != format_map.end(); ++it) { | 431 it != format_map.end(); ++it) { |
428 out.push_back(it->first); | 432 out.push_back(it->first); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 type == *it) { | 468 type == *it) { |
465 out.push_back(*it); | 469 out.push_back(*it); |
466 } | 470 } |
467 } | 471 } |
468 } | 472 } |
469 } | 473 } |
470 | 474 |
471 return TargetList(out, &atom_cache_); | 475 return TargetList(out, &atom_cache_); |
472 } | 476 } |
473 | 477 |
474 std::vector< ::Atom> Clipboard::AuraX11Details::GetTextAtoms() const { | 478 std::vector<::Atom> ClipboardAuraX11::AuraX11Details::GetTextAtoms() const { |
475 return GetTextAtomsFrom(&atom_cache_); | 479 return GetTextAtomsFrom(&atom_cache_); |
476 } | 480 } |
477 | 481 |
478 std::vector< ::Atom> Clipboard::AuraX11Details::GetAtomsForFormat( | 482 std::vector<::Atom> ClipboardAuraX11::AuraX11Details::GetAtomsForFormat( |
479 const Clipboard::FormatType& format) { | 483 const Clipboard::FormatType& format) { |
480 std::vector< ::Atom> atoms; | 484 std::vector< ::Atom> atoms; |
481 atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); | 485 atoms.push_back(atom_cache_.GetAtom(format.ToString().c_str())); |
482 return atoms; | 486 return atoms; |
483 } | 487 } |
484 | 488 |
485 void Clipboard::AuraX11Details::Clear(ClipboardType type) { | 489 void ClipboardAuraX11::AuraX11Details::Clear(ClipboardType type) { |
486 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 490 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
487 clipboard_owner_.ClearSelectionOwner(); | 491 clipboard_owner_.ClearSelectionOwner(); |
488 else | 492 else |
489 primary_owner_.ClearSelectionOwner(); | 493 primary_owner_.ClearSelectionOwner(); |
490 } | 494 } |
491 | 495 |
492 void Clipboard::AuraX11Details::StoreCopyPasteDataAndWait() { | 496 void ClipboardAuraX11::AuraX11Details::StoreCopyPasteDataAndWait() { |
493 ::Atom selection = GetCopyPasteSelection(); | 497 ::Atom selection = GetCopyPasteSelection(); |
494 if (XGetSelectionOwner(x_display_, selection) != x_window_) | 498 if (XGetSelectionOwner(x_display_, selection) != x_window_) |
495 return; | 499 return; |
496 | 500 |
497 ::Atom clipboard_manager_atom = atom_cache_.GetAtom(kClipboardManager); | 501 ::Atom clipboard_manager_atom = atom_cache_.GetAtom(kClipboardManager); |
498 if (XGetSelectionOwner(x_display_, clipboard_manager_atom) == None) | 502 if (XGetSelectionOwner(x_display_, clipboard_manager_atom) == None) |
499 return; | 503 return; |
500 | 504 |
501 const SelectionFormatMap& format_map = LookupStorageForAtom(selection); | 505 const SelectionFormatMap& format_map = LookupStorageForAtom(selection); |
502 if (format_map.size() == 0) | 506 if (format_map.size() == 0) |
503 return; | 507 return; |
504 std::vector<Atom> targets = format_map.GetTypes(); | 508 std::vector<Atom> targets = format_map.GetTypes(); |
505 | 509 |
506 base::TimeTicks start = base::TimeTicks::Now(); | 510 base::TimeTicks start = base::TimeTicks::Now(); |
507 selection_requestor_.PerformBlockingConvertSelectionWithParameter( | 511 selection_requestor_.PerformBlockingConvertSelectionWithParameter( |
508 atom_cache_.GetAtom(kClipboardManager), | 512 atom_cache_.GetAtom(kClipboardManager), |
509 atom_cache_.GetAtom(kSaveTargets), | 513 atom_cache_.GetAtom(kSaveTargets), |
510 targets); | 514 targets); |
511 UMA_HISTOGRAM_TIMES("Clipboard.X11StoreCopyPasteDuration", | 515 UMA_HISTOGRAM_TIMES("Clipboard.X11StoreCopyPasteDuration", |
512 base::TimeTicks::Now() - start); | 516 base::TimeTicks::Now() - start); |
513 } | 517 } |
514 | 518 |
515 bool Clipboard::AuraX11Details::CanDispatchEvent(const PlatformEvent& event) { | 519 bool ClipboardAuraX11::AuraX11Details::CanDispatchEvent( |
| 520 const PlatformEvent& event) { |
516 if (event->xany.window == x_window_) | 521 if (event->xany.window == x_window_) |
517 return true; | 522 return true; |
518 | 523 |
519 if (event->type == PropertyNotify) { | 524 if (event->type == PropertyNotify) { |
520 return primary_owner_.CanDispatchPropertyEvent(*event) || | 525 return primary_owner_.CanDispatchPropertyEvent(*event) || |
521 clipboard_owner_.CanDispatchPropertyEvent(*event) || | 526 clipboard_owner_.CanDispatchPropertyEvent(*event) || |
522 selection_requestor_.CanDispatchPropertyEvent(*event); | 527 selection_requestor_.CanDispatchPropertyEvent(*event); |
523 } | 528 } |
524 return false; | 529 return false; |
525 } | 530 } |
526 | 531 |
527 uint32_t Clipboard::AuraX11Details::DispatchEvent(const PlatformEvent& xev) { | 532 uint32_t ClipboardAuraX11::AuraX11Details::DispatchEvent( |
| 533 const PlatformEvent& xev) { |
528 switch (xev->type) { | 534 switch (xev->type) { |
529 case SelectionRequest: { | 535 case SelectionRequest: { |
530 if (xev->xselectionrequest.selection == XA_PRIMARY) { | 536 if (xev->xselectionrequest.selection == XA_PRIMARY) { |
531 primary_owner_.OnSelectionRequest(*xev); | 537 primary_owner_.OnSelectionRequest(*xev); |
532 } else { | 538 } else { |
533 // We should not get requests for the CLIPBOARD_MANAGER selection | 539 // We should not get requests for the CLIPBOARD_MANAGER selection |
534 // because we never take ownership of it. | 540 // because we never take ownership of it. |
535 DCHECK_EQ(GetCopyPasteSelection(), xev->xselectionrequest.selection); | 541 DCHECK_EQ(GetCopyPasteSelection(), xev->xselectionrequest.selection); |
536 clipboard_owner_.OnSelectionRequest(*xev); | 542 clipboard_owner_.OnSelectionRequest(*xev); |
537 } | 543 } |
(...skipping 25 matching lines...) Expand all Loading... |
563 } | 569 } |
564 default: | 570 default: |
565 break; | 571 break; |
566 } | 572 } |
567 | 573 |
568 return POST_DISPATCH_NONE; | 574 return POST_DISPATCH_NONE; |
569 } | 575 } |
570 | 576 |
571 /////////////////////////////////////////////////////////////////////////////// | 577 /////////////////////////////////////////////////////////////////////////////// |
572 // Clipboard | 578 // Clipboard |
| 579 // static |
| 580 Clipboard::FormatType Clipboard::GetFormatType( |
| 581 const std::string& format_string) { |
| 582 return FormatType::Deserialize(format_string); |
| 583 } |
573 | 584 |
574 Clipboard::Clipboard() | 585 // static |
575 : aurax11_details_(new AuraX11Details) { | 586 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { |
| 587 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); |
| 588 return type; |
| 589 } |
| 590 |
| 591 // static |
| 592 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { |
| 593 return GetUrlFormatType(); |
| 594 } |
| 595 |
| 596 // static |
| 597 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { |
| 598 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); |
| 599 return type; |
| 600 } |
| 601 |
| 602 // static |
| 603 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { |
| 604 return GetPlainTextFormatType(); |
| 605 } |
| 606 |
| 607 // static |
| 608 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { |
| 609 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); |
| 610 return type; |
| 611 } |
| 612 |
| 613 // static |
| 614 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { |
| 615 return Clipboard::GetFilenameFormatType(); |
| 616 } |
| 617 |
| 618 // static |
| 619 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { |
| 620 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); |
| 621 return type; |
| 622 } |
| 623 |
| 624 // static |
| 625 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { |
| 626 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); |
| 627 return type; |
| 628 } |
| 629 |
| 630 // static |
| 631 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { |
| 632 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePNG)); |
| 633 return type; |
| 634 } |
| 635 |
| 636 // static |
| 637 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { |
| 638 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); |
| 639 return type; |
| 640 } |
| 641 |
| 642 // static |
| 643 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 644 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
| 645 return type; |
| 646 } |
| 647 |
| 648 // static |
| 649 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 650 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
| 651 return type; |
| 652 } |
| 653 |
| 654 // static |
| 655 Clipboard* Clipboard::Create() { |
| 656 return new ClipboardAuraX11; |
| 657 } |
| 658 |
| 659 /////////////////////////////////////////////////////////////////////////////// |
| 660 // ClipboardAuraX11 |
| 661 |
| 662 ClipboardAuraX11::ClipboardAuraX11() : aurax11_details_(new AuraX11Details) { |
576 DCHECK(CalledOnValidThread()); | 663 DCHECK(CalledOnValidThread()); |
577 } | 664 } |
578 | 665 |
579 Clipboard::~Clipboard() { | 666 ClipboardAuraX11::~ClipboardAuraX11() { |
580 DCHECK(CalledOnValidThread()); | 667 DCHECK(CalledOnValidThread()); |
581 | 668 |
582 aurax11_details_->StoreCopyPasteDataAndWait(); | 669 aurax11_details_->StoreCopyPasteDataAndWait(); |
583 } | 670 } |
584 | 671 |
585 void Clipboard::WriteObjects(ClipboardType type, const ObjectMap& objects) { | 672 uint64 ClipboardAuraX11::GetSequenceNumber(ClipboardType type) { |
| 673 DCHECK(CalledOnValidThread()); |
| 674 if (type == CLIPBOARD_TYPE_COPY_PASTE) |
| 675 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); |
| 676 else |
| 677 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); |
| 678 } |
| 679 |
| 680 bool ClipboardAuraX11::IsFormatAvailable(const FormatType& format, |
| 681 ClipboardType type) const { |
586 DCHECK(CalledOnValidThread()); | 682 DCHECK(CalledOnValidThread()); |
587 DCHECK(IsSupportedClipboardType(type)); | 683 DCHECK(IsSupportedClipboardType(type)); |
588 | 684 |
589 aurax11_details_->CreateNewClipboardData(); | |
590 for (ObjectMap::const_iterator iter = objects.begin(); | |
591 iter != objects.end(); ++iter) { | |
592 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | |
593 } | |
594 aurax11_details_->TakeOwnershipOfSelection(type); | |
595 | |
596 if (type == CLIPBOARD_TYPE_COPY_PASTE) { | |
597 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); | |
598 if (text_iter != objects.end()) { | |
599 aurax11_details_->CreateNewClipboardData(); | |
600 const ObjectMapParams& params_vector = text_iter->second; | |
601 if (params_vector.size()) { | |
602 const ObjectMapParam& char_vector = params_vector[0]; | |
603 if (char_vector.size()) | |
604 WriteText(&char_vector.front(), char_vector.size()); | |
605 } | |
606 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION); | |
607 } | |
608 } | |
609 } | |
610 | |
611 bool Clipboard::IsFormatAvailable(const FormatType& format, | |
612 ClipboardType type) const { | |
613 DCHECK(CalledOnValidThread()); | |
614 DCHECK(IsSupportedClipboardType(type)); | |
615 | |
616 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); | 685 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); |
617 if (format.Equals(GetPlainTextFormatType()) || | 686 if (format.Equals(GetPlainTextFormatType()) || |
618 format.Equals(GetUrlFormatType())) { | 687 format.Equals(GetUrlFormatType())) { |
619 return target_list.ContainsText(); | 688 return target_list.ContainsText(); |
620 } | 689 } |
621 return target_list.ContainsFormat(format); | 690 return target_list.ContainsFormat(format); |
622 } | 691 } |
623 | 692 |
624 void Clipboard::Clear(ClipboardType type) { | 693 void ClipboardAuraX11::Clear(ClipboardType type) { |
625 DCHECK(CalledOnValidThread()); | 694 DCHECK(CalledOnValidThread()); |
626 DCHECK(IsSupportedClipboardType(type)); | 695 DCHECK(IsSupportedClipboardType(type)); |
627 aurax11_details_->Clear(type); | 696 aurax11_details_->Clear(type); |
628 } | 697 } |
629 | 698 |
630 void Clipboard::ReadAvailableTypes(ClipboardType type, | 699 void ClipboardAuraX11::ReadAvailableTypes(ClipboardType type, |
631 std::vector<base::string16>* types, | 700 std::vector<base::string16>* types, |
632 bool* contains_filenames) const { | 701 bool* contains_filenames) const { |
633 DCHECK(CalledOnValidThread()); | 702 DCHECK(CalledOnValidThread()); |
634 if (!types || !contains_filenames) { | 703 if (!types || !contains_filenames) { |
635 NOTREACHED(); | 704 NOTREACHED(); |
636 return; | 705 return; |
637 } | 706 } |
638 | 707 |
639 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); | 708 TargetList target_list = aurax11_details_->WaitAndGetTargetsList(type); |
640 | 709 |
641 types->clear(); | 710 types->clear(); |
642 | 711 |
643 if (target_list.ContainsText()) | 712 if (target_list.ContainsText()) |
644 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); | 713 types->push_back(base::UTF8ToUTF16(kMimeTypeText)); |
645 if (target_list.ContainsFormat(GetHtmlFormatType())) | 714 if (target_list.ContainsFormat(GetHtmlFormatType())) |
646 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); | 715 types->push_back(base::UTF8ToUTF16(kMimeTypeHTML)); |
647 if (target_list.ContainsFormat(GetRtfFormatType())) | 716 if (target_list.ContainsFormat(GetRtfFormatType())) |
648 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); | 717 types->push_back(base::UTF8ToUTF16(kMimeTypeRTF)); |
649 if (target_list.ContainsFormat(GetBitmapFormatType())) | 718 if (target_list.ContainsFormat(GetBitmapFormatType())) |
650 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); | 719 types->push_back(base::UTF8ToUTF16(kMimeTypePNG)); |
651 *contains_filenames = false; | 720 *contains_filenames = false; |
652 | 721 |
653 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 722 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
654 type, aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); | 723 type, aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); |
655 if (data.IsValid()) | 724 if (data.IsValid()) |
656 ReadCustomDataTypes(data.GetData(), data.GetSize(), types); | 725 ReadCustomDataTypes(data.GetData(), data.GetSize(), types); |
657 } | 726 } |
658 | 727 |
659 void Clipboard::ReadText(ClipboardType type, base::string16* result) const { | 728 void ClipboardAuraX11::ReadText(ClipboardType type, |
| 729 base::string16* result) const { |
660 DCHECK(CalledOnValidThread()); | 730 DCHECK(CalledOnValidThread()); |
661 | 731 |
662 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 732 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
663 type, aurax11_details_->GetTextAtoms())); | 733 type, aurax11_details_->GetTextAtoms())); |
664 if (data.IsValid()) { | 734 if (data.IsValid()) { |
665 std::string text = data.GetText(); | 735 std::string text = data.GetText(); |
666 *result = base::UTF8ToUTF16(text); | 736 *result = base::UTF8ToUTF16(text); |
667 } | 737 } |
668 } | 738 } |
669 | 739 |
670 void Clipboard::ReadAsciiText(ClipboardType type, std::string* result) const { | 740 void ClipboardAuraX11::ReadAsciiText(ClipboardType type, |
| 741 std::string* result) const { |
671 DCHECK(CalledOnValidThread()); | 742 DCHECK(CalledOnValidThread()); |
672 | 743 |
673 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 744 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
674 type, aurax11_details_->GetTextAtoms())); | 745 type, aurax11_details_->GetTextAtoms())); |
675 if (data.IsValid()) | 746 if (data.IsValid()) |
676 result->assign(data.GetText()); | 747 result->assign(data.GetText()); |
677 } | 748 } |
678 | 749 |
679 // TODO(estade): handle different charsets. | 750 // TODO(estade): handle different charsets. |
680 // TODO(port): set *src_url. | 751 // TODO(port): set *src_url. |
681 void Clipboard::ReadHTML(ClipboardType type, | 752 void ClipboardAuraX11::ReadHTML(ClipboardType type, |
682 base::string16* markup, | 753 base::string16* markup, |
683 std::string* src_url, | 754 std::string* src_url, |
684 uint32* fragment_start, | 755 uint32* fragment_start, |
685 uint32* fragment_end) const { | 756 uint32* fragment_end) const { |
686 DCHECK(CalledOnValidThread()); | 757 DCHECK(CalledOnValidThread()); |
687 markup->clear(); | 758 markup->clear(); |
688 if (src_url) | 759 if (src_url) |
689 src_url->clear(); | 760 src_url->clear(); |
690 *fragment_start = 0; | 761 *fragment_start = 0; |
691 *fragment_end = 0; | 762 *fragment_end = 0; |
692 | 763 |
693 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 764 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
694 type, aurax11_details_->GetAtomsForFormat(GetHtmlFormatType()))); | 765 type, aurax11_details_->GetAtomsForFormat(GetHtmlFormatType()))); |
695 if (data.IsValid()) { | 766 if (data.IsValid()) { |
696 *markup = data.GetHtml(); | 767 *markup = data.GetHtml(); |
697 | 768 |
698 *fragment_start = 0; | 769 *fragment_start = 0; |
699 DCHECK(markup->length() <= kuint32max); | 770 DCHECK(markup->length() <= kuint32max); |
700 *fragment_end = static_cast<uint32>(markup->length()); | 771 *fragment_end = static_cast<uint32>(markup->length()); |
701 } | 772 } |
702 } | 773 } |
703 | 774 |
704 void Clipboard::ReadRTF(ClipboardType type, std::string* result) const { | 775 void ClipboardAuraX11::ReadRTF(ClipboardType type, std::string* result) const { |
705 DCHECK(CalledOnValidThread()); | 776 DCHECK(CalledOnValidThread()); |
706 | 777 |
707 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 778 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
708 type, aurax11_details_->GetAtomsForFormat(GetRtfFormatType()))); | 779 type, aurax11_details_->GetAtomsForFormat(GetRtfFormatType()))); |
709 if (data.IsValid()) | 780 if (data.IsValid()) |
710 data.AssignTo(result); | 781 data.AssignTo(result); |
711 } | 782 } |
712 | 783 |
713 SkBitmap Clipboard::ReadImage(ClipboardType type) const { | 784 SkBitmap ClipboardAuraX11::ReadImage(ClipboardType type) const { |
714 DCHECK(CalledOnValidThread()); | 785 DCHECK(CalledOnValidThread()); |
715 | 786 |
716 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 787 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
717 type, aurax11_details_->GetAtomsForFormat(GetBitmapFormatType()))); | 788 type, aurax11_details_->GetAtomsForFormat(GetBitmapFormatType()))); |
718 if (data.IsValid()) { | 789 if (data.IsValid()) { |
719 SkBitmap bitmap; | 790 SkBitmap bitmap; |
720 if (gfx::PNGCodec::Decode(data.GetData(), data.GetSize(), &bitmap)) | 791 if (gfx::PNGCodec::Decode(data.GetData(), data.GetSize(), &bitmap)) |
721 return SkBitmap(bitmap); | 792 return SkBitmap(bitmap); |
722 } | 793 } |
723 | 794 |
724 return SkBitmap(); | 795 return SkBitmap(); |
725 } | 796 } |
726 | 797 |
727 void Clipboard::ReadCustomData(ClipboardType clipboard_type, | 798 void ClipboardAuraX11::ReadCustomData(ClipboardType clipboard_type, |
728 const base::string16& type, | 799 const base::string16& type, |
729 base::string16* result) const { | 800 base::string16* result) const { |
730 DCHECK(CalledOnValidThread()); | 801 DCHECK(CalledOnValidThread()); |
731 | 802 |
732 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 803 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
733 clipboard_type, | 804 clipboard_type, |
734 aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); | 805 aurax11_details_->GetAtomsForFormat(GetWebCustomDataFormatType()))); |
735 if (data.IsValid()) | 806 if (data.IsValid()) |
736 ReadCustomDataForType(data.GetData(), data.GetSize(), type, result); | 807 ReadCustomDataForType(data.GetData(), data.GetSize(), type, result); |
737 } | 808 } |
738 | 809 |
739 void Clipboard::ReadBookmark(base::string16* title, std::string* url) const { | 810 void ClipboardAuraX11::ReadBookmark(base::string16* title, |
| 811 std::string* url) const { |
740 DCHECK(CalledOnValidThread()); | 812 DCHECK(CalledOnValidThread()); |
741 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too. | 813 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too. |
742 NOTIMPLEMENTED(); | 814 NOTIMPLEMENTED(); |
743 } | 815 } |
744 | 816 |
745 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 817 void ClipboardAuraX11::ReadData(const FormatType& format, |
| 818 std::string* result) const { |
746 DCHECK(CalledOnValidThread()); | 819 DCHECK(CalledOnValidThread()); |
747 | 820 |
748 SelectionData data(aurax11_details_->RequestAndWaitForTypes( | 821 SelectionData data(aurax11_details_->RequestAndWaitForTypes( |
749 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format))); | 822 CLIPBOARD_TYPE_COPY_PASTE, aurax11_details_->GetAtomsForFormat(format))); |
750 if (data.IsValid()) | 823 if (data.IsValid()) |
751 data.AssignTo(result); | 824 data.AssignTo(result); |
752 } | 825 } |
753 | 826 |
754 uint64 Clipboard::GetSequenceNumber(ClipboardType type) { | 827 void ClipboardAuraX11::WriteObjects(ClipboardType type, |
| 828 const ObjectMap& objects) { |
755 DCHECK(CalledOnValidThread()); | 829 DCHECK(CalledOnValidThread()); |
756 if (type == CLIPBOARD_TYPE_COPY_PASTE) | 830 DCHECK(IsSupportedClipboardType(type)); |
757 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); | 831 |
758 else | 832 aurax11_details_->CreateNewClipboardData(); |
759 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); | 833 for (ObjectMap::const_iterator iter = objects.begin(); iter != objects.end(); |
| 834 ++iter) { |
| 835 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 836 } |
| 837 aurax11_details_->TakeOwnershipOfSelection(type); |
| 838 |
| 839 if (type == CLIPBOARD_TYPE_COPY_PASTE) { |
| 840 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); |
| 841 if (text_iter != objects.end()) { |
| 842 aurax11_details_->CreateNewClipboardData(); |
| 843 const ObjectMapParams& params_vector = text_iter->second; |
| 844 if (params_vector.size()) { |
| 845 const ObjectMapParam& char_vector = params_vector[0]; |
| 846 if (char_vector.size()) |
| 847 WriteText(&char_vector.front(), char_vector.size()); |
| 848 } |
| 849 aurax11_details_->TakeOwnershipOfSelection(CLIPBOARD_TYPE_SELECTION); |
| 850 } |
| 851 } |
760 } | 852 } |
761 | 853 |
762 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 854 void ClipboardAuraX11::WriteText(const char* text_data, size_t text_len) { |
763 std::string str(text_data, text_len); | 855 std::string str(text_data, text_len); |
764 scoped_refptr<base::RefCountedMemory> mem( | 856 scoped_refptr<base::RefCountedMemory> mem( |
765 base::RefCountedString::TakeString(&str)); | 857 base::RefCountedString::TakeString(&str)); |
766 | 858 |
767 aurax11_details_->InsertMapping(kMimeTypeText, mem); | 859 aurax11_details_->InsertMapping(kMimeTypeText, mem); |
768 aurax11_details_->InsertMapping(kText, mem); | 860 aurax11_details_->InsertMapping(kText, mem); |
769 aurax11_details_->InsertMapping(kString, mem); | 861 aurax11_details_->InsertMapping(kString, mem); |
770 aurax11_details_->InsertMapping(kUtf8String, mem); | 862 aurax11_details_->InsertMapping(kUtf8String, mem); |
771 } | 863 } |
772 | 864 |
773 void Clipboard::WriteHTML(const char* markup_data, | 865 void ClipboardAuraX11::WriteHTML(const char* markup_data, |
774 size_t markup_len, | 866 size_t markup_len, |
775 const char* url_data, | 867 const char* url_data, |
776 size_t url_len) { | 868 size_t url_len) { |
777 // TODO(estade): We need to expand relative links with |url_data|. | 869 // TODO(estade): We need to expand relative links with |url_data|. |
778 static const char* html_prefix = "<meta http-equiv=\"content-type\" " | 870 static const char* html_prefix = "<meta http-equiv=\"content-type\" " |
779 "content=\"text/html; charset=utf-8\">"; | 871 "content=\"text/html; charset=utf-8\">"; |
780 std::string data = html_prefix; | 872 std::string data = html_prefix; |
781 data += std::string(markup_data, markup_len); | 873 data += std::string(markup_data, markup_len); |
782 // Some programs expect NULL-terminated data. See http://crbug.com/42624 | 874 // Some programs expect NULL-terminated data. See http://crbug.com/42624 |
783 data += '\0'; | 875 data += '\0'; |
784 | 876 |
785 scoped_refptr<base::RefCountedMemory> mem( | 877 scoped_refptr<base::RefCountedMemory> mem( |
786 base::RefCountedString::TakeString(&data)); | 878 base::RefCountedString::TakeString(&data)); |
787 aurax11_details_->InsertMapping(kMimeTypeHTML, mem); | 879 aurax11_details_->InsertMapping(kMimeTypeHTML, mem); |
788 } | 880 } |
789 | 881 |
790 void Clipboard::WriteRTF(const char* rtf_data, size_t data_len) { | 882 void ClipboardAuraX11::WriteRTF(const char* rtf_data, size_t data_len) { |
791 WriteData(GetRtfFormatType(), rtf_data, data_len); | 883 WriteData(GetRtfFormatType(), rtf_data, data_len); |
792 } | 884 } |
793 | 885 |
794 void Clipboard::WriteBookmark(const char* title_data, | 886 void ClipboardAuraX11::WriteBookmark(const char* title_data, |
795 size_t title_len, | 887 size_t title_len, |
796 const char* url_data, | 888 const char* url_data, |
797 size_t url_len) { | 889 size_t url_len) { |
798 // Write as a mozilla url (UTF16: URL, newline, title). | 890 // Write as a mozilla url (UTF16: URL, newline, title). |
799 base::string16 url = base::UTF8ToUTF16(std::string(url_data, url_len) + "\n"); | 891 base::string16 url = base::UTF8ToUTF16(std::string(url_data, url_len) + "\n"); |
800 base::string16 title = base::UTF8ToUTF16(std::string(title_data, title_len)); | 892 base::string16 title = base::UTF8ToUTF16(std::string(title_data, title_len)); |
801 | 893 |
802 std::vector<unsigned char> data; | 894 std::vector<unsigned char> data; |
803 ui::AddString16ToVector(url, &data); | 895 ui::AddString16ToVector(url, &data); |
804 ui::AddString16ToVector(title, &data); | 896 ui::AddString16ToVector(title, &data); |
805 scoped_refptr<base::RefCountedMemory> mem( | 897 scoped_refptr<base::RefCountedMemory> mem( |
806 base::RefCountedBytes::TakeVector(&data)); | 898 base::RefCountedBytes::TakeVector(&data)); |
807 | 899 |
808 aurax11_details_->InsertMapping(kMimeTypeMozillaURL, mem); | 900 aurax11_details_->InsertMapping(kMimeTypeMozillaURL, mem); |
809 } | 901 } |
810 | 902 |
811 // Write an extra flavor that signifies WebKit was the last to modify the | 903 // Write an extra flavor that signifies WebKit was the last to modify the |
812 // pasteboard. This flavor has no data. | 904 // pasteboard. This flavor has no data. |
813 void Clipboard::WriteWebSmartPaste() { | 905 void ClipboardAuraX11::WriteWebSmartPaste() { |
814 std::string empty; | 906 std::string empty; |
815 aurax11_details_->InsertMapping( | 907 aurax11_details_->InsertMapping( |
816 kMimeTypeWebkitSmartPaste, | 908 kMimeTypeWebkitSmartPaste, |
817 scoped_refptr<base::RefCountedMemory>( | 909 scoped_refptr<base::RefCountedMemory>( |
818 base::RefCountedString::TakeString(&empty))); | 910 base::RefCountedString::TakeString(&empty))); |
819 } | 911 } |
820 | 912 |
821 void Clipboard::WriteBitmap(const SkBitmap& bitmap) { | 913 void ClipboardAuraX11::WriteBitmap(const SkBitmap& bitmap) { |
822 // Encode the bitmap as a PNG for transport. | 914 // Encode the bitmap as a PNG for transport. |
823 std::vector<unsigned char> output; | 915 std::vector<unsigned char> output; |
824 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) { | 916 if (gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, false, &output)) { |
825 aurax11_details_->InsertMapping(kMimeTypePNG, | 917 aurax11_details_->InsertMapping(kMimeTypePNG, |
826 base::RefCountedBytes::TakeVector( | 918 base::RefCountedBytes::TakeVector( |
827 &output)); | 919 &output)); |
828 } | 920 } |
829 } | 921 } |
830 | 922 |
831 void Clipboard::WriteData(const FormatType& format, | 923 void ClipboardAuraX11::WriteData(const FormatType& format, |
832 const char* data_data, | 924 const char* data_data, |
833 size_t data_len) { | 925 size_t data_len) { |
834 // We assume that certain mapping types are only written by trusted code. | 926 // We assume that certain mapping types are only written by trusted code. |
835 // Therefore we must upkeep their integrity. | 927 // Therefore we must upkeep their integrity. |
836 if (format.Equals(GetBitmapFormatType())) | 928 if (format.Equals(GetBitmapFormatType())) |
837 return; | 929 return; |
838 | 930 |
839 std::vector<unsigned char> bytes(data_data, data_data + data_len); | 931 std::vector<unsigned char> bytes(data_data, data_data + data_len); |
840 scoped_refptr<base::RefCountedMemory> mem( | 932 scoped_refptr<base::RefCountedMemory> mem( |
841 base::RefCountedBytes::TakeVector(&bytes)); | 933 base::RefCountedBytes::TakeVector(&bytes)); |
842 aurax11_details_->InsertMapping(format.ToString(), mem); | 934 aurax11_details_->InsertMapping(format.ToString(), mem); |
843 } | 935 } |
844 | 936 |
845 // static | |
846 Clipboard::FormatType Clipboard::GetFormatType( | |
847 const std::string& format_string) { | |
848 return FormatType::Deserialize(format_string); | |
849 } | |
850 | |
851 // static | |
852 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { | |
853 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); | |
854 return type; | |
855 } | |
856 | |
857 // static | |
858 const Clipboard::FormatType& Clipboard::GetUrlWFormatType() { | |
859 return GetUrlFormatType(); | |
860 } | |
861 | |
862 // static | |
863 const Clipboard::FormatType& Clipboard::GetPlainTextFormatType() { | |
864 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeText)); | |
865 return type; | |
866 } | |
867 | |
868 // static | |
869 const Clipboard::FormatType& Clipboard::GetPlainTextWFormatType() { | |
870 return GetPlainTextFormatType(); | |
871 } | |
872 | |
873 // static | |
874 const Clipboard::FormatType& Clipboard::GetFilenameFormatType() { | |
875 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeFilename)); | |
876 return type; | |
877 } | |
878 | |
879 // static | |
880 const Clipboard::FormatType& Clipboard::GetFilenameWFormatType() { | |
881 return Clipboard::GetFilenameFormatType(); | |
882 } | |
883 | |
884 // static | |
885 const Clipboard::FormatType& Clipboard::GetHtmlFormatType() { | |
886 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeHTML)); | |
887 return type; | |
888 } | |
889 | |
890 // static | |
891 const Clipboard::FormatType& Clipboard::GetRtfFormatType() { | |
892 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeRTF)); | |
893 return type; | |
894 } | |
895 | |
896 // static | |
897 const Clipboard::FormatType& Clipboard::GetBitmapFormatType() { | |
898 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePNG)); | |
899 return type; | |
900 } | |
901 | |
902 // static | |
903 const Clipboard::FormatType& Clipboard::GetWebKitSmartPasteFormatType() { | |
904 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebkitSmartPaste)); | |
905 return type; | |
906 } | |
907 | |
908 // static | |
909 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | |
910 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | |
911 return type; | |
912 } | |
913 | |
914 // static | |
915 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | |
916 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | |
917 return type; | |
918 } | |
919 | |
920 } // namespace ui | 937 } // namespace ui |
OLD | NEW |