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

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

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed includes + style changes Created 7 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
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 16 matching lines...) Expand all
27 27
28 // Clipboard data format used by AuraClipboard. 28 // Clipboard data format used by AuraClipboard.
29 enum AuraClipboardFormat { 29 enum AuraClipboardFormat {
30 TEXT = 1 << 0, 30 TEXT = 1 << 0,
31 HTML = 1 << 1, 31 HTML = 1 << 1,
32 RTF = 1 << 2, 32 RTF = 1 << 2,
33 BOOKMARK = 1 << 3, 33 BOOKMARK = 1 << 3,
34 BITMAP = 1 << 4, 34 BITMAP = 1 << 4,
35 CUSTOM = 1 << 5, 35 CUSTOM = 1 << 5,
36 WEB = 1 << 6, 36 WEB = 1 << 6,
37 SOURCETAG = 1 << 7,
37 }; 38 };
38 39
39 // ClipboardData contains data copied to the Clipboard for a variety of formats. 40 // ClipboardData contains data copied to the Clipboard for a variety of formats.
40 // It mostly just provides APIs to cleanly access and manipulate this data. 41 // It mostly just provides APIs to cleanly access and manipulate this data.
41 class ClipboardData { 42 class ClipboardData {
42 public: 43 public:
43 ClipboardData() 44 ClipboardData()
44 : bitmap_data_(), 45 : bitmap_data_(),
46 source_tag_(),
45 web_smart_paste_(false), 47 web_smart_paste_(false),
46 format_(0) {} 48 format_(0) {}
47 49
48 virtual ~ClipboardData() {} 50 virtual ~ClipboardData() {}
49 51
50 // Bitmask of AuraClipboardFormat types. 52 // Bitmask of AuraClipboardFormat types.
51 const int format() const { return format_; } 53 const int format() const { return format_; }
52 54
53 const std::string& text() const { return text_; } 55 const std::string& text() const { return text_; }
54 void set_text(const std::string& text) { 56 void set_text(const std::string& text) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 custom_data_format_ = data_format; 113 custom_data_format_ = data_format;
112 format_ |= CUSTOM; 114 format_ |= CUSTOM;
113 } 115 }
114 116
115 bool web_smart_paste() const { return web_smart_paste_; } 117 bool web_smart_paste() const { return web_smart_paste_; }
116 void set_web_smart_paste(bool web_smart_paste) { 118 void set_web_smart_paste(bool web_smart_paste) {
117 web_smart_paste_ = web_smart_paste; 119 web_smart_paste_ = web_smart_paste;
118 format_ |= WEB; 120 format_ |= WEB;
119 } 121 }
120 122
123 Clipboard::SourceTag source_tag() const { return source_tag_; }
124 void set_source_tag(Clipboard::SourceTag tag) {
125 source_tag_ = tag;
126 format_ |= SOURCETAG;
127 }
128
121 private: 129 private:
122 // Plain text in UTF8 format. 130 // Plain text in UTF8 format.
123 std::string text_; 131 std::string text_;
124 132
125 // HTML markup data in UTF8 format. 133 // HTML markup data in UTF8 format.
126 std::string markup_data_; 134 std::string markup_data_;
127 std::string url_; 135 std::string url_;
128 136
129 // RTF data. 137 // RTF data.
130 std::string rtf_data_; 138 std::string rtf_data_;
131 139
132 // Bookmark title in UTF8 format. 140 // Bookmark title in UTF8 format.
133 std::string bookmark_title_; 141 std::string bookmark_title_;
134 std::string bookmark_url_; 142 std::string bookmark_url_;
135 143
136 // Filenames. 144 // Filenames.
137 std::vector<std::string> files_; 145 std::vector<std::string> files_;
138 146
139 // Bitmap images. 147 // Bitmap images.
140 scoped_ptr<uint8_t[]> bitmap_data_; 148 scoped_ptr<uint8_t[]> bitmap_data_;
141 gfx::Size bitmap_size_; 149 gfx::Size bitmap_size_;
142 150
143 // Data with custom format. 151 // Data with custom format.
144 std::string custom_data_format_; 152 std::string custom_data_format_;
145 std::string custom_data_data_; 153 std::string custom_data_data_;
146 154
155 // SourceTag.
156 Clipboard::SourceTag source_tag_;
157
147 // WebKit smart paste data. 158 // WebKit smart paste data.
148 bool web_smart_paste_; 159 bool web_smart_paste_;
149 160
150 int format_; 161 int format_;
151 162
152 DISALLOW_COPY_AND_ASSIGN(ClipboardData); 163 DISALLOW_COPY_AND_ASSIGN(ClipboardData);
153 }; 164 };
154 165
155 // Platform clipboard implementation for Aura. This handles things like format 166 // Platform clipboard implementation for Aura. This handles things like format
156 // conversion, versioning of clipboard items etc. The goal is to roughly provide 167 // conversion, versioning of clipboard items etc. The goal is to roughly provide
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 300
290 void ReadData(const std::string& type, std::string* result) const { 301 void ReadData(const std::string& type, std::string* result) const {
291 result->clear(); 302 result->clear();
292 const ClipboardData* data = GetData(); 303 const ClipboardData* data = GetData();
293 if (!HasFormat(CUSTOM) || type != data->custom_data_format()) 304 if (!HasFormat(CUSTOM) || type != data->custom_data_format())
294 return; 305 return;
295 306
296 *result = data->custom_data_data(); 307 *result = data->custom_data_data();
297 } 308 }
298 309
310 Clipboard::SourceTag ReadSourceTag() const {
311 if (!HasFormat(SOURCETAG))
312 return Clipboard::SourceTag();
313 const ClipboardData* data = GetData();
314 return data->source_tag();
315 }
316
299 // Writes |data| to the top of the clipboard stack. 317 // Writes |data| to the top of the clipboard stack.
300 void WriteData(ClipboardData* data) { 318 void WriteData(ClipboardData* data) {
301 DCHECK(data); 319 DCHECK(data);
302 AddToListEnsuringSize(data); 320 AddToListEnsuringSize(data);
303 } 321 }
304 322
305 private: 323 private:
306 // True if the data on top of the clipboard stack has format |format|. 324 // True if the data on top of the clipboard stack has format |format|.
307 bool HasFormat(AuraClipboardFormat format) const { 325 bool HasFormat(AuraClipboardFormat format) const {
308 const ClipboardData* data = GetData(); 326 const ClipboardData* data = GetData();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 data->SetBitmapData(pixel_data, size_data); 410 data->SetBitmapData(pixel_data, size_data);
393 } 411 }
394 412
395 static void WriteData(const std::string& format, 413 static void WriteData(const std::string& format,
396 const char* data_data, 414 const char* data_data,
397 size_t data_len) { 415 size_t data_len) {
398 ClipboardData* data = GetCurrentData(); 416 ClipboardData* data = GetCurrentData();
399 data->SetCustomData(format, std::string(data_data, data_len)); 417 data->SetCustomData(format, std::string(data_data, data_len));
400 } 418 }
401 419
420 static void WriteSourceTag(Clipboard::SourceTag tag) {
421 ClipboardData* data = GetCurrentData();
422 data->set_source_tag(tag);
423 }
424
402 private: 425 private:
403 static ClipboardData* GetCurrentData() { 426 static ClipboardData* GetCurrentData() {
404 if (!current_data_) 427 if (!current_data_)
405 current_data_ = new ClipboardData; 428 current_data_ = new ClipboardData;
406 return current_data_; 429 return current_data_;
407 } 430 }
408 431
409 static ClipboardData* current_data_; 432 static ClipboardData* current_data_;
410 }; 433 };
411 434
(...skipping 29 matching lines...) Expand all
441 DCHECK(CalledOnValidThread()); 464 DCHECK(CalledOnValidThread());
442 // Make sure clipboard is created. 465 // Make sure clipboard is created.
443 GetClipboard(); 466 GetClipboard();
444 } 467 }
445 468
446 Clipboard::~Clipboard() { 469 Clipboard::~Clipboard() {
447 DCHECK(CalledOnValidThread()); 470 DCHECK(CalledOnValidThread());
448 DeleteClipboard(); 471 DeleteClipboard();
449 } 472 }
450 473
451 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { 474 void Clipboard::WriteObjectsImpl(Buffer buffer,
475 const ObjectMap& objects,
476 SourceTag tag) {
452 DCHECK(CalledOnValidThread()); 477 DCHECK(CalledOnValidThread());
453 DCHECK(IsValidBuffer(buffer)); 478 DCHECK(IsValidBuffer(buffer));
454 for (ObjectMap::const_iterator iter = objects.begin(); 479 for (ObjectMap::const_iterator iter = objects.begin();
455 iter != objects.end(); ++iter) { 480 iter != objects.end(); ++iter) {
456 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 481 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
457 } 482 }
483 WriteSourceTag(tag);
458 ClipboardDataBuilder::CommitToClipboard(); 484 ClipboardDataBuilder::CommitToClipboard();
459 } 485 }
460 486
461 bool Clipboard::IsFormatAvailable(const FormatType& format, 487 bool Clipboard::IsFormatAvailable(const FormatType& format,
462 Buffer buffer) const { 488 Buffer buffer) const {
463 DCHECK(CalledOnValidThread()); 489 DCHECK(CalledOnValidThread());
464 DCHECK(IsValidBuffer(buffer)); 490 DCHECK(IsValidBuffer(buffer));
465 AuraClipboard* clipboard = GetClipboard(); 491 AuraClipboard* clipboard = GetClipboard();
466 if (GetPlainTextFormatType().Equals(format) || 492 if (GetPlainTextFormatType().Equals(format) ||
467 GetUrlFormatType().Equals(format)) 493 GetUrlFormatType().Equals(format))
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 580 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
555 DCHECK(CalledOnValidThread()); 581 DCHECK(CalledOnValidThread());
556 GetClipboard()->ReadBookmark(title, url); 582 GetClipboard()->ReadBookmark(title, url);
557 } 583 }
558 584
559 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 585 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
560 DCHECK(CalledOnValidThread()); 586 DCHECK(CalledOnValidThread());
561 GetClipboard()->ReadData(format.ToString(), result); 587 GetClipboard()->ReadData(format.ToString(), result);
562 } 588 }
563 589
590 Clipboard::SourceTag Clipboard::ReadSourceTag() const {
dcheng 2013/02/06 22:31:40 Can we just use ReadData() and WriteData() like th
vasilii 2013/02/07 17:30:05 Unfortunately no. ClipboardData has an explicit me
dcheng 2013/02/08 05:42:19 ... yikes. That's a bug. This is fine for now, but
591 DCHECK(CalledOnValidThread());
592 return GetClipboard()->ReadSourceTag();
593 }
594
564 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 595 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
565 DCHECK(CalledOnValidThread()); 596 DCHECK(CalledOnValidThread());
566 return GetClipboard()->GetNumClipboardEntries(); 597 return GetClipboard()->GetNumClipboardEntries();
567 } 598 }
568 599
569 void Clipboard::WriteText(const char* text_data, size_t text_len) { 600 void Clipboard::WriteText(const char* text_data, size_t text_len) {
570 ClipboardDataBuilder::WriteText(text_data, text_len); 601 ClipboardDataBuilder::WriteText(text_data, text_len);
571 } 602 }
572 603
573 void Clipboard::WriteHTML(const char* markup_data, 604 void Clipboard::WriteHTML(const char* markup_data,
(...skipping 21 matching lines...) Expand all
595 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) { 626 void Clipboard::WriteBitmap(const char* pixel_data, const char* size_data) {
596 ClipboardDataBuilder::WriteBitmap(pixel_data, size_data); 627 ClipboardDataBuilder::WriteBitmap(pixel_data, size_data);
597 } 628 }
598 629
599 void Clipboard::WriteData(const FormatType& format, 630 void Clipboard::WriteData(const FormatType& format,
600 const char* data_data, 631 const char* data_data,
601 size_t data_len) { 632 size_t data_len) {
602 ClipboardDataBuilder::WriteData(format.ToString(), data_data, data_len); 633 ClipboardDataBuilder::WriteData(format.ToString(), data_data, data_len);
603 } 634 }
604 635
636 void Clipboard::WriteSourceTag(SourceTag tag) {
637 if (tag != SourceTag())
638 ClipboardDataBuilder::WriteSourceTag(tag);
639 }
640
605 // static 641 // static
606 Clipboard::FormatType Clipboard::GetFormatType( 642 Clipboard::FormatType Clipboard::GetFormatType(
607 const std::string& format_string) { 643 const std::string& format_string) {
608 return FormatType::Deserialize(format_string); 644 return FormatType::Deserialize(format_string);
609 } 645 }
610 646
611 // static 647 // static
612 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { 648 const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
613 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); 649 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList));
614 return type; 650 return type;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 return type; 707 return type;
672 } 708 }
673 709
674 // static 710 // static
675 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 711 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
676 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 712 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
677 return type; 713 return type;
678 } 714 }
679 715
680 } // namespace ui 716 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698