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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/metrics/histogram.h" |
12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
13 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
14 | 15 |
15 namespace ui { | 16 namespace ui { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // A compromised renderer could send us bad data, so validate it. | 20 // A compromised renderer could send us bad data, so validate it. |
20 // This function only checks that the size parameter makes sense, the caller | 21 // This function only checks that the size parameter makes sense, the caller |
21 // is responsible for further validating the bitmap buffer against | 22 // is responsible for further validating the bitmap buffer against |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 97 |
97 // The union serves to easily convert SourceTag into its binary representation | 98 // The union serves to easily convert SourceTag into its binary representation |
98 // and vice versa. | 99 // and vice versa. |
99 union SourceTag2BinaryHelper { | 100 union SourceTag2BinaryHelper { |
100 Clipboard::SourceTag tag; | 101 Clipboard::SourceTag tag; |
101 uint8 bytes[kSourceTagSize]; | 102 uint8 bytes[kSourceTagSize]; |
102 }; | 103 }; |
103 | 104 |
104 } // namespace | 105 } // namespace |
105 | 106 |
| 107 const Clipboard::SourceTag Clipboard::kInvalidSourceTag = |
| 108 reinterpret_cast<void*>(1); |
106 const char Clipboard::kMimeTypeText[] = "text/plain"; | 109 const char Clipboard::kMimeTypeText[] = "text/plain"; |
107 const char Clipboard::kMimeTypeURIList[] = "text/uri-list"; | 110 const char Clipboard::kMimeTypeURIList[] = "text/uri-list"; |
108 const char Clipboard::kMimeTypeDownloadURL[] = "downloadurl"; | 111 const char Clipboard::kMimeTypeDownloadURL[] = "downloadurl"; |
109 const char Clipboard::kMimeTypeHTML[] = "text/html"; | 112 const char Clipboard::kMimeTypeHTML[] = "text/html"; |
110 const char Clipboard::kMimeTypeRTF[] = "text/rtf"; | 113 const char Clipboard::kMimeTypeRTF[] = "text/rtf"; |
111 const char Clipboard::kMimeTypePNG[] = "image/png"; | 114 const char Clipboard::kMimeTypePNG[] = "image/png"; |
112 | 115 |
113 // static | 116 // static |
114 Clipboard::ObjectMapParam Clipboard::SourceTag2Binary(SourceTag tag) { | 117 Clipboard::ObjectMapParam Clipboard::SourceTag2Binary(SourceTag tag) { |
115 SourceTag2BinaryHelper helper; | 118 SourceTag2BinaryHelper helper; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 clipboard_map->erase(it); | 182 clipboard_map->erase(it); |
180 } | 183 } |
181 } | 184 } |
182 | 185 |
183 void Clipboard::WriteObjects(Buffer buffer, | 186 void Clipboard::WriteObjects(Buffer buffer, |
184 const ObjectMap& objects, | 187 const ObjectMap& objects, |
185 SourceTag tag) { | 188 SourceTag tag) { |
186 WriteObjectsImpl(buffer, objects, tag); | 189 WriteObjectsImpl(buffer, objects, tag); |
187 if (!write_objects_callback_.is_null()) | 190 if (!write_objects_callback_.is_null()) |
188 write_objects_callback_.Run(buffer); | 191 write_objects_callback_.Run(buffer); |
| 192 ReportAction(buffer, tag == SourceTag() ? WRITE_CLIPBOARD_NO_SOURCE_TAG |
| 193 : WRITE_CLIPBOARD_SOURCE_TAG); |
189 } | 194 } |
190 | 195 |
191 void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) { | 196 void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) { |
192 // All types apart from CBF_WEBKIT need at least 1 non-empty param. | 197 // All types apart from CBF_WEBKIT need at least 1 non-empty param. |
193 if (type != CBF_WEBKIT && (params.empty() || params[0].empty())) | 198 if (type != CBF_WEBKIT && (params.empty() || params[0].empty())) |
194 return; | 199 return; |
195 // Some other types need a non-empty 2nd param. | 200 // Some other types need a non-empty 2nd param. |
196 if ((type == CBF_BOOKMARK || type == CBF_BITMAP || | 201 if ((type == CBF_BOOKMARK || type == CBF_BITMAP || |
197 type == CBF_SMBITMAP || type == CBF_DATA) && | 202 type == CBF_SMBITMAP || type == CBF_DATA) && |
198 (params.size() != 2 || params[1].empty())) | 203 (params.size() != 2 || params[1].empty())) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 // We store the shared memory object pointer so it can be retrieved by the | 297 // We store the shared memory object pointer so it can be retrieved by the |
293 // UI thread (see DispatchObject()). | 298 // UI thread (see DispatchObject()). |
294 iter->second[0].clear(); | 299 iter->second[0].clear(); |
295 for (size_t i = 0; i < sizeof(SharedMemory*); ++i) | 300 for (size_t i = 0; i < sizeof(SharedMemory*); ++i) |
296 iter->second[0].push_back(reinterpret_cast<char*>(&bitmap)[i]); | 301 iter->second[0].push_back(reinterpret_cast<char*>(&bitmap)[i]); |
297 has_shared_bitmap = true; | 302 has_shared_bitmap = true; |
298 } | 303 } |
299 } | 304 } |
300 } | 305 } |
301 | 306 |
| 307 void Clipboard::ReportAction(Buffer buffer, TrackedAction action) const |
| 308 { |
| 309 if (buffer != BUFFER_STANDARD) |
| 310 return; |
| 311 |
| 312 switch (action) { |
| 313 case WRITE_CLIPBOARD_NO_SOURCE_TAG: |
| 314 case WRITE_CLIPBOARD_SOURCE_TAG: |
| 315 UMA_HISTOGRAM_ENUMERATION("Clipboard.IncognitoUseCase", |
| 316 action, |
| 317 MAX_TRACKED_ACTION); |
| 318 break; |
| 319 // The code below counts cases when there is the kInvalidSourceTag in the |
| 320 // clipboard. That is, original data came from Incognito window and was |
| 321 // destroyed with that window. |
| 322 case READ_TEXT: |
| 323 if (kInvalidSourceTag == ReadSourceTag(buffer)) { |
| 324 UMA_HISTOGRAM_ENUMERATION("Clipboard.IncognitoUseCase", |
| 325 action, |
| 326 MAX_TRACKED_ACTION); |
| 327 } |
| 328 break; |
| 329 case MAX_TRACKED_ACTION: |
| 330 break; |
| 331 } |
| 332 } |
| 333 |
302 } // namespace ui | 334 } // namespace ui |
OLD | NEW |