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

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: Renamed set_write_objects_callback() 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());
dcheng 2013/02/15 07:29:23 Do we need to do the same thing that we do on GTK
vasilii 2013/02/15 10:37:39 Done.
905 aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION); 910 aurax11_details_->TakeOwnershipOfSelection(BUFFER_SELECTION);
906 } 911 }
907 } 912 }
908 } 913 }
909 914
910 bool Clipboard::IsFormatAvailable(const FormatType& format, 915 bool Clipboard::IsFormatAvailable(const FormatType& format,
911 Buffer buffer) const { 916 Buffer buffer) const {
912 DCHECK(CalledOnValidThread()); 917 DCHECK(CalledOnValidThread());
913 DCHECK(IsValidBuffer(buffer)); 918 DCHECK(IsValidBuffer(buffer));
914 919
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 ReadCustomDataForType(data->data(), data->size(), type, result); 1046 ReadCustomDataForType(data->data(), data->size(), type, result);
1042 } 1047 }
1043 1048
1044 void Clipboard::ReadBookmark(string16* title, std::string* url) const { 1049 void Clipboard::ReadBookmark(string16* title, std::string* url) const {
1045 DCHECK(CalledOnValidThread()); 1050 DCHECK(CalledOnValidThread());
1046 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too. 1051 // TODO(erg): This was left NOTIMPLEMENTED() in the gtk port too.
1047 NOTIMPLEMENTED(); 1052 NOTIMPLEMENTED();
1048 } 1053 }
1049 1054
1050 void Clipboard::ReadData(const FormatType& format, std::string* result) const { 1055 void Clipboard::ReadData(const FormatType& format, std::string* result) const {
1056 ReadDataImpl(BUFFER_STANDARD, format, result);
1057 }
1058
1059 void Clipboard::ReadDataImpl(Buffer buffer,
1060 const FormatType& format,
1061 std::string* result) const {
1051 DCHECK(CalledOnValidThread()); 1062 DCHECK(CalledOnValidThread());
1052 1063
1053 scoped_ptr<SelectionData> data(aurax11_details_->RequestAndWaitForTypes( 1064 scoped_ptr<SelectionData> data(aurax11_details_->RequestAndWaitForTypes(
1054 BUFFER_STANDARD, aurax11_details_->GetAtomsForFormat(format))); 1065 buffer, aurax11_details_->GetAtomsForFormat(format)));
1055 if (data.get()) 1066 if (data.get())
1056 data->AssignTo(result); 1067 data->AssignTo(result);
1057 } 1068 }
1058 1069
1070 Clipboard::SourceTag Clipboard::ReadSourceTag(Buffer buffer) const {
1071 std::string result;
1072 ReadDataImpl(buffer, GetSourceTagFormatType(), &result);
1073 return Binary2SourceTag(result);
1074 }
1075
1059 uint64 Clipboard::GetSequenceNumber(Buffer buffer) { 1076 uint64 Clipboard::GetSequenceNumber(Buffer buffer) {
1060 DCHECK(CalledOnValidThread()); 1077 DCHECK(CalledOnValidThread());
1061 if (buffer == BUFFER_STANDARD) 1078 if (buffer == BUFFER_STANDARD)
1062 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number(); 1079 return SelectionChangeObserver::GetInstance()->clipboard_sequence_number();
1063 else 1080 else
1064 return SelectionChangeObserver::GetInstance()->primary_sequence_number(); 1081 return SelectionChangeObserver::GetInstance()->primary_sequence_number();
1065 } 1082 }
1066 1083
1067 void Clipboard::WriteText(const char* text_data, size_t text_len) { 1084 void Clipboard::WriteText(const char* text_data, size_t text_len) {
1068 char* data = new char[text_len]; 1085 char* data = new char[text_len];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 size_t data_len) { 1147 size_t data_len) {
1131 // We assume that certain mapping types are only written by trusted code. 1148 // We assume that certain mapping types are only written by trusted code.
1132 // Therefore we must upkeep their integrity. 1149 // Therefore we must upkeep their integrity.
1133 if (format.Equals(GetBitmapFormatType())) 1150 if (format.Equals(GetBitmapFormatType()))
1134 return; 1151 return;
1135 char* data = new char[data_len]; 1152 char* data = new char[data_len];
1136 memcpy(data, data_data, data_len); 1153 memcpy(data, data_data, data_len);
1137 aurax11_details_->InsertMapping(format.ToString(), data, data_len); 1154 aurax11_details_->InsertMapping(format.ToString(), data, data_len);
1138 } 1155 }
1139 1156
1157 void Clipboard::WriteSourceTag(SourceTag tag) {
1158 if (tag != SourceTag()) {
1159 ObjectMapParam binary = SourceTag2Binary(tag);
1160 WriteData(GetSourceTagFormatType(), &binary[0], binary.size());
1161 }
1162 }
1163
1140 // static 1164 // static
1141 Clipboard::FormatType Clipboard::GetFormatType( 1165 Clipboard::FormatType Clipboard::GetFormatType(
1142 const std::string& format_string) { 1166 const std::string& format_string) {
1143 return FormatType::Deserialize(format_string); 1167 return FormatType::Deserialize(format_string);
1144 } 1168 }
1145 1169
1146 // static 1170 // static
1147 const Clipboard::FormatType& Clipboard::GetUrlFormatType() { 1171 const Clipboard::FormatType& Clipboard::GetUrlFormatType() {
1148 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList)); 1172 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeURIList));
1149 return type; 1173 return type;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData)); 1229 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypeWebCustomData));
1206 return type; 1230 return type;
1207 } 1231 }
1208 1232
1209 // static 1233 // static
1210 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 1234 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
1211 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 1235 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
1212 return type; 1236 return type;
1213 } 1237 }
1214 1238
1239 // static
1240 const Clipboard::FormatType& Clipboard::GetSourceTagFormatType() {
1241 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kSourceTagType));
1242 return type;
1243 }
1244
1215 } // namespace ui 1245 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698