OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This file declares the ScopedClipboardWriter class, a wrapper around | |
6 // the Clipboard class which simplifies writing data to the system clipboard. | |
7 // Upon deletion the class atomically writes all data to |clipboard_|, | |
8 // avoiding any potential race condition with other processes that are also | |
9 // writing to the system clipboard. | |
10 #ifndef BASE_SCOPED_CLIPBOARD_WRITER_H_ | |
11 #define BASE_SCOPED_CLIPBOARD_WRITER_H_ | |
12 | |
13 #include <string> | |
14 #include <vector> | |
15 | |
16 #include "base/clipboard.h" | |
17 #include "base/file_path.h" | |
18 #include "base/string16.h" | |
19 | |
20 class Pickle; | |
21 | |
22 // This class is a wrapper for |Clipboard| that handles packing data | |
23 // into a Clipboard::ObjectMap. | |
24 // NB: You should probably NOT be using this class if you include | |
25 // webkit_glue.h. Use ScopedClipboardWriterGlue instead. | |
26 class ScopedClipboardWriter { | |
27 public: | |
28 // Create an instance that is a simple wrapper around clipboard. | |
29 ScopedClipboardWriter(Clipboard* clipboard); | |
30 | |
31 ~ScopedClipboardWriter(); | |
32 | |
33 // Converts |text| to UTF-8 and adds it to the clipboard. | |
34 void WriteText(const string16& text); | |
35 | |
36 // Converts the text of the URL to UTF-8 and adds it to the clipboard, then | |
37 // notifies the Clipboard that we just wrote a URL. | |
38 void WriteURL(const string16& text); | |
39 | |
40 // Adds HTML to the clipboard. The url parameter is optional, but especially | |
41 // useful if the HTML fragment contains relative links. | |
42 void WriteHTML(const string16& markup, const std::string& source_url); | |
43 | |
44 // Adds a bookmark to the clipboard. | |
45 void WriteBookmark(const string16& bookmark_title, | |
46 const std::string& url); | |
47 | |
48 // Adds an html hyperlink (<a href>) to the clipboard. |anchor_text| should | |
49 // be escaped prior to being passed in. | |
50 void WriteHyperlink(const std::string& anchor_text, const std::string& url); | |
51 | |
52 // Adds a file or group of files to the clipboard. | |
53 void WriteFile(const FilePath& file); | |
54 void WriteFiles(const std::vector<FilePath>& files); | |
55 | |
56 // Used by WebKit to determine whether WebKit wrote the clipboard last | |
57 void WriteWebSmartPaste(); | |
58 | |
59 // Adds a bitmap to the clipboard | |
60 // Pixel format is assumed to be 32-bit BI_RGB. | |
61 void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); | |
62 | |
63 // Adds arbitrary data to clipboard. | |
64 void WritePickledData(const Pickle& pickle, Clipboard::FormatType format); | |
65 | |
66 protected: | |
67 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we | |
68 // also notify the clipboard of that fact. | |
69 void WriteTextOrURL(const string16& text, bool is_url); | |
70 | |
71 // We accumulate the data passed to the various targets in the |objects_| | |
72 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | |
73 Clipboard::ObjectMap objects_; | |
74 Clipboard* clipboard_; | |
75 | |
76 // We keep around the UTF-8 text of the URL in order to pass it to | |
77 // Clipboard::DidWriteURL(). | |
78 std::string url_text_; | |
79 | |
80 private: | |
81 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | |
82 }; | |
83 | |
84 #endif // BASE_SCOPED_CLIPBOARD_WRITER_H_ | |
OLD | NEW |