Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Side by Side Diff: ui/base/clipboard/clipboard_aurax11.cc

Issue 9419036: Change all platforms except Windows to access the clipboard solely from the UI thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 Clipboard::FormatType Clipboard::FormatType::Deserialize( 440 Clipboard::FormatType Clipboard::FormatType::Deserialize(
441 const std::string& serialization) { 441 const std::string& serialization) {
442 return FormatType(serialization); 442 return FormatType(serialization);
443 } 443 }
444 444
445 bool Clipboard::FormatType::Equals(const FormatType& other) const { 445 bool Clipboard::FormatType::Equals(const FormatType& other) const {
446 return data_ == other.data_; 446 return data_ == other.data_;
447 } 447 }
448 448
449 Clipboard::Clipboard() { 449 Clipboard::Clipboard() {
450 DCHECK(CalledOnValidThread());
450 // Make sure clipboard is created. 451 // Make sure clipboard is created.
451 GetClipboard(); 452 GetClipboard();
452 } 453 }
453 454
454 Clipboard::~Clipboard() { 455 Clipboard::~Clipboard() {
456 DCHECK(CalledOnValidThread());
455 DeleteClipboard(); 457 DeleteClipboard();
456 } 458 }
457 459
458 void Clipboard::WriteObjects(const ObjectMap& objects) { 460 void Clipboard::WriteObjects(const ObjectMap& objects) {
461 DCHECK(CalledOnValidThread());
459 for (ObjectMap::const_iterator iter = objects.begin(); 462 for (ObjectMap::const_iterator iter = objects.begin();
460 iter != objects.end(); ++iter) { 463 iter != objects.end(); ++iter) {
461 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 464 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
462 } 465 }
463 ClipboardDataBuilder::CommitToClipboard(); 466 ClipboardDataBuilder::CommitToClipboard();
464 } 467 }
465 468
466 bool Clipboard::IsFormatAvailable(const FormatType& format, 469 bool Clipboard::IsFormatAvailable(const FormatType& format,
467 Buffer buffer) const { 470 Buffer buffer) const {
471 DCHECK(CalledOnValidThread());
468 DCHECK(IsValidBuffer(buffer)); 472 DCHECK(IsValidBuffer(buffer));
469 AuraClipboard* clipboard = GetClipboard(); 473 AuraClipboard* clipboard = GetClipboard();
470 if (GetPlainTextFormatType().Equals(format)) 474 if (GetPlainTextFormatType().Equals(format))
471 return clipboard->IsFormatAvailable(TEXT); 475 return clipboard->IsFormatAvailable(TEXT);
472 else if (GetHtmlFormatType().Equals(format)) 476 else if (GetHtmlFormatType().Equals(format))
473 return clipboard->IsFormatAvailable(HTML); 477 return clipboard->IsFormatAvailable(HTML);
474 else if (GetBitmapFormatType().Equals(format)) 478 else if (GetBitmapFormatType().Equals(format))
475 return clipboard->IsFormatAvailable(BITMAP); 479 return clipboard->IsFormatAvailable(BITMAP);
476 else if (GetFilenameFormatType().Equals(format)) 480 else if (GetFilenameFormatType().Equals(format))
477 return clipboard->IsFormatAvailable(FILES); 481 return clipboard->IsFormatAvailable(FILES);
478 else if (GetWebKitSmartPasteFormatType().Equals(format)) 482 else if (GetWebKitSmartPasteFormatType().Equals(format))
479 return clipboard->IsFormatAvailable(WEB); 483 return clipboard->IsFormatAvailable(WEB);
480 else { 484 else {
481 const ClipboardData* data = clipboard->GetData(); 485 const ClipboardData* data = clipboard->GetData();
482 if (data && data->custom_data_format() == format.ToString()) 486 if (data && data->custom_data_format() == format.ToString())
483 return true; 487 return true;
484 } 488 }
485 return false; 489 return false;
486 } 490 }
487 491
488 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, 492 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types,
489 bool* contains_filenames) const { 493 bool* contains_filenames) const {
494 DCHECK(CalledOnValidThread());
490 if (!types || !contains_filenames) { 495 if (!types || !contains_filenames) {
491 NOTREACHED(); 496 NOTREACHED();
492 return; 497 return;
493 } 498 }
494 499
495 types->clear(); 500 types->clear();
496 *contains_filenames = false; 501 *contains_filenames = false;
497 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) 502 if (IsFormatAvailable(GetPlainTextFormatType(), buffer))
498 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString())); 503 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString()));
499 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) 504 if (IsFormatAvailable(GetHtmlFormatType(), buffer))
500 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString())); 505 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString()));
501 if (IsFormatAvailable(GetFilenameFormatType(), buffer)) { 506 if (IsFormatAvailable(GetFilenameFormatType(), buffer)) {
502 types->push_back(UTF8ToUTF16(GetFilenameFormatType().ToString())); 507 types->push_back(UTF8ToUTF16(GetFilenameFormatType().ToString()));
503 *contains_filenames = true; 508 *contains_filenames = true;
504 } 509 }
505 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) 510 if (IsFormatAvailable(GetBitmapFormatType(), buffer))
506 types->push_back(UTF8ToUTF16(GetBitmapFormatType().ToString())); 511 types->push_back(UTF8ToUTF16(GetBitmapFormatType().ToString()));
507 512
508 AuraClipboard* clipboard = GetClipboard(); 513 AuraClipboard* clipboard = GetClipboard();
509 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) { 514 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) {
510 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data(), 515 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data(),
511 clipboard->GetData()->custom_data_len(), types); 516 clipboard->GetData()->custom_data_len(), types);
512 } 517 }
513 } 518 }
514 519
515 void Clipboard::ReadText(Buffer buffer, string16* result) const { 520 void Clipboard::ReadText(Buffer buffer, string16* result) const {
521 DCHECK(CalledOnValidThread());
516 GetClipboard()->ReadText(result); 522 GetClipboard()->ReadText(result);
517 } 523 }
518 524
519 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { 525 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const {
526 DCHECK(CalledOnValidThread());
520 GetClipboard()->ReadAsciiText(result); 527 GetClipboard()->ReadAsciiText(result);
521 } 528 }
522 529
523 void Clipboard::ReadHTML(Buffer buffer, 530 void Clipboard::ReadHTML(Buffer buffer,
524 string16* markup, 531 string16* markup,
525 std::string* src_url, 532 std::string* src_url,
526 uint32* fragment_start, 533 uint32* fragment_start,
527 uint32* fragment_end) const { 534 uint32* fragment_end) const {
535 DCHECK(CalledOnValidThread());
528 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); 536 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end);
529 } 537 }
530 538
531 SkBitmap Clipboard::ReadImage(Buffer buffer) const { 539 SkBitmap Clipboard::ReadImage(Buffer buffer) const {
540 DCHECK(CalledOnValidThread());
532 return GetClipboard()->ReadImage(); 541 return GetClipboard()->ReadImage();
533 } 542 }
534 543
535 void Clipboard::ReadCustomData(Buffer buffer, 544 void Clipboard::ReadCustomData(Buffer buffer,
536 const string16& type, 545 const string16& type,
537 string16* result) const { 546 string16* result) const {
547 DCHECK(CalledOnValidThread());
538 GetClipboard()->ReadCustomData(type, result); 548 GetClipboard()->ReadCustomData(type, result);
539 } 549 }
540 550
541 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 551 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
552 DCHECK(CalledOnValidThread());
542 GetClipboard()->ReadBookmark(title, url); 553 GetClipboard()->ReadBookmark(title, url);
543 } 554 }
544 555
545 void Clipboard::ReadFile(FilePath* file) const { 556 void Clipboard::ReadFile(FilePath* file) const {
557 DCHECK(CalledOnValidThread());
546 GetClipboard()->ReadFile(file); 558 GetClipboard()->ReadFile(file);
547 } 559 }
548 560
549 void Clipboard::ReadFiles(std::vector<FilePath>* files) const { 561 void Clipboard::ReadFiles(std::vector<FilePath>* files) const {
550 GetClipboard()->ReadFiles(files); 562 GetClipboard()->ReadFiles(files);
551 } 563 }
552 564
553 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 565 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
566 DCHECK(CalledOnValidThread());
554 GetClipboard()->ReadData(format.ToString(), result); 567 GetClipboard()->ReadData(format.ToString(), result);
555 } 568 }
556 569
557 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 570 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
571 DCHECK(CalledOnValidThread());
558 return GetClipboard()->GetNumClipboardEntries(); 572 return GetClipboard()->GetNumClipboardEntries();
559 } 573 }
560 574
561 void Clipboard::WriteText(const char* text_data, size_t text_len) { 575 void Clipboard::WriteText(const char* text_data, size_t text_len) {
562 ClipboardDataBuilder::WriteText(text_data, text_len); 576 ClipboardDataBuilder::WriteText(text_data, text_len);
563 } 577 }
564 578
565 void Clipboard::WriteHTML(const char* markup_data, 579 void Clipboard::WriteHTML(const char* markup_data,
566 size_t markup_len, 580 size_t markup_len,
567 const char* url_data, 581 const char* url_data,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 return type; 650 return type;
637 } 651 }
638 652
639 // static 653 // static
640 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { 654 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() {
641 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); 655 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData));
642 return type; 656 return type;
643 } 657 }
644 658
645 } // namespace ui 659 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698