Index: ui/base/clipboard/clipboard.h |
diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h |
index 39cb5d4b27c4b79862fd93015d6d0eb5d2a5293a..9993423da45667dddd7b942aabc055381b0654a8 100644 |
--- a/ui/base/clipboard/clipboard.h |
+++ b/ui/base/clipboard/clipboard.h |
@@ -16,6 +16,10 @@ |
#include "base/string16.h" |
#include "ui/base/ui_export.h" |
+#if defined(TOOLKIT_USES_GTK) |
+#include <gdk/gdk.h> |
+#endif |
+ |
namespace gfx { |
class Size; |
} |
@@ -27,11 +31,49 @@ class SkBitmap; |
typedef struct _GtkClipboard GtkClipboard; |
#endif |
+#ifdef __OBJC__ |
+@class NSString; |
+#else |
+class NSString; |
+#endif |
+ |
namespace ui { |
class UI_EXPORT Clipboard { |
public: |
- typedef std::string FormatType; |
+ // Platform neutral holder for native data representation of a clipboard type. |
+ struct UI_EXPORT FormatType { |
+ // This only exists for the sake of IPC::Message serialization and |
+ // deserialization. |
+ FormatType(); |
+ ~FormatType(); |
+ |
+ private: |
+ friend class Clipboard; |
+ |
+#if defined(OS_WIN) |
+ explicit FormatType(UINT native_format); |
+ UINT data() const { return data_; } |
+ UINT data_; |
+#elif defined(USE_AURA) |
+ explicit FormatType(const std::string& native_format); |
+ const std::string& data() const { return data_; } |
+ std::string data_; |
+#elif defined(TOOLKIT_USES_GTK) |
+ explicit FormatType(const std::string& native_format); |
+ explicit FormatType(const GdkAtom& native_format); |
+ const GdkAtom& data() const { return data_; } |
+ GdkAtom data_; |
+#elif defined(OS_MACOSX) |
+ explicit FormatType(NSString* native_format); |
+ NSString* data() const { return data_; } |
+ // We don't use scoped_nsobject because this header gets included in a lot |
+ // of places. |
+ NSString* data_; |
+#else |
+#error No FormatType definition. |
+#endif |
+ }; |
// ObjectType designates the type of data to be stored in the clipboard. This |
// designation is shared across all OSes. The system-specific designation |
@@ -132,11 +174,6 @@ class UI_EXPORT Clipboard { |
// Tests whether the clipboard contains a certain format |
bool IsFormatAvailable(const FormatType& format, Buffer buffer) const; |
- // As above, but instead of interpreting |format| by some platform-specific |
- // definition, interpret it as a literal MIME type. |
- bool IsFormatAvailableByString(const std::string& format, |
- Buffer buffer) const; |
- |
void ReadAvailableTypes(Buffer buffer, std::vector<string16>* types, |
bool* contains_filenames) const; |
@@ -170,23 +207,32 @@ class UI_EXPORT Clipboard { |
// Reads raw data from the clipboard with the given format type. Stores result |
// as a byte vector. |
- // TODO(dcheng): Due to platform limitations on Windows, we should make sure |
- // format is never controlled by the user. |
- void ReadData(const std::string& format, std::string* result) const; |
- |
- // Get format Identifiers for various types. |
- static FormatType GetUrlFormatType(); |
- static FormatType GetUrlWFormatType(); |
- static FormatType GetMozUrlFormatType(); |
- static FormatType GetPlainTextFormatType(); |
- static FormatType GetPlainTextWFormatType(); |
- static FormatType GetFilenameFormatType(); |
- static FormatType GetFilenameWFormatType(); |
- static FormatType GetWebKitSmartPasteFormatType(); |
+ void ReadData(const FormatType& format, std::string* result) const; |
+ |
+ // Converts a format name into a FormatType, registering it with the system as |
+ // needed. Due to Windows/Linux limitiations, |format_string| must never be |
+ // controlled by the user. |
+ static FormatType RegisterFormatType(const std::string& format_string); |
tony
2011/12/06 18:58:29
Nit: I would perhaps name this GetFormatType since
dcheng
2011/12/06 22:57:02
Done.
|
+ |
+ // Helpers to serialize/deserialize FormatType to strings. These probably do |
+ // NOT do what you want. They are intended to help serialize FormatTypes for |
+ // IPC messages. |
+ static std::string FormatTypeToString(const FormatType& type); |
+ static FormatType StringToFormatType(const std::string& format_string); |
tony
2011/12/06 18:58:29
Why not just call these methods SerializeFormatTyp
dcheng
2011/12/06 22:57:02
Done.
|
+ |
+ // Get format identifiers for various types. |
+ static const FormatType& GetUrlFormatType(); |
+ static const FormatType& GetUrlWFormatType(); |
+ static const FormatType& GetMozUrlFormatType(); |
+ static const FormatType& GetPlainTextFormatType(); |
+ static const FormatType& GetPlainTextWFormatType(); |
+ static const FormatType& GetFilenameFormatType(); |
+ static const FormatType& GetFilenameWFormatType(); |
+ static const FormatType& GetWebKitSmartPasteFormatType(); |
// Win: MS HTML Format, Other: Generic HTML format |
- static FormatType GetHtmlFormatType(); |
- static FormatType GetBitmapFormatType(); |
- static FormatType GetWebCustomDataFormatType(); |
+ static const FormatType& GetHtmlFormatType(); |
+ static const FormatType& GetBitmapFormatType(); |
+ static const FormatType& GetWebCustomDataFormatType(); |
// Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle| |
// belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in |
@@ -198,10 +244,10 @@ class UI_EXPORT Clipboard { |
base::ProcessHandle process); |
#if defined(OS_WIN) |
// Firefox text/html |
- static FormatType GetTextHtmlFormatType(); |
- static FormatType GetCFHDropFormatType(); |
- static FormatType GetFileDescriptorFormatType(); |
- static FormatType GetFileContentFormatZeroType(); |
+ static const FormatType& GetTextHtmlFormatType(); |
+ static const FormatType& GetCFHDropFormatType(); |
+ static const FormatType& GetFileDescriptorFormatType(); |
+ static const FormatType& GetFileContentFormatZeroType(); |
#endif |
private: |
@@ -226,9 +272,9 @@ class UI_EXPORT Clipboard { |
void WriteBitmap(const char* pixel_data, const char* size_data); |
- // |format_name| is an ASCII string and should be NULL-terminated. |
- void WriteData(const char* format_name, size_t format_len, |
- const char* data_data, size_t data_len); |
+ void WriteData(const FormatType& format, |
+ const char* data_data, |
+ size_t data_len); |
#if defined(OS_WIN) |
void WriteBitmapFromHandle(HBITMAP source_hbitmap, |
const gfx::Size& size); |
@@ -262,7 +308,7 @@ class UI_EXPORT Clipboard { |
// contents of clipboard_data_. |
public: |
- typedef std::map<FormatType, std::pair<char*, size_t> > TargetMap; |
+ typedef std::map<std::string, std::pair<char*, size_t> > TargetMap; |
private: |
// Write changes to gtk clipboard. |