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[]; | |
| 
 
sky
2016/05/26 23:10:27
Move over todo about removal?
 
Elliot Glaysher
2016/05/31 17:01:40
The bug is closed and archived.
 
 | |
| 66 | 69 | 
| 67 // Platform neutral holder for native data representation of a clipboard type. | 70 // Platform neutral holder for native data representation of a clipboard type. | 
| 68 struct UI_BASE_EXPORT FormatType { | 71 struct UI_BASE_EXPORT FormatType { | 
| 69 FormatType(); | 72 FormatType(); | 
| 70 ~FormatType(); | 73 ~FormatType(); | 
| 71 | 74 | 
| 72 // Serializes and deserializes a FormatType for use in IPC messages. | 75 // Serializes and deserializes a FormatType for use in IPC messages. | 
| 73 std::string Serialize() const; | 76 std::string Serialize() const; | 
| 74 static FormatType Deserialize(const std::string& serialization); | 77 static FormatType Deserialize(const std::string& serialization); | 
| 75 | 78 | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 } | 133 } | 
| 131 | 134 | 
| 132 static ClipboardType FromInt(int32_t type) { | 135 static ClipboardType FromInt(int32_t type) { | 
| 133 return static_cast<ClipboardType>(type); | 136 return static_cast<ClipboardType>(type); | 
| 134 } | 137 } | 
| 135 | 138 | 
| 136 // Sets the list of threads that are allowed to access the clipboard. | 139 // Sets the list of threads that are allowed to access the clipboard. | 
| 137 static void SetAllowedThreads( | 140 static void SetAllowedThreads( | 
| 138 const std::vector<base::PlatformThreadId>& allowed_threads); | 141 const std::vector<base::PlatformThreadId>& allowed_threads); | 
| 139 | 142 | 
| 143 // Builds the clipboard for the current thread. Previously, there was only | |
| 
 
sky
2016/05/26 23:10:27
This comment is a bit confusing. It's not building
 
 | |
| 144 // one clipboard implementation on a platform; now that mus exists, during | |
| 145 // mus app startup, we need to specifically initialize mus instead of the | |
| 146 // current platform clipboard. We take ownership of |platform_clipboard|. (We | |
| 147 // can't use unique_ptr since we don't want to expose the destructor.) | |
| 
 
sky
2016/05/26 23:10:27
Have this class friend unique_ptr? Alternatively t
 
Elliot Glaysher
2016/05/31 17:01:40
Done.
 
 | |
| 148 static void SetClipboardForCurrentThread(Clipboard* platform_clipboard); | |
| 149 | |
| 140 // Returns the clipboard object for the current thread. | 150 // Returns the clipboard object for the current thread. | 
| 141 // | 151 // | 
| 142 // Most implementations will have at most one clipboard which will live on | 152 // 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 | 153 // 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 | 154 // be two clipboards: one that lives on the UI thread and one that lives on | 
| 145 // the IO thread. | 155 // the IO thread. | 
| 146 static Clipboard* GetForCurrentThread(); | 156 static Clipboard* GetForCurrentThread(); | 
| 147 | 157 | 
| 148 // Destroys the clipboard for the current thread. Usually, this will clean up | 158 // Destroys the clipboard for the current thread. Usually, this will clean up | 
| 149 // all clipboards, except on Windows. (Previous code leaks the IO thread | 159 // all clipboards, except on Windows. (Previous code leaks the IO thread | 
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 | 314 | 
| 305 virtual void WriteData(const FormatType& format, | 315 virtual void WriteData(const FormatType& format, | 
| 306 const char* data_data, | 316 const char* data_data, | 
| 307 size_t data_len) = 0; | 317 size_t data_len) = 0; | 
| 308 | 318 | 
| 309 private: | 319 private: | 
| 310 // For access to WriteObjects(). | 320 // For access to WriteObjects(). | 
| 311 friend class ScopedClipboardWriter; | 321 friend class ScopedClipboardWriter; | 
| 312 friend class TestClipboard; | 322 friend class TestClipboard; | 
| 313 | 323 | 
| 324 static base::PlatformThreadId GetAndValidateThreadID(); | |
| 325 | |
| 314 // A list of allowed threads. By default, this is empty and no thread checking | 326 // 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 | 327 // is done (in the unit test case), but a user (like content) can set which | 
| 316 // threads are allowed to call this method. | 328 // threads are allowed to call this method. | 
| 317 typedef std::vector<base::PlatformThreadId> AllowedThreadsVector; | 329 typedef std::vector<base::PlatformThreadId> AllowedThreadsVector; | 
| 318 static base::LazyInstance<AllowedThreadsVector> allowed_threads_; | 330 static base::LazyInstance<AllowedThreadsVector> allowed_threads_; | 
| 319 | 331 | 
| 320 // Mapping from threads to clipboard objects. | 332 // Mapping from threads to clipboard objects. | 
| 321 typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap; | 333 typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap; | 
| 322 static base::LazyInstance<ClipboardMap> clipboard_map_; | 334 static base::LazyInstance<ClipboardMap> clipboard_map_; | 
| 323 | 335 | 
| 324 // Mutex that controls access to |g_clipboard_map|. | 336 // Mutex that controls access to |g_clipboard_map|. | 
| 325 static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_; | 337 static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_; | 
| 326 | 338 | 
| 327 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 339 DISALLOW_COPY_AND_ASSIGN(Clipboard); | 
| 328 }; | 340 }; | 
| 329 | 341 | 
| 330 } // namespace ui | 342 } // namespace ui | 
| 331 | 343 | 
| 332 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 344 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ | 
| OLD | NEW |