Index: ui/base/clipboard/clipboard.h |
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h |
index c85b90adcd20319bc78d5e1bfe9c046d5db59cbe..2ce52c275b6cb8b0bd40d6b87a0f751f2cace8f0 100644 |
--- a/ui/base/clipboard/clipboard.h |
+++ b/ui/base/clipboard/clipboard.h |
@@ -11,6 +11,7 @@ |
#include "base/compiler_specific.h" |
#include "base/gtest_prod_util.h" |
+#include "base/observer_list.h" |
#include "base/process.h" |
#include "base/shared_memory.h" |
#include "base/string16.h" |
@@ -169,6 +170,12 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
typedef std::vector<ObjectMapParam> ObjectMapParams; |
typedef std::map<int /* ObjectType */, ObjectMapParams> ObjectMap; |
+ // WriteObject() caller can use the SourceTag that will be stored in the |
+ // clipboard. NULL value means "no tag". |
+ typedef void* SourceTag; |
+ static ObjectMapParam SourceTag2Binary(SourceTag tag); |
+ static SourceTag Binary2SourceTag(const std::string& serialization); |
+ |
// Buffer designates which clipboard the action should be applied to. |
// Only platforms that use the X Window System support the selection |
// buffer. |
@@ -177,6 +184,24 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
BUFFER_SELECTION, |
}; |
+ // This observer does track only calls to Clipboard::WriteObjects. |
+ // Don't use it for notification about changed OS clipboard. |
+ class ClipboardObserverForTesting { |
jam
2013/02/11 21:28:53
observer interfaces for one callback is too heavyw
vasilii
2013/02/13 16:57:26
Done.
|
+ public: |
+ // Called at the end of Clipboard::WriteObjects(). |
+ virtual void OnWriteObjects(Buffer buffer) = 0; |
+ protected: |
+ virtual ~ClipboardObserverForTesting() {} |
+ }; |
+ |
+ void AddObserver(ClipboardObserverForTesting* obs) { |
+ observer_list_.AddObserver(obs); |
+ } |
+ |
+ void RemoveObserver(ClipboardObserverForTesting* obs) { |
+ observer_list_.RemoveObserver(obs); |
+ } |
+ |
static bool IsValidBuffer(int32 buffer) { |
switch (buffer) { |
case BUFFER_STANDARD: |
@@ -214,7 +239,9 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
// contents of |objects|. On Windows they are copied to the system clipboard. |
// On linux they are copied into a structure owned by the Clipboard object and |
// kept until the system clipboard is set again. |
- void WriteObjects(Buffer buffer, const ObjectMap& objects); |
+ // SourceTag is optional value to be stored in the clipboard, NULL won't be |
+ // stored. |
+ void WriteObjects(Buffer buffer, const ObjectMap& objects, SourceTag tag); |
// Returns a sequence number which uniquely identifies clipboard state. |
// This can be used to version the data on the clipboard and determine |
@@ -261,6 +288,9 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
// as a byte vector. |
void ReadData(const FormatType& format, std::string* result) const; |
+ // Reads Source tag from the clipboard, if available. |
+ SourceTag ReadSourceTag(Buffer buffer) const; |
+ |
// Gets the FormatType corresponding to an arbitrary format string, |
// registering it with the system if needed. Due to Windows/Linux |
// limitiations, |format_string| must never be controlled by the user. |
@@ -283,6 +313,7 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
// crbug.com/158399. |
static const FormatType& GetWebCustomDataFormatType(); |
static const FormatType& GetPepperCustomDataFormatType(); |
+ static const FormatType& GetSourceTagFormatType(); |
// Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle| |
// belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in |
@@ -310,6 +341,8 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
void DispatchObject(ObjectType type, const ObjectMapParams& params); |
+ void WriteObjectsImpl(Buffer buffer, const ObjectMap& objects, SourceTag tag); |
+ |
void WriteText(const char* text_data, size_t text_len); |
void WriteHTML(const char* markup_data, |
@@ -331,6 +364,8 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
void WriteData(const FormatType& format, |
const char* data_data, |
size_t data_len); |
+ |
+ void WriteSourceTag(SourceTag tag); |
#if defined(OS_WIN) |
void WriteBitmapFromHandle(HBITMAP source_hbitmap, |
const gfx::Size& size); |
@@ -368,23 +403,32 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { |
private: |
// Write changes to gtk clipboard. |
- void SetGtkClipboard(Buffer buffer); |
+ void SetGtkClipboard(Buffer buffer, SourceTag tag); |
// Insert a mapping into clipboard_data_. |
void InsertMapping(const char* key, char* data, size_t data_len); |
// Find the gtk clipboard for the passed buffer enum. |
GtkClipboard* LookupBackingClipboard(Buffer clipboard) const; |
+ // Reads raw data from the specified clipboard with the given format type. |
dcheng
2013/02/11 22:58:21
I think in the long run, I'd prefer to see ReadDat
vasilii
2013/02/12 15:58:32
Yes, I agree to modify ReadData(). But note that R
|
+ void ReadDataImpl(Buffer buffer, |
+ const FormatType& format, |
+ std::string* result) const; |
TargetMap* clipboard_data_; |
GtkClipboard* clipboard_; |
GtkClipboard* primary_selection_; |
#elif defined(USE_AURA) && defined(USE_X11) && !defined(OS_CHROMEOS) |
private: |
+ // Reads raw data from the specified clipboard with the given format type. |
+ void ReadDataImpl(Buffer buffer, |
+ const FormatType& format, |
+ std::string* result) const; |
// We keep our implementation details private because otherwise we bring in |
// the X11 headers and break chrome compile. |
class AuraX11Details; |
scoped_ptr<AuraX11Details> aurax11_details_; |
#endif |
+ ObserverList<ClipboardObserverForTesting> observer_list_; |
DISALLOW_COPY_AND_ASSIGN(Clipboard); |
}; |