diff options
-rw-r--r-- | ppapi/c/private/ppb_flash_clipboard.h | 16 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_clipboard_proxy.cc | 40 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_clipboard_proxy.h | 4 | ||||
-rw-r--r-- | webkit/glue/webclipboard_impl.cc | 11 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc | 35 | ||||
-rw-r--r-- | webkit/tools/test_shell/mock_webclipboard_impl.cc | 3 |
7 files changed, 109 insertions, 5 deletions
diff --git a/ppapi/c/private/ppb_flash_clipboard.h b/ppapi/c/private/ppb_flash_clipboard.h index c16ae36..e95e19c 100644 --- a/ppapi/c/private/ppb_flash_clipboard.h +++ b/ppapi/c/private/ppb_flash_clipboard.h @@ -5,10 +5,11 @@ #ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ #define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ +#include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_var.h" -#define PPB_FLASH_CLIPBOARD_INTERFACE "PPB_Flash_Clipboard;2" +#define PPB_FLASH_CLIPBOARD_INTERFACE "PPB_Flash_Clipboard;3" typedef enum { PP_FLASH_CLIPBOARD_TYPE_STANDARD = 0, @@ -16,7 +17,18 @@ typedef enum { PP_FLASH_CLIPBOARD_TYPE_DRAG = 2 } PP_Flash_Clipboard_Type; +typedef enum { + PP_FLASH_CLIPBOARD_FORMAT_INVALID = 0, + PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT = 1, + PP_FLASH_CLIPBOARD_FORMAT_HTML = 2 +} PP_Flash_Clipboard_Format; + struct PPB_Flash_Clipboard { + // Returns true if the given format is available from the given clipboard. + PP_Bool (*IsFormatAvailable)(PP_Instance instance_id, + PP_Flash_Clipboard_Type clipboard_type, + PP_Flash_Clipboard_Format format); + // Reads plain text data from the clipboard. struct PP_Var (*ReadPlainText)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type); @@ -27,7 +39,7 @@ struct PPB_Flash_Clipboard { PP_Flash_Clipboard_Type clipboard_type, struct PP_Var text); - // TODO(vtl): More formats, a |IsFormatAvailable()|, .... + // TODO(vtl): More formats (e.g., HTML).... }; #endif // PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 3681d1e..6f5aae8 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -391,6 +391,11 @@ IPC_SYNC_MESSAGE_ROUTED1_0(PpapiHostMsg_PPBFlash_QuitMessageLoop, PP_Instance /* instance */) // PPB_Flash_Clipboard. +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, + PP_Instance /* instance */, + int /* clipboard_type */, + int /* format */, + bool /* result */) IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, PP_Instance /* instance */, int /* clipboard_type */, diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc index a849071..efe1df3 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc @@ -21,6 +21,32 @@ bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { clipboard_type == PP_FLASH_CLIPBOARD_TYPE_DRAG; } +bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { + // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|. + return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || + format == PP_FLASH_CLIPBOARD_FORMAT_HTML; +} + +PP_Bool IsFormatAvailable(PP_Instance instance_id, + PP_Flash_Clipboard_Type clipboard_type, + PP_Flash_Clipboard_Format format) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); + if (!dispatcher) + return PP_FALSE; + + if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) + return PP_FALSE; + + bool result = false; + dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( + INTERFACE_ID_PPB_FLASH_CLIPBOARD, + instance_id, + static_cast<int>(clipboard_type), + static_cast<int>(format), + &result)); + return BoolToPPBool(result); +} + PP_Var ReadPlainText(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); @@ -57,6 +83,7 @@ int32_t WritePlainText(PP_Instance instance_id, } const PPB_Flash_Clipboard flash_clipboard_interface = { + &IsFormatAvailable, &ReadPlainText, &WritePlainText }; @@ -91,6 +118,8 @@ const InterfaceProxy::Info* PPB_Flash_Clipboard_Proxy::GetInfo() { bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, + OnMsgIsFormatAvailable) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadPlainText, OnMsgReadPlainText) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WritePlainText, @@ -100,6 +129,17 @@ bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { return handled; } +void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( + PP_Instance instance_id, + int clipboard_type, + int format, + bool* result) { + *result = PPBoolToBool(ppb_flash_clipboard_target()->IsFormatAvailable( + instance_id, + static_cast<PP_Flash_Clipboard_Type>(clipboard_type), + static_cast<PP_Flash_Clipboard_Format>(format))); +} + void PPB_Flash_Clipboard_Proxy::OnMsgReadPlainText( PP_Instance instance_id, int clipboard_type, diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.h b/ppapi/proxy/ppb_flash_clipboard_proxy.h index 2d68183..6d9604f 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.h +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.h @@ -33,6 +33,10 @@ class PPB_Flash_Clipboard_Proxy : public InterfaceProxy { private: // Message handlers. + void OnMsgIsFormatAvailable(PP_Instance instance_id, + int clipboard_type, + int format, + bool* result); void OnMsgReadPlainText(PP_Instance instance_id, int clipboard_type, SerializedVarReturnValue result); diff --git a/webkit/glue/webclipboard_impl.cc b/webkit/glue/webclipboard_impl.cc index 9eddb68..10dddab 100644 --- a/webkit/glue/webclipboard_impl.cc +++ b/webkit/glue/webclipboard_impl.cc @@ -67,7 +67,15 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { ui::Clipboard::FormatType format_type; ui::Clipboard::Buffer buffer_type; + if (!ConvertBufferType(buffer, &buffer_type)) + return false; + switch (format) { + case FormatPlainText: + return ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), + buffer_type) || + ClipboardIsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), + buffer_type); case FormatHTML: format_type = ui::Clipboard::GetHtmlFormatType(); break; @@ -84,9 +92,6 @@ bool WebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { return false; } - if (!ConvertBufferType(buffer, &buffer_type)) - return false; - return ClipboardIsFormatAvailable(format_type, buffer_type); } diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc index 630a897..c0b3273 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc @@ -16,6 +16,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKitClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" +#include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/resource_tracker.h" #include "webkit/plugins/ppapi/var.h" @@ -42,6 +43,39 @@ WebKit::WebClipboard::Buffer ConvertClipboardType( } } +WebKit::WebClipboard::Format ConvertClipboardFormat( + PP_Flash_Clipboard_Format format) { + switch (format) { + case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: + return WebKit::WebClipboard::FormatPlainText; + case PP_FLASH_CLIPBOARD_FORMAT_HTML: + return WebKit::WebClipboard::FormatHTML; + case PP_FLASH_CLIPBOARD_FORMAT_INVALID: + default: + NOTREACHED(); + return WebKit::WebClipboard::FormatPlainText; // Gotta return something. + } +} + +PP_Bool IsFormatAvailable(PP_Instance instance_id, + PP_Flash_Clipboard_Type clipboard_type, + PP_Flash_Clipboard_Format format) { + // If you don't give us an instance, we don't give you anything. + PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); + if (!instance) + return PP_FALSE; + + WebKit::WebClipboard* web_clipboard = WebKit::webKitClient()->clipboard(); + if (!web_clipboard) { + NOTREACHED(); + return PP_FALSE; + } + + return BoolToPPBool( + web_clipboard->isFormatAvailable(ConvertClipboardFormat(format), + ConvertClipboardType(clipboard_type))); +} + PP_Var ReadPlainText(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); @@ -86,6 +120,7 @@ int32_t WritePlainText(PP_Instance instance_id, } const PPB_Flash_Clipboard ppb_flash_clipboard = { + &IsFormatAvailable, &ReadPlainText, &WritePlainText, }; diff --git a/webkit/tools/test_shell/mock_webclipboard_impl.cc b/webkit/tools/test_shell/mock_webclipboard_impl.cc index c10a32d..1e00f70 100644 --- a/webkit/tools/test_shell/mock_webclipboard_impl.cc +++ b/webkit/tools/test_shell/mock_webclipboard_impl.cc @@ -18,6 +18,9 @@ using WebKit::WebVector; bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { switch (format) { + case FormatPlainText: + return !m_plainText.isEmpty(); + case FormatHTML: return !m_htmlText.isEmpty(); |