Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: ui/base/clipboard/clipboard.h

Issue 574273002: Rewrite clipboard write IPC handling to be easier to understand. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/shared_memory.h"
16 #include "base/process/process.h"
17 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
18 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
19 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
20 #include "ui/base/clipboard/clipboard_types.h" 18 #include "ui/base/clipboard/clipboard_types.h"
21 #include "ui/base/ui_base_export.h" 19 #include "ui/base/ui_base_export.h"
22 20
23 #if defined(OS_WIN) 21 #if defined(OS_WIN)
24 #include <objidl.h> 22 #include <objidl.h>
25 #elif defined(OS_ANDROID) 23 #elif defined(OS_ANDROID)
26 #include <jni.h> 24 #include <jni.h>
27 25
28 #include "base/android/jni_android.h" 26 #include "base/android/jni_android.h"
29 #include "base/android/scoped_java_ref.h" 27 #include "base/android/scoped_java_ref.h"
30 #endif 28 #endif
31 29
32 #if defined(USE_AURA) && defined(USE_X11) 30 #if defined(USE_AURA) && defined(USE_X11)
33 #include "base/memory/scoped_ptr.h" 31 #include "base/memory/scoped_ptr.h"
34 #endif 32 #endif
35 33
36 namespace base { 34 namespace base {
37 class FilePath; 35 class FilePath;
38 36
39 namespace win { 37 namespace win {
40 class MessageWindow; 38 class MessageWindow;
41 } // namespace win 39 } // namespace win
42 } // namespace base 40 } // namespace base
43 41
44 // TODO(dcheng): Temporary until the IPC layer doesn't use WriteObjects().
45 namespace content {
46 class ClipboardMessageFilter;
47 }
48
49 namespace gfx { 42 namespace gfx {
50 class Size; 43 class Size;
51 } 44 }
52 45
53 class SkBitmap; 46 class SkBitmap;
54 47
55 #ifdef __OBJC__ 48 #ifdef __OBJC__
56 @class NSString; 49 @class NSString;
57 #else 50 #else
58 class NSString; 51 class NSString;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 explicit FormatType(const std::string& native_format); 119 explicit FormatType(const std::string& native_format);
127 const std::string& data() const { return data_; } 120 const std::string& data() const { return data_; }
128 std::string data_; 121 std::string data_;
129 #else 122 #else
130 #error No FormatType definition. 123 #error No FormatType definition.
131 #endif 124 #endif
132 125
133 // Copyable and assignable, since this is essentially an opaque value type. 126 // Copyable and assignable, since this is essentially an opaque value type.
134 }; 127 };
135 128
136 // TODO(dcheng): Make this private once the IPC layer no longer needs to
137 // serialize this information.
138 // ObjectType designates the type of data to be stored in the clipboard. This
139 // designation is shared across all OSes. The system-specific designation
140 // is defined by FormatType. A single ObjectType might be represented by
141 // several system-specific FormatTypes. For example, on Linux the CBF_TEXT
142 // ObjectType maps to "text/plain", "STRING", and several other formats. On
143 // windows it maps to CF_UNICODETEXT.
144 enum ObjectType {
145 CBF_TEXT,
146 CBF_HTML,
147 CBF_RTF,
148 CBF_BOOKMARK,
149 CBF_WEBKIT,
150 CBF_SMBITMAP, // Bitmap from shared memory.
151 CBF_DATA, // Arbitrary block of bytes.
152 };
153
154 // ObjectMap is a map from ObjectType to associated data.
155 // The data is organized differently for each ObjectType. The following
156 // table summarizes what kind of data is stored for each key.
157 // * indicates an optional argument.
158 //
159 // Key Arguments Type
160 // -------------------------------------
161 // CBF_TEXT text char array
162 // CBF_HTML html char array
163 // url* char array
164 // CBF_RTF data byte array
165 // CBF_BOOKMARK html char array
166 // url char array
167 // CBF_WEBKIT none empty vector
168 // CBF_SMBITMAP shared_mem A pointer to an unmapped base::SharedMemory
169 // object containing the bitmap data. The bitmap
170 // data should be premultiplied.
171 // size gfx::Size struct
172 // CBF_DATA format char array
173 // data byte array
174 typedef std::vector<char> ObjectMapParam;
175 typedef std::vector<ObjectMapParam> ObjectMapParams;
176 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap;
177
178 static bool IsSupportedClipboardType(int32 type) { 129 static bool IsSupportedClipboardType(int32 type) {
179 switch (type) { 130 switch (type) {
180 case CLIPBOARD_TYPE_COPY_PASTE: 131 case CLIPBOARD_TYPE_COPY_PASTE:
181 return true; 132 return true;
182 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS) 133 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS)
183 case CLIPBOARD_TYPE_SELECTION: 134 case CLIPBOARD_TYPE_SELECTION:
184 return true; 135 return true;
185 #endif 136 #endif
186 } 137 }
187 return false; 138 return false;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 static const FormatType& GetWebKitSmartPasteFormatType(); 224 static const FormatType& GetWebKitSmartPasteFormatType();
274 // Win: MS HTML Format, Other: Generic HTML format 225 // Win: MS HTML Format, Other: Generic HTML format
275 static const FormatType& GetHtmlFormatType(); 226 static const FormatType& GetHtmlFormatType();
276 static const FormatType& GetRtfFormatType(); 227 static const FormatType& GetRtfFormatType();
277 static const FormatType& GetBitmapFormatType(); 228 static const FormatType& GetBitmapFormatType();
278 // TODO(raymes): Unify web custom data and pepper custom data: 229 // TODO(raymes): Unify web custom data and pepper custom data:
279 // crbug.com/158399. 230 // crbug.com/158399.
280 static const FormatType& GetWebCustomDataFormatType(); 231 static const FormatType& GetWebCustomDataFormatType();
281 static const FormatType& GetPepperCustomDataFormatType(); 232 static const FormatType& GetPepperCustomDataFormatType();
282 233
283 // Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle|
284 // belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in
285 // |objects|. The pointer is deleted by DispatchObjects().
286 //
287 // On non-Windows platforms, |process| is ignored.
288 static bool ReplaceSharedMemHandle(ObjectMap* objects,
289 base::SharedMemoryHandle bitmap_handle,
290 base::ProcessHandle process)
291 WARN_UNUSED_RESULT;
292 #if defined(OS_WIN) 234 #if defined(OS_WIN)
293 // Firefox text/html 235 // Firefox text/html
294 static const FormatType& GetTextHtmlFormatType(); 236 static const FormatType& GetTextHtmlFormatType();
295 static const FormatType& GetCFHDropFormatType(); 237 static const FormatType& GetCFHDropFormatType();
296 static const FormatType& GetFileDescriptorFormatType(); 238 static const FormatType& GetFileDescriptorFormatType();
297 static const FormatType& GetFileContentZeroFormatType(); 239 static const FormatType& GetFileContentZeroFormatType();
298 static const FormatType& GetIDListFormatType(); 240 static const FormatType& GetIDListFormatType();
299 #endif 241 #endif
300 242
301 private: 243 private:
302 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); 244 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest);
303 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); 245 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest);
304 friend class ClipboardTest; 246 friend class ClipboardTest;
305 // For access to WriteObjects(). 247 // For access to WriteObjects().
306 // TODO(dcheng): Remove the temporary exception for content.
307 friend class content::ClipboardMessageFilter;
308 friend class ScopedClipboardWriter; 248 friend class ScopedClipboardWriter;
309 249
310 Clipboard(); 250 Clipboard();
311 ~Clipboard(); 251 ~Clipboard();
312 252
253 // ObjectType designates the type of data to be stored in the clipboard. This
254 // designation is shared across all OSes. The system-specific designation
255 // is defined by FormatType. A single ObjectType might be represented by
256 // several system-specific FormatTypes. For example, on Linux the CBF_TEXT
257 // ObjectType maps to "text/plain", "STRING", and several other formats. On
258 // windows it maps to CF_UNICODETEXT.
259 enum ObjectType {
260 CBF_TEXT,
261 CBF_HTML,
262 CBF_RTF,
263 CBF_BOOKMARK,
264 CBF_WEBKIT,
265 CBF_SMBITMAP, // Bitmap from shared memory.
266 CBF_DATA, // Arbitrary block of bytes.
267 };
268
269 // ObjectMap is a map from ObjectType to associated data.
270 // The data is organized differently for each ObjectType. The following
271 // table summarizes what kind of data is stored for each key.
272 // * indicates an optional argument.
273 //
274 // Key Arguments Type
275 // -------------------------------------
276 // CBF_TEXT text char array
277 // CBF_HTML html char array
278 // url* char array
279 // CBF_RTF data byte array
280 // CBF_BOOKMARK html char array
281 // url char array
282 // CBF_WEBKIT none empty vector
283 // CBF_SMBITMAP bitmap A pointer to a SkBitmap. The caller must ensure
dcheng 2014/09/18 17:02:22 This is really horrible, but I don't want to shave
sky 2014/09/18 19:47:53 It's all awful. Are you going to make this less fr
dcheng 2014/09/18 21:06:00 I would like to make it less fragile, but I don't
284 // the SkBitmap remains live for the duration of
285 // the WriteObjects call.
286 // CBF_DATA format char array
287 // data byte array
288 typedef std::vector<char> ObjectMapParam;
289 typedef std::vector<ObjectMapParam> ObjectMapParams;
290 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap;
291
313 // Write a bunch of objects to the system clipboard. Copies are made of the 292 // Write a bunch of objects to the system clipboard. Copies are made of the
314 // contents of |objects|. 293 // contents of |objects|.
315 void WriteObjects(ClipboardType type, const ObjectMap& objects); 294 void WriteObjects(ClipboardType type, const ObjectMap& objects);
316 295
317 void DispatchObject(ObjectType type, const ObjectMapParams& params); 296 void DispatchObject(ObjectType type, const ObjectMapParams& params);
318 297
319 void WriteText(const char* text_data, size_t text_len); 298 void WriteText(const char* text_data, size_t text_len);
320 299
321 void WriteHTML(const char* markup_data, 300 void WriteHTML(const char* markup_data,
322 size_t markup_len, 301 size_t markup_len,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 class AuraX11Details; 344 class AuraX11Details;
366 scoped_ptr<AuraX11Details> aurax11_details_; 345 scoped_ptr<AuraX11Details> aurax11_details_;
367 #endif 346 #endif
368 347
369 DISALLOW_COPY_AND_ASSIGN(Clipboard); 348 DISALLOW_COPY_AND_ASSIGN(Clipboard);
370 }; 349 };
371 350
372 } // namespace ui 351 } // namespace ui
373 352
374 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ 353 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698