diff options
author | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 23:39:34 +0000 |
---|---|---|
committer | raymes@chromium.org <raymes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 23:39:34 +0000 |
commit | a1686e279d7f6ec3cebc91cd759af80963e2c0ad (patch) | |
tree | 19f9986146e49985b8ddecee53a241c4efe7b083 | |
parent | 259359a48b7f497a355bcd9fea7ae3bd361a7539 (diff) | |
download | chromium_src-a1686e279d7f6ec3cebc91cd759af80963e2c0ad.zip chromium_src-a1686e279d7f6ec3cebc91cd759af80963e2c0ad.tar.gz chromium_src-a1686e279d7f6ec3cebc91cd759af80963e2c0ad.tar.bz2 |
Move flash clipboard to the new proxy and add custom format support
This moves the flash clipboard interface to the new pepper proxy. It also adds support for copying/pasting data of custom data formats (which is needed for flash).
BUG=154497
TEST=Added new pepper tests
Review URL: https://chromiumcodereview.appspot.com/11225021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165548 0039d316-1c4b-4281-b951-d872f2087c98
63 files changed, 1334 insertions, 613 deletions
diff --git a/chrome/test/ppapi/ppapi_browsertest.cc b/chrome/test/ppapi/ppapi_browsertest.cc index de808d2..620281e 100644 --- a/chrome/test/ppapi/ppapi_browsertest.cc +++ b/chrome/test/ppapi/ppapi_browsertest.cc @@ -598,9 +598,6 @@ TEST_PPAPI_IN_PROCESS_VIA_HTTP(MAYBE_Fullscreen) TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(MAYBE_Fullscreen) TEST_PPAPI_NACL_VIA_HTTP(MAYBE_Fullscreen) -TEST_PPAPI_IN_PROCESS(FlashClipboard) -TEST_PPAPI_OUT_OF_PROCESS(FlashClipboard) - TEST_PPAPI_IN_PROCESS(X509CertificatePrivate) TEST_PPAPI_OUT_OF_PROCESS(X509CertificatePrivate) @@ -936,7 +933,8 @@ TEST_PPAPI_OUT_OF_PROCESS(MessageLoop_Basics) TEST_PPAPI_OUT_OF_PROCESS(MessageLoop_Post) #endif -// Only enabled in out-of-process mode. +// Going forward, Flash APIs will only work out-of-process. +TEST_PPAPI_OUT_OF_PROCESS(FlashClipboard) TEST_PPAPI_OUT_OF_PROCESS(FlashFile_CreateTemporaryFile) #endif // ADDRESS_SANITIZER diff --git a/content/browser/renderer_host/clipboard_message_filter.cc b/content/browser/renderer_host/clipboard_message_filter.cc index 80d69fe7..d447dc0 100644 --- a/content/browser/renderer_host/clipboard_message_filter.cc +++ b/content/browser/renderer_host/clipboard_message_filter.cc @@ -81,6 +81,7 @@ bool ClipboardMessageFilter::OnMessageReceived(const IPC::Message& message, IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadRTF, OnReadRTF) IPC_MESSAGE_HANDLER_DELAY_REPLY(ClipboardHostMsg_ReadImage, OnReadImage) IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadCustomData, OnReadCustomData) + IPC_MESSAGE_HANDLER(ClipboardHostMsg_ReadData, OnReadData) #if defined(OS_MACOSX) IPC_MESSAGE_HANDLER(ClipboardHostMsg_FindPboardWriteStringAsync, OnFindPboardWriteString) @@ -240,6 +241,11 @@ void ClipboardMessageFilter::OnReadCustomData( GetClipboard()->ReadCustomData(buffer, type, result); } +void ClipboardMessageFilter::OnReadData(const ui::Clipboard::FormatType& format, + std::string* data) { + GetClipboard()->ReadData(format, data); +} + // static ui::Clipboard* ClipboardMessageFilter::GetClipboard() { // We have a static instance of the clipboard service for use by all message diff --git a/content/browser/renderer_host/clipboard_message_filter.h b/content/browser/renderer_host/clipboard_message_filter.h index d275fc7..73cfdd0 100644 --- a/content/browser/renderer_host/clipboard_message_filter.h +++ b/content/browser/renderer_host/clipboard_message_filter.h @@ -51,6 +51,9 @@ class ClipboardMessageFilter : public BrowserMessageFilter { void OnReadCustomData(ui::Clipboard::Buffer buffer, const string16& type, string16* result); + void OnReadData(const ui::Clipboard::FormatType& format, + std::string* data); + #if defined(OS_MACOSX) void OnFindPboardWriteString(const string16& text); #endif diff --git a/content/common/clipboard_messages.h b/content/common/clipboard_messages.h index 7900a46..2d04b82 100644 --- a/content/common/clipboard_messages.h +++ b/content/common/clipboard_messages.h @@ -81,6 +81,9 @@ IPC_SYNC_MESSAGE_CONTROL2_1(ClipboardHostMsg_ReadCustomData, ui::Clipboard::Buffer /* buffer */, string16 /* type */, string16 /* result */) +IPC_SYNC_MESSAGE_CONTROL1_1(ClipboardHostMsg_ReadData, + ui::Clipboard::FormatType /* format */, + std::string /* result */) #if defined(OS_MACOSX) IPC_MESSAGE_CONTROL1(ClipboardHostMsg_FindPboardWriteStringAsync, diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi index 4d0d1b8..47cfd5e 100644 --- a/content/content_renderer.gypi +++ b/content/content_renderer.gypi @@ -169,6 +169,8 @@ 'renderer/pepper/pepper_device_enumeration_event_handler.h', 'renderer/pepper/pepper_file_chooser_host.cc', 'renderer/pepper/pepper_file_chooser_host.h', + 'renderer/pepper/pepper_flash_clipboard_host.cc', + 'renderer/pepper/pepper_flash_clipboard_host.h', 'renderer/pepper/pepper_flash_host.cc', 'renderer/pepper/pepper_flash_host.h', 'renderer/pepper/pepper_hung_plugin_filter.cc', diff --git a/content/renderer/pepper/content_renderer_pepper_host_factory.cc b/content/renderer/pepper/content_renderer_pepper_host_factory.cc index 732db9f..2b4998f 100644 --- a/content/renderer/pepper/content_renderer_pepper_host_factory.cc +++ b/content/renderer/pepper/content_renderer_pepper_host_factory.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "content/renderer/pepper/pepper_file_chooser_host.h" +#include "content/renderer/pepper/pepper_flash_clipboard_host.h" #include "content/renderer/pepper/pepper_flash_host.h" #include "content/renderer/pepper/pepper_websocket_host.h" #include "content/renderer/pepper/renderer_ppapi_host_impl.h" @@ -63,6 +64,9 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost( case PpapiHostMsg_Flash_Create::ID: return scoped_ptr<ResourceHost>(new PepperFlashHost( host_, instance, params.pp_resource())); + case PpapiHostMsg_FlashClipboard_Create::ID: + return scoped_ptr<ResourceHost>(new PepperFlashClipboardHost( + host_, instance, params.pp_resource())); } } diff --git a/content/renderer/pepper/pepper_flash_clipboard_host.cc b/content/renderer/pepper/pepper_flash_clipboard_host.cc new file mode 100644 index 0000000..686d7f9 --- /dev/null +++ b/content/renderer/pepper/pepper_flash_clipboard_host.cc @@ -0,0 +1,339 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/renderer/pepper/pepper_flash_clipboard_host.h" + +#include "base/pickle.h" +#include "base/utf_string_conversions.h" +#include "content/public/renderer/renderer_ppapi_host.h" +#include "content/renderer/renderer_clipboard_client.h" +#include "ipc/ipc_message_macros.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/host/dispatch_host_message.h" +#include "ppapi/host/ppapi_host.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/resource_message_params.h" +#include "webkit/glue/clipboard_client.h" +#include "webkit/glue/scoped_clipboard_writer_glue.h" + +namespace content { + +namespace { + +const size_t kMaxClipboardWriteSize = 1000000; + +ui::Clipboard::Buffer ConvertClipboardType(uint32_t type) { + switch (type) { + case PP_FLASH_CLIPBOARD_TYPE_STANDARD: + return ui::Clipboard::BUFFER_STANDARD; + case PP_FLASH_CLIPBOARD_TYPE_SELECTION: + return ui::Clipboard::BUFFER_SELECTION; + } + NOTREACHED(); + return ui::Clipboard::BUFFER_STANDARD; +} + +// Functions to pack/unpack custom data from a pickle. See the header file for +// more detail on custom formats in Pepper. +// TODO(raymes): Currently pepper custom formats are stored in their own +// native format type. However we should be able to store them in the same way +// as "Web Custom" formats are. This would allow clipboard data to be shared +// between pepper applications and web applications. However currently web apps +// assume all data that is placed on the clipboard is UTF16 and pepper allows +// arbitrary data so this change would require some reworking of the chrome +// clipboard interface for custom data. +bool JumpToFormatInPickle(const string16& format, PickleIterator* iter) { + uint64 size = 0; + if (!iter->ReadUInt64(&size)) + return false; + for (uint64 i = 0; i < size; ++i) { + string16 stored_format; + if (!iter->ReadString16(&stored_format)) + return false; + if (stored_format == format) + return true; + int skip_length; + if (!iter->ReadLength(&skip_length)) + return false; + if (!iter->SkipBytes(skip_length)) + return false; + } + return false; +} + +bool IsFormatAvailableInPickle(const string16& format, const Pickle& pickle) { + PickleIterator iter(pickle); + return JumpToFormatInPickle(format, &iter); +} + +std::string ReadDataFromPickle(const string16& format, const Pickle& pickle) { + std::string result; + PickleIterator iter(pickle); + if (!JumpToFormatInPickle(format, &iter) || !iter.ReadString(&result)) + return std::string(); + return result; +} + +bool WriteDataToPickle(const std::map<string16, std::string>& data, + Pickle* pickle) { + pickle->WriteUInt64(data.size()); + for (std::map<string16, std::string>::const_iterator it = data.begin(); + it != data.end(); ++it) { + if (!pickle->WriteString16(it->first)) + return false; + if (!pickle->WriteString(it->second)) + return false; + } + return true; +} + +} // namespace + +PepperFlashClipboardHost::PepperFlashClipboardHost( + RendererPpapiHost* host, + PP_Instance instance, + PP_Resource resource) + : ResourceHost(host->GetPpapiHost(), instance, resource), + clipboard_client_(new RendererClipboardClient) { +} + +PepperFlashClipboardHost::~PepperFlashClipboardHost() { +} + +int32_t PepperFlashClipboardHost::OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) { + IPC_BEGIN_MESSAGE_MAP(PepperFlashClipboardHost, msg) + PPAPI_DISPATCH_HOST_RESOURCE_CALL( + PpapiHostMsg_FlashClipboard_RegisterCustomFormat, + OnMsgRegisterCustomFormat); + PPAPI_DISPATCH_HOST_RESOURCE_CALL( + PpapiHostMsg_FlashClipboard_IsFormatAvailable, + OnMsgIsFormatAvailable); + PPAPI_DISPATCH_HOST_RESOURCE_CALL( + PpapiHostMsg_FlashClipboard_ReadData, + OnMsgReadData); + PPAPI_DISPATCH_HOST_RESOURCE_CALL( + PpapiHostMsg_FlashClipboard_WriteData, + OnMsgWriteData); + IPC_END_MESSAGE_MAP() + return PP_ERROR_FAILED; +} + +int32_t PepperFlashClipboardHost::OnMsgRegisterCustomFormat( + ppapi::host::HostMessageContext* host_context, + const std::string& format_name) { + uint32_t format = custom_formats_.RegisterFormat(format_name); + if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) + return PP_ERROR_FAILED; + host_context->reply_msg = + PpapiPluginMsg_FlashClipboard_RegisterCustomFormatReply(format); + return PP_OK; +} + +int32_t PepperFlashClipboardHost::OnMsgIsFormatAvailable( + ppapi::host::HostMessageContext* host_context, + uint32_t clipboard_type, + uint32_t format) { + if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { + NOTIMPLEMENTED(); + return PP_ERROR_FAILED; + } + + ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); + bool available = false; + switch (format) { + case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { + bool plain = clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetPlainTextFormatType(), buffer_type); + bool plainw = clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetPlainTextWFormatType(), buffer_type); + available = plain || plainw; + break; + } + case PP_FLASH_CLIPBOARD_FORMAT_HTML: + available = clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetHtmlFormatType(), buffer_type); + break; + case PP_FLASH_CLIPBOARD_FORMAT_RTF: + available = clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetRtfFormatType(), buffer_type); + break; + case PP_FLASH_CLIPBOARD_FORMAT_INVALID: + break; + default: + if (custom_formats_.IsFormatRegistered(format)) { + std::string format_name = custom_formats_.GetFormatName(format); + std::string clipboard_data; + clipboard_client_->ReadData( + ui::Clipboard::GetPepperCustomDataFormatType(), &clipboard_data); + Pickle pickle(clipboard_data.data(), clipboard_data.size()); + available = IsFormatAvailableInPickle(UTF8ToUTF16(format_name), pickle); + } + break; + } + + return available ? PP_OK : PP_ERROR_FAILED; +} + +int32_t PepperFlashClipboardHost::OnMsgReadData( + ppapi::host::HostMessageContext* host_context, + uint32_t clipboard_type, + uint32_t format) { + if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { + NOTIMPLEMENTED(); + return PP_ERROR_FAILED; + } + + ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); + std::string clipboard_string; + int32_t result = PP_ERROR_FAILED; + switch (format) { + case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { + if (clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetPlainTextWFormatType(), buffer_type)) { + string16 text; + clipboard_client_->ReadText(buffer_type, &text); + if (!text.empty()) { + result = PP_OK; + clipboard_string = UTF16ToUTF8(text); + break; + } + } + // If the PlainTextW format isn't available or is empty, take the + // ASCII text format. + if (clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetPlainTextFormatType(), buffer_type)) { + result = PP_OK; + clipboard_client_->ReadAsciiText(buffer_type, &clipboard_string); + } + break; + } + case PP_FLASH_CLIPBOARD_FORMAT_HTML: { + if (!clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetHtmlFormatType(), buffer_type)) { + break; + } + + string16 html; + GURL gurl; + uint32 fragment_start; + uint32 fragment_end; + clipboard_client_->ReadHTML(buffer_type, &html, &gurl, &fragment_start, + &fragment_end); + result = PP_OK; + clipboard_string = UTF16ToUTF8( + html.substr(fragment_start, fragment_end - fragment_start)); + break; + } + case PP_FLASH_CLIPBOARD_FORMAT_RTF: { + if (!clipboard_client_->IsFormatAvailable( + ui::Clipboard::GetRtfFormatType(), buffer_type)) { + break; + } + result = PP_OK; + clipboard_client_->ReadRTF(buffer_type, &clipboard_string); + break; + } + case PP_FLASH_CLIPBOARD_FORMAT_INVALID: + break; + default: { + if (custom_formats_.IsFormatRegistered(format)) { + string16 format_name = UTF8ToUTF16( + custom_formats_.GetFormatName(format)); + std::string clipboard_data; + clipboard_client_->ReadData( + ui::Clipboard::GetPepperCustomDataFormatType(), &clipboard_data); + Pickle pickle(clipboard_data.data(), clipboard_data.size()); + if (IsFormatAvailableInPickle(format_name, pickle)) { + result = PP_OK; + clipboard_string = ReadDataFromPickle(format_name, pickle); + } + } + break; + } + } + + if (result == PP_OK) { + host_context->reply_msg = + PpapiPluginMsg_FlashClipboard_ReadDataReply(clipboard_string); + } + return result; +} + +int32_t PepperFlashClipboardHost::OnMsgWriteData( + ppapi::host::HostMessageContext* host_context, + uint32_t clipboard_type, + const std::vector<uint32_t>& formats, + const std::vector<std::string>& data) { + if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { + NOTIMPLEMENTED(); + return PP_ERROR_FAILED; + } + + DCHECK(formats.size() == data.size()); + // If no formats are passed in clear the clipboard. + if (formats.size() == 0) { + clipboard_client_->Clear(ConvertClipboardType(clipboard_type)); + return PP_OK; + } + + webkit_glue::ScopedClipboardWriterGlue scw(clipboard_client_.get()); + std::map<string16, std::string> custom_data_map; + int32_t res = PP_OK; + for (uint32_t i = 0; i < formats.size(); ++i) { + if (data[i].length() > kMaxClipboardWriteSize) { + res = PP_ERROR_NOSPACE; + break; + } + + switch (formats[i]) { + case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: + scw.WriteText(UTF8ToUTF16(data[i])); + break; + case PP_FLASH_CLIPBOARD_FORMAT_HTML: + scw.WriteHTML(UTF8ToUTF16(data[i]), ""); + break; + case PP_FLASH_CLIPBOARD_FORMAT_RTF: + scw.WriteRTF(data[i]); + break; + case PP_FLASH_CLIPBOARD_FORMAT_INVALID: + res = PP_ERROR_BADARGUMENT; + break; + default: + if (custom_formats_.IsFormatRegistered(formats[i])) { + std::string format_name = custom_formats_.GetFormatName(formats[i]); + custom_data_map[UTF8ToUTF16(format_name)] = data[i]; + } else { + // Invalid format. + res = PP_ERROR_BADARGUMENT; + break; + } + } + + if (res != PP_OK) + break; + } + + if (custom_data_map.size() > 0) { + Pickle pickle; + if (WriteDataToPickle(custom_data_map, &pickle)) { + scw.WritePickledData(pickle, + ui::Clipboard::GetPepperCustomDataFormatType()); + } else { + res = PP_ERROR_BADARGUMENT; + } + } + + if (res != PP_OK) { + // Need to clear the objects so nothing is written. + scw.Reset(); + } + + return res; +} + +} // namespace content + diff --git a/content/renderer/pepper/pepper_flash_clipboard_host.h b/content/renderer/pepper/pepper_flash_clipboard_host.h new file mode 100644 index 0000000..e327c2e --- /dev/null +++ b/content/renderer/pepper/pepper_flash_clipboard_host.h @@ -0,0 +1,81 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_RENDERER_PEPPER_PEPPER_FLASH_CLIPBOARD_HOST_H_ +#define CONTENT_RENDERER_PEPPER_PEPPER_FLASH_CLIPBOARD_HOST_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "ipc/ipc_message.h" +#include "ppapi/host/host_message_context.h" +#include "ppapi/host/resource_host.h" +#include "ppapi/shared_impl/flash_clipboard_format_registry.h" + +namespace webkit_glue { +class ClipboardClient; +class ScopedClipboardWriterGlue; +} + +namespace content { + +class RendererPpapiHost; + +// The host resource for accessing the clipboard in Pepper. Pepper supports +// reading/writing custom formats from the clipboard. Currently, all custom +// formats that are read/written from the clipboard through pepper are stored +// in a single real clipboard format (in the same way the "web custom" clipboard +// formats are). This is done so that we don't have to have use real clipboard +// types for each custom clipboard format which may be a limited resource on +// a particular platform. + +// TODO(raymes): This host can be moved to the browser process and we would +// avoid crossing an additional process boundary to access the clipboard from +// pepper. Moving the host code to the browser is straightforward but it also +// means we have to deal with handling the clipboard accesses on the clipboard +// thread. +class PepperFlashClipboardHost : public ppapi::host::ResourceHost { + public: + PepperFlashClipboardHost(RendererPpapiHost* host, + PP_Instance instance, + PP_Resource resource); + virtual ~PepperFlashClipboardHost(); + + virtual int32_t OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) OVERRIDE; + + private: + int32_t OnMsgRegisterCustomFormat( + ppapi::host::HostMessageContext* host_context, + const std::string& format_name); + int32_t OnMsgIsFormatAvailable( + ppapi::host::HostMessageContext* host_context, + uint32_t clipboard_type, + uint32_t format); + int32_t OnMsgReadData( + ppapi::host::HostMessageContext* host_context, + uint32_t clipoard_type, + uint32_t format); + int32_t OnMsgWriteData( + ppapi::host::HostMessageContext* host_context, + uint32_t clipboard_type, + const std::vector<uint32_t>& formats, + const std::vector<std::string>& data); + + int32_t WriteClipboardDataItem( + uint32_t format, + const std::string& data, + webkit_glue::ScopedClipboardWriterGlue* scw); + + scoped_ptr<webkit_glue::ClipboardClient> clipboard_client_; + ppapi::FlashClipboardFormatRegistry custom_formats_; + + DISALLOW_COPY_AND_ASSIGN(PepperFlashClipboardHost); +}; + +} // namespace content + +#endif // CONTENT_RENDERER_PEPPER_PEPPER_FLASH_CLIPBOARD_HOST_H_ diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc index 5ed73d5..f0efd98 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc @@ -54,7 +54,6 @@ #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/render_widget_fullscreen_pepper.h" -#include "content/renderer/renderer_clipboard_client.h" #include "content/renderer/webplugin_delegate_proxy.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_channel_handle.h" @@ -1864,9 +1863,4 @@ MouseLockDispatcher* PepperPluginDelegateImpl::GetMouseLockDispatcher( } } -webkit_glue::ClipboardClient* - PepperPluginDelegateImpl::CreateClipboardClient() const { - return new RendererClipboardClient; -} - } // namespace content diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h index 05adf5e..bab3569 100644 --- a/content/renderer/pepper/pepper_plugin_delegate_impl.h +++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h @@ -391,7 +391,6 @@ class PepperPluginDelegateImpl PP_DeviceType_Dev type, const EnumerateDevicesCallback& callback) OVERRIDE; virtual void StopEnumerateDevices(int request_id) OVERRIDE; - virtual webkit_glue::ClipboardClient* CreateClipboardClient() const OVERRIDE; virtual std::string GetDeviceID() OVERRIDE; virtual PP_FlashLSORestrictions GetLocalDataRestrictions( const GURL& document_url, diff --git a/content/renderer/renderer_clipboard_client.cc b/content/renderer/renderer_clipboard_client.cc index 9c0a30f..82dd4fa 100644 --- a/content/renderer/renderer_clipboard_client.cc +++ b/content/renderer/renderer_clipboard_client.cc @@ -178,6 +178,12 @@ void RendererClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer, new ClipboardHostMsg_ReadCustomData(buffer, type, data)); } +void RendererClipboardClient::ReadData(const ui::Clipboard::FormatType& format, + std::string* data) { + RenderThreadImpl::current()->Send( + new ClipboardHostMsg_ReadData(format, data)); +} + webkit_glue::ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() { return new RendererClipboardWriteContext; diff --git a/content/renderer/renderer_clipboard_client.h b/content/renderer/renderer_clipboard_client.h index 8e7df78..e2d9051 100644 --- a/content/renderer/renderer_clipboard_client.h +++ b/content/renderer/renderer_clipboard_client.h @@ -38,6 +38,8 @@ class RendererClipboardClient : public webkit_glue::ClipboardClient { virtual void ReadCustomData(ui::Clipboard::Buffer buffer, const string16& type, string16* data) OVERRIDE; + virtual void ReadData(const ui::Clipboard::FormatType& format, + std::string* data) OVERRIDE; virtual WriteContext* CreateWriteContext() OVERRIDE; }; diff --git a/ppapi/api/private/ppb_flash_clipboard.idl b/ppapi/api/private/ppb_flash_clipboard.idl index 24380de..c8a01eb 100644 --- a/ppapi/api/private/ppb_flash_clipboard.idl +++ b/ppapi/api/private/ppb_flash_clipboard.idl @@ -9,18 +9,10 @@ */ label Chrome { - M17 = 3.0, - M19 = 4.0 + M19 = 4.0, + M24 = 5.0 }; -#inline c -/** - * The old version string for this interface, equivalent to version 3.0. - * TODO(viettrungluu): Remove this when enough time has passed. crbug.com/104184 - */ -#define PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY "PPB_Flash_Clipboard;3" -#endinl - /** * This enumeration contains the types of clipboards that can be accessed. * These types correspond to clipboard types in WebKit. @@ -34,7 +26,7 @@ enum PP_Flash_Clipboard_Type { }; /** - * This enumeration contains the supported clipboard data formats. + * This enumeration contains the predfined clipboard data formats. */ [assert_size(4)] enum PP_Flash_Clipboard_Format { @@ -64,30 +56,60 @@ enum PP_Flash_Clipboard_Format { */ interface PPB_Flash_Clipboard { /** - * Checks whether a given data format is available from the given clipboard. - * Returns true if the given format is available from the given clipboard. + * Deprecated in 5.0. */ + [version=4.0, deprecate=5.0] PP_Bool IsFormatAvailable( [in] PP_Instance instance_id, [in] PP_Flash_Clipboard_Type clipboard_type, [in] PP_Flash_Clipboard_Format format); /** - * Deprecated in 4.0. + * Deprecated in 5.0. + */ + [version=4.0, deprecate=5.0] + PP_Var ReadData([in] PP_Instance instance_id, + [in] PP_Flash_Clipboard_Type clipboard_type, + [in] PP_Flash_Clipboard_Format format); + + /** + * Deprecated in 5.0. + */ + [version=4.0, deprecate=5.0] + int32_t WriteData([in] PP_Instance instance_id, + [in] PP_Flash_Clipboard_Type clipboard_type, + [in] uint32_t data_item_count, + [in, size_is(data_item_count)] PP_Flash_Clipboard_Format[] formats, + [in, size_is(data_item_count)] PP_Var[] data_items); + + /** + * Registers a custom clipboard format. The format is identified by a + * string. An id identifying the format will be returned if the format is + * successfully registered, which can be used to read/write data of that + * format. If the format has already been registered, the id associated with + * that format will be returned. If the format fails to be registered + * <code>PP_FLASH_CLIPBOARD_FORMAT_INVALID</code> will be returned. + * + * All custom data should be read/written as <code>PP_Var</code> array + * buffers. The clipboard format is pepper-specific meaning that although the + * data will be stored on the system clipboard, it can only be accessed in a + * sensible way by using the pepper API. Data stored in custom formats can + * be safely shared between different applications that use pepper. */ - [version=3.0, deprecate=4.0] - PP_Var ReadPlainText( + [version=5.0] + uint32_t RegisterCustomFormat( [in] PP_Instance instance_id, - [in] PP_Flash_Clipboard_Type clipboard_type); + [in] str_t format_name); /** - * Deprecated in 4.0. + * Checks whether a given data format is available from the given clipboard. + * Returns true if the given format is available from the given clipboard. */ - [version=3.0, deprecate=4.0] - int32_t WritePlainText( + [version=5.0] + PP_Bool IsFormatAvailable( [in] PP_Instance instance_id, [in] PP_Flash_Clipboard_Type clipboard_type, - [in] PP_Var text); + [in] uint32_t format); /** * Reads data in the given <code>format</code> from the clipboard. An @@ -95,10 +117,10 @@ interface PPB_Flash_Clipboard { * the clipboard data and a null <code>PP_Var</code> is returned if there is * no data of the specified <code>format</code> to read. */ - [version=4.0] + [version=5.0] PP_Var ReadData([in] PP_Instance instance_id, [in] PP_Flash_Clipboard_Type clipboard_type, - [in] PP_Flash_Clipboard_Format format); + [in] uint32_t format); /** * Writes the given array of data items to the clipboard. All existing @@ -114,10 +136,10 @@ interface PPB_Flash_Clipboard { * cannot be converted into the format supplied or <code>PP_FAILED</code> * if the format is not supported. */ - [version=4.0] + [version=5.0] int32_t WriteData([in] PP_Instance instance_id, [in] PP_Flash_Clipboard_Type clipboard_type, [in] uint32_t data_item_count, - [in, size_is(data_item_count)] PP_Flash_Clipboard_Format[] formats, + [in, size_is(data_item_count)] uint32_t[] formats, [in, size_is(data_item_count)] PP_Var[] data_items); }; diff --git a/ppapi/c/private/ppb_flash_clipboard.h b/ppapi/c/private/ppb_flash_clipboard.h index 3498d61..5da06cc6 100644 --- a/ppapi/c/private/ppb_flash_clipboard.h +++ b/ppapi/c/private/ppb_flash_clipboard.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From private/ppb_flash_clipboard.idl modified Wed Mar 28 16:49:38 2012. */ +/* From private/ppb_flash_clipboard.idl modified Mon Oct 29 12:51:16 2012. */ #ifndef PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ #define PPAPI_C_PRIVATE_PPB_FLASH_CLIPBOARD_H_ @@ -14,9 +14,9 @@ #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_var.h" -#define PPB_FLASH_CLIPBOARD_INTERFACE_3_0 "PPB_Flash_Clipboard;3.0" #define PPB_FLASH_CLIPBOARD_INTERFACE_4_0 "PPB_Flash_Clipboard;4.0" -#define PPB_FLASH_CLIPBOARD_INTERFACE PPB_FLASH_CLIPBOARD_INTERFACE_4_0 +#define PPB_FLASH_CLIPBOARD_INTERFACE_5_0 "PPB_Flash_Clipboard;5.0" +#define PPB_FLASH_CLIPBOARD_INTERFACE PPB_FLASH_CLIPBOARD_INTERFACE_5_0 /** * @file @@ -26,12 +26,6 @@ /** - * The old version string for this interface, equivalent to version 3.0. - * TODO(viettrungluu): Remove this when enough time has passed. crbug.com/104184 - */ -#define PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY "PPB_Flash_Clipboard;3" - -/** * @addtogroup Enums * @{ */ @@ -48,7 +42,7 @@ typedef enum { PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_Clipboard_Type, 4); /** - * This enumeration contains the supported clipboard data formats. + * This enumeration contains the predfined clipboard data formats. */ typedef enum { /** Indicates an invalid or unsupported clipboard data format. */ @@ -83,14 +77,30 @@ PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_Flash_Clipboard_Format, 4); * used by Pepper Flash to access the clipboard. * */ -struct PPB_Flash_Clipboard_4_0 { +struct PPB_Flash_Clipboard_5_0 { + /** + * Registers a custom clipboard format. The format is identified by a + * string. An id identifying the format will be returned if the format is + * successfully registered, which can be used to read/write data of that + * format. If the format has already been registered, the id associated with + * that format will be returned. If the format fails to be registered + * <code>PP_FLASH_CLIPBOARD_FORMAT_INVALID</code> will be returned. + * + * All custom data should be read/written as <code>PP_Var</code> array + * buffers. The clipboard format is pepper-specific meaning that although the + * data will be stored on the system clipboard, it can only be accessed in a + * sensible way by using the pepper API. Data stored in custom formats can + * be safely shared between different applications that use pepper. + */ + uint32_t (*RegisterCustomFormat)(PP_Instance instance_id, + const char* format_name); /** * Checks whether a given data format is available from the given 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); + uint32_t format); /** * Reads data in the given <code>format</code> from the clipboard. An * undefined <code>PP_Var</code> is returned if there is an error in reading @@ -99,7 +109,7 @@ struct PPB_Flash_Clipboard_4_0 { */ struct PP_Var (*ReadData)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format); + uint32_t format); /** * Writes the given array of data items to the clipboard. All existing * clipboard data in any format is erased before writing this data. Thus, @@ -117,21 +127,24 @@ struct PPB_Flash_Clipboard_4_0 { int32_t (*WriteData)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], + const uint32_t formats[], const struct PP_Var data_items[]); }; -typedef struct PPB_Flash_Clipboard_4_0 PPB_Flash_Clipboard; +typedef struct PPB_Flash_Clipboard_5_0 PPB_Flash_Clipboard; -struct PPB_Flash_Clipboard_3_0 { +struct PPB_Flash_Clipboard_4_0 { PP_Bool (*IsFormatAvailable)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format); - struct PP_Var (*ReadPlainText)(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type); - int32_t (*WritePlainText)(PP_Instance instance_id, + struct PP_Var (*ReadData)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, - struct PP_Var text); + PP_Flash_Clipboard_Format format); + int32_t (*WriteData)(PP_Instance instance_id, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t data_item_count, + const PP_Flash_Clipboard_Format formats[], + const struct PP_Var data_items[]); }; /** * @} diff --git a/ppapi/cpp/private/flash_clipboard.cc b/ppapi/cpp/private/flash_clipboard.cc index 6107f98..c63f747 100644 --- a/ppapi/cpp/private/flash_clipboard.cc +++ b/ppapi/cpp/private/flash_clipboard.cc @@ -20,23 +20,43 @@ template <> const char* interface_name<PPB_Flash_Clipboard_4_0>() { return PPB_FLASH_CLIPBOARD_INTERFACE_4_0; } +template <> const char* interface_name<PPB_Flash_Clipboard_5_0>() { + return PPB_FLASH_CLIPBOARD_INTERFACE_5_0; +} + } // namespace namespace flash { // static bool Clipboard::IsAvailable() { - return has_interface<PPB_Flash_Clipboard_4_0>(); + return has_interface<PPB_Flash_Clipboard_5_0>() || + has_interface<PPB_Flash_Clipboard_4_0>() ; +} + +// static +uint32_t Clipboard::RegisterCustomFormat(const InstanceHandle& instance, + const std::string& format_name) { + uint32_t rv = PP_FLASH_CLIPBOARD_FORMAT_INVALID; + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + rv = get_interface<PPB_Flash_Clipboard_5_0>()->RegisterCustomFormat( + instance.pp_instance(), format_name.c_str()); + } + return rv; } // static bool Clipboard::IsFormatAvailable(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { + uint32_t format) { bool rv = false; - if (has_interface<PPB_Flash_Clipboard_4_0>()) { - rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_4_0>()->IsFormatAvailable( + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_5_0>()->IsFormatAvailable( instance.pp_instance(), clipboard_type, format)); + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { + rv = PP_ToBool(get_interface<PPB_Flash_Clipboard_4_0>()->IsFormatAvailable( + instance.pp_instance(), clipboard_type, + static_cast<PP_Flash_Clipboard_Format>(format))); } return rv; } @@ -45,14 +65,21 @@ bool Clipboard::IsFormatAvailable(const InstanceHandle& instance, bool Clipboard::ReadData( const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format clipboard_format, + uint32_t format, Var* out) { bool rv = false; - if (has_interface<PPB_Flash_Clipboard_4_0>()) { + if (has_interface<PPB_Flash_Clipboard_5_0>()) { + PP_Var result = get_interface<PPB_Flash_Clipboard_5_0>()->ReadData( + instance.pp_instance(), + clipboard_type, + format); + *out = Var(PASS_REF, result); + rv = true; + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { PP_Var result = get_interface<PPB_Flash_Clipboard_4_0>()->ReadData( instance.pp_instance(), clipboard_type, - clipboard_format); + static_cast<PP_Flash_Clipboard_Format>(format)); *out = Var(PASS_REF, result); rv = true; } @@ -63,13 +90,13 @@ bool Clipboard::ReadData( bool Clipboard::WriteData( const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - const std::vector<PP_Flash_Clipboard_Format>& formats, + const std::vector<uint32_t>& formats, const std::vector<Var>& data_items) { if (formats.size() != data_items.size()) return false; bool rv = false; - if (has_interface<PPB_Flash_Clipboard_4_0>()) { + if (has_interface<PPB_Flash_Clipboard_5_0>()) { // Convert vector of pp::Var into a vector of PP_Var. std::vector<PP_Var> data_items_vector; for (uint32_t i = 0; i < data_items.size(); ++i) @@ -78,13 +105,38 @@ bool Clipboard::WriteData( // Ensure that we don't dereference the memory in empty vectors. We still // want to call WriteData because it has the effect of clearing the // clipboard. - const PP_Flash_Clipboard_Format* formats_ptr(NULL); + const uint32_t* formats_ptr(NULL); const PP_Var* data_items_ptr(NULL); if (data_items.size() > 0) { formats_ptr = &formats[0]; data_items_ptr = &data_items_vector[0]; } + rv = (get_interface<PPB_Flash_Clipboard_5_0>()->WriteData( + instance.pp_instance(), + clipboard_type, + data_items.size(), + formats_ptr, + data_items_ptr) == PP_OK); + } else if (has_interface<PPB_Flash_Clipboard_4_0>()) { + // Convert vector of pp::Var into a vector of PP_Var. + std::vector<PP_Var> data_items_vector; + std::vector<PP_Flash_Clipboard_Format> old_formats; + for (uint32_t i = 0; i < data_items.size(); ++i) { + data_items_vector.push_back(data_items[i].pp_var()); + old_formats.push_back(static_cast<PP_Flash_Clipboard_Format>(formats[i])); + } + + // Ensure that we don't dereference the memory in empty vectors. We still + // want to call WriteData because it has the effect of clearing the + // clipboard. + const PP_Flash_Clipboard_Format* formats_ptr(NULL); + const PP_Var* data_items_ptr(NULL); + if (data_items.size() > 0) { + formats_ptr = &old_formats[0]; + data_items_ptr = &data_items_vector[0]; + } + rv = (get_interface<PPB_Flash_Clipboard_4_0>()->WriteData( instance.pp_instance(), clipboard_type, diff --git a/ppapi/cpp/private/flash_clipboard.h b/ppapi/cpp/private/flash_clipboard.h index 2894c8f..aab06ef 100644 --- a/ppapi/cpp/private/flash_clipboard.h +++ b/ppapi/cpp/private/flash_clipboard.h @@ -22,23 +22,28 @@ class Clipboard { // Returns true if the required interface is available. static bool IsAvailable(); + // Returns a format ID on success or PP_FLASH_CLIPBOARD_FORMAT_INVALID on + // failure. + static uint32_t RegisterCustomFormat(const InstanceHandle& instance, + const std::string& format_name); + // Returns true if the given format is available from the given clipboard. static bool IsFormatAvailable(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format); + uint32_t format); // Returns true on success, in which case |out| will be filled with // data read from the given clipboard in the given format. static bool ReadData(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format clipboard_format, + uint32_t clipboard_format, Var* out); // Returns true on success in which case all of |data| will be written to // the clipboard. Otherwise nothing will be written. static bool WriteData(const InstanceHandle& instance, PP_Flash_Clipboard_Type clipboard_type, - const std::vector<PP_Flash_Clipboard_Format>& formats, + const std::vector<uint32_t>& formats, const std::vector<Var>& data_items); }; diff --git a/ppapi/host/ppapi_host.cc b/ppapi/host/ppapi_host.cc index 1361da2..44d3ee5 100644 --- a/ppapi/host/ppapi_host.cc +++ b/ppapi/host/ppapi_host.cc @@ -139,6 +139,11 @@ void PpapiHost::HandleResourceCall( // When no response is required, the message handler should not have // written a message to be returned. DCHECK(context->reply_msg.type() == 0); + + // If there is no callback and the result of running the message handler + // was not PP_OK the client won't find out. + DLOG_IF(WARNING, reply_context.params.result() != PP_OK) + << "'Post' message handler failed to complete successfully."; } } else { reply_context.params.set_result(PP_ERROR_BADRESOURCE); diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 45c4736..0346320 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* Last generated from IDL: Mon Oct 29 11:08:12 2012. */ +/* Last generated from IDL: Mon Oct 29 12:56:27 2012. */ #include "ppapi/generators/pnacl_shim.h" #include "ppapi/c/ppb.h" @@ -212,8 +212,8 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_12_3; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_12_4; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_12_5; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_12_6; -static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_DeviceID_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_FontFile_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_FlashFullscreen_0_1; @@ -2633,49 +2633,55 @@ int32_t Pnacl_M24_PPB_Flash_EnumerateVideoCaptureDevices(PP_Instance instance, P /* End wrapper methods for PPB_Flash_12_6 */ -/* Begin wrapper methods for PPB_Flash_Clipboard_3_0 */ +/* Begin wrapper methods for PPB_Flash_Clipboard_4_0 */ static __attribute__((pnaclcall)) -PP_Bool Pnacl_M17_PPB_Flash_Clipboard_IsFormatAvailable(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { - const struct PPB_Flash_Clipboard_3_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0.real_iface; +PP_Bool Pnacl_M19_PPB_Flash_Clipboard_IsFormatAvailable(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { + const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; return iface->IsFormatAvailable(instance_id, clipboard_type, format); } static __attribute__((pnaclcall)) -struct PP_Var Pnacl_M17_PPB_Flash_Clipboard_ReadPlainText(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type) { - const struct PPB_Flash_Clipboard_3_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0.real_iface; - return iface->ReadPlainText(instance_id, clipboard_type); +struct PP_Var Pnacl_M19_PPB_Flash_Clipboard_ReadData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { + const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; + return iface->ReadData(instance_id, clipboard_type, format); } static __attribute__((pnaclcall)) -int32_t Pnacl_M17_PPB_Flash_Clipboard_WritePlainText(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, struct PP_Var text) { - const struct PPB_Flash_Clipboard_3_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0.real_iface; - return iface->WritePlainText(instance_id, clipboard_type, text); +int32_t Pnacl_M19_PPB_Flash_Clipboard_WriteData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, const PP_Flash_Clipboard_Format formats[], const struct PP_Var data_items[]) { + const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; + return iface->WriteData(instance_id, clipboard_type, data_item_count, formats, data_items); } -/* End wrapper methods for PPB_Flash_Clipboard_3_0 */ +/* End wrapper methods for PPB_Flash_Clipboard_4_0 */ -/* Begin wrapper methods for PPB_Flash_Clipboard_4_0 */ +/* Begin wrapper methods for PPB_Flash_Clipboard_5_0 */ static __attribute__((pnaclcall)) -PP_Bool Pnacl_M19_PPB_Flash_Clipboard_IsFormatAvailable(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { - const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; +uint32_t Pnacl_M24_PPB_Flash_Clipboard_RegisterCustomFormat(PP_Instance instance_id, const char* format_name) { + const struct PPB_Flash_Clipboard_5_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0.real_iface; + return iface->RegisterCustomFormat(instance_id, format_name); +} + +static __attribute__((pnaclcall)) +PP_Bool Pnacl_M24_PPB_Flash_Clipboard_IsFormatAvailable(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t format) { + const struct PPB_Flash_Clipboard_5_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0.real_iface; return iface->IsFormatAvailable(instance_id, clipboard_type, format); } static __attribute__((pnaclcall)) -struct PP_Var Pnacl_M19_PPB_Flash_Clipboard_ReadData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { - const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; +struct PP_Var Pnacl_M24_PPB_Flash_Clipboard_ReadData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t format) { + const struct PPB_Flash_Clipboard_5_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0.real_iface; return iface->ReadData(instance_id, clipboard_type, format); } static __attribute__((pnaclcall)) -int32_t Pnacl_M19_PPB_Flash_Clipboard_WriteData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, const PP_Flash_Clipboard_Format formats[], const struct PP_Var data_items[]) { - const struct PPB_Flash_Clipboard_4_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0.real_iface; +int32_t Pnacl_M24_PPB_Flash_Clipboard_WriteData(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, const uint32_t formats[], const struct PP_Var data_items[]) { + const struct PPB_Flash_Clipboard_5_0 *iface = Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0.real_iface; return iface->WriteData(instance_id, clipboard_type, data_item_count, formats, data_items); } -/* End wrapper methods for PPB_Flash_Clipboard_4_0 */ +/* End wrapper methods for PPB_Flash_Clipboard_5_0 */ /* Begin wrapper methods for PPB_Flash_DeviceID_1_0 */ @@ -4110,18 +4116,19 @@ struct PPB_Flash_12_6 Pnacl_Wrappers_PPB_Flash_12_6 = { .EnumerateVideoCaptureDevices = (int32_t (*)(PP_Instance instance, PP_Resource video_capture, struct PP_ArrayOutput devices))&Pnacl_M24_PPB_Flash_EnumerateVideoCaptureDevices }; -struct PPB_Flash_Clipboard_3_0 Pnacl_Wrappers_PPB_Flash_Clipboard_3_0 = { - .IsFormatAvailable = (PP_Bool (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format))&Pnacl_M17_PPB_Flash_Clipboard_IsFormatAvailable, - .ReadPlainText = (struct PP_Var (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type))&Pnacl_M17_PPB_Flash_Clipboard_ReadPlainText, - .WritePlainText = (int32_t (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, struct PP_Var text))&Pnacl_M17_PPB_Flash_Clipboard_WritePlainText -}; - struct PPB_Flash_Clipboard_4_0 Pnacl_Wrappers_PPB_Flash_Clipboard_4_0 = { .IsFormatAvailable = (PP_Bool (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format))&Pnacl_M19_PPB_Flash_Clipboard_IsFormatAvailable, .ReadData = (struct PP_Var (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format))&Pnacl_M19_PPB_Flash_Clipboard_ReadData, .WriteData = (int32_t (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, const PP_Flash_Clipboard_Format formats[], const struct PP_Var data_items[]))&Pnacl_M19_PPB_Flash_Clipboard_WriteData }; +struct PPB_Flash_Clipboard_5_0 Pnacl_Wrappers_PPB_Flash_Clipboard_5_0 = { + .RegisterCustomFormat = (uint32_t (*)(PP_Instance instance_id, const char* format_name))&Pnacl_M24_PPB_Flash_Clipboard_RegisterCustomFormat, + .IsFormatAvailable = (PP_Bool (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t format))&Pnacl_M24_PPB_Flash_Clipboard_IsFormatAvailable, + .ReadData = (struct PP_Var (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t format))&Pnacl_M24_PPB_Flash_Clipboard_ReadData, + .WriteData = (int32_t (*)(PP_Instance instance_id, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, const uint32_t formats[], const struct PP_Var data_items[]))&Pnacl_M24_PPB_Flash_Clipboard_WriteData +}; + struct PPB_Flash_DeviceID_1_0 Pnacl_Wrappers_PPB_Flash_DeviceID_1_0 = { .Create = (PP_Resource (*)(PP_Instance instance))&Pnacl_M21_PPB_Flash_DeviceID_Create, .GetDeviceID = (int32_t (*)(PP_Resource device_id, struct PP_Var* id, struct PP_CompletionCallback callback))&Pnacl_M21_PPB_Flash_DeviceID_GetDeviceID @@ -4916,18 +4923,18 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_12_6 = { .real_iface = NULL }; -static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0 = { - .iface_macro = PPB_FLASH_CLIPBOARD_INTERFACE_3_0, - .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Flash_Clipboard_3_0, - .real_iface = NULL -}; - static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0 = { .iface_macro = PPB_FLASH_CLIPBOARD_INTERFACE_4_0, .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Flash_Clipboard_4_0, .real_iface = NULL }; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0 = { + .iface_macro = PPB_FLASH_CLIPBOARD_INTERFACE_5_0, + .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Flash_Clipboard_5_0, + .real_iface = NULL +}; + static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Flash_DeviceID_1_0 = { .iface_macro = PPB_FLASH_DEVICEID_INTERFACE_1_0, .wrapped_iface = (void *) &Pnacl_Wrappers_PPB_Flash_DeviceID_1_0, @@ -5188,8 +5195,8 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_Flash_12_4, &Pnacl_WrapperInfo_PPB_Flash_12_5, &Pnacl_WrapperInfo_PPB_Flash_12_6, - &Pnacl_WrapperInfo_PPB_Flash_Clipboard_3_0, &Pnacl_WrapperInfo_PPB_Flash_Clipboard_4_0, + &Pnacl_WrapperInfo_PPB_Flash_Clipboard_5_0, &Pnacl_WrapperInfo_PPB_Flash_DeviceID_1_0, &Pnacl_WrapperInfo_PPB_Flash_FontFile_0_1, &Pnacl_WrapperInfo_PPB_FlashFullscreen_0_1, diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 5cb4a86..0c63ba6 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -31,6 +31,8 @@ 'proxy/flash_device_id_resource.h', 'proxy/flash_font_file_resource.cc', 'proxy/flash_font_file_resource.h', + 'proxy/flash_clipboard_resource.cc', + 'proxy/flash_clipboard_resource.h', 'proxy/flash_resource.cc', 'proxy/flash_resource.h', 'proxy/gamepad_resource.cc', @@ -176,6 +178,7 @@ 'proxy/broker_dispatcher.cc', 'proxy/flash_device_id_resource.cc', 'proxy/flash_font_file_resource.cc', + 'proxy/flash_clipboard_resource.cc', 'proxy/flash_resource.cc', 'proxy/ppb_audio_input_proxy.cc', 'proxy/ppb_broker_proxy.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 4c3c48d..fffc465 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -28,6 +28,8 @@ 'shared_impl/file_path.h', 'shared_impl/file_type_conversion.cc', 'shared_impl/file_type_conversion.h', + 'shared_impl/flash_clipboard_format_registry.cc', + 'shared_impl/flash_clipboard_format_registry.h', 'shared_impl/host_resource.cc', 'shared_impl/host_resource.h', 'shared_impl/id_assignment.cc', @@ -251,6 +253,7 @@ 'target_conditions': [ ['>(nacl_untrusted_build)==1 or >(nacl_win64_target)==1', { 'sources!': [ + 'shared_impl/flash_clipboard_format_registry.cc', 'shared_impl/ppb_audio_input_shared.cc', 'shared_impl/ppb_url_util_shared.cc', 'shared_impl/ppb_video_decoder_shared.cc', diff --git a/ppapi/proxy/flash_clipboard_resource.cc b/ppapi/proxy/flash_clipboard_resource.cc new file mode 100644 index 0000000..1ef90e2 --- /dev/null +++ b/ppapi/proxy/flash_clipboard_resource.cc @@ -0,0 +1,156 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/flash_clipboard_resource.h" + +#include "ipc/ipc_message.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/ppapi_globals.h" +#include "ppapi/shared_impl/var.h" +#include "ppapi/shared_impl/var_tracker.h" + +namespace ppapi { +namespace proxy { + +namespace { + +// Returns whether the given clipboard type is valid. +bool IsValidClipboardType(PP_Flash_Clipboard_Type type) { + return type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || + type == PP_FLASH_CLIPBOARD_TYPE_SELECTION; +} + +// Convert a PP_Var to/from a string which is transmitted to the pepper host. +// These functions assume the format is valid. +bool PPVarToClipboardString(int32_t format, + const PP_Var& var, + std::string* string_out) { + if (format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || + format == PP_FLASH_CLIPBOARD_FORMAT_HTML) { + StringVar* string_var = StringVar::FromPPVar(var); + if (!string_var) + return false; + *string_out = string_var->value(); + return true; + } else { + // All other formats are expected to be array buffers. + ArrayBufferVar* array_buffer_var = ArrayBufferVar::FromPPVar(var); + if (!array_buffer_var) + return false; + *string_out = std::string(static_cast<const char*>(array_buffer_var->Map()), + array_buffer_var->ByteLength()); + return true; + } +} + +PP_Var ClipboardStringToPPVar(int32_t format, + const std::string& string) { + if (format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || + format == PP_FLASH_CLIPBOARD_FORMAT_HTML) { + return StringVar::StringToPPVar(string); + } else { + // All other formats are expected to be array buffers. + return PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( + string.size(), string.data()); + } +} +} // namespace + +FlashClipboardResource::FlashClipboardResource( + Connection connection, PP_Instance instance) + : PluginResource(connection, instance) { + SendCreate(RENDERER, PpapiHostMsg_FlashClipboard_Create()); +} + +FlashClipboardResource::~FlashClipboardResource() { +} + +thunk::PPB_Flash_Clipboard_API* +FlashClipboardResource::AsPPB_Flash_Clipboard_API() { + return this; +} + +uint32_t FlashClipboardResource::RegisterCustomFormat( + PP_Instance instance, + const char* format_name) { + // Check to see if the format has already been registered. + uint32_t format = clipboard_formats_.GetFormatID(format_name); + if (format != PP_FLASH_CLIPBOARD_FORMAT_INVALID) + return format; + int32_t result = + SyncCall<PpapiPluginMsg_FlashClipboard_RegisterCustomFormatReply>( + RENDERER, + PpapiHostMsg_FlashClipboard_RegisterCustomFormat(format_name), + &format); + if (result != PP_OK || format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) + return PP_FLASH_CLIPBOARD_FORMAT_INVALID; + clipboard_formats_.SetRegisteredFormat(format_name, format); + return format; +} + +PP_Bool FlashClipboardResource::IsFormatAvailable( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) { + if (IsValidClipboardType(clipboard_type) && + (FlashClipboardFormatRegistry::IsValidPredefinedFormat(format) || + clipboard_formats_.IsFormatRegistered(format))) { + int32_t result = SyncCall<IPC::Message>(RENDERER, + PpapiHostMsg_FlashClipboard_IsFormatAvailable(clipboard_type, format)); + return result == PP_OK ? PP_TRUE : PP_FALSE; + } + return PP_FALSE; +} + +PP_Var FlashClipboardResource::ReadData( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) { + std::string value; + int32_t result = + SyncCall<PpapiPluginMsg_FlashClipboard_ReadDataReply>( + RENDERER, + PpapiHostMsg_FlashClipboard_ReadData(clipboard_type, format), + &value); + if (result != PP_OK) + return PP_MakeUndefined(); + + return ClipboardStringToPPVar(format, value); +} + +int32_t FlashClipboardResource::WriteData( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t data_item_count, + const uint32_t formats[], + const PP_Var data_items[]) { + if (!IsValidClipboardType(clipboard_type)) + return PP_ERROR_BADARGUMENT; + std::vector<uint32_t> formats_vector; + std::vector<std::string> data_items_vector; + for (size_t i = 0; i < data_item_count; ++i) { + if (!clipboard_formats_.IsFormatRegistered(formats[i]) && + !FlashClipboardFormatRegistry::IsValidPredefinedFormat(formats[i])) { + return PP_ERROR_BADARGUMENT; + } + formats_vector.push_back(formats[i]); + std::string string; + if (!PPVarToClipboardString(formats[i], data_items[i], &string)) + return PP_ERROR_BADARGUMENT; + data_items_vector.push_back(string); + } + + Post(RENDERER, + PpapiHostMsg_FlashClipboard_WriteData( + static_cast<uint32_t>(clipboard_type), + formats_vector, + data_items_vector)); + + // Assume success, since it allows us to avoid a sync IPC. + return PP_OK; +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/flash_clipboard_resource.h b/ppapi/proxy/flash_clipboard_resource.h new file mode 100644 index 0000000..fdb7e79 --- /dev/null +++ b/ppapi/proxy/flash_clipboard_resource.h @@ -0,0 +1,50 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_FLASH_CLIPBOARD_RESOURCE_H_ +#define PPAPI_PROXY_FLASH_CLIPBOARD_RESOURCE_H_ + +#include "ppapi/proxy/connection.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/shared_impl/flash_clipboard_format_registry.h" +#include "ppapi/thunk/ppb_flash_clipboard_api.h" + +namespace ppapi { +namespace proxy { + +class FlashClipboardResource + : public PluginResource, + public NON_EXPORTED_BASE(thunk::PPB_Flash_Clipboard_API) { + public: + FlashClipboardResource(Connection connection, PP_Instance instance); + virtual ~FlashClipboardResource(); + + // Resource implementation. + virtual thunk::PPB_Flash_Clipboard_API* AsPPB_Flash_Clipboard_API() OVERRIDE; + + // PPB_Flash_Clipboard_API implementation. + virtual uint32_t RegisterCustomFormat(PP_Instance instance, + const char* format_name) OVERRIDE; + virtual PP_Bool IsFormatAvailable(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) OVERRIDE; + virtual PP_Var ReadData(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) OVERRIDE; + virtual int32_t WriteData(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t data_item_count, + const uint32_t formats[], + const PP_Var data_items[]) OVERRIDE; + + private: + FlashClipboardFormatRegistry clipboard_formats_; + + DISALLOW_COPY_AND_ASSIGN(FlashClipboardResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_FLASH_CLIPBOARD_RESOURCE_H_ diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 8e05a1c..908e1d6 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -15,6 +15,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/proxy/flash_resource.h" +#include "ppapi/proxy/flash_clipboard_resource.h" #include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/interface_proxy.h" diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 017f957..e7668f3 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -34,6 +34,7 @@ class ResourceCreationAPI; namespace proxy { +class FlashClipboardResource; class FlashResource; class GamepadResource; class ResourceMessageReplyParams; @@ -54,6 +55,7 @@ struct InstanceData { // (These are singleton-style resources). scoped_refptr<GamepadResource> gamepad_resource; scoped_refptr<FlashResource> flash_resource; + scoped_refptr<FlashClipboardResource> flash_clipboard_resource; // Calls to |RequestSurroundingText()| are done by posted tasks. Track whether // a) a task is pending, to avoid redundant calls, and b) whether we should diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index cf85b19..776aa75 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1420,21 +1420,6 @@ IPC_MESSAGE_ROUTED0(PpapiHostMsg_PPBFlash_UpdateActivity) IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBFlash_GetDeviceID, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* id */) -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable, - PP_Instance /* instance */, - int /* clipboard_type */, - int /* format */, - bool /* result */) -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_ReadClipboardData, - PP_Instance /* instance */, - int /* clipboard_type */, - int /* format */, - ppapi::proxy::SerializedVar /* result */) -IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFlash_WriteClipboardData, - PP_Instance /* instance */, - int /* clipboard_type */, - std::vector<int> /* formats */, - std::vector<ppapi::proxy::SerializedVar> /* data */) IPC_SYNC_MESSAGE_ROUTED3_2(PpapiHostMsg_PPBFlash_OpenFileRef, PP_Instance /* instance */, ppapi::HostResource /* file_ref */, @@ -1720,6 +1705,25 @@ IPC_MESSAGE_CONTROL4(PpapiPluginMsg_WebSocket_ClosedReply, std::string /* reason */) #if !defined(OS_NACL) && !defined(NACL_WIN64) + +// Flash clipboard. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_FlashClipboard_Create) +IPC_MESSAGE_CONTROL1(PpapiHostMsg_FlashClipboard_RegisterCustomFormat, + std::string /* format_name */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FlashClipboard_RegisterCustomFormatReply, + uint32_t /* format */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_FlashClipboard_IsFormatAvailable, + uint32_t /* clipboard_type */, + uint32_t /* format */) +IPC_MESSAGE_CONTROL2(PpapiHostMsg_FlashClipboard_ReadData, + uint32_t /* clipboard_type */, + uint32_t /* format */) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FlashClipboard_ReadDataReply, + std::string /* result */) +IPC_MESSAGE_CONTROL3(PpapiHostMsg_FlashClipboard_WriteData, + uint32_t /* clipboard_type */, + std::vector<uint32_t> /* formats */, + std::vector<std::string> /* data */) // Flash font file. IPC_MESSAGE_CONTROL2(PpapiHostMsg_FlashFontFile_Create, ppapi::proxy::SerializedFontDescription /* description */, diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index 096e1d7..23e335d 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -122,12 +122,6 @@ bool PPB_Flash_Proxy::OnMessageReceived(const IPC::Message& msg) { OnHostMsgFlashSetFullscreen) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_FlashGetScreenSize, OnHostMsgFlashGetScreenSize) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable, - OnHostMsgIsClipboardFormatAvailable) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_ReadClipboardData, - OnHostMsgReadClipboardData) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_WriteClipboardData, - OnHostMsgWriteClipboardData) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_OpenFileRef, OnHostMsgOpenFileRef) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlash_QueryFileRef, @@ -363,68 +357,6 @@ PP_Bool PPB_Flash_Proxy::SetCrashData(PP_Instance instance, return PP_FALSE; } -PP_Bool PPB_Flash_Proxy::IsClipboardFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) - return PP_FALSE; - - bool result = false; - dispatcher()->Send(new PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable( - API_ID_PPB_FLASH, - instance, - static_cast<int>(clipboard_type), - static_cast<int>(format), - &result)); - return PP_FromBool(result); -} - -PP_Var PPB_Flash_Proxy::ReadClipboardData( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!IsValidClipboardType(clipboard_type) || !IsValidClipboardFormat(format)) - return PP_MakeUndefined(); - - ReceiveSerializedVarReturnValue result; - dispatcher()->Send(new PpapiHostMsg_PPBFlash_ReadClipboardData( - API_ID_PPB_FLASH, instance, - static_cast<int>(clipboard_type), static_cast<int>(format), &result)); - return result.Return(dispatcher()); -} - -int32_t PPB_Flash_Proxy::WriteClipboardData( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], - const PP_Var data_items[]) { - if (!IsValidClipboardType(clipboard_type)) - return PP_ERROR_BADARGUMENT; - - std::vector<SerializedVar> data_items_vector; - SerializedVarSendInput::ConvertVector( - dispatcher(), - data_items, - data_item_count, - &data_items_vector); - for (size_t i = 0; i < data_item_count; ++i) { - if (!IsValidClipboardFormat(formats[i])) - return PP_ERROR_BADARGUMENT; - } - - std::vector<int> formats_vector(formats, formats + data_item_count); - dispatcher()->Send(new PpapiHostMsg_PPBFlash_WriteClipboardData( - API_ID_PPB_FLASH, - instance, - static_cast<int>(clipboard_type), - formats_vector, - data_items_vector)); - // Assume success, since it allows us to avoid a sync IPC. - return PP_OK; -} - bool PPB_Flash_Proxy::CreateThreadAdapterForInstance(PP_Instance instance) { return true; } @@ -770,66 +702,6 @@ void PPB_Flash_Proxy::OnHostMsgFlashGetScreenSize(PP_Instance instance, } } -void PPB_Flash_Proxy::OnHostMsgIsClipboardFormatAvailable( - PP_Instance instance, - int clipboard_type, - int format, - bool* result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - *result = PP_ToBool( - enter.functions()->GetFlashAPI()->IsClipboardFormatAvailable( - instance, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - static_cast<PP_Flash_Clipboard_Format>(format))); - } else { - *result = false; - } -} - -void PPB_Flash_Proxy::OnHostMsgReadClipboardData( - PP_Instance instance, - int clipboard_type, - int format, - SerializedVarReturnValue result) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - result.Return(dispatcher(), - enter.functions()->GetFlashAPI()->ReadClipboardData( - instance, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - static_cast<PP_Flash_Clipboard_Format>(format))); - } -} - -void PPB_Flash_Proxy::OnHostMsgWriteClipboardData( - PP_Instance instance, - int clipboard_type, - const std::vector<int>& formats, - SerializedVarVectorReceiveInput data_items) { - EnterInstanceNoLock enter(instance); - if (enter.succeeded()) { - uint32_t data_item_count; - PP_Var* data_items_array = data_items.Get(dispatcher(), &data_item_count); - CHECK(data_item_count == formats.size()); - - scoped_array<PP_Flash_Clipboard_Format> formats_array( - new PP_Flash_Clipboard_Format[formats.size()]); - for (uint32_t i = 0; i < formats.size(); ++i) - formats_array[i] = static_cast<PP_Flash_Clipboard_Format>(formats[i]); - - int32_t result = enter.functions()->GetFlashAPI()->WriteClipboardData( - instance, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - data_item_count, - formats_array.get(), - data_items_array); - DLOG_IF(WARNING, result != PP_OK) - << "Write to clipboard failed unexpectedly."; - (void)result; // Prevent warning in release mode. - } -} - void PPB_Flash_Proxy::OnHostMsgOpenFileRef( PP_Instance instance, const HostResource& host_resource, diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h index 477b1ae..09728ef 100644 --- a/ppapi/proxy/ppb_flash_proxy.h +++ b/ppapi/proxy/ppb_flash_proxy.h @@ -88,18 +88,6 @@ class PPB_Flash_Proxy : public InterfaceProxy, public PPB_Flash_Shared { virtual PP_Bool SetCrashData(PP_Instance instance, PP_FlashCrashKey key, PP_Var value) OVERRIDE; - virtual PP_Bool IsClipboardFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual PP_Var ReadClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual int32_t WriteClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], - const PP_Var data_items[]) OVERRIDE; virtual bool CreateThreadAdapterForInstance(PP_Instance instance) OVERRIDE; virtual void ClearThreadAdapterForInstance(PP_Instance instance) OVERRIDE; virtual int32_t OpenFile(PP_Instance instance, @@ -164,18 +152,6 @@ class PPB_Flash_Proxy : public InterfaceProxy, public PPB_Flash_Shared { void OnHostMsgFlashGetScreenSize(PP_Instance instance, PP_Bool* result, PP_Size* size); - void OnHostMsgIsClipboardFormatAvailable(PP_Instance instance, - int clipboard_type, - int format, - bool* result); - void OnHostMsgReadClipboardData(PP_Instance instance, - int clipboard_type, - int format, - SerializedVarReturnValue result); - void OnHostMsgWriteClipboardData(PP_Instance instance, - int clipboard_type, - const std::vector<int>& formats, - SerializedVarVectorReceiveInput data_items); void OnHostMsgOpenFileRef(PP_Instance instance, const ppapi::HostResource& host_resource, int32_t mode, diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 5f10cf8..836117f 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -15,6 +15,7 @@ #include "ppapi/c/private/pp_content_decryptor.h" #include "ppapi/proxy/content_decryptor_private_serializer.h" #include "ppapi/proxy/enter_proxy.h" +#include "ppapi/proxy/flash_clipboard_resource.h" #include "ppapi/proxy/flash_resource.h" #include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/host_dispatcher.h" @@ -321,6 +322,8 @@ thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { return static_cast<PPB_Flash_Proxy*>(ip); } +// TODO(raymes): We can most likely cut down this boilerplate for grabbing +// singleton resource APIs. thunk::PPB_Flash_Functions_API* PPB_Instance_Proxy::GetFlashFunctionsAPI( PP_Instance instance) { #if !defined(OS_NACL) && !defined(NACL_WIN64) @@ -343,6 +346,29 @@ thunk::PPB_Flash_Functions_API* PPB_Instance_Proxy::GetFlashFunctionsAPI( #endif // !defined(OS_NACL) && !defined(NACL_WIN64) } +thunk::PPB_Flash_Clipboard_API* PPB_Instance_Proxy::GetFlashClipboardAPI( + PP_Instance instance) { +#if !defined(OS_NACL) && !defined(NACL_WIN64) + InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> + GetInstanceData(instance); + if (!data) + return NULL; + + if (!data->flash_clipboard_resource.get()) { + Connection connection( + PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), + dispatcher()); + data->flash_clipboard_resource = + new FlashClipboardResource(connection, instance); + } + return data->flash_clipboard_resource.get(); +#else + // Flash functions aren't implemented for nacl. + NOTIMPLEMENTED(); + return NULL; +#endif // !defined(OS_NACL) && !defined(NACL_WIN64) +} + thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI( PP_Instance instance) { InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index a30797cd..9b4de32 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -72,6 +72,8 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual thunk::PPB_Flash_API* GetFlashAPI() OVERRIDE; virtual thunk::PPB_Flash_Functions_API* GetFlashFunctionsAPI( PP_Instance instance) OVERRIDE; + virtual thunk::PPB_Flash_Clipboard_API* GetFlashClipboardAPI( + PP_Instance instance) OVERRIDE; virtual thunk::PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; diff --git a/ppapi/shared_impl/flash_clipboard_format_registry.cc b/ppapi/shared_impl/flash_clipboard_format_registry.cc new file mode 100644 index 0000000..a5d50c6 --- /dev/null +++ b/ppapi/shared_impl/flash_clipboard_format_registry.cc @@ -0,0 +1,91 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/flash_clipboard_format_registry.h" + +#include <cctype> + +namespace ppapi { + +namespace { + +// These values are chosen arbitrarily. Flash will never exceed these but if +// the interface becomes public, we can reconsider these. +const size_t kMaxNumFormats = 10; +const size_t kMaxFormatNameLength = 50; + +// All formats in PP_Flash_Clipboard_Format should be added here. +const PP_Flash_Clipboard_Format kPredefinedFormats[] = { + PP_FLASH_CLIPBOARD_FORMAT_INVALID, + PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, + PP_FLASH_CLIPBOARD_FORMAT_HTML, + PP_FLASH_CLIPBOARD_FORMAT_RTF +}; + +// The first custom format ID will be the ID after that max value in +// PP_Flash_Clipboard_Format. +const size_t kFirstCustomFormat = arraysize(kPredefinedFormats); + +// Checks the validity of the given format name. +bool IsValidFormatName(const std::string& format_name) { + if (format_name.empty() || format_name.length() > kMaxFormatNameLength) + return false; + return true; +} + +} // namespace + +FlashClipboardFormatRegistry::FlashClipboardFormatRegistry() { +} + +FlashClipboardFormatRegistry::~FlashClipboardFormatRegistry() { +} + +uint32_t FlashClipboardFormatRegistry::RegisterFormat( + const std::string& format_name) { + if (!IsValidFormatName(format_name) || + custom_formats_.size() > kMaxNumFormats) { + return PP_FLASH_CLIPBOARD_FORMAT_INVALID; + } + uint32_t key = kFirstCustomFormat + custom_formats_.size(); + custom_formats_[key] = format_name; + return key; +} + +void FlashClipboardFormatRegistry::SetRegisteredFormat( + const std::string& format_name, + uint32_t format) { + custom_formats_[format] = format_name; +} + +bool FlashClipboardFormatRegistry::IsFormatRegistered(uint32_t format) const { + return custom_formats_.find(format) != custom_formats_.end(); +} + +std::string FlashClipboardFormatRegistry::GetFormatName( + uint32_t format) const { + FormatMap::const_iterator it = custom_formats_.find(format); + if (it == custom_formats_.end()) + return std::string(); + return it->second; +} + +uint32_t FlashClipboardFormatRegistry::GetFormatID( + const std::string& format_name) const { + for (FormatMap::const_iterator it = custom_formats_.begin(); + it != custom_formats_.end(); ++it) { + if (it->second == format_name) + return it->first; + } + return PP_FLASH_CLIPBOARD_FORMAT_INVALID; +} + +// static +bool FlashClipboardFormatRegistry::IsValidPredefinedFormat(uint32_t format) { + if (format == PP_FLASH_CLIPBOARD_FORMAT_INVALID) + return false; + return format < kFirstCustomFormat; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/flash_clipboard_format_registry.h b/ppapi/shared_impl/flash_clipboard_format_registry.h new file mode 100644 index 0000000..90520ea --- /dev/null +++ b/ppapi/shared_impl/flash_clipboard_format_registry.h @@ -0,0 +1,65 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_ +#define PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_ + +#include <map> +#include <string> + +#include "base/basictypes.h" +#include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" + +namespace ppapi { + +// This class manages custom clipboard formats that can be registered by a user +// of PPB_Flash_Clipboard. It is used by both the plugin and host side +// of the proxy. The host side is the definitive source of which formats +// have been registered but format registration is tracked on the plugin +// side to better handle error cases. +class PPAPI_SHARED_EXPORT FlashClipboardFormatRegistry { + public: + FlashClipboardFormatRegistry(); + ~FlashClipboardFormatRegistry(); + + // Registers a custom format with the given string. The ID of the format is + // returned if registered successfully, otherwise + // PP_FLASH_CLIPBOARD_FORMAT_INVALID is returned. If a format with a + // particular name is already registered, the ID associated with that name + // will be returned. The format name is checked for validity. + uint32_t RegisterFormat(const std::string& format_name); + + // This sets the name of a particular format in the registry. This is only + // used on the plugin side in order to track format IDs that are returned + // by the host. + void SetRegisteredFormat(const std::string& format_name, uint32_t format); + + // Checks whether the given custom format ID has been registered. + bool IsFormatRegistered(uint32_t format) const; + + // Returns the name of a particular format. + std::string GetFormatName(uint32_t format) const; + + // Gets the ID of a particular format name that has already been registered. + // PP_FLASH_CLIPBOARD_FORMAT_INVALID is returned if the format has not been + // registered. + uint32_t GetFormatID(const std::string& format_name) const; + + // Returns whether the given clipboard format is a valid predefined format + // (i.e. one defined in the PP_Flash_Clipboard_Format enum). + static bool IsValidPredefinedFormat(uint32_t format); + + private: + // A map of custom format ID to format name. + typedef std::map<uint32_t, std::string> FormatMap; + FormatMap custom_formats_; + + DISALLOW_COPY_AND_ASSIGN(FlashClipboardFormatRegistry); +}; + +} // ppapi + +#endif // PPAPI_SHARED_IMPL_FLASH_CLIPBOARD_FORMAT_REGISTRY_H_ + diff --git a/ppapi/shared_impl/ppb_flash_shared.cc b/ppapi/shared_impl/ppb_flash_shared.cc index e78392c..c310e0e 100644 --- a/ppapi/shared_impl/ppb_flash_shared.cc +++ b/ppapi/shared_impl/ppb_flash_shared.cc @@ -20,20 +20,4 @@ void PPB_Flash_Shared::FreeDirContents(PP_Instance instance, delete contents; } -// static -bool PPB_Flash_Shared::IsValidClipboardType( - PP_Flash_Clipboard_Type clipboard_type) { - return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || - clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION; -} - -// static -bool PPB_Flash_Shared::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 || - format == PP_FLASH_CLIPBOARD_FORMAT_RTF; -} - } // namespace ppapi diff --git a/ppapi/shared_impl/ppb_flash_shared.h b/ppapi/shared_impl/ppb_flash_shared.h index dfd209d..29f8973 100644 --- a/ppapi/shared_impl/ppb_flash_shared.h +++ b/ppapi/shared_impl/ppb_flash_shared.h @@ -21,10 +21,6 @@ class PPAPI_SHARED_EXPORT PPB_Flash_Shared : public thunk::PPB_Flash_API { virtual void FreeDirContents(PP_Instance instance, PP_DirContents_Dev* contents) OVERRIDE; - protected: - static bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type); - static bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format); - private: DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Shared); }; diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index 442f1ce..c8b7d1f 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -35,6 +35,7 @@ F(PPB_FileRef_API) \ F(PPB_FileSystem_API) \ F(PPB_Find_API) \ + F(PPB_Flash_Clipboard_API) \ F(PPB_Flash_DeviceID_API) \ F(PPB_Flash_FontFile_API) \ F(PPB_Flash_Functions_API) \ diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc index 034a08e..432e5d5 100644 --- a/ppapi/tests/test_flash_clipboard.cc +++ b/ppapi/tests/test_flash_clipboard.cc @@ -31,14 +31,14 @@ void TestFlashClipboard::RunTests(const std::string& filter) { RUN_TEST(ReadWritePlainText, filter); RUN_TEST(ReadWriteHTML, filter); RUN_TEST(ReadWriteRTF, filter); + RUN_TEST(ReadWriteCustomData, filter); RUN_TEST(ReadWriteMultipleFormats, filter); RUN_TEST(Clear, filter); RUN_TEST(InvalidFormat, filter); + RUN_TEST(RegisterCustomFormat, filter); } -bool TestFlashClipboard::ReadStringVar( - PP_Flash_Clipboard_Format format, - std::string* result) { +bool TestFlashClipboard::ReadStringVar(uint32_t format, std::string* result) { pp::Var text; bool success = pp::flash::Clipboard::ReadData( instance_, @@ -52,9 +52,9 @@ bool TestFlashClipboard::ReadStringVar( return false; } -bool TestFlashClipboard::WriteStringVar(PP_Flash_Clipboard_Format format, +bool TestFlashClipboard::WriteStringVar(uint32_t format, const std::string& text) { - std::vector<PP_Flash_Clipboard_Format> formats_vector(1, format); + std::vector<uint32_t> formats_vector(1, format); std::vector<pp::Var> data_vector(1, pp::Var(text)); bool success = pp::flash::Clipboard::WriteData( instance_, @@ -64,9 +64,8 @@ bool TestFlashClipboard::WriteStringVar(PP_Flash_Clipboard_Format format, return success; } -bool TestFlashClipboard::IsFormatAvailableMatches( - PP_Flash_Clipboard_Format format, - bool expected) { +bool TestFlashClipboard::IsFormatAvailableMatches(uint32_t format, + bool expected) { for (int i = 0; i < kMaxIntervals; ++i) { bool is_available = pp::flash::Clipboard::IsFormatAvailable( instance_, @@ -136,10 +135,9 @@ std::string TestFlashClipboard::TestReadWriteRTF() { "This is some {\\b bold} text.\\par\n" "}"; pp::VarArrayBuffer array_buffer(rtf_string.size()); - char *bytes = static_cast<char*>(array_buffer.Map()); + char* bytes = static_cast<char*>(array_buffer.Map()); std::copy(rtf_string.data(), rtf_string.data() + rtf_string.size(), bytes); - std::vector<PP_Flash_Clipboard_Format> formats_vector(1, - PP_FLASH_CLIPBOARD_FORMAT_RTF); + std::vector<uint32_t> formats_vector(1, PP_FLASH_CLIPBOARD_FORMAT_RTF); std::vector<pp::Var> data_vector(1, array_buffer); ASSERT_TRUE(pp::flash::Clipboard::WriteData( instance_, @@ -158,7 +156,42 @@ std::string TestFlashClipboard::TestReadWriteRTF() { ASSERT_TRUE(rtf_result.is_array_buffer()); pp::VarArrayBuffer array_buffer_result(rtf_result); ASSERT_TRUE(array_buffer_result.ByteLength() == array_buffer.ByteLength()); - char *bytes_result = static_cast<char*>(array_buffer_result.Map()); + char* bytes_result = static_cast<char*>(array_buffer_result.Map()); + ASSERT_TRUE(std::equal(bytes, bytes + array_buffer.ByteLength(), + bytes_result)); + + PASS(); +} + +std::string TestFlashClipboard::TestReadWriteCustomData() { + std::string custom_data = "custom_data"; + pp::VarArrayBuffer array_buffer(custom_data.size()); + char* bytes = static_cast<char*>(array_buffer.Map()); + std::copy(custom_data.begin(), custom_data.end(), bytes); + uint32_t format_id = + pp::flash::Clipboard::RegisterCustomFormat(instance_, "my-format"); + ASSERT_NE(format_id, PP_FLASH_CLIPBOARD_FORMAT_INVALID); + + std::vector<uint32_t> formats_vector(1, format_id); + std::vector<pp::Var> data_vector(1, array_buffer); + ASSERT_TRUE(pp::flash::Clipboard::WriteData( + instance_, + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + formats_vector, + data_vector)); + + ASSERT_TRUE(IsFormatAvailableMatches(format_id, true)); + + pp::Var custom_data_result; + ASSERT_TRUE(pp::flash::Clipboard::ReadData( + instance_, + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + format_id, + &custom_data_result)); + ASSERT_TRUE(custom_data_result.is_array_buffer()); + pp::VarArrayBuffer array_buffer_result(custom_data_result); + ASSERT_EQ(array_buffer_result.ByteLength(), array_buffer.ByteLength()); + char* bytes_result = static_cast<char*>(array_buffer_result.Map()); ASSERT_TRUE(std::equal(bytes, bytes + array_buffer.ByteLength(), bytes_result)); @@ -166,7 +199,7 @@ std::string TestFlashClipboard::TestReadWriteRTF() { } std::string TestFlashClipboard::TestReadWriteMultipleFormats() { - std::vector<PP_Flash_Clipboard_Format> formats; + std::vector<uint32_t> formats; std::vector<pp::Var> data; formats.push_back(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); data.push_back(pp::Var("plain text")); @@ -195,7 +228,7 @@ std::string TestFlashClipboard::TestClear() { bool success = pp::flash::Clipboard::WriteData( instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, - std::vector<PP_Flash_Clipboard_Format>(), + std::vector<uint32_t>(), std::vector<pp::Var>()); ASSERT_TRUE(success); ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, @@ -205,8 +238,7 @@ std::string TestFlashClipboard::TestClear() { } std::string TestFlashClipboard::TestInvalidFormat() { - PP_Flash_Clipboard_Format invalid_format = - static_cast<PP_Flash_Clipboard_Format>(-1); + uint32_t invalid_format = 999; ASSERT_FALSE(WriteStringVar(invalid_format, "text")); ASSERT_TRUE(IsFormatAvailableMatches(invalid_format, false)); std::string unused; @@ -214,3 +246,30 @@ std::string TestFlashClipboard::TestInvalidFormat() { PASS(); } + +std::string TestFlashClipboard::TestRegisterCustomFormat() { + // Test an empty name is rejected. + uint32_t format_id = + pp::flash::Clipboard::RegisterCustomFormat(instance_, ""); + ASSERT_EQ(format_id, PP_FLASH_CLIPBOARD_FORMAT_INVALID); + + // Test a valid format name. + format_id = pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b"); + ASSERT_NE(format_id, PP_FLASH_CLIPBOARD_FORMAT_INVALID); + // Make sure the format doesn't collide with predefined formats. + ASSERT_NE(format_id, PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); + ASSERT_NE(format_id, PP_FLASH_CLIPBOARD_FORMAT_HTML); + ASSERT_NE(format_id, PP_FLASH_CLIPBOARD_FORMAT_RTF); + + // Check that if the same name is registered, the same id comes out. + uint32_t format_id2 = + pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b"); + ASSERT_EQ(format_id, format_id2); + + // Check that the second format registered has a different id. + uint32_t format_id3 = + pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b-c"); + ASSERT_NE(format_id, format_id3); + + PASS(); +} diff --git a/ppapi/tests/test_flash_clipboard.h b/ppapi/tests/test_flash_clipboard.h index e04f89d..3b11d5b 100644 --- a/ppapi/tests/test_flash_clipboard.h +++ b/ppapi/tests/test_flash_clipboard.h @@ -20,11 +20,9 @@ class TestFlashClipboard : public TestCase { private: // Helpers. - bool ReadStringVar(PP_Flash_Clipboard_Format format, std::string* result); - bool WriteStringVar(PP_Flash_Clipboard_Format format, - const std::string& text); - bool IsFormatAvailableMatches(PP_Flash_Clipboard_Format format, - bool expected); + bool ReadStringVar(uint32_t format, std::string* result); + bool WriteStringVar(uint32_t format, const std::string& text); + bool IsFormatAvailableMatches(uint32_t format, bool expected); bool ReadPlainTextMatches(const std::string& expected); bool ReadHTMLMatches(const std::string& expected); @@ -33,8 +31,10 @@ class TestFlashClipboard : public TestCase { std::string TestReadWriteHTML(); std::string TestReadWriteRTF(); std::string TestReadWriteMultipleFormats(); + std::string TestReadWriteCustomData(); std::string TestClear(); std::string TestInvalidFormat(); + std::string TestRegisterCustomFormat(); }; #endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ diff --git a/ppapi/thunk/interfaces_ppb_private_flash.h b/ppapi/thunk/interfaces_ppb_private_flash.h index 7a3b423..89f9f2b8 100644 --- a/ppapi/thunk/interfaces_ppb_private_flash.h +++ b/ppapi/thunk/interfaces_ppb_private_flash.h @@ -31,15 +31,6 @@ PROXIED_IFACE(PPB_Flash, PPB_Flash_12_6) PROXIED_IFACE(PPB_Flash, - PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY, - PPB_Flash_Clipboard_3_0) -PROXIED_IFACE(PPB_Flash, - PPB_FLASH_CLIPBOARD_INTERFACE_3_0, - PPB_Flash_Clipboard_3_0) -PROXIED_IFACE(PPB_Flash, - PPB_FLASH_CLIPBOARD_INTERFACE_4_0, - PPB_Flash_Clipboard_4_0) -PROXIED_IFACE(PPB_Flash, PPB_FLASH_FILE_MODULELOCAL_INTERFACE_2_0, PPB_Flash_File_ModuleLocal_2_0) PROXIED_IFACE(PPB_Flash, @@ -48,6 +39,13 @@ PROXIED_IFACE(PPB_Flash, PROXIED_IFACE(PPB_Flash, PPB_FLASH_FILE_FILEREF_INTERFACE, PPB_Flash_File_FileRef) +PROXIED_IFACE(NoAPIName, + PPB_FLASH_CLIPBOARD_INTERFACE_4_0, + PPB_Flash_Clipboard_4_0) +PROXIED_IFACE(NoAPIName, + PPB_FLASH_CLIPBOARD_INTERFACE_5_0, + PPB_Flash_Clipboard_5_0) + PROXIED_IFACE(NoAPIName, PPB_FLASH_DEVICEID_INTERFACE_1_0, diff --git a/ppapi/thunk/ppb_flash_api.h b/ppapi/thunk/ppb_flash_api.h index 7a1a641..1a7ed5b 100644 --- a/ppapi/thunk/ppb_flash_api.h +++ b/ppapi/thunk/ppb_flash_api.h @@ -6,7 +6,6 @@ #define PPAPI_THUNK_PPB_FLASH_API_H_ #include "ppapi/c/private/ppb_flash.h" -#include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/c/private/ppb_flash_file.h" #include "ppapi/thunk/ppapi_thunk_export.h" @@ -68,20 +67,6 @@ class PPAPI_THUNK_EXPORT PPB_Flash_API { PP_FlashCrashKey key, PP_Var value) = 0; - // FlashClipboard. - virtual PP_Bool IsClipboardFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) = 0; - virtual PP_Var ReadClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) = 0; - virtual int32_t WriteClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], - const PP_Var data_items[]) = 0; - // FlashFile_ModuleLocal. virtual bool CreateThreadAdapterForInstance(PP_Instance instance) = 0; virtual void ClearThreadAdapterForInstance(PP_Instance instance) = 0; diff --git a/ppapi/thunk/ppb_flash_clipboard_api.h b/ppapi/thunk/ppb_flash_clipboard_api.h new file mode 100644 index 0000000..ef022c4a --- /dev/null +++ b/ppapi/thunk/ppb_flash_clipboard_api.h @@ -0,0 +1,40 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_PPB_FLASH_CLIPBOARD_API_H_ +#define PPAPI_THUNK_PPB_FLASH_CLIPBOARD_API_H_ + +#include "ppapi/c/private/ppb_flash_clipboard.h" + +namespace ppapi { +namespace thunk { + +class PPB_Flash_Clipboard_API { + public: + virtual ~PPB_Flash_Clipboard_API() {} + + // PPB_Flash_Clipboard. + virtual uint32_t RegisterCustomFormat( + PP_Instance instance, + const char* format_name) = 0; + virtual PP_Bool IsFormatAvailable( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) = 0; + virtual PP_Var ReadData( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t format) = 0; + virtual int32_t WriteData( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t data_item_count, + const uint32_t formats[], + const PP_Var data_items[]) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FLASH_CLIPBOARD_API_H_ diff --git a/ppapi/thunk/ppb_flash_clipboard_thunk.cc b/ppapi/thunk/ppb_flash_clipboard_thunk.cc index 084b937..d982cd5 100644 --- a/ppapi/thunk/ppb_flash_clipboard_thunk.cc +++ b/ppapi/thunk/ppb_flash_clipboard_thunk.cc @@ -2,70 +2,92 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/memory/scoped_ptr.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_clipboard_api.h" #include "ppapi/thunk/thunk.h" -#include "ppapi/thunk/ppb_flash_api.h" namespace ppapi { namespace thunk { namespace { +uint32_t RegisterCustomFormat(PP_Instance instance, + const char* format_name) { + EnterInstance enter(instance); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->GetFlashClipboardAPI( + instance)->RegisterCustomFormat(instance, format_name); +} + PP_Bool IsFormatAvailable(PP_Instance instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { + uint32_t format) { EnterInstance enter(instance); if (enter.failed()) return PP_FALSE; - return enter.functions()->GetFlashAPI()->IsClipboardFormatAvailable( - instance, clipboard_type, format); + return enter.functions()->GetFlashClipboardAPI( + instance)->IsFormatAvailable(instance, clipboard_type, format); } PP_Var ReadData(PP_Instance instance, PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { + uint32_t format) { EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); - return enter.functions()->GetFlashAPI()->ReadClipboardData( + return enter.functions()->GetFlashClipboardAPI(instance)->ReadData( instance, clipboard_type, format); } int32_t WriteData(PP_Instance instance, PP_Flash_Clipboard_Type clipboard_type, uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], + const uint32_t formats[], const PP_Var data_items[]) { EnterInstance enter(instance); if (enter.failed()) return enter.retval(); - return enter.functions()->GetFlashAPI()->WriteClipboardData( + return enter.functions()->GetFlashClipboardAPI(instance)->WriteData( instance, clipboard_type, data_item_count, formats, data_items); } -PP_Var ReadPlainText(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type) { - return ReadData(instance, - clipboard_type, - PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); +PP_Bool IsFormatAvailable_4_0(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + PP_Flash_Clipboard_Format format) { + return IsFormatAvailable(instance, clipboard_type, + static_cast<uint32_t>(format)); } -int32_t WritePlainText(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Var text) { - PP_Flash_Clipboard_Format format = PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT; - return WriteData(instance, clipboard_type, 1, &format, &text); +PP_Var ReadData_4_0(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + PP_Flash_Clipboard_Format format) { + return ReadData(instance, clipboard_type, static_cast<uint32_t>(format)); } -const PPB_Flash_Clipboard_3_0 g_ppb_flash_clipboard_thunk_3_0 = { - &IsFormatAvailable, - &ReadPlainText, - &WritePlainText -}; +int32_t WriteData_4_0(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + uint32_t data_item_count, + const PP_Flash_Clipboard_Format formats[], + const PP_Var data_items[]) { + scoped_array<uint32_t> new_formats(new uint32_t[data_item_count]); + for (uint32_t i = 0; i < data_item_count; ++i) + new_formats[i] = static_cast<uint32_t>(formats[i]); + return WriteData(instance, clipboard_type, data_item_count, + new_formats.get(), data_items); +} const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { + &IsFormatAvailable_4_0, + &ReadData_4_0, + &WriteData_4_0 +}; + +const PPB_Flash_Clipboard_5_0 g_ppb_flash_clipboard_thunk_5_0 = { + &RegisterCustomFormat, &IsFormatAvailable, &ReadData, &WriteData @@ -73,13 +95,13 @@ const PPB_Flash_Clipboard_4_0 g_ppb_flash_clipboard_thunk_4_0 = { } // namespace -const PPB_Flash_Clipboard_3_0* GetPPB_Flash_Clipboard_3_0_Thunk() { - return &g_ppb_flash_clipboard_thunk_3_0; -} - const PPB_Flash_Clipboard_4_0* GetPPB_Flash_Clipboard_4_0_Thunk() { return &g_ppb_flash_clipboard_thunk_4_0; } +const PPB_Flash_Clipboard_5_0* GetPPB_Flash_Clipboard_5_0_Thunk() { + return &g_ppb_flash_clipboard_thunk_5_0; +} + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index f91febd..c5f26e6 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -38,6 +38,7 @@ struct ViewData; namespace thunk { class PPB_Flash_API; +class PPB_Flash_Clipboard_API; class PPB_Flash_Functions_API; class PPB_Gamepad_API; @@ -95,6 +96,10 @@ class PPB_Instance_API { virtual PPB_Flash_Functions_API* GetFlashFunctionsAPI( PP_Instance instance) = 0; + // Flash_Clipboard. + virtual PPB_Flash_Clipboard_API* GetFlashClipboardAPI( + PP_Instance instance) = 0; + // Gamepad. virtual PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) = 0; diff --git a/ui/base/clipboard/clipboard.h b/ui/base/clipboard/clipboard.h index e7785f0..16e0275 100644 --- a/ui/base/clipboard/clipboard.h +++ b/ui/base/clipboard/clipboard.h @@ -286,7 +286,10 @@ class UI_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { static const FormatType& GetHtmlFormatType(); static const FormatType& GetRtfFormatType(); static const FormatType& GetBitmapFormatType(); + // TODO(raymes): Unify web custom data and pepper custom data: + // crbug.com/158399. static const FormatType& GetWebCustomDataFormatType(); + static const FormatType& GetPepperCustomDataFormatType(); // Embeds a pointer to a SharedMemory object pointed to by |bitmap_handle| // belonging to |process| into a shared bitmap [CBF_SMBITMAP] slot in diff --git a/ui/base/clipboard/clipboard_android.cc b/ui/base/clipboard/clipboard_android.cc index 4d310fb..b3df974 100644 --- a/ui/base/clipboard/clipboard_android.cc +++ b/ui/base/clipboard/clipboard_android.cc @@ -38,6 +38,7 @@ const char kRTFFormat[] = "rtf"; const char kBitmapFormat[] = "bitmap"; const char kWebKitSmartPasteFormat[] = "webkit_smart"; const char kBookmarkFormat[] = "bookmark"; +const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; const char kMimeTypeWebCustomData[] = "chromium/x-web-custom-data"; class ClipboardMap { @@ -357,6 +358,12 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { return type; } +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); + return type; +} + void Clipboard::WriteText(const char* text_data, size_t text_len) { g_map.Get().Set(kPlainTextFormat, std::string(text_data, text_len)); } diff --git a/ui/base/clipboard/clipboard_aurax11.cc b/ui/base/clipboard/clipboard_aurax11.cc index b37d636..b8f6670 100644 --- a/ui/base/clipboard/clipboard_aurax11.cc +++ b/ui/base/clipboard/clipboard_aurax11.cc @@ -36,6 +36,7 @@ const char kClipboard[] = "CLIPBOARD"; const char kMimeTypeBitmap[] = "image/bmp"; const char kMimeTypeFilename[] = "chromium/filename"; const char kMimeTypeMozillaURL[] = "text/x-moz-url"; +const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; const char kMultiple[] = "MULTIPLE"; const char kString[] = "STRING"; @@ -1207,4 +1208,10 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { return type; } +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); + return type; +} + } // namespace ui diff --git a/ui/base/clipboard/clipboard_chromeos.cc b/ui/base/clipboard/clipboard_chromeos.cc index 0a2c491..07bc124 100644 --- a/ui/base/clipboard/clipboard_chromeos.cc +++ b/ui/base/clipboard/clipboard_chromeos.cc @@ -21,6 +21,7 @@ namespace ui { namespace { const char kMimeTypeFilename[] = "chromium/filename"; const char kMimeTypeBitmap[] = "image/bmp"; +const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; const size_t kMaxClipboardSize = 1; @@ -670,4 +671,10 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { return type; } +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); + return type; +} + } // namespace ui diff --git a/ui/base/clipboard/clipboard_gtk.cc b/ui/base/clipboard/clipboard_gtk.cc index b3666be..40c58ca 100644 --- a/ui/base/clipboard/clipboard_gtk.cc +++ b/ui/base/clipboard/clipboard_gtk.cc @@ -108,6 +108,7 @@ GdkFilterReturn SelectionChangeObserver::OnXEvent(GdkXEvent* xevent, const char kMimeTypeBitmap[] = "image/bmp"; const char kMimeTypeMozillaURL[] = "text/x-moz-url"; +const char kMimeTypePepperCustomData[] = "chromium/x-pepper-custom-data"; const char kMimeTypeWebkitSmartPaste[] = "chromium/x-webkit-paste"; std::string GdkAtomToString(const GdkAtom& atom) { @@ -650,6 +651,12 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { return type; } +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); + return type; +} + void Clipboard::InsertMapping(const char* key, char* data, size_t data_len) { diff --git a/ui/base/clipboard/clipboard_mac.mm b/ui/base/clipboard/clipboard_mac.mm index 0367448..da915e3 100644 --- a/ui/base/clipboard/clipboard_mac.mm +++ b/ui/base/clipboard/clipboard_mac.mm @@ -33,6 +33,10 @@ NSString* const kUTTypeURLName = @"public.url-name"; // actual data associated with this type. NSString* const kWebSmartPastePboardType = @"NeXT smart paste pasteboard type"; +// Pepper custom data format type. +NSString* const kPepperCustomDataPboardType = + @"org.chromium.pepper-custom-data"; + NSPasteboard* GetPasteboard() { // The pasteboard should not be nil in a UI session, but this handy DCHECK // can help track down problems if someone tries using clipboard code outside @@ -475,4 +479,10 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { return type; } +// static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL(FormatType, type, (kPepperCustomDataPboardType)); + return type; +} + } // namespace ui diff --git a/ui/base/clipboard/clipboard_util_win.cc b/ui/base/clipboard/clipboard_util_win.cc index e6b527f..398ac81 100644 --- a/ui/base/clipboard/clipboard_util_win.cc +++ b/ui/base/clipboard/clipboard_util_win.cc @@ -218,6 +218,12 @@ FORMATETC* ClipboardUtil::GetWebCustomDataFormat() { return &format; } +FORMATETC* ClipboardUtil::GetPepperCustomDataFormat() { + static UINT cf = + RegisterClipboardFormat(L"Chromium Pepper MIME Data Format"); + static FORMATETC format = {cf, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL}; + return &format; +} bool ClipboardUtil::HasUrl(IDataObject* data_object) { DCHECK(data_object); diff --git a/ui/base/clipboard/clipboard_util_win.h b/ui/base/clipboard/clipboard_util_win.h index 24cf540..e599856 100644 --- a/ui/base/clipboard/clipboard_util_win.h +++ b/ui/base/clipboard/clipboard_util_win.h @@ -39,6 +39,7 @@ class UI_EXPORT ClipboardUtil { static FORMATETC* GetFileContentFormatZero(); static FORMATETC* GetWebKitSmartPasteFormat(); static FORMATETC* GetWebCustomDataFormat(); + static FORMATETC* GetPepperCustomDataFormat(); ///////////////////////////////////////////////////////////////////////////// // These methods check to see if |data_object| has the requested type. diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc index 6ea0cb1..2a93859 100644 --- a/ui/base/clipboard/clipboard_win.cc +++ b/ui/base/clipboard/clipboard_win.cc @@ -827,6 +827,15 @@ const Clipboard::FormatType& Clipboard::GetWebCustomDataFormatType() { } // static +const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { + CR_DEFINE_STATIC_LOCAL( + FormatType, + type, + (ClipboardUtil::GetPepperCustomDataFormat()->cfFormat)); + return type; +} + +// static void Clipboard::FreeData(unsigned int format, HANDLE data) { if (format == CF_BITMAP) ::DeleteObject(static_cast<HBITMAP>(data)); diff --git a/ui/base/clipboard/scoped_clipboard_writer.h b/ui/base/clipboard/scoped_clipboard_writer.h index d2f5b31..576922b 100644 --- a/ui/base/clipboard/scoped_clipboard_writer.h +++ b/ui/base/clipboard/scoped_clipboard_writer.h @@ -61,7 +61,7 @@ class UI_EXPORT ScopedClipboardWriter { // Pixel format is assumed to be 32-bit BI_RGB. void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); - // Adds arbitrary data to clipboard. + // Adds arbitrary pickled data to clipboard. void WritePickledData(const Pickle& pickle, const Clipboard::FormatType& format); diff --git a/webkit/glue/clipboard_client.h b/webkit/glue/clipboard_client.h index 9d69c98..5126e9f 100644 --- a/webkit/glue/clipboard_client.h +++ b/webkit/glue/clipboard_client.h @@ -70,6 +70,10 @@ class ClipboardClient { const string16& type, string16* data) = 0; + // Reads raw data from the clipboard for a given format. + virtual void ReadData(const ui::Clipboard::FormatType& format, + std::string* data) = 0; + // Creates a context to write clipboard data. May return NULL. virtual WriteContext* CreateWriteContext() = 0; }; diff --git a/webkit/glue/scoped_clipboard_writer_glue.cc b/webkit/glue/scoped_clipboard_writer_glue.cc index f648b7b..b16ac04 100644 --- a/webkit/glue/scoped_clipboard_writer_glue.cc +++ b/webkit/glue/scoped_clipboard_writer_glue.cc @@ -5,6 +5,8 @@ #include "webkit/glue/scoped_clipboard_writer_glue.h" #include "base/logging.h" +namespace webkit_glue { + ScopedClipboardWriterGlue::ScopedClipboardWriterGlue( webkit_glue::ClipboardClient* client) : ui::ScopedClipboardWriter(client->GetClipboard(), @@ -29,3 +31,5 @@ void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels, ScopedClipboardWriter::WriteBitmapFromPixels(pixels, size); } } + +} // namespace webkit_glue diff --git a/webkit/glue/scoped_clipboard_writer_glue.h b/webkit/glue/scoped_clipboard_writer_glue.h index 0eb13fc..915b427 100644 --- a/webkit/glue/scoped_clipboard_writer_glue.h +++ b/webkit/glue/scoped_clipboard_writer_glue.h @@ -8,12 +8,16 @@ #include "ui/base/clipboard/scoped_clipboard_writer.h" #include "base/memory/scoped_ptr.h" #include "webkit/glue/clipboard_client.h" +#include "webkit/glue/webkit_glue_export.h" -class ScopedClipboardWriterGlue : public ui::ScopedClipboardWriter { +namespace webkit_glue { + +class WEBKIT_GLUE_EXPORT ScopedClipboardWriterGlue + : public ui::ScopedClipboardWriter { public: explicit ScopedClipboardWriterGlue(webkit_glue::ClipboardClient* client); - ~ScopedClipboardWriterGlue(); + virtual ~ScopedClipboardWriterGlue(); void WriteBitmapFromPixels(const void* pixels, const gfx::Size& size); @@ -22,4 +26,6 @@ class ScopedClipboardWriterGlue : public ui::ScopedClipboardWriter { DISALLOW_COPY_AND_ASSIGN(ScopedClipboardWriterGlue); }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_SCOPED_CLIPBOARD_WRITER_GLUE_H_ diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc index 95d5940..7de9f91 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.cc +++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc @@ -468,11 +468,6 @@ int MockPluginDelegate::EnumerateDevices( void MockPluginDelegate::StopEnumerateDevices(int request_id) { } -webkit_glue::ClipboardClient* -MockPluginDelegate::CreateClipboardClient() const { - return NULL; -} - std::string MockPluginDelegate::GetDeviceID() { return std::string(); } diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h index b7f17f0..39e072a 100644 --- a/webkit/plugins/ppapi/mock_plugin_delegate.h +++ b/webkit/plugins/ppapi/mock_plugin_delegate.h @@ -9,7 +9,6 @@ struct PP_NetAddress_Private; namespace ppapi { class PPB_X509Certificate_Fields; } -namespace webkit_glue { class ClipboardClient; } namespace webkit { namespace ppapi { @@ -210,7 +209,6 @@ class MockPluginDelegate : public PluginDelegate { virtual int EnumerateDevices(PP_DeviceType_Dev type, const EnumerateDevicesCallback& callback); virtual void StopEnumerateDevices(int request_id); - virtual webkit_glue::ClipboardClient* CreateClipboardClient() const; virtual std::string GetDeviceID(); virtual PP_FlashLSORestrictions GetLocalDataRestrictions( const GURL& document_url, diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h index e623edc..f412135 100644 --- a/webkit/plugins/ppapi/plugin_delegate.h +++ b/webkit/plugins/ppapi/plugin_delegate.h @@ -668,9 +668,6 @@ class PluginDelegate { // Stop enumerating devices of the specified |request_id|. The |request_id| // is the return value of EnumerateDevicesCallback. virtual void StopEnumerateDevices(int request_id) = 0; - // Create a ClipboardClient for writing to the clipboard. The caller will own - // the pointer to this. - virtual webkit_glue::ClipboardClient* CreateClipboardClient() const = 0; // Returns a Device ID virtual std::string GetDeviceID() = 0; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 8d56799..af4e370 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -2882,6 +2882,12 @@ PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { return &flash_impl_; } +::ppapi::thunk::PPB_Flash_Clipboard_API* +PluginInstance::GetFlashClipboardAPI(PP_Instance /*instance*/) { + NOTIMPLEMENTED(); + return NULL; +} + ::ppapi::thunk::PPB_Flash_Functions_API* PluginInstance::GetFlashFunctionsAPI(PP_Instance /*instance*/) { NOTIMPLEMENTED(); diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 9d7d178..426106e 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -42,6 +42,7 @@ #include "ppapi/c/private/ppp_instance_private.h" #include "ppapi/shared_impl/ppb_instance_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" +#include "ppapi/thunk/ppb_flash_clipboard_api.h" #include "ppapi/thunk/ppb_flash_functions_api.h" #include "ppapi/thunk/ppb_gamepad_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -402,10 +403,12 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : virtual void SelectedFindResultChanged(PP_Instance instance, int32_t index) OVERRIDE; virtual PP_Bool SetFullscreen(PP_Instance instance, - PP_Bool fullscreen) OVERRIDE; + PP_Bool fullscreen) OVERRIDE; virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; virtual ::ppapi::thunk::PPB_Flash_API* GetFlashAPI() OVERRIDE; + virtual ::ppapi::thunk::PPB_Flash_Clipboard_API* GetFlashClipboardAPI( + PP_Instance instance) OVERRIDE; virtual ::ppapi::thunk::PPB_Flash_Functions_API* GetFlashFunctionsAPI( PP_Instance instance) OVERRIDE; virtual ::ppapi::thunk::PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index 94a85a6..ccad022 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -32,8 +32,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" #include "ui/gfx/rect.h" -#include "webkit/glue/clipboard_client.h" -#include "webkit/glue/scoped_clipboard_writer_glue.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/host_globals.h" #include "webkit/plugins/ppapi/plugin_delegate.h" @@ -55,24 +53,6 @@ using ppapi::thunk::PPB_URLRequestInfo_API; namespace webkit { namespace ppapi { -namespace { - -const size_t kMaxClipboardWriteSize = 1000000; - -ui::Clipboard::Buffer ConvertClipboardType( - PP_Flash_Clipboard_Type type) { - switch (type) { - case PP_FLASH_CLIPBOARD_TYPE_STANDARD: - return ui::Clipboard::BUFFER_STANDARD; - case PP_FLASH_CLIPBOARD_TYPE_SELECTION: - return ui::Clipboard::BUFFER_SELECTION; - } - NOTREACHED(); - return ui::Clipboard::BUFFER_STANDARD; -} - -} // namespace - PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) : instance_(instance) { } @@ -278,135 +258,6 @@ PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, return PP_FALSE; } - -PP_Bool PPB_Flash_Impl::IsClipboardFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!InitClipboard()) - return PP_FALSE; - - if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { - NOTIMPLEMENTED(); - return PP_FALSE; - } - - ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); - switch (format) { - case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { - bool plain = clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextFormatType(), buffer_type); - bool plainw = clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextWFormatType(), buffer_type); - return BoolToPPBool(plain || plainw); - } - case PP_FLASH_CLIPBOARD_FORMAT_HTML: - return BoolToPPBool(clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetHtmlFormatType(), buffer_type)); - case PP_FLASH_CLIPBOARD_FORMAT_RTF: - return BoolToPPBool(clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetRtfFormatType(), buffer_type)); - case PP_FLASH_CLIPBOARD_FORMAT_INVALID: - break; - } - - return PP_FALSE; -} - -PP_Var PPB_Flash_Impl::ReadClipboardData( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!InitClipboard()) - return PP_MakeUndefined(); - - if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { - NOTIMPLEMENTED(); - return PP_MakeUndefined(); - } - - if (!IsClipboardFormatAvailable(instance, clipboard_type, format)) - return PP_MakeNull(); - - ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); - - switch (format) { - case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { - if (clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextWFormatType(), buffer_type)) { - string16 text; - clipboard_client_->ReadText(buffer_type, &text); - if (!text.empty()) - return StringVar::StringToPPVar(UTF16ToUTF8(text)); - } - - if (clipboard_client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextFormatType(), buffer_type)) { - std::string text; - clipboard_client_->ReadAsciiText(buffer_type, &text); - if (!text.empty()) - return StringVar::StringToPPVar(text); - } - - return PP_MakeNull(); - } - case PP_FLASH_CLIPBOARD_FORMAT_HTML: { - string16 html; - GURL gurl; - uint32 fragment_start; - uint32 fragment_end; - clipboard_client_->ReadHTML(buffer_type, - &html, - &gurl, - &fragment_start, - &fragment_end); - return StringVar::StringToPPVar(UTF16ToUTF8( - html.substr(fragment_start, fragment_end - fragment_start))); - } - case PP_FLASH_CLIPBOARD_FORMAT_RTF: { - std::string result; - clipboard_client_->ReadRTF(buffer_type, &result); - return ::ppapi::PpapiGlobals::Get()->GetVarTracker()-> - MakeArrayBufferPPVar(result.size(), result.data()); - } - case PP_FLASH_CLIPBOARD_FORMAT_INVALID: - break; - } - - return PP_MakeUndefined(); -} - -int32_t PPB_Flash_Impl::WriteClipboardData( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], - const PP_Var data_items[]) { - if (!InitClipboard()) - return PP_ERROR_FAILED; - - if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { - NOTIMPLEMENTED(); - return PP_ERROR_FAILED; - } - - if (data_item_count == 0) { - clipboard_client_->Clear(ConvertClipboardType(clipboard_type)); - return PP_OK; - } - ScopedClipboardWriterGlue scw(clipboard_client_.get()); - for (uint32_t i = 0; i < data_item_count; ++i) { - int32_t res = WriteClipboardDataItem(formats[i], data_items[i], &scw); - if (res != PP_OK) { - // Need to clear the objects so nothing is written. - scw.Reset(); - return res; - } - } - - return PP_OK; -} - bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { return false; // No multithreaded access allowed. } @@ -642,65 +493,5 @@ PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, return instance_->GetScreenSize(instance, size); } -bool PPB_Flash_Impl::InitClipboard() { - // Initialize the ClipboardClient for writing to the clipboard. - if (!clipboard_client_.get()) { - if (!instance_) - return false; - PluginDelegate* plugin_delegate = instance_->delegate(); - if (!plugin_delegate) - return false; - clipboard_client_.reset(plugin_delegate->CreateClipboardClient()); - } - return true; -} - -int32_t PPB_Flash_Impl::WriteClipboardDataItem( - const PP_Flash_Clipboard_Format format, - const PP_Var& data, - ScopedClipboardWriterGlue* scw) { - switch (format) { - case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { - StringVar* text_string = StringVar::FromPPVar(data); - if (!text_string) - return PP_ERROR_BADARGUMENT; - - if (text_string->value().length() > kMaxClipboardWriteSize) - return PP_ERROR_NOSPACE; - - scw->WriteText(UTF8ToUTF16(text_string->value())); - return PP_OK; - } - case PP_FLASH_CLIPBOARD_FORMAT_HTML: { - StringVar* text_string = StringVar::FromPPVar(data); - if (!text_string) - return PP_ERROR_BADARGUMENT; - - if (text_string->value().length() > kMaxClipboardWriteSize) - return PP_ERROR_NOSPACE; - - scw->WriteHTML(UTF8ToUTF16(text_string->value()), ""); - return PP_OK; - } - case PP_FLASH_CLIPBOARD_FORMAT_RTF: { - ::ppapi::ArrayBufferVar* rtf_data = - ::ppapi::ArrayBufferVar::FromPPVar(data); - if (!rtf_data) - return PP_ERROR_BADARGUMENT; - - if (rtf_data->ByteLength() > kMaxClipboardWriteSize) - return PP_ERROR_NOSPACE; - - scw->WriteRTF(std::string(static_cast<char*>(rtf_data->Map()), - rtf_data->ByteLength())); - return PP_OK; - } - case PP_FLASH_CLIPBOARD_FORMAT_INVALID: - break; - } - - return PP_ERROR_BADARGUMENT; -} - } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_flash_impl.h b/webkit/plugins/ppapi/ppb_flash_impl.h index d8aef6f..c7edb45 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_impl.h @@ -11,12 +11,6 @@ #include "build/build_config.h" #include "ppapi/shared_impl/ppb_flash_shared.h" -class ScopedClipboardWriterGlue; - -namespace webkit_glue { -class ClipboardClient; -} - namespace webkit { namespace ppapi { @@ -65,18 +59,6 @@ class PPB_Flash_Impl : public ::ppapi::PPB_Flash_Shared { virtual PP_Bool SetCrashData(PP_Instance instance, PP_FlashCrashKey key, PP_Var value) OVERRIDE; - virtual PP_Bool IsClipboardFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual PP_Var ReadClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual int32_t WriteClipboardData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - uint32_t data_item_count, - const PP_Flash_Clipboard_Format formats[], - const PP_Var data_items[]) OVERRIDE; virtual bool CreateThreadAdapterForInstance(PP_Instance instance) OVERRIDE; virtual void ClearThreadAdapterForInstance(PP_Instance instance) OVERRIDE; virtual int32_t OpenFile(PP_Instance instance, @@ -112,19 +94,8 @@ class PPB_Flash_Impl : public ::ppapi::PPB_Flash_Shared { PP_Size* size) OVERRIDE; private: - // Call to ensure that the clipboard_client is properly initialized. Returns - // true on success. On failure, you should not use the client. - bool InitClipboard(); - - int32_t WriteClipboardDataItem(const PP_Flash_Clipboard_Format format, - const PP_Var& data, - ScopedClipboardWriterGlue* scw); - PluginInstance* instance_; - // This object is lazily created by InitClipboard. - scoped_ptr<webkit_glue::ClipboardClient> clipboard_client_; - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Impl); }; diff --git a/webkit/tools/test_shell/simple_clipboard_impl.cc b/webkit/tools/test_shell/simple_clipboard_impl.cc index d51e109..b018b71 100644 --- a/webkit/tools/test_shell/simple_clipboard_impl.cc +++ b/webkit/tools/test_shell/simple_clipboard_impl.cc @@ -111,6 +111,11 @@ void SimpleClipboardClient::ReadCustomData(ui::Clipboard::Buffer buffer, GetClipboard()->ReadCustomData(buffer, type, data); } +void SimpleClipboardClient::ReadData(const ui::Clipboard::FormatType& format, + std::string* data) { + GetClipboard()->ReadData(format, data); +} + webkit_glue::ClipboardClient::WriteContext* SimpleClipboardClient::CreateWriteContext() { return NULL; diff --git a/webkit/tools/test_shell/simple_clipboard_impl.h b/webkit/tools/test_shell/simple_clipboard_impl.h index 52571bf..98d8d5b 100644 --- a/webkit/tools/test_shell/simple_clipboard_impl.h +++ b/webkit/tools/test_shell/simple_clipboard_impl.h @@ -35,6 +35,8 @@ class SimpleClipboardClient : public webkit_glue::ClipboardClient { virtual void ReadCustomData(ui::Clipboard::Buffer buffer, const string16& type, string16* data) OVERRIDE; + virtual void ReadData(const ui::Clipboard::FormatType& format, + std::string* data) OVERRIDE; virtual WriteContext* CreateWriteContext() OVERRIDE; }; |