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 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 5 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 28 matching lines...) Expand all Loading... |
39 typedef struct _GtkClipboard GtkClipboard; | 39 typedef struct _GtkClipboard GtkClipboard; |
40 #endif | 40 #endif |
41 | 41 |
42 #ifdef __OBJC__ | 42 #ifdef __OBJC__ |
43 @class NSString; | 43 @class NSString; |
44 #else | 44 #else |
45 class NSString; | 45 class NSString; |
46 #endif | 46 #endif |
47 | 47 |
48 namespace ui { | 48 namespace ui { |
| 49 class ClipboardTest; |
49 | 50 |
50 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { | 51 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
51 public: | 52 public: |
52 // MIME type constants. | 53 // MIME type constants. |
53 static const char kMimeTypeText[]; | 54 static const char kMimeTypeText[]; |
54 static const char kMimeTypeURIList[]; | 55 static const char kMimeTypeURIList[]; |
55 static const char kMimeTypeDownloadURL[]; | 56 static const char kMimeTypeDownloadURL[]; |
56 static const char kMimeTypeHTML[]; | 57 static const char kMimeTypeHTML[]; |
57 static const char kMimeTypeRTF[]; | 58 static const char kMimeTypeRTF[]; |
58 static const char kMimeTypePNG[]; | 59 static const char kMimeTypePNG[]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return true; | 176 return true; |
176 #endif | 177 #endif |
177 } | 178 } |
178 return false; | 179 return false; |
179 } | 180 } |
180 | 181 |
181 static Buffer FromInt(int32 buffer) { | 182 static Buffer FromInt(int32 buffer) { |
182 return static_cast<Buffer>(buffer); | 183 return static_cast<Buffer>(buffer); |
183 } | 184 } |
184 | 185 |
185 Clipboard(); | 186 // Returns the clipboard object for the current thread. |
186 ~Clipboard(); | 187 // |
| 188 // Most implementations will have at most one clipboard which will live on |
| 189 // the main UI thread, but Windows has tricky semantics where there have to |
| 190 // be two clipboards: one that lives on the UI thread and one that lives on |
| 191 // the IO thread. |
| 192 static Clipboard* GetForCurrentThread(); |
| 193 |
| 194 // Destroys all thread local clipboards during shutdown. Each clipboard will |
| 195 // be destructed on its associated thread. |
| 196 static void DestroyClipboards(); |
187 | 197 |
188 // Write a bunch of objects to the system clipboard. Copies are made of the | 198 // Write a bunch of objects to the system clipboard. Copies are made of the |
189 // contents of |objects|. On Windows they are copied to the system clipboard. | 199 // contents of |objects|. On Windows they are copied to the system clipboard. |
190 // On linux they are copied into a structure owned by the Clipboard object and | 200 // On linux they are copied into a structure owned by the Clipboard object and |
191 // kept until the system clipboard is set again. | 201 // kept until the system clipboard is set again. |
192 void WriteObjects(Buffer buffer, const ObjectMap& objects); | 202 void WriteObjects(Buffer buffer, const ObjectMap& objects); |
193 | 203 |
194 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most | 204 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most |
195 // platforms don't care. | 205 // platforms don't care. |
196 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ | 206 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // Firefox text/html | 287 // Firefox text/html |
278 static const FormatType& GetTextHtmlFormatType(); | 288 static const FormatType& GetTextHtmlFormatType(); |
279 static const FormatType& GetCFHDropFormatType(); | 289 static const FormatType& GetCFHDropFormatType(); |
280 static const FormatType& GetFileDescriptorFormatType(); | 290 static const FormatType& GetFileDescriptorFormatType(); |
281 static const FormatType& GetFileContentFormatZeroType(); | 291 static const FormatType& GetFileContentFormatZeroType(); |
282 #endif | 292 #endif |
283 | 293 |
284 private: | 294 private: |
285 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); | 295 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); |
286 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); | 296 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); |
| 297 friend class ClipboardTest; |
| 298 |
| 299 Clipboard(); |
| 300 ~Clipboard(); |
287 | 301 |
288 void DispatchObject(ObjectType type, const ObjectMapParams& params); | 302 void DispatchObject(ObjectType type, const ObjectMapParams& params); |
289 | 303 |
290 void WriteText(const char* text_data, size_t text_len); | 304 void WriteText(const char* text_data, size_t text_len); |
291 | 305 |
292 void WriteHTML(const char* markup_data, | 306 void WriteHTML(const char* markup_data, |
293 size_t markup_len, | 307 size_t markup_len, |
294 const char* url_data, | 308 const char* url_data, |
295 size_t url_len); | 309 size_t url_len); |
296 | 310 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 GtkClipboard* clipboard_; | 370 GtkClipboard* clipboard_; |
357 GtkClipboard* primary_selection_; | 371 GtkClipboard* primary_selection_; |
358 #endif | 372 #endif |
359 | 373 |
360 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 374 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
361 }; | 375 }; |
362 | 376 |
363 } // namespace ui | 377 } // namespace ui |
364 | 378 |
365 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 379 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
OLD | NEW |