Chromium Code Reviews| 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 the 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 |
| 11 #ifndef UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 11 #ifndef UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
| 12 #define UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 12 #define UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
| 18 #include "ui/base/ui_base_export.h" | 18 #include "ui/base/ui_base_export.h" |
| 19 | 19 |
| 20 class Pickle; | 20 class Pickle; |
| 21 | 21 |
| 22 namespace ui { | 22 namespace ui { |
| 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 class UI_BASE_EXPORT ScopedClipboardWriter { | 26 class UI_BASE_EXPORT ScopedClipboardWriter { |
| 27 public: | 27 public: |
| 28 // Create an instance that is a simple wrapper around clipboard. | 28 // Create an instance that is a simple wrapper around the clipboard of the |
| 29 ScopedClipboardWriter(Clipboard* clipboard, ClipboardType type); | 29 // given type. |
| 30 explicit ScopedClipboardWriter(ClipboardType type); | |
| 30 | 31 |
| 31 ~ScopedClipboardWriter(); | 32 ~ScopedClipboardWriter(); |
| 32 | 33 |
| 33 // Converts |text| to UTF-8 and adds it to the clipboard. | 34 // Converts |text| to UTF-8 and adds it to the clipboard. |
| 34 void WriteText(const base::string16& text); | 35 void WriteText(const base::string16& text); |
| 35 | 36 |
| 36 // Converts the text of the URL to UTF-8 and adds it to the clipboard, then | 37 // 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 // notifies the Clipboard that we just wrote a URL. |
| 38 void WriteURL(const base::string16& text); | 39 void WriteURL(const base::string16& text); |
| 39 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 63 // Removes all objects that would be written to the clipboard. | 64 // Removes all objects that would be written to the clipboard. |
| 64 void Reset(); | 65 void Reset(); |
| 65 | 66 |
| 66 protected: | 67 protected: |
| 67 // Converts |text| to UTF-8 and adds it to the clipboard. If it's a URL, we | 68 // 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 // also notify the clipboard of that fact. |
| 69 void WriteTextOrURL(const base::string16& text, bool is_url); | 70 void WriteTextOrURL(const base::string16& text, bool is_url); |
| 70 | 71 |
| 71 // We accumulate the data passed to the various targets in the |objects_| | 72 // We accumulate the data passed to the various targets in the |objects_| |
| 72 // vector, and pass it to Clipboard::WriteObjects() during object destruction. | 73 // vector, and pass it to Clipboard::WriteObjects() during object destruction. |
| 73 Clipboard::ObjectMap objects_; | 74 Clipboard::ObjectMap objects_; |
|
sky
2014/09/17 15:41:50
style guide says members should be private.
dcheng
2014/09/17 17:10:48
Yeah, ScopedClipboardWriterGlue directly modifies
| |
| 74 Clipboard* clipboard_; | 75 const ClipboardType type_; |
| 75 ClipboardType type_; | |
| 76 | 76 |
| 77 // We keep around the UTF-8 text of the URL in order to pass it to | 77 // We keep around the UTF-8 text of the URL in order to pass it to |
| 78 // Clipboard::DidWriteURL(). | 78 // Clipboard::DidWriteURL(). |
| 79 std::string url_text_; | 79 std::string url_text_; |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); | 82 DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriter); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 } // namespace ui | 85 } // namespace ui |
| 86 | 86 |
| 87 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ | 87 #endif // UI_BASE_CLIPBOARD_SCOPED_CLIPBOARD_WRITER_H_ |
| 88 | 88 |
| OLD | NEW |