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

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

Issue 12041078: Clear the clipboard closing Incognito window (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Moved the feature to 'content' layer Created 7 years, 10 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/observer_list.h"
14 #include "base/process.h" 15 #include "base/process.h"
15 #include "base/shared_memory.h" 16 #include "base/shared_memory.h"
16 #include "base/string16.h" 17 #include "base/string16.h"
17 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
18 #include "base/threading/platform_thread.h" 19 #include "base/threading/platform_thread.h"
19 #include "ui/base/ui_export.h" 20 #include "ui/base/ui_export.h"
20 21
21 #if defined(TOOLKIT_GTK) 22 #if defined(TOOLKIT_GTK)
22 #include <gdk/gdk.h> 23 #include <gdk/gdk.h>
23 #endif 24 #endif
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 enum ObjectType { 126 enum ObjectType {
126 CBF_TEXT, 127 CBF_TEXT,
127 CBF_HTML, 128 CBF_HTML,
128 CBF_RTF, 129 CBF_RTF,
129 CBF_BOOKMARK, 130 CBF_BOOKMARK,
130 CBF_FILES, 131 CBF_FILES,
131 CBF_WEBKIT, 132 CBF_WEBKIT,
132 CBF_BITMAP, 133 CBF_BITMAP,
133 CBF_SMBITMAP, // Bitmap from shared memory. 134 CBF_SMBITMAP, // Bitmap from shared memory.
134 CBF_DATA, // Arbitrary block of bytes. 135 CBF_DATA, // Arbitrary block of bytes.
136 CBF_INCOGNITO_MARKER, // Signifies that data came from Incognito mode.
135 }; 137 };
136 138
137 // ObjectMap is a map from ObjectType to associated data. 139 // ObjectMap is a map from ObjectType to associated data.
138 // The data is organized differently for each ObjectType. The following 140 // The data is organized differently for each ObjectType. The following
139 // table summarizes what kind of data is stored for each key. 141 // table summarizes what kind of data is stored for each key.
140 // * indicates an optional argument. 142 // * indicates an optional argument.
141 // 143 //
142 // Key Arguments Type 144 // Key Arguments Type
143 // ------------------------------------- 145 // -------------------------------------
144 // CBF_TEXT text char array 146 // CBF_TEXT text char array
(...skipping 10 matching lines...) Expand all
155 // The filenames are encoded in platform-specific 157 // The filenames are encoded in platform-specific
156 // encoding. 158 // encoding.
157 // CBF_WEBKIT none empty vector 159 // CBF_WEBKIT none empty vector
158 // CBF_BITMAP pixels byte array 160 // CBF_BITMAP pixels byte array
159 // size gfx::Size struct 161 // size gfx::Size struct
160 // CBF_SMBITMAP shared_mem A pointer to an unmapped base::SharedMemory 162 // CBF_SMBITMAP shared_mem A pointer to an unmapped base::SharedMemory
161 // object containing the bitmap data. 163 // object containing the bitmap data.
162 // size gfx::Size struct 164 // size gfx::Size struct
163 // CBF_DATA format char array 165 // CBF_DATA format char array
164 // data byte array 166 // data byte array
167 // CBF_INCOGNITO_MARKER
168 // data byte array
165 typedef std::vector<char> ObjectMapParam; 169 typedef std::vector<char> ObjectMapParam;
166 typedef std::vector<ObjectMapParam> ObjectMapParams; 170 typedef std::vector<ObjectMapParam> ObjectMapParams;
167 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; 171 typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap;
168 172
169 // Buffer designates which clipboard the action should be applied to. 173 // Buffer designates which clipboard the action should be applied to.
170 // Only platforms that use the X Window System support the selection 174 // Only platforms that use the X Window System support the selection
171 // buffer. 175 // buffer.
172 enum Buffer { 176 enum Buffer {
173 BUFFER_STANDARD, 177 BUFFER_STANDARD,
174 BUFFER_SELECTION, 178 BUFFER_SELECTION,
175 }; 179 };
176 180
181 class ClipboardObserver {
182 public:
183 // Called at the end of Clipboard::WriteObjects()
184 virtual void OnWriteObjects(Buffer buffer) = 0;
185 protected:
186 virtual ~ClipboardObserver() {}
187 };
188
189 void AddObserver(ClipboardObserver* obs) {
190 observer_list_.AddObserver(obs);
191 }
192
193 void RemoveObserver(ClipboardObserver* obs) {
194 observer_list_.RemoveObserver(obs);
195 }
196
177 static bool IsValidBuffer(int32 buffer) { 197 static bool IsValidBuffer(int32 buffer) {
178 switch (buffer) { 198 switch (buffer) {
179 case BUFFER_STANDARD: 199 case BUFFER_STANDARD:
180 return true; 200 return true;
181 #if defined(USE_X11) && !defined(OS_CHROMEOS) 201 #if defined(USE_X11) && !defined(OS_CHROMEOS)
182 case BUFFER_SELECTION: 202 case BUFFER_SELECTION:
183 return true; 203 return true;
184 #endif 204 #endif
185 } 205 }
186 return false; 206 return false;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 static const FormatType& GetFilenameWFormatType(); 293 static const FormatType& GetFilenameWFormatType();
274 static const FormatType& GetWebKitSmartPasteFormatType(); 294 static const FormatType& GetWebKitSmartPasteFormatType();
275 // Win: MS HTML Format, Other: Generic HTML format 295 // Win: MS HTML Format, Other: Generic HTML format
276 static const FormatType& GetHtmlFormatType(); 296 static const FormatType& GetHtmlFormatType();
277 static const FormatType& GetRtfFormatType(); 297 static const FormatType& GetRtfFormatType();
278 static const FormatType& GetBitmapFormatType(); 298 static const FormatType& GetBitmapFormatType();
279 // TODO(raymes): Unify web custom data and pepper custom data: 299 // TODO(raymes): Unify web custom data and pepper custom data:
280 // crbug.com/158399. 300 // crbug.com/158399.
281 static const FormatType& GetWebCustomDataFormatType(); 301 static const FormatType& GetWebCustomDataFormatType();
282 static const FormatType& GetPepperCustomDataFormatType(); 302 static const FormatType& GetPepperCustomDataFormatType();
303 static const FormatType& GetIncognitoMarkerFormatType();
283 304
284 // Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle| 305 // Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle|
285 // belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in 306 // belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in
286 // |objects|. The pointer is deleted by DispatchObjects(). 307 // |objects|. The pointer is deleted by DispatchObjects().
287 // 308 //
288 // On non-Windows platforms, |process| is ignored. 309 // On non-Windows platforms, |process| is ignored.
289 static void ReplaceSharedMemHandle(ObjectMap* objects, 310 static void ReplaceSharedMemHandle(ObjectMap* objects,
290 base::SharedMemoryHandle bitmap_handle, 311 base::SharedMemoryHandle bitmap_handle,
291 base::ProcessHandle process); 312 base::ProcessHandle process);
292 #if defined(OS_WIN) 313 #if defined(OS_WIN)
293 // Firefox text/html 314 // Firefox text/html
294 static const FormatType& GetTextHtmlFormatType(); 315 static const FormatType& GetTextHtmlFormatType();
295 static const FormatType& GetCFHDropFormatType(); 316 static const FormatType& GetCFHDropFormatType();
296 static const FormatType& GetFileDescriptorFormatType(); 317 static const FormatType& GetFileDescriptorFormatType();
297 static const FormatType& GetFileContentFormatZeroType(); 318 static const FormatType& GetFileContentFormatZeroType();
298 #endif 319 #endif
299 320
300 private: 321 private:
301 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest); 322 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, SharedBitmapTest);
302 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest); 323 FRIEND_TEST_ALL_PREFIXES(ClipboardTest, EmptyHTMLTest);
303 friend class ClipboardTest; 324 friend class ClipboardTest;
304 325
305 Clipboard(); 326 Clipboard();
306 ~Clipboard(); 327 ~Clipboard();
307 328
308 void DispatchObject(ObjectType type, const ObjectMapParams& params); 329 void DispatchObject(ObjectType type, const ObjectMapParams& params);
309 330
331 void WriteObjectsImpl(Buffer buffer, const ObjectMap& objects);
332
310 void WriteText(const char* text_data, size_t text_len); 333 void WriteText(const char* text_data, size_t text_len);
311 334
312 void WriteHTML(const char* markup_data, 335 void WriteHTML(const char* markup_data,
313 size_t markup_len, 336 size_t markup_len,
314 const char* url_data, 337 const char* url_data,
315 size_t url_len); 338 size_t url_len);
316 339
317 void WriteRTF(const char* rtf_data, size_t data_len); 340 void WriteRTF(const char* rtf_data, size_t data_len);
318 341
319 void WriteBookmark(const char* title_data, 342 void WriteBookmark(const char* title_data,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 TargetMap* clipboard_data_; 398 TargetMap* clipboard_data_;
376 GtkClipboard* clipboard_; 399 GtkClipboard* clipboard_;
377 GtkClipboard* primary_selection_; 400 GtkClipboard* primary_selection_;
378 #elif defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS) 401 #elif defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS)
379 private: 402 private:
380 // We keep our implementation details private because otherwise we bring in 403 // We keep our implementation details private because otherwise we bring in
381 // the X11 headers and break chrome compile. 404 // the X11 headers and break chrome compile.
382 class AuraX11Details; 405 class AuraX11Details;
383 scoped_ptr<AuraX11Details> aurax11_details_; 406 scoped_ptr<AuraX11Details> aurax11_details_;
384 #endif 407 #endif
408 ObserverList<ClipboardObserver> observer_list_;
385 409
386 DISALLOW_COPY_AND_ASSIGN(Clipboard); 410 DISALLOW_COPY_AND_ASSIGN(Clipboard);
387 }; 411 };
388 412
389 } // namespace ui 413 } // namespace ui
390 414
391 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ 415 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698