| 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> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 18 #include "base/threading/platform_thread.h" |
| 18 #include "ui/base/ui_export.h" | 19 #include "ui/base/ui_export.h" |
| 19 | 20 |
| 20 #if defined(TOOLKIT_GTK) | 21 #if defined(TOOLKIT_GTK) |
| 21 #include <gdk/gdk.h> | 22 #include <gdk/gdk.h> |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 25 #include <jni.h> | 26 #include <jni.h> |
| 26 | 27 |
| 27 #include "base/android/jni_android.h" | 28 #include "base/android/jni_android.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 typedef struct _GtkClipboard GtkClipboard; | 40 typedef struct _GtkClipboard GtkClipboard; |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 #ifdef __OBJC__ | 43 #ifdef __OBJC__ |
| 43 @class NSString; | 44 @class NSString; |
| 44 #else | 45 #else |
| 45 class NSString; | 46 class NSString; |
| 46 #endif | 47 #endif |
| 47 | 48 |
| 48 namespace ui { | 49 namespace ui { |
| 50 class ClipboardTest; |
| 49 | 51 |
| 50 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { | 52 class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
| 51 public: | 53 public: |
| 52 // MIME type constants. | 54 // MIME type constants. |
| 53 static const char kMimeTypeText[]; | 55 static const char kMimeTypeText[]; |
| 54 static const char kMimeTypeURIList[]; | 56 static const char kMimeTypeURIList[]; |
| 55 static const char kMimeTypeDownloadURL[]; | 57 static const char kMimeTypeDownloadURL[]; |
| 56 static const char kMimeTypeHTML[]; | 58 static const char kMimeTypeHTML[]; |
| 57 static const char kMimeTypeRTF[]; | 59 static const char kMimeTypeRTF[]; |
| 58 static const char kMimeTypePNG[]; | 60 static const char kMimeTypePNG[]; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return true; | 177 return true; |
| 176 #endif | 178 #endif |
| 177 } | 179 } |
| 178 return false; | 180 return false; |
| 179 } | 181 } |
| 180 | 182 |
| 181 static Buffer FromInt(int32 buffer) { | 183 static Buffer FromInt(int32 buffer) { |
| 182 return static_cast<Buffer>(buffer); | 184 return static_cast<Buffer>(buffer); |
| 183 } | 185 } |
| 184 | 186 |
| 185 Clipboard(); | 187 // Sets the list of threads that are allowed to access the clipboard. |
| 186 ~Clipboard(); | 188 static void SetAllowedThreads( |
| 189 const std::vector<base::PlatformThreadId>& allowed_threads); |
| 190 |
| 191 // Returns the clipboard object for the current thread. |
| 192 // |
| 193 // Most implementations will have at most one clipboard which will live on |
| 194 // the main UI thread, but Windows has tricky semantics where there have to |
| 195 // be two clipboards: one that lives on the UI thread and one that lives on |
| 196 // the IO thread. |
| 197 static Clipboard* GetForCurrentThread(); |
| 198 |
| 199 // Destroys the clipboard for the current thread. Usually, this will clean up |
| 200 // all clipboards, except on Windows. (Previous code leaks the IO thread |
| 201 // clipboard, so it shouldn't be a problem.) |
| 202 static void DestroyClipboardForCurrentThread(); |
| 187 | 203 |
| 188 // Write a bunch of objects to the system clipboard. Copies are made of the | 204 // 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. | 205 // 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 | 206 // On linux they are copied into a structure owned by the Clipboard object and |
| 191 // kept until the system clipboard is set again. | 207 // kept until the system clipboard is set again. |
| 192 void WriteObjects(Buffer buffer, const ObjectMap& objects); | 208 void WriteObjects(Buffer buffer, const ObjectMap& objects); |
| 193 | 209 |
| 194 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most | 210 // On Linux/BSD, we need to know when the clipboard is set to a URL. Most |
| 195 // platforms don't care. | 211 // platforms don't care. |
| 196 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA) \ | 212 #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 | 293 // Firefox text/html |
| 278 static const FormatType& GetTextHtmlFormatType(); | 294 static const FormatType& GetTextHtmlFormatType(); |
| 279 static const FormatType& GetCFHDropFormatType(); | 295 static const FormatType& GetCFHDropFormatType(); |
| 280 static const FormatType& GetFileDescriptorFormatType(); | 296 static const FormatType& GetFileDescriptorFormatType(); |
| 281 static const FormatType& GetFileContentFormatZeroType(); | 297 static const FormatType& GetFileContentFormatZeroType(); |
| 282 #endif | 298 #endif |
| 283 | 299 |
| 284 private: | 300 private: |
| 285 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); | 301 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); |
| 286 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); | 302 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); |
| 303 friend class ClipboardTest; |
| 304 |
| 305 Clipboard(); |
| 306 ~Clipboard(); |
| 287 | 307 |
| 288 void DispatchObject(ObjectType type, const ObjectMapParams& params); | 308 void DispatchObject(ObjectType type, const ObjectMapParams& params); |
| 289 | 309 |
| 290 void WriteText(const char* text_data, size_t text_len); | 310 void WriteText(const char* text_data, size_t text_len); |
| 291 | 311 |
| 292 void WriteHTML(const char* markup_data, | 312 void WriteHTML(const char* markup_data, |
| 293 size_t markup_len, | 313 size_t markup_len, |
| 294 const char* url_data, | 314 const char* url_data, |
| 295 size_t url_len); | 315 size_t url_len); |
| 296 | 316 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 GtkClipboard* clipboard_; | 376 GtkClipboard* clipboard_; |
| 357 GtkClipboard* primary_selection_; | 377 GtkClipboard* primary_selection_; |
| 358 #endif | 378 #endif |
| 359 | 379 |
| 360 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 380 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
| 361 }; | 381 }; |
| 362 | 382 |
| 363 } // namespace ui | 383 } // namespace ui |
| 364 | 384 |
| 365 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 385 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
| OLD | NEW |