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

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

Powered by Google App Engine
This is Rietveld 408576698