diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 19:26:40 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 19:26:40 +0000 |
commit | d1e33ca1b734b9a4a33ac702554e8be129a26f2a (patch) | |
tree | da7e529be1d7794f10b29e8c401a406b31073597 | |
parent | ab5918a6b6d3d19122e0b90fae1155938043fdf0 (diff) | |
download | chromium_src-d1e33ca1b734b9a4a33ac702554e8be129a26f2a.zip chromium_src-d1e33ca1b734b9a4a33ac702554e8be129a26f2a.tar.gz chromium_src-d1e33ca1b734b9a4a33ac702554e8be129a26f2a.tar.bz2 |
Move the FlashClipboard API into the Flash one.
This allows us to delete the separate proxy files for this.
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/10163012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133955 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 574 insertions, 690 deletions
diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 472d484..63132d0 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -88,8 +88,6 @@ 'proxy/ppb_file_ref_proxy.h', 'proxy/ppb_file_system_proxy.cc', 'proxy/ppb_file_system_proxy.h', - 'proxy/ppb_flash_clipboard_proxy.cc', - 'proxy/ppb_flash_clipboard_proxy.h', 'proxy/ppb_flash_file_proxy.cc', 'proxy/ppb_flash_file_proxy.h', 'proxy/ppb_flash_proxy.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 51f2383..d452d63 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -82,6 +82,8 @@ 'shared_impl/ppb_file_io_shared.h', 'shared_impl/ppb_file_ref_shared.cc', 'shared_impl/ppb_file_ref_shared.h', + 'shared_impl/ppb_flash_shared.cc', + 'shared_impl/ppb_flash_shared.h', 'shared_impl/ppb_graphics_3d_shared.cc', 'shared_impl/ppb_graphics_3d_shared.h', 'shared_impl/ppb_image_data_shared.cc', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index ed640da..4a92812 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -79,7 +79,6 @@ #include "ppapi/proxy/ppb_file_io_proxy.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_file_system_proxy.h" -#include "ppapi/proxy/ppb_flash_clipboard_proxy.h" #include "ppapi/proxy/ppb_flash_file_proxy.h" #include "ppapi/proxy/ppb_flash_menu_proxy.h" #include "ppapi/proxy/ppb_flash_message_loop_proxy.h" @@ -305,15 +304,6 @@ const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { #if !defined(OS_NACL) void InterfaceList::AddFlashInterfaces() { - AddProxy(API_ID_PPB_FLASH_CLIPBOARD, - &ProxyFactory<PPB_Flash_Clipboard_Proxy>); - AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_4_0, API_ID_PPB_FLASH_CLIPBOARD, - thunk::GetPPB_Flash_Clipboard_4_0_Thunk()); - AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_3_0, API_ID_PPB_FLASH_CLIPBOARD, - thunk::GetPPB_Flash_Clipboard_3_0_Thunk()); - AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY, API_ID_PPB_FLASH_CLIPBOARD, - thunk::GetPPB_Flash_Clipboard_3_0_Thunk()); - AddProxy(API_ID_PPB_FLASH_FILE_FILEREF, &ProxyFactory<PPB_Flash_File_FileRef_Proxy>); AddPPB(PPB_FLASH_FILE_FILEREF_INTERFACE, API_ID_PPB_FLASH_FILE_FILEREF, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index 565adf0..307574a 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1141,8 +1141,9 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBFlash_SetInstanceAlwaysOnTop, PP_Bool /* on_top */) // This has to be synchronous becuase the caller may want to composite on // top of the resulting text after the call is complete. -IPC_SYNC_MESSAGE_ROUTED1_1( +IPC_SYNC_MESSAGE_ROUTED2_1( PpapiHostMsg_PPBFlash_DrawGlyphs, + PP_Instance /* instance */, ppapi::proxy::PPBFlash_DrawGlyphs_Params /* params */, PP_Bool /* result */) IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBFlash_GetProxyForURL, @@ -1178,19 +1179,17 @@ IPC_SYNC_MESSAGE_ROUTED1_2(PpapiHostMsg_PPBFlash_FlashGetScreenSize, IPC_MESSAGE_ROUTED0(PpapiHostMsg_PPBFlash_UpdateActivity) IPC_SYNC_MESSAGE_ROUTED0_1(PpapiHostMsg_PPBFlash_GetDeviceID, std::string /* id */) - -// PPB_Flash_Clipboard. -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_IsClipboardFormatAvailable, PP_Instance /* instance */, int /* clipboard_type */, int /* format */, bool /* result */) -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlashClipboard_ReadData, +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBFlash_ReadClipboardData, PP_Instance /* instance */, int /* clipboard_type */, int /* format */, ppapi::proxy::SerializedVar /* result */) -IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFlashClipboard_WriteData, +IPC_MESSAGE_ROUTED4(PpapiHostMsg_PPBFlash_WriteClipboardData, PP_Instance /* instance */, int /* clipboard_type */, std::vector<int> /* formats */, diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc deleted file mode 100644 index 73b987e..0000000 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc +++ /dev/null @@ -1,189 +0,0 @@ -// 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/ppb_flash_clipboard_proxy.h" - -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/private/ppb_flash_clipboard.h" -#include "ppapi/proxy/plugin_dispatcher.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/serialized_var.h" -#include "ppapi/thunk/enter.h" - -using ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI; - -namespace ppapi { -namespace proxy { - -namespace { - -typedef thunk::EnterFunctionNoLock<PPB_Flash_Clipboard_FunctionAPI> - EnterFlashClipboardNoLock; - -bool IsValidClipboardType(PP_Flash_Clipboard_Type clipboard_type) { - return clipboard_type == PP_FLASH_CLIPBOARD_TYPE_STANDARD || - clipboard_type == PP_FLASH_CLIPBOARD_TYPE_SELECTION; -} - -bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { - // Purposely excludes |PP_FLASH_CLIPBOARD_FORMAT_INVALID|. - return format == PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT || - format == PP_FLASH_CLIPBOARD_FORMAT_HTML || - format == PP_FLASH_CLIPBOARD_FORMAT_RTF; -} - -} // namespace - -PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher) { -} - -PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() { -} - -PPB_Flash_Clipboard_FunctionAPI* -PPB_Flash_Clipboard_Proxy::AsPPB_Flash_Clipboard_FunctionAPI() { - return this; -} - -PP_Bool PPB_Flash_Clipboard_Proxy::IsFormatAvailable( - 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_PPBFlashClipboard_IsFormatAvailable( - API_ID_PPB_FLASH_CLIPBOARD, - instance, - static_cast<int>(clipboard_type), - static_cast<int>(format), - &result)); - return PP_FromBool(result); -} -PP_Var PPB_Flash_Clipboard_Proxy::ReadData( - 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_PPBFlashClipboard_ReadData( - API_ID_PPB_FLASH_CLIPBOARD, instance, - static_cast<int>(clipboard_type), static_cast<int>(format), &result)); - return result.Return(dispatcher()); -} - - -int32_t PPB_Flash_Clipboard_Proxy::WriteData( - 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; - - 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); - - std::vector<SerializedVar> data_items_vector; - SerializedVarSendInput::ConvertVector( - dispatcher(), - data_items, - data_item_count, - &data_items_vector); - - dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WriteData( - API_ID_PPB_FLASH_CLIPBOARD, - 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_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable, - OnMsgIsFormatAvailable) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_ReadData, - OnMsgReadData) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashClipboard_WriteData, - OnMsgWriteData) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( - PP_Instance instance, - int clipboard_type, - int format, - bool* result) { - EnterFlashClipboardNoLock enter(instance, true); - if (enter.succeeded()) { - *result = PP_ToBool(enter.functions()->IsFormatAvailable( - instance, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - static_cast<PP_Flash_Clipboard_Format>(format))); - } else { - *result = false; - } -} - -void PPB_Flash_Clipboard_Proxy::OnMsgReadData( - PP_Instance instance, - int clipboard_type, - int format, - SerializedVarReturnValue result) { - EnterFlashClipboardNoLock enter(instance, true); - if (enter.succeeded()) { - result.Return(dispatcher(), - enter.functions()->ReadData( - instance, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - static_cast<PP_Flash_Clipboard_Format>(format))); - } -} - -void PPB_Flash_Clipboard_Proxy::OnMsgWriteData( - PP_Instance instance, - int clipboard_type, - const std::vector<int>& formats, - SerializedVarVectorReceiveInput data_items) { - EnterFlashClipboardNoLock enter(instance, true); - 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()->WriteData( - 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. - } -} - -} // namespace proxy -} // namespace ppapi diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.h b/ppapi/proxy/ppb_flash_clipboard_proxy.h deleted file mode 100644 index 90cb07a..0000000 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.h +++ /dev/null @@ -1,69 +0,0 @@ -// 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_PPB_FLASH_CLIPBOARD_PROXY_H_ -#define PPAPI_PROXY_PPB_FLASH_CLIPBOARD_PROXY_H_ - -#include <vector> - -#include "ppapi/c/pp_instance.h" -#include "ppapi/proxy/interface_proxy.h" -#include "ppapi/thunk/ppb_flash_clipboard_api.h" - -namespace ppapi { -namespace proxy { - -class SerializedVarReceiveInput; -class SerializedVarReturnValue; -class SerializedVarVectorReceiveInput; - -class PPB_Flash_Clipboard_Proxy - : public InterfaceProxy, - public thunk::PPB_Flash_Clipboard_FunctionAPI { - public: - PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher); - virtual ~PPB_Flash_Clipboard_Proxy(); - - // FunctionGroupBase overrides. - thunk::PPB_Flash_Clipboard_FunctionAPI* AsPPB_Flash_Clipboard_FunctionAPI() - OVERRIDE; - - // PPB_Flash_Clipboard_FunctionAPI implementation. - virtual PP_Bool IsFormatAvailable(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual PP_Var ReadData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual int32_t WriteData(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; - - // InterfaceProxy implementation. - virtual bool OnMessageReceived(const IPC::Message& msg); - - static const ApiID kApiID = API_ID_PPB_FLASH_CLIPBOARD; - - private: - // Message handlers. - void OnMsgIsFormatAvailable(PP_Instance instance, - int clipboard_type, - int format, - bool* result); - void OnMsgReadData(PP_Instance instance, - int clipboard_type, - int format, - SerializedVarReturnValue result); - void OnMsgWriteData(PP_Instance instance, - int clipboard_type, - const std::vector<int>& formats, - SerializedVarVectorReceiveInput data_items); -}; - -} // namespace proxy -} // namespace ppapi - -#endif // PPAPI_PROXY_PPB_FLASH_CLIPBOARD_PROXY_H_ diff --git a/ppapi/proxy/ppb_flash_proxy.cc b/ppapi/proxy/ppb_flash_proxy.cc index f176bd0..c6fc525 100644 --- a/ppapi/proxy/ppb_flash_proxy.cc +++ b/ppapi/proxy/ppb_flash_proxy.cc @@ -30,15 +30,13 @@ #include "ppapi/thunk/ppb_url_request_info_api.h" #include "ppapi/thunk/resource_creation_api.h" +using ppapi::thunk::EnterInstanceNoLock; + namespace ppapi { namespace proxy { PPB_Flash_Proxy::PPB_Flash_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_impl_(NULL) { - if (!dispatcher->IsPlugin()) - ppb_flash_impl_ = static_cast<const PPB_Flash*>( - dispatcher->local_get_interface()(PPB_FLASH_INTERFACE)); + : InterfaceProxy(dispatcher) { } PPB_Flash_Proxy::~PPB_Flash_Proxy() { @@ -71,6 +69,12 @@ 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_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() // TODO(brettw) handle bad messages! @@ -124,7 +128,7 @@ PP_Bool PPB_Flash_Proxy::DrawGlyphs(PP_Instance instance, PP_Bool result = PP_FALSE; dispatcher()->Send(new PpapiHostMsg_PPBFlash_DrawGlyphs( - API_ID_PPB_FLASH, params, &result)); + API_ID_PPB_FLASH, instance, params, &result)); return result; } @@ -202,6 +206,68 @@ PP_Var PPB_Flash_Proxy::GetDeviceID(PP_Instance instance) { return StringVar::StringToPPVar(id); } +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; +} + PP_Bool PPB_Flash_Proxy::FlashIsFullscreen(PP_Instance instance) { InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> GetInstanceData(instance); @@ -228,13 +294,19 @@ PP_Bool PPB_Flash_Proxy::FlashGetScreenSize(PP_Instance instance, void PPB_Flash_Proxy::OnHostMsgSetInstanceAlwaysOnTop(PP_Instance instance, PP_Bool on_top) { - ppb_flash_impl_->SetInstanceAlwaysOnTop(instance, on_top); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) + enter.functions()->GetFlashAPI()->SetInstanceAlwaysOnTop(instance, on_top); } void PPB_Flash_Proxy::OnHostMsgDrawGlyphs( + PP_Instance instance, const PPBFlash_DrawGlyphs_Params& params, PP_Bool* result) { *result = PP_FALSE; + EnterInstanceNoLock enter(instance); + if (enter.failed()) + return; PP_FontDescription_Dev font_desc; params.font_desc.SetToPPFontDescription(dispatcher(), &font_desc, false); @@ -243,7 +315,7 @@ void PPB_Flash_Proxy::OnHostMsgDrawGlyphs( params.glyph_indices.empty()) return; - *result = ppb_flash_impl_->DrawGlyphs( + *result = enter.functions()->GetFlashAPI()->DrawGlyphs( 0, // Unused instance param. params.image_data.host_resource(), &font_desc, params.color, ¶ms.position, ¶ms.clip, @@ -257,8 +329,14 @@ void PPB_Flash_Proxy::OnHostMsgDrawGlyphs( void PPB_Flash_Proxy::OnHostMsgGetProxyForURL(PP_Instance instance, const std::string& url, SerializedVarReturnValue result) { - result.Return(dispatcher(), ppb_flash_impl_->GetProxyForURL( - instance, url.c_str())); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) { + result.Return(dispatcher(), + enter.functions()->GetFlashAPI()->GetProxyForURL( + instance, url.c_str())); + } else { + result.Return(dispatcher(), PP_MakeUndefined()); + } } void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance, @@ -266,6 +344,11 @@ void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance, const std::string& target, PP_Bool from_user_action, int32_t* result) { + EnterInstanceNoLock enter_instance(instance); + if (enter_instance.failed()) { + *result = PP_ERROR_BADARGUMENT; + return; + } DCHECK(!dispatcher()->IsPlugin()); // Validate the PP_Instance since we'll be constructing resources on its @@ -294,51 +377,127 @@ void PPB_Flash_Proxy::OnHostMsgNavigate(PP_Instance instance, ScopedPPResource::PassRef(), enter.functions()->CreateURLRequestInfo(instance, data)); - *result = ppb_flash_impl_->Navigate(request_resource, - target.c_str(), - from_user_action); + *result = enter_instance.functions()->GetFlashAPI()->Navigate( + instance, request_resource, target.c_str(), from_user_action); } void PPB_Flash_Proxy::OnHostMsgRunMessageLoop(PP_Instance instance) { - ppb_flash_impl_->RunMessageLoop(instance); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) + enter.functions()->GetFlashAPI()->RunMessageLoop(instance); } void PPB_Flash_Proxy::OnHostMsgQuitMessageLoop(PP_Instance instance) { - ppb_flash_impl_->QuitMessageLoop(instance); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) + enter.functions()->GetFlashAPI()->QuitMessageLoop(instance); } void PPB_Flash_Proxy::OnHostMsgGetLocalTimeZoneOffset(PP_Instance instance, PP_Time t, double* result) { - *result = ppb_flash_impl_->GetLocalTimeZoneOffset(instance, t); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) { + *result = enter.functions()->GetFlashAPI()->GetLocalTimeZoneOffset( + instance, t); + } else { + *result = 0.0; + } } void PPB_Flash_Proxy::OnHostMsgIsRectTopmost(PP_Instance instance, PP_Rect rect, PP_Bool* result) { - *result = ppb_flash_impl_->IsRectTopmost(instance, &rect); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) + *result = enter.functions()->GetFlashAPI()->IsRectTopmost(instance, &rect); + else + *result = PP_FALSE; } void PPB_Flash_Proxy::OnHostMsgFlashSetFullscreen(PP_Instance instance, PP_Bool fullscreen, PP_Bool* result) { - thunk::EnterFunctionNoLock<thunk::PPB_Instance_FunctionAPI> enter( - instance, false); - if (enter.failed()) - return; - *result = enter.functions()->GetFlashAPI()->FlashSetFullscreen( - instance, fullscreen); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) { + *result = enter.functions()->GetFlashAPI()->FlashSetFullscreen( + instance, fullscreen); + } else { + *result = PP_FALSE; + } } void PPB_Flash_Proxy::OnHostMsgFlashGetScreenSize(PP_Instance instance, PP_Bool* result, PP_Size* size) { - thunk::EnterFunctionNoLock<thunk::PPB_Instance_FunctionAPI> enter( - instance, false); - if (enter.failed()) - return; - *result = enter.functions()->GetFlashAPI()->FlashGetScreenSize( - instance, size); + EnterInstanceNoLock enter(instance); + if (enter.succeeded()) { + *result = enter.functions()->GetFlashAPI()->FlashGetScreenSize( + instance, size); + } else { + size->width = 0; + size->height = 0; + } +} + +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. + } } } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_proxy.h b/ppapi/proxy/ppb_flash_proxy.h index 1c051e5..5541697 100644 --- a/ppapi/proxy/ppb_flash_proxy.h +++ b/ppapi/proxy/ppb_flash_proxy.h @@ -16,8 +16,9 @@ #include "ppapi/c/pp_time.h" #include "ppapi/c/private/ppb_flash.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/serialized_var.h" #include "ppapi/shared_impl/host_resource.h" -#include "ppapi/thunk/ppb_flash_api.h" +#include "ppapi/shared_impl/ppb_flash_shared.h" namespace ppapi { @@ -28,8 +29,7 @@ namespace proxy { struct PPBFlash_DrawGlyphs_Params; class SerializedVarReturnValue; -class PPB_Flash_Proxy : public InterfaceProxy, - public thunk::PPB_Flash_API { +class PPB_Flash_Proxy : public InterfaceProxy, public PPB_Flash_Shared { public: explicit PPB_Flash_Proxy(Dispatcher* dispatcher); virtual ~PPB_Flash_Proxy(); @@ -65,6 +65,18 @@ class PPB_Flash_Proxy : public InterfaceProxy, virtual int32_t InvokePrinting(PP_Instance instance) OVERRIDE; virtual void UpdateActivity(PP_Instance instance) OVERRIDE; virtual PP_Var GetDeviceID(PP_Instance instance) 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 PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE; virtual PP_Bool FlashSetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; @@ -77,7 +89,8 @@ class PPB_Flash_Proxy : public InterfaceProxy, // Message handlers. void OnHostMsgSetInstanceAlwaysOnTop(PP_Instance instance, PP_Bool on_top); - void OnHostMsgDrawGlyphs(const PPBFlash_DrawGlyphs_Params& params, + void OnHostMsgDrawGlyphs(PP_Instance instance, + const PPBFlash_DrawGlyphs_Params& params, PP_Bool* result); void OnHostMsgGetProxyForURL(PP_Instance instance, const std::string& url, @@ -100,11 +113,18 @@ class PPB_Flash_Proxy : public InterfaceProxy, void OnHostMsgFlashGetScreenSize(PP_Instance instance, PP_Bool* result, PP_Size* size); - - // When this proxy is in the host side, this value caches the interface - // pointer so we don't have to retrieve it from the dispatcher each time. - // In the plugin, this value is always NULL. - const PPB_Flash* ppb_flash_impl_; + 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); DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Proxy); }; diff --git a/ppapi/shared_impl/api_id.h b/ppapi/shared_impl/api_id.h index 8d02e59..be4be56 100644 --- a/ppapi/shared_impl/api_id.h +++ b/ppapi/shared_impl/api_id.h @@ -25,7 +25,6 @@ enum ApiID { API_ID_PPB_FILE_REF, API_ID_PPB_FILE_SYSTEM, API_ID_PPB_FLASH, - API_ID_PPB_FLASH_CLIPBOARD, API_ID_PPB_FLASH_FILE_FILEREF, API_ID_PPB_FLASH_FILE_MODULELOCAL, API_ID_PPB_FLASH_MENU, diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index bbf149a..e09b893 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -12,7 +12,6 @@ #define FOR_ALL_PPAPI_FUNCTION_APIS(F) \ F(PPB_CharSet_FunctionAPI) \ F(PPB_CursorControl_FunctionAPI) \ - F(PPB_Flash_Clipboard_FunctionAPI) \ F(PPB_Font_FunctionAPI) \ F(PPB_Fullscreen_FunctionAPI) \ F(PPB_Instance_FunctionAPI) \ diff --git a/ppapi/shared_impl/ppb_flash_shared.cc b/ppapi/shared_impl/ppb_flash_shared.cc new file mode 100644 index 0000000..c0504bf --- /dev/null +++ b/ppapi/shared_impl/ppb_flash_shared.cc @@ -0,0 +1,31 @@ +// 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/ppb_flash_shared.h" + +namespace ppapi { + +PPB_Flash_Shared::PPB_Flash_Shared() { +} + +PPB_Flash_Shared::~PPB_Flash_Shared() { +} + +// 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 new file mode 100644 index 0000000..b7de3bd --- /dev/null +++ b/ppapi/shared_impl/ppb_flash_shared.h @@ -0,0 +1,30 @@ +// 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_PPB_FLASH_SHARED_H_ +#define PPAPI_SHARED_IMPL_PPB_FLASH_SHARED_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" +#include "ppapi/thunk/ppb_flash_api.h" + +namespace ppapi { + +class PPAPI_SHARED_EXPORT PPB_Flash_Shared : public thunk::PPB_Flash_API { + public: + PPB_Flash_Shared(); + virtual ~PPB_Flash_Shared(); + + 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); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_PPB_FLASH_SHARED_H_ diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc index d8d4291..6b2208a 100644 --- a/ppapi/thunk/enter.cc +++ b/ppapi/thunk/enter.cc @@ -163,5 +163,12 @@ EnterInstance::EnterInstance(PP_Instance instance, EnterInstance::~EnterInstance() { } +EnterInstanceNoLock::EnterInstanceNoLock(PP_Instance instance) + : EnterFunctionNoLock<PPB_Instance_FunctionAPI>(instance, true) { +} + +EnterInstanceNoLock::~EnterInstanceNoLock() { +} + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index 4172ce0..5c69acf 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -262,6 +262,13 @@ class PPAPI_THUNK_EXPORT EnterInstance ~EnterInstance(); }; +class PPAPI_THUNK_EXPORT EnterInstanceNoLock + : public EnterFunctionNoLock<PPB_Instance_FunctionAPI> { + public: + EnterInstanceNoLock(PP_Instance instance); + ~EnterInstanceNoLock(); +}; + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/interfaces_ppb_private_flash.h b/ppapi/thunk/interfaces_ppb_private_flash.h index 6d9fa82..1a96fbc 100644 --- a/ppapi/thunk/interfaces_ppb_private_flash.h +++ b/ppapi/thunk/interfaces_ppb_private_flash.h @@ -22,4 +22,14 @@ PROXIED_IFACE(PPB_Flash, PPB_FLASH_INTERFACE_12_2, PPB_Flash_12_2) +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) + #include "ppapi/thunk/interfaces_postamble.h" diff --git a/ppapi/thunk/ppb_flash_api.h b/ppapi/thunk/ppb_flash_api.h index eacc9e8..b54bba3 100644 --- a/ppapi/thunk/ppb_flash_api.h +++ b/ppapi/thunk/ppb_flash_api.h @@ -6,6 +6,7 @@ #define PPAPI_THUNK_PPB_FLASH_API_H_ #include "ppapi/c/private/ppb_flash.h" +#include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/thunk/ppapi_thunk_export.h" namespace ppapi { @@ -42,6 +43,20 @@ class PPAPI_THUNK_EXPORT PPB_Flash_API { virtual void UpdateActivity(PP_Instance instance) = 0; virtual PP_Var GetDeviceID(PP_Instance instance) = 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; + // FlashFullscreen. virtual PP_Bool FlashIsFullscreen(PP_Instance instance) = 0; virtual PP_Bool FlashSetFullscreen(PP_Instance instance, diff --git a/ppapi/thunk/ppb_flash_clipboard_api.h b/ppapi/thunk/ppb_flash_clipboard_api.h deleted file mode 100644 index 02155e1..0000000 --- a/ppapi/thunk/ppb_flash_clipboard_api.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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" -#include "ppapi/shared_impl/api_id.h" - -namespace ppapi { -namespace thunk { - -class PPB_Flash_Clipboard_FunctionAPI { - public: - virtual ~PPB_Flash_Clipboard_FunctionAPI() {} - - virtual PP_Bool IsFormatAvailable(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) = 0; - virtual PP_Var ReadData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) = 0; - virtual int32_t WriteData(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; - - static const ApiID kApiID = API_ID_PPB_FLASH_CLIPBOARD; -}; - -} // 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 efc7307..084b937 100644 --- a/ppapi/thunk/ppb_flash_clipboard_thunk.cc +++ b/ppapi/thunk/ppb_flash_clipboard_thunk.cc @@ -6,31 +6,31 @@ #include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/thunk.h" -#include "ppapi/thunk/ppb_flash_clipboard_api.h" +#include "ppapi/thunk/ppb_flash_api.h" namespace ppapi { namespace thunk { namespace { -typedef EnterFunction<PPB_Flash_Clipboard_FunctionAPI> EnterFlashClipboard; - PP_Bool IsFormatAvailable(PP_Instance instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { - EnterFlashClipboard enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_FALSE; - return enter.functions()->IsFormatAvailable(instance, clipboard_type, format); + return enter.functions()->GetFlashAPI()->IsClipboardFormatAvailable( + instance, clipboard_type, format); } PP_Var ReadData(PP_Instance instance, PP_Flash_Clipboard_Type clipboard_type, PP_Flash_Clipboard_Format format) { - EnterFlashClipboard enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return PP_MakeUndefined(); - return enter.functions()->ReadData(instance, clipboard_type, format); + return enter.functions()->GetFlashAPI()->ReadClipboardData( + instance, clipboard_type, format); } int32_t WriteData(PP_Instance instance, @@ -38,14 +38,11 @@ int32_t WriteData(PP_Instance instance, uint32_t data_item_count, const PP_Flash_Clipboard_Format formats[], const PP_Var data_items[]) { - EnterFlashClipboard enter(instance, true); + EnterInstance enter(instance); if (enter.failed()) return enter.retval(); - return enter.functions()->WriteData(instance, - clipboard_type, - data_item_count, - formats, - data_items); + return enter.functions()->GetFlashAPI()->WriteClipboardData( + instance, clipboard_type, data_item_count, formats, data_items); } PP_Var ReadPlainText(PP_Instance instance, diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index a3d6ed5..424476e 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -271,8 +271,6 @@ '../plugins/ppapi/ppb_file_ref_impl.h', '../plugins/ppapi/ppb_file_system_impl.cc', '../plugins/ppapi/ppb_file_system_impl.h', - '../plugins/ppapi/ppb_flash_clipboard_impl.cc', - '../plugins/ppapi/ppb_flash_clipboard_impl.h', '../plugins/ppapi/ppb_flash_file_impl.cc', '../plugins/ppapi/ppb_flash_file_impl.h', '../plugins/ppapi/ppb_flash_impl.cc', diff --git a/webkit/plugins/ppapi/host_globals.cc b/webkit/plugins/ppapi/host_globals.cc index e7ebc4d..1030da9 100644 --- a/webkit/plugins/ppapi/host_globals.cc +++ b/webkit/plugins/ppapi/host_globals.cc @@ -22,7 +22,6 @@ #include "webkit/plugins/plugin_switches.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" -#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" #include "webkit/plugins/ppapi/ppb_text_input_impl.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" @@ -148,9 +147,6 @@ HostGlobals::~HostGlobals() { case ::ppapi::API_ID_RESOURCE_CREATION: proxy.reset(new ResourceCreationImpl(instance)); break; - case ::ppapi::API_ID_PPB_FLASH_CLIPBOARD: - proxy.reset(new PPB_Flash_Clipboard_Impl(instance)); - break; default: NOTREACHED(); } diff --git a/webkit/plugins/ppapi/plugin_module.cc b/webkit/plugins/ppapi/plugin_module.cc index ff8ecc34..f68b79a 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -109,7 +109,6 @@ #include "webkit/plugins/ppapi/ppapi_interface_factory.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" -#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" #include "webkit/plugins/ppapi/ppb_flash_file_impl.h" #include "webkit/plugins/ppapi/ppb_flash_impl.h" #include "webkit/plugins/ppapi/ppb_flash_menu_impl.h" @@ -311,12 +310,6 @@ const void* GetInterface(const char* name) { return ::ppapi::thunk::GetPPB_BufferTrusted_0_1_Thunk(); if (strcmp(name, PPB_CORE_INTERFACE_1_0) == 0) return &core_interface; - if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE_4_0) == 0) - return ::ppapi::thunk::GetPPB_Flash_Clipboard_4_0_Thunk(); - if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE_3_0) == 0) - return ::ppapi::thunk::GetPPB_Flash_Clipboard_3_0_Thunk(); - if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE_3_LEGACY) == 0) - return ::ppapi::thunk::GetPPB_Flash_Clipboard_3_0_Thunk(); if (strcmp(name, PPB_FLASH_FILE_FILEREF_INTERFACE) == 0) return PPB_Flash_File_FileRef_Impl::GetInterface(); if (strcmp(name, PPB_FLASH_FILE_MODULELOCAL_INTERFACE) == 0) diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc deleted file mode 100644 index fdebb2dd..0000000 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ /dev/null @@ -1,249 +0,0 @@ -// 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 "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" - -#include <algorithm> -#include <string> - -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/utf_string_conversions.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/private/ppb_flash_clipboard.h" -#include "ppapi/shared_impl/ppapi_globals.h" -#include "ppapi/shared_impl/var.h" -#include "ppapi/shared_impl/var_tracker.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/ppapi_plugin_instance.h" - -using ppapi::StringVar; - -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_Clipboard_Impl::PPB_Flash_Clipboard_Impl(PluginInstance* instance) - : instance_(instance), - client_() { -} - -bool PPB_Flash_Clipboard_Impl::Init() { - // Initialize the ClipboardClient for writing to the clipboard. - if (!client_.get()) { - if (!instance_) - return false; - PluginDelegate* plugin_delegate = instance_->delegate(); - if (!plugin_delegate) - return false; - client_.reset(plugin_delegate->CreateClipboardClient()); - } - return true; -} - -PPB_Flash_Clipboard_Impl::~PPB_Flash_Clipboard_Impl() { -} - -::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI* -PPB_Flash_Clipboard_Impl::AsPPB_Flash_Clipboard_FunctionAPI() { - return this; -} - -PP_Bool PPB_Flash_Clipboard_Impl::IsFormatAvailable( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!Init()) - 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 = client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextFormatType(), buffer_type); - bool plainw = client_->IsFormatAvailable( - ui::Clipboard::GetPlainTextWFormatType(), buffer_type); - return BoolToPPBool(plain || plainw); - } - case PP_FLASH_CLIPBOARD_FORMAT_HTML: - return BoolToPPBool(client_->IsFormatAvailable( - ui::Clipboard::GetHtmlFormatType(), buffer_type)); - case PP_FLASH_CLIPBOARD_FORMAT_RTF: - return BoolToPPBool(client_->IsFormatAvailable( - ui::Clipboard::GetRtfFormatType(), buffer_type)); - case PP_FLASH_CLIPBOARD_FORMAT_INVALID: - break; - } - - return PP_FALSE; -} - -PP_Var PPB_Flash_Clipboard_Impl::ReadData( - PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - if (!Init()) - return PP_MakeUndefined(); - - if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { - NOTIMPLEMENTED(); - return PP_MakeUndefined(); - } - - if (!IsFormatAvailable(instance, clipboard_type, format)) { - return PP_MakeNull(); - } - - ui::Clipboard::Buffer buffer_type = ConvertClipboardType(clipboard_type); - - switch (format) { - case PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT: { - if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextWFormatType(), - buffer_type)) { - string16 text; - client_->ReadText(buffer_type, &text); - if (!text.empty()) - return StringVar::StringToPPVar(UTF16ToUTF8(text)); - } - - if (client_->IsFormatAvailable(ui::Clipboard::GetPlainTextFormatType(), - buffer_type)) { - std::string text; - client_->ReadAsciiText(buffer_type, &text); - if (!text.empty()) - return StringVar::StringToPPVar(text); - } - - return PP_MakeNull(); - } - case PP_FLASH_CLIPBOARD_FORMAT_HTML: { - string16 html_stdstr; - GURL gurl; - uint32 fragment_start; - uint32 fragment_end; - client_->ReadHTML(buffer_type, - &html_stdstr, - &gurl, - &fragment_start, - &fragment_end); - return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); - } - case PP_FLASH_CLIPBOARD_FORMAT_RTF: { - std::string result; - 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_Clipboard_Impl::WriteDataItem( - 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; -} - -int32_t PPB_Flash_Clipboard_Impl::WriteData( - 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 (!Init()) - return PP_ERROR_FAILED; - - if (clipboard_type != PP_FLASH_CLIPBOARD_TYPE_STANDARD) { - NOTIMPLEMENTED(); - return PP_ERROR_FAILED; - } - - if (data_item_count == 0) { - client_->Clear(ConvertClipboardType(clipboard_type)); - return PP_OK; - } - ScopedClipboardWriterGlue scw(client_.get()); - for (uint32_t i = 0; i < data_item_count; ++i) { - int32_t res = WriteDataItem(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; -} - -} // namespace ppapi -} // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h deleted file mode 100644 index da2f785..0000000 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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 WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_ -#define WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ppapi/shared_impl/function_group_base.h" -#include "ppapi/thunk/ppb_flash_clipboard_api.h" - -namespace webkit_glue { class ClipboardClient; } -class ScopedClipboardWriterGlue; - -namespace webkit { -namespace ppapi { - -class PluginInstance; - -class PPB_Flash_Clipboard_Impl - : public ::ppapi::FunctionGroupBase, - public ::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI { - public: - PPB_Flash_Clipboard_Impl(PluginInstance* instance); - virtual ~PPB_Flash_Clipboard_Impl(); - - // FunctionGroupBase overrides. - virtual ::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI* - AsPPB_Flash_Clipboard_FunctionAPI() OVERRIDE; - - // PPB_Flash_Clipboard_FunctionAPI implementation. - virtual PP_Bool IsFormatAvailable(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) OVERRIDE; - virtual PP_Var ReadData(PP_Instance instance, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format); - virtual int32_t WriteData(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[]); - - private: - bool Init(); - int32_t WriteDataItem(const PP_Flash_Clipboard_Format format, - const PP_Var& data, - ScopedClipboardWriterGlue* scw); - - PluginInstance* instance_; - scoped_ptr<webkit_glue::ClipboardClient> client_; - - DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Clipboard_Impl); -}; - -} // namespace ppapi -} // namespace webkit - -#endif // WEBKIT_PLUGINS_PPAPI_PPB_FLASH_CLIPBOARD_IMPL_H_ diff --git a/webkit/plugins/ppapi/ppb_flash_impl.cc b/webkit/plugins/ppapi/ppb_flash_impl.cc index c1e453f..16780ca 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_impl.cc @@ -9,6 +9,7 @@ #include "base/message_loop.h" #include "base/time.h" +#include "base/utf_string_conversions.h" #include "googleurl/src/gurl.h" #include "ppapi/c/dev/ppb_font_dev.h" #include "ppapi/c/private/ppb_flash.h" @@ -24,6 +25,8 @@ #include "third_party/skia/include/core/SkTemplates.h" #include "third_party/skia/include/core/SkTypeface.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" @@ -42,6 +45,24 @@ 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) { } @@ -218,6 +239,133 @@ PP_Var PPB_Flash_Impl::GetDeviceID(PP_Instance pp_instance) { return PP_MakeUndefined(); } +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_stdstr; + GURL gurl; + uint32 fragment_start; + uint32 fragment_end; + clipboard_client_->ReadHTML(buffer_type, + &html_stdstr, + &gurl, + &fragment_start, + &fragment_end); + return StringVar::StringToPPVar(UTF16ToUTF8(html_stdstr)); + } + 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; +} + PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { return PP_FromBool(instance_->flash_fullscreen()); } @@ -233,5 +381,65 @@ 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 60e3e5f..911f5ae 100644 --- a/webkit/plugins/ppapi/ppb_flash_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_impl.h @@ -7,15 +7,22 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "build/build_config.h" -#include "ppapi/thunk/ppb_flash_api.h" +#include "ppapi/shared_impl/ppb_flash_shared.h" + +class ScopedClipboardWriterGlue; + +namespace webkit_glue { +class ClipboardClient; +} namespace webkit { namespace ppapi { class PluginInstance; -class PPB_Flash_Impl : public ::ppapi::thunk::PPB_Flash_API { +class PPB_Flash_Impl : public ::ppapi::PPB_Flash_Shared { public: explicit PPB_Flash_Impl(PluginInstance* instance); virtual ~PPB_Flash_Impl(); @@ -48,6 +55,18 @@ class PPB_Flash_Impl : public ::ppapi::thunk::PPB_Flash_API { virtual int32_t InvokePrinting(PP_Instance instance) OVERRIDE; virtual void UpdateActivity(PP_Instance instance) OVERRIDE; virtual PP_Var GetDeviceID(PP_Instance instance) 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 PP_Bool FlashIsFullscreen(PP_Instance instance) OVERRIDE; virtual PP_Bool FlashSetFullscreen(PP_Instance instance, PP_Bool fullscreen) OVERRIDE; @@ -55,8 +74,19 @@ class PPB_Flash_Impl : public ::ppapi::thunk::PPB_Flash_API { 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); }; |