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

Side by Side Diff: ui/base/clipboard/clipboard_aurax11.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 <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>
(...skipping 21 matching lines...) Expand all
32 namespace { 32 namespace {
33 33
34 const char kChromeSelection[] = "CHROME_SELECTION"; 34 const char kChromeSelection[] = "CHROME_SELECTION";
35 const char kClipboard[] = "CLIPBOARD"; 35 const char kClipboard[] = "CLIPBOARD";
36 const char kMimeTypeBitmap[] = "image/bmp"; 36 const char kMimeTypeBitmap[] = "image/bmp";
37 const char kMimeTypeFilename[] = "chromium/filename"; 37 const char kMimeTypeFilename[] = "chromium/filename";
38 const char kMimeTypeMozillaURL[] = "text/x-moz-url"; 38 const char kMimeTypeMozillaURL[] = "text/x-moz-url";
39 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; 39 const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data";
40 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; 40 const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste";
41 const char kMultiple[] = "MULTIPLE"; 41 const char kMultiple[] = "MULTIPLE";
42 const char kSourceTagType[] = "org.chromium.source-tag";
42 const char kString[] = "STRING"; 43 const char kString[] = "STRING";
43 const char kTargets[] = "TARGETS"; 44 const char kTargets[] = "TARGETS";
44 const char kText[] = "TEXT"; 45 const char kText[] = "TEXT";
45 const char kUtf8String[] = "UTF8_STRING"; 46 const char kUtf8String[] = "UTF8_STRING";
46 47
47 const char* kAtomsToCache[] = { 48 const char* kAtomsToCache[] = {
48 kChromeSelection, 49 kChromeSelection,
49 kClipboard, 50 kClipboard,
50 kMimeTypeBitmap, 51 kMimeTypeBitmap,
51 kMimeTypeFilename, 52 kMimeTypeFilename,
52 kMimeTypeMozillaURL, 53 kMimeTypeMozillaURL,
53 kMimeTypeWebkitSmartPaste, 54 kMimeTypeWebkitSmartPaste,
54 kMultiple, 55 kMultiple,
56 kSourceTagType,
55 kString, 57 kString,
56 kTargets, 58 kTargets,
57 kText, 59 kText,
58 kUtf8String, 60 kUtf8String,
59 NULL 61 NULL
60 }; 62 };
61 63
62 /////////////////////////////////////////////////////////////////////////////// 64 ///////////////////////////////////////////////////////////////////////////////
63 65
64 // Returns a list of all text atoms that we handle. 66 // Returns a list of all text atoms that we handle.
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 } 880 }
879 881
880 Clipboard::~Clipboard() { 882 Clipboard::~Clipboard() {
881 DCHECK(CalledOnValidThread()); 883 DCHECK(CalledOnValidThread());
882 884
883 // TODO(erg): We need to do whatever the equivalent of 885 // TODO(erg): We need to do whatever the equivalent of
884 // gtk_clipboard_store(clipboard_) is here. When we shut down, we want the 886 // gtk_clipboard_store(clipboard_) is here. When we shut down, we want the
885 // current selection to live on. 887 // current selection to live on.
886 } 888 }
887 889
888 void Clipboard::WriteObjects(Buffer buffer, const ObjectMap& objects) { 890 void Clipboard::WriteObjectsImpl(Buffer buffer,
891 const ObjectMap& objects,
892 SourceTag tag) {
889 DCHECK(CalledOnValidThread()); 893 DCHECK(CalledOnValidThread());
890 DCHECK(IsValidBuffer(buffer)); 894 DCHECK(IsValidBuffer(buffer));
891 895
892 aurax11_details_->CreateNewClipboardData(); 896 aurax11_details_->CreateNewClipboardData();
893 for (ObjectMap::const_iterator iter = objects.begin(); 897 for (ObjectMap::const_iterator iter = objects.begin();
894 iter != objects.end(); ++iter) { 898 iter != objects.end(); ++iter) {
895 DispatchObject(static_cast<ObjectType>(iter->first), iter->second); 899 DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
896 } 900 }
901 WriteSourceTag(tag);
897 aurax11_details_->TakeOwnershipOfSelection(buffer); 902 aurax11_details_->TakeOwnershipOfSelection(buffer);
898 903
899 if (buffer == BUFFER_STANDARD) { 904 if (buffer == BUFFER_STANDARD) {
900 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT); 905 ObjectMap::const_iterator text_iter = objects.find(CBF_TEXT);
901 if (text_iter != objects.end()) { 906 if (text_iter != objects.end()) {
902 aurax11_details_->CreateNewClipboardData(); 907 aurax11_details_->CreateNewClipboardData();
903 const ObjectMapParam& char_vector = text_iter->second[0]; 908 const ObjectMapParam& char_vector = text_iter->second[0];
904 WriteText(&char_vector.front(), char_vector.size()); 909 WriteText(&char_vector.front(), char_vector.size());
905 aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION); 910 aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION);
906 } 911 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1054
1050 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 1055 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
1051 DCHECK(CalledOnValidThread()); 1056 DCHECK(CalledOnValidThread());
1052 1057
1053 scoped_ptr<SelectionData> data(aurax11_details_->RequestAndWaitForTypes( 1058 scoped_ptr<SelectionData> data(aurax11_details_->RequestAndWaitForTypes(
1054 BUFFER_STANDARD, aurax11_details_->GetAtomsForFormat(format))); 1059 BUFFER_STANDARD, aurax11_details_->GetAtomsForFormat(format)));
1055 if (data.get()) 1060 if (data.get())
1056 data->AssignTo(result); 1061 data->AssignTo(result);
1057 } 1062 }
1058 1063
1064 Clipboard::SourceTag Clipboard::ReadSourceTag() const {
1065 std::string result;
1066 ReadData(GetSourceTagFormatType(), &result);
1067 return Binary2SourceTag(result);
1068 }
1069
1059 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 1070 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
1060 DCHECK(CalledOnValidThread()); 1071 DCHECK(CalledOnValidThread());
1061 if (buffer == BUFFER_STANDARD) 1072 if (buffer == BUFFER_STANDARD)
1062 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); 1073 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number();
1063 else 1074 else
1064 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); 1075 return SelectionChangeObserver::GetInstance()->primary_sequence_number();
1065 } 1076 }
1066 1077
1067 void Clipboard::WriteText(const char* text_data, size_t text_len) { 1078 void Clipboard::WriteText(const char* text_data, size_t text_len) {
1068 char* data = new char[text_len]; 1079 char* data = new char[text_len];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 size_t data_len) { 1141 size_t data_len) {
1131 // We assume that certain mapping types are only written by trusted code. 1142 // We assume that certain mapping types are only written by trusted code.
1132 // Therefore we must upkeep their integrity. 1143 // Therefore we must upkeep their integrity.
1133 if (format.Equals(GetBitmapFormatType())) 1144 if (format.Equals(GetBitmapFormatType()))
1134 return; 1145 return;
1135 char* data = new char[data_len]; 1146 char* data = new char[data_len];
1136 memcpy(data, data_data, data_len); 1147 memcpy(data, data_data, data_len);
1137 aurax11_details_->InsertMapping(format.ToString(), data, data_len); 1148 aurax11_details_->InsertMapping(format.ToString(), data, data_len);
1138 } 1149 }
1139 1150
1151 void Clipboard::WriteSourceTag(SourceTag tag) {
1152 if (tag != SourceTag()) {
1153 ObjectMapParam binary = SourceTag2Binary(tag);
1154 WriteData(GetSourceTagFormatType(), &binary[0], binary.size());
1155 }
1156 }
1157
1140 // static 1158 // static
1141 Clipboard::FormatType Clipboard::GetFormatType( 1159 Clipboard::FormatType Clipboard::GetFormatType(
1142 const std::string& format_string) { 1160 const std::string& format_string) {
1143 return FormatType::Deserialize(format_string); 1161 return FormatType::Deserialize(format_string);
1144 } 1162 }
1145 1163
1146 // static 1164 // static
1147 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { 1165 const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
1148 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); 1166 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList));
1149 return type; 1167 return type;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); 1223 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData));
1206 return type; 1224 return type;
1207 } 1225 }
1208 1226
1209 // static 1227 // static
1210 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 1228 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
1211 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 1229 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
1212 return type; 1230 return type;
1213 } 1231 }
1214 1232
1233 // static
1234 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() {
1235 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagType));
1236 return type;
1237 }
1238
1215 } // namespace ui 1239 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698