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 // This file declares the ScopedClipboardWriter class, a wrapper around | 5 // This file declares the ScopedClipboardWriter class, a wrapper around |
6 // the Clipboard class which simplifies writing data to the system clipboard. | 6 // the Clipboard class which simplifies writing data to the system clipboard. |
7 // Upon deletion the class atomically writes all data to |clipboard_|, | 7 // Upon deletion the class atomically writes all data to |clipboard_|, |
8 // avoiding any potential race condition with other processes that are also | 8 // avoiding any potential race condition with other processes that are also |
9 // writing to the system clipboard. | 9 // writing to the system clipboard. |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // This class is a wrapper for |Clipboard| that handles packing data | 24 // This class is a wrapper for |Clipboard| that handles packing data |
25 // into a Clipboard::ObjectMap. | 25 // into a Clipboard::ObjectMap. |
26 // NB: You should probably NOT be using this class if you include | 26 // NB: You should probably NOT be using this class if you include |
27 // webkit_glue.h. Use ScopedClipboardWriterGlue instead. | 27 // webkit_glue.h. Use ScopedClipboardWriterGlue instead. |
28 class UI_EXPORT ScopedClipboardWriter { | 28 class UI_EXPORT ScopedClipboardWriter { |
29 public: | 29 public: |
30 // Create an instance that is a simple wrapper around clipboard. | 30 // Create an instance that is a simple wrapper around clipboard. |
31 ScopedClipboardWriter(Clipboard* clipboard, Clipboard::Buffer buffer); | 31 ScopedClipboardWriter(Clipboard* clipboard, Clipboard::Buffer buffer); |
32 | 32 |
33 ScopedClipboardWriter(Clipboard* clipboard, | |
34 Clipboard::Buffer buffer, | |
35 Clipboard::SourceTag source_tag); | |
36 | |
37 ~ScopedClipboardWriter(); | 33 ~ScopedClipboardWriter(); |
38 | 34 |
39 // Converts |text| to UTF-8 and adds it to the clipboard. | 35 // Converts |text| to UTF-8 and adds it to the clipboard. |
40 void WriteText(const string16& text); | 36 void WriteText(const string16& text); |
41 | 37 |
42 // Converts the text of the URL to UTF-8 and adds it to the clipboard, then | 38 // Converts the text of the URL to UTF-8 and adds it to the clipboard, then |
43 // notifies the Clipboard that we just wrote a URL. | 39 // notifies the Clipboard that we just wrote a URL. |
44 void WriteURL(const string16& text); | 40 void WriteURL(const string16& text); |
45 | 41 |
46 // Adds HTML to the clipboard. The url parameter is optional, but especially | 42 // Adds HTML to the clipboard. The url parameter is optional, but especially |
(...skipping 28 matching lines...) Expand all Loading... |
75 protected: | 71 protected: |
76 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we | 72 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we |
77 // also notify the clipboard of that fact. | 73 // also notify the clipboard of that fact. |
78 void WriteTextOrURL(const string16& text, bool is_url); | 74 void WriteTextOrURL(const string16& text, bool is_url); |
79 | 75 |
80 // We accumulate the data passed to the various targets in the |objects_| | 76 // We accumulate the data passed to the various targets in the |objects_| |
81 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | 77 // vector, and pass it to Clipboard::WriteObjects() during object destruction. |
82 Clipboard::ObjectMap objects_; | 78 Clipboard::ObjectMap objects_; |
83 Clipboard* clipboard_; | 79 Clipboard* clipboard_; |
84 Clipboard::Buffer buffer_; | 80 Clipboard::Buffer buffer_; |
85 Clipboard::SourceTag source_tag_; | |
86 | 81 |
87 // We keep around the UTF-8 text of the URL in order to pass it to | 82 // We keep around the UTF-8 text of the URL in order to pass it to |
88 // Clipboard::DidWriteURL(). | 83 // Clipboard::DidWriteURL(). |
89 std::string url_text_; | 84 std::string url_text_; |
90 | 85 |
91 private: | 86 private: |
92 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | 87 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); |
93 }; | 88 }; |
94 | 89 |
95 } // namespace ui | 90 } // namespace ui |
96 | 91 |
97 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 92 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
98 | 93 |
OLD | NEW |