| 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 15 matching lines...) Expand all Loading... |
| 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, ClipboardType type); | 31 ScopedClipboardWriter(Clipboard* clipboard, ClipboardType type); |
| 32 | 32 |
| 33 ~ScopedClipboardWriter(); | 33 ~ScopedClipboardWriter(); |
| 34 | 34 |
| 35 // Converts |text| to UTF-8 and adds it to the clipboard. | 35 // Converts |text| to UTF-8 and adds it to the clipboard. |
| 36 void WriteText(const string16& text); | 36 void WriteText(const base::string16& text); |
| 37 | 37 |
| 38 // 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 |
| 39 // notifies the Clipboard that we just wrote a URL. | 39 // notifies the Clipboard that we just wrote a URL. |
| 40 void WriteURL(const string16& text); | 40 void WriteURL(const base::string16& text); |
| 41 | 41 |
| 42 // 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 |
| 43 // useful if the HTML fragment contains relative links. | 43 // useful if the HTML fragment contains relative links. |
| 44 void WriteHTML(const string16& markup, const std::string& source_url); | 44 void WriteHTML(const base::string16& markup, const std::string& source_url); |
| 45 | 45 |
| 46 // Adds RTF to the clipboard. | 46 // Adds RTF to the clipboard. |
| 47 void WriteRTF(const std::string& rtf_data); | 47 void WriteRTF(const std::string& rtf_data); |
| 48 | 48 |
| 49 // Adds a bookmark to the clipboard. | 49 // Adds a bookmark to the clipboard. |
| 50 void WriteBookmark(const string16& bookmark_title, | 50 void WriteBookmark(const base::string16& bookmark_title, |
| 51 const std::string& url); | 51 const std::string& url); |
| 52 | 52 |
| 53 // Adds an html hyperlink (<a href>) to the clipboard. |anchor_text| and | 53 // Adds an html hyperlink (<a href>) to the clipboard. |anchor_text| and |
| 54 // |url| will be escaped as needed. | 54 // |url| will be escaped as needed. |
| 55 void WriteHyperlink(const string16& anchor_text, const std::string& url); | 55 void WriteHyperlink(const base::string16& anchor_text, |
| 56 const std::string& url); |
| 56 | 57 |
| 57 // Used by WebKit to determine whether WebKit wrote the clipboard last | 58 // Used by WebKit to determine whether WebKit wrote the clipboard last |
| 58 void WriteWebSmartPaste(); | 59 void WriteWebSmartPaste(); |
| 59 | 60 |
| 60 // Adds arbitrary pickled data to clipboard. | 61 // Adds arbitrary pickled data to clipboard. |
| 61 void WritePickledData(const Pickle& pickle, | 62 void WritePickledData(const Pickle& pickle, |
| 62 const Clipboard::FormatType& format); | 63 const Clipboard::FormatType& format); |
| 63 | 64 |
| 64 // Removes all objects that would be written to the clipboard. | 65 // Removes all objects that would be written to the clipboard. |
| 65 void Reset(); | 66 void Reset(); |
| 66 | 67 |
| 67 protected: | 68 protected: |
| 68 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we | 69 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we |
| 69 // also notify the clipboard of that fact. | 70 // also notify the clipboard of that fact. |
| 70 void WriteTextOrURL(const string16& text, bool is_url); | 71 void WriteTextOrURL(const base::string16& text, bool is_url); |
| 71 | 72 |
| 72 // We accumulate the data passed to the various targets in the |objects_| | 73 // We accumulate the data passed to the various targets in the |objects_| |
| 73 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | 74 // vector, and pass it to Clipboard::WriteObjects() during object destruction. |
| 74 Clipboard::ObjectMap objects_; | 75 Clipboard::ObjectMap objects_; |
| 75 Clipboard* clipboard_; | 76 Clipboard* clipboard_; |
| 76 ClipboardType type_; | 77 ClipboardType type_; |
| 77 | 78 |
| 78 // We keep around the UTF-8 text of the URL in order to pass it to | 79 // We keep around the UTF-8 text of the URL in order to pass it to |
| 79 // Clipboard::DidWriteURL(). | 80 // Clipboard::DidWriteURL(). |
| 80 std::string url_text_; | 81 std::string url_text_; |
| 81 | 82 |
| 82 private: | 83 private: |
| 83 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | 84 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 } // namespace ui | 87 } // namespace ui |
| 87 | 88 |
| 88 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 89 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
| 89 | 90 |
| OLD | NEW |