Chromium Code Reviews| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | |
| 12 #include <string> | 13 #include <string> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 16 #include "base/lazy_instance.h" | 17 #include "base/lazy_instance.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "base/threading/platform_thread.h" | 22 #include "base/threading/platform_thread.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 class ClipboardTest; | 54 class ClipboardTest; |
| 54 class TestClipboard; | 55 class TestClipboard; |
| 55 class ScopedClipboardWriter; | 56 class ScopedClipboardWriter; |
| 56 | 57 |
| 57 class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { | 58 class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
| 58 public: | 59 public: |
| 59 // MIME type constants. | 60 // MIME type constants. |
| 60 static const char kMimeTypeText[]; | 61 static const char kMimeTypeText[]; |
| 61 static const char kMimeTypeURIList[]; | 62 static const char kMimeTypeURIList[]; |
| 62 static const char kMimeTypeDownloadURL[]; | 63 static const char kMimeTypeDownloadURL[]; |
| 64 static const char kMimeTypeMozillaURL[]; | |
| 63 static const char kMimeTypeHTML[]; | 65 static const char kMimeTypeHTML[]; |
| 64 static const char kMimeTypeRTF[]; | 66 static const char kMimeTypeRTF[]; |
| 65 static const char kMimeTypePNG[]; | 67 static const char kMimeTypePNG[]; |
| 68 static const char kMimeTypeWebCustomData[]; | |
| 69 static const char kMimeTypeWebkitSmartPaste[]; | |
| 70 static const char kMimeTypePepperCustomData[]; | |
| 66 | 71 |
| 67 // Platform neutral holder for native data representation of a clipboard type. | 72 // Platform neutral holder for native data representation of a clipboard type. |
| 68 struct UI_BASE_EXPORT FormatType { | 73 struct UI_BASE_EXPORT FormatType { |
| 69 FormatType(); | 74 FormatType(); |
| 70 ~FormatType(); | 75 ~FormatType(); |
| 71 | 76 |
| 72 // Serializes and deserializes a FormatType for use in IPC messages. | 77 // Serializes and deserializes a FormatType for use in IPC messages. |
| 73 std::string Serialize() const; | 78 std::string Serialize() const; |
| 74 static FormatType Deserialize(const std::string& serialization); | 79 static FormatType Deserialize(const std::string& serialization); |
| 75 | 80 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 135 } |
| 131 | 136 |
| 132 static ClipboardType FromInt(int32_t type) { | 137 static ClipboardType FromInt(int32_t type) { |
| 133 return static_cast<ClipboardType>(type); | 138 return static_cast<ClipboardType>(type); |
| 134 } | 139 } |
| 135 | 140 |
| 136 // Sets the list of threads that are allowed to access the clipboard. | 141 // Sets the list of threads that are allowed to access the clipboard. |
| 137 static void SetAllowedThreads( | 142 static void SetAllowedThreads( |
| 138 const std::vector<base::PlatformThreadId>& allowed_threads); | 143 const std::vector<base::PlatformThreadId>& allowed_threads); |
| 139 | 144 |
| 145 // Sets the clipboard for the current thread. Previously, there was only | |
| 146 // one clipboard implementation on a platform; now that mus exists, during | |
| 147 // mus app startup, we need to specifically initialize mus instead of the | |
| 148 // current platform clipboard. We take ownership of |platform_clipboard|. (We | |
| 149 // can't use unique_ptr since we don't want to expose the destructor.) | |
|
dcheng
2016/06/04 06:14:00
Is the last part of this comment still accurate?
Elliot Glaysher
2016/06/06 20:10:12
Done.
| |
| 150 static void SetClipboardForCurrentThread( | |
| 151 std::unique_ptr<Clipboard> platform_clipboard); | |
| 152 | |
| 140 // Returns the clipboard object for the current thread. | 153 // Returns the clipboard object for the current thread. |
| 141 // | 154 // |
| 142 // Most implementations will have at most one clipboard which will live on | 155 // Most implementations will have at most one clipboard which will live on |
| 143 // the main UI thread, but Windows has tricky semantics where there have to | 156 // the main UI thread, but Windows has tricky semantics where there have to |
| 144 // be two clipboards: one that lives on the UI thread and one that lives on | 157 // be two clipboards: one that lives on the UI thread and one that lives on |
| 145 // the IO thread. | 158 // the IO thread. |
| 146 static Clipboard* GetForCurrentThread(); | 159 static Clipboard* GetForCurrentThread(); |
| 147 | 160 |
| 148 // Destroys the clipboard for the current thread. Usually, this will clean up | 161 // Destroys the clipboard for the current thread. Usually, this will clean up |
| 149 // all clipboards, except on Windows. (Previous code leaks the IO thread | 162 // all clipboards, except on Windows. (Previous code leaks the IO thread |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 virtual void WriteBitmap(const SkBitmap& bitmap) = 0; | 316 virtual void WriteBitmap(const SkBitmap& bitmap) = 0; |
| 304 | 317 |
| 305 virtual void WriteData(const FormatType& format, | 318 virtual void WriteData(const FormatType& format, |
| 306 const char* data_data, | 319 const char* data_data, |
| 307 size_t data_len) = 0; | 320 size_t data_len) = 0; |
| 308 | 321 |
| 309 private: | 322 private: |
| 310 // For access to WriteObjects(). | 323 // For access to WriteObjects(). |
| 311 friend class ScopedClipboardWriter; | 324 friend class ScopedClipboardWriter; |
| 312 friend class TestClipboard; | 325 friend class TestClipboard; |
| 326 // For SetClipboardForCurrentThread's argument. | |
| 327 friend struct std::default_delete<Clipboard>; | |
| 328 | |
| 329 static base::PlatformThreadId GetAndValidateThreadID(); | |
| 313 | 330 |
| 314 // A list of allowed threads. By default, this is empty and no thread checking | 331 // A list of allowed threads. By default, this is empty and no thread checking |
| 315 // is done (in the unit test case), but a user (like content) can set which | 332 // is done (in the unit test case), but a user (like content) can set which |
| 316 // threads are allowed to call this method. | 333 // threads are allowed to call this method. |
| 317 typedef std::vector<base::PlatformThreadId> AllowedThreadsVector; | 334 typedef std::vector<base::PlatformThreadId> AllowedThreadsVector; |
| 318 static base::LazyInstance<AllowedThreadsVector> allowed_threads_; | 335 static base::LazyInstance<AllowedThreadsVector> allowed_threads_; |
| 319 | 336 |
| 320 // Mapping from threads to clipboard objects. | 337 // Mapping from threads to clipboard objects. |
| 321 typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap; | 338 typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap; |
| 322 static base::LazyInstance<ClipboardMap> clipboard_map_; | 339 static base::LazyInstance<ClipboardMap> clipboard_map_; |
| 323 | 340 |
| 324 // Mutex that controls access to |g_clipboard_map|. | 341 // Mutex that controls access to |g_clipboard_map|. |
| 325 static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_; | 342 static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_; |
| 326 | 343 |
| 327 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 344 DISALLOW_COPY_AND_ASSIGN(Clipboard); |
| 328 }; | 345 }; |
| 329 | 346 |
| 330 } // namespace ui | 347 } // namespace ui |
| 331 | 348 |
| 332 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 349 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ |
| OLD | NEW |