| 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.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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 Clipboard::FormatType Clipboard::FormatType::Deserialize( | 409 Clipboard::FormatType Clipboard::FormatType::Deserialize( |
| 410 const std::string& serialization) { | 410 const std::string& serialization) { |
| 411 return FormatType(serialization); | 411 return FormatType(serialization); |
| 412 } | 412 } |
| 413 | 413 |
| 414 bool Clipboard::FormatType::Equals(const FormatType& other) const { | 414 bool Clipboard::FormatType::Equals(const FormatType& other) const { |
| 415 return data_ == other.data_; | 415 return data_ == other.data_; |
| 416 } | 416 } |
| 417 | 417 |
| 418 Clipboard::Clipboard() { | 418 Clipboard::Clipboard() { |
| 419 DCHECK(CalledOnValidThread()); |
| 419 // Make sure clipboard is created. | 420 // Make sure clipboard is created. |
| 420 GetClipboard(); | 421 GetClipboard(); |
| 421 } | 422 } |
| 422 | 423 |
| 423 Clipboard::~Clipboard() { | 424 Clipboard::~Clipboard() { |
| 425 DCHECK(CalledOnValidThread()); |
| 424 DeleteClipboard(); | 426 DeleteClipboard(); |
| 425 } | 427 } |
| 426 | 428 |
| 427 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { | 429 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { |
| 430 DCHECK(CalledOnValidThread()); |
| 428 DCHECK(IsValidBuffer(buffer)); | 431 DCHECK(IsValidBuffer(buffer)); |
| 429 for (ObjectMap::const_iterator iter = objects.begin(); | 432 for (ObjectMap::const_iterator iter = objects.begin(); |
| 430 iter != objects.end(); ++iter) { | 433 iter != objects.end(); ++iter) { |
| 431 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); | 434 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); |
| 432 } | 435 } |
| 433 ClipboardDataBuilder::CommitToClipboard(); | 436 ClipboardDataBuilder::CommitToClipboard(); |
| 434 } | 437 } |
| 435 | 438 |
| 436 bool Clipboard::IsFormatAvailable(const FormatType& format, | 439 bool Clipboard::IsFormatAvailable(const FormatType& format, |
| 437 Buffer buffer) const { | 440 Buffer buffer) const { |
| 441 DCHECK(CalledOnValidThread()); |
| 438 DCHECK(IsValidBuffer(buffer)); | 442 DCHECK(IsValidBuffer(buffer)); |
| 439 AuraClipboard* clipboard = GetClipboard(); | 443 AuraClipboard* clipboard = GetClipboard(); |
| 440 if (GetPlainTextFormatType().Equals(format)) | 444 if (GetPlainTextFormatType().Equals(format)) |
| 441 return clipboard->IsFormatAvailable(TEXT); | 445 return clipboard->IsFormatAvailable(TEXT); |
| 442 else if (GetHtmlFormatType().Equals(format)) | 446 else if (GetHtmlFormatType().Equals(format)) |
| 443 return clipboard->IsFormatAvailable(HTML); | 447 return clipboard->IsFormatAvailable(HTML); |
| 444 else if (GetBitmapFormatType().Equals(format)) | 448 else if (GetBitmapFormatType().Equals(format)) |
| 445 return clipboard->IsFormatAvailable(BITMAP); | 449 return clipboard->IsFormatAvailable(BITMAP); |
| 446 else if (GetWebKitSmartPasteFormatType().Equals(format)) | 450 else if (GetWebKitSmartPasteFormatType().Equals(format)) |
| 447 return clipboard->IsFormatAvailable(WEB); | 451 return clipboard->IsFormatAvailable(WEB); |
| 448 else { | 452 else { |
| 449 const ClipboardData* data = clipboard->GetData(); | 453 const ClipboardData* data = clipboard->GetData(); |
| 450 if (data && data->custom_data_format() == format.ToString()) | 454 if (data && data->custom_data_format() == format.ToString()) |
| 451 return true; | 455 return true; |
| 452 } | 456 } |
| 453 return false; | 457 return false; |
| 454 } | 458 } |
| 455 | 459 |
| 456 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, | 460 void Clipboard::ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, |
| 457 bool* contains_filenames) const { | 461 bool* contains_filenames) const { |
| 462 DCHECK(CalledOnValidThread()); |
| 458 if (!types || !contains_filenames) { | 463 if (!types || !contains_filenames) { |
| 459 NOTREACHED(); | 464 NOTREACHED(); |
| 460 return; | 465 return; |
| 461 } | 466 } |
| 462 | 467 |
| 463 types->clear(); | 468 types->clear(); |
| 464 *contains_filenames = false; | 469 *contains_filenames = false; |
| 465 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) | 470 if (IsFormatAvailable(GetPlainTextFormatType(), buffer)) |
| 466 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString())); | 471 types->push_back(UTF8ToUTF16(GetPlainTextFormatType().ToString())); |
| 467 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) | 472 if (IsFormatAvailable(GetHtmlFormatType(), buffer)) |
| 468 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString())); | 473 types->push_back(UTF8ToUTF16(GetHtmlFormatType().ToString())); |
| 469 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) | 474 if (IsFormatAvailable(GetBitmapFormatType(), buffer)) |
| 470 types->push_back(UTF8ToUTF16(GetBitmapFormatType().ToString())); | 475 types->push_back(UTF8ToUTF16(GetBitmapFormatType().ToString())); |
| 471 | 476 |
| 472 AuraClipboard* clipboard = GetClipboard(); | 477 AuraClipboard* clipboard = GetClipboard(); |
| 473 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) { | 478 if (clipboard->IsFormatAvailable(CUSTOM) && clipboard->GetData()) { |
| 474 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data(), | 479 ui::ReadCustomDataTypes(clipboard->GetData()->custom_data_data(), |
| 475 clipboard->GetData()->custom_data_len(), types); | 480 clipboard->GetData()->custom_data_len(), types); |
| 476 } | 481 } |
| 477 } | 482 } |
| 478 | 483 |
| 479 void Clipboard::ReadText(Buffer buffer, string16* result) const { | 484 void Clipboard::ReadText(Buffer buffer, string16* result) const { |
| 485 DCHECK(CalledOnValidThread()); |
| 480 GetClipboard()->ReadText(result); | 486 GetClipboard()->ReadText(result); |
| 481 } | 487 } |
| 482 | 488 |
| 483 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { | 489 void Clipboard::ReadAsciiText(Buffer buffer, std::string* result) const { |
| 490 DCHECK(CalledOnValidThread()); |
| 484 GetClipboard()->ReadAsciiText(result); | 491 GetClipboard()->ReadAsciiText(result); |
| 485 } | 492 } |
| 486 | 493 |
| 487 void Clipboard::ReadHTML(Buffer buffer, | 494 void Clipboard::ReadHTML(Buffer buffer, |
| 488 string16* markup, | 495 string16* markup, |
| 489 std::string* src_url, | 496 std::string* src_url, |
| 490 uint32* fragment_start, | 497 uint32* fragment_start, |
| 491 uint32* fragment_end) const { | 498 uint32* fragment_end) const { |
| 499 DCHECK(CalledOnValidThread()); |
| 492 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); | 500 GetClipboard()->ReadHTML(markup, src_url, fragment_start, fragment_end); |
| 493 } | 501 } |
| 494 | 502 |
| 495 SkBitmap Clipboard::ReadImage(Buffer buffer) const { | 503 SkBitmap Clipboard::ReadImage(Buffer buffer) const { |
| 504 DCHECK(CalledOnValidThread()); |
| 496 return GetClipboard()->ReadImage(); | 505 return GetClipboard()->ReadImage(); |
| 497 } | 506 } |
| 498 | 507 |
| 499 void Clipboard::ReadCustomData(Buffer buffer, | 508 void Clipboard::ReadCustomData(Buffer buffer, |
| 500 const string16& type, | 509 const string16& type, |
| 501 string16* result) const { | 510 string16* result) const { |
| 511 DCHECK(CalledOnValidThread()); |
| 502 GetClipboard()->ReadCustomData(type, result); | 512 GetClipboard()->ReadCustomData(type, result); |
| 503 } | 513 } |
| 504 | 514 |
| 505 void Clipboard::ReadBookmark(string16* title, std::string* url) const { | 515 void Clipboard::ReadBookmark(string16* title, std::string* url) const { |
| 516 DCHECK(CalledOnValidThread()); |
| 506 GetClipboard()->ReadBookmark(title, url); | 517 GetClipboard()->ReadBookmark(title, url); |
| 507 } | 518 } |
| 508 | 519 |
| 509 void Clipboard::ReadData(const FormatType& format, std::string* result) const { | 520 void Clipboard::ReadData(const FormatType& format, std::string* result) const { |
| 521 DCHECK(CalledOnValidThread()); |
| 510 GetClipboard()->ReadData(format.ToString(), result); | 522 GetClipboard()->ReadData(format.ToString(), result); |
| 511 } | 523 } |
| 512 | 524 |
| 513 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { | 525 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { |
| 526 DCHECK(CalledOnValidThread()); |
| 514 return GetClipboard()->GetNumClipboardEntries(); | 527 return GetClipboard()->GetNumClipboardEntries(); |
| 515 } | 528 } |
| 516 | 529 |
| 517 void Clipboard::WriteText(const char* text_data, size_t text_len) { | 530 void Clipboard::WriteText(const char* text_data, size_t text_len) { |
| 518 ClipboardDataBuilder::WriteText(text_data, text_len); | 531 ClipboardDataBuilder::WriteText(text_data, text_len); |
| 519 } | 532 } |
| 520 | 533 |
| 521 void Clipboard::WriteHTML(const char* markup_data, | 534 void Clipboard::WriteHTML(const char* markup_data, |
| 522 size_t markup_len, | 535 size_t markup_len, |
| 523 const char* url_data, | 536 const char* url_data, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 return type; | 605 return type; |
| 593 } | 606 } |
| 594 | 607 |
| 595 // static | 608 // static |
| 596 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { | 609 const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { |
| 597 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); | 610 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); |
| 598 return type; | 611 return type; |
| 599 } | 612 } |
| 600 | 613 |
| 601 } // namespace ui | 614 } // namespace ui |
| OLD | NEW |