diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 16:13:22 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-22 16:13:22 +0000 |
commit | fe833c999534725ddd1c01291023ab8ac20b796a (patch) | |
tree | 9d73f21c8b6a71b17fea72efc3e2d4c74f73270f | |
parent | 56c802fa1fd078b7f43338a7be9d016ccf582750 (diff) | |
download | chromium_src-fe833c999534725ddd1c01291023ab8ac20b796a.zip chromium_src-fe833c999534725ddd1c01291023ab8ac20b796a.tar.gz chromium_src-fe833c999534725ddd1c01291023ab8ac20b796a.tar.bz2 |
Convert the flash clipboard API to thunk system.
This adds a new clipboard API and thunks for it, and converts the existing
proxy to use the new system. This adds a UI test for this feature.
BUG=
TEST=included
Review URL: http://codereview.chromium.org/8365017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106857 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/ui/ppapi_uitest.cc | 3 | ||||
-rw-r--r-- | ppapi/ppapi_shared.gypi | 2 | ||||
-rw-r--r-- | ppapi/ppapi_tests.gypi | 12 | ||||
-rw-r--r-- | ppapi/proxy/interface_list.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_clipboard_proxy.cc | 138 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_clipboard_proxy.h | 32 | ||||
-rw-r--r-- | ppapi/shared_impl/function_group_base.h | 1 | ||||
-rw-r--r-- | ppapi/tests/test_flash_clipboard.cc | 49 | ||||
-rw-r--r-- | ppapi/tests/test_flash_clipboard.h | 28 | ||||
-rw-r--r-- | ppapi/tests/test_flash_fullscreen.h | 6 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_clipboard_api.h | 33 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_clipboard_thunk.cc | 57 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/host_globals.cc | 4 | ||||
-rw-r--r-- | webkit/plugins/ppapi/plugin_module.cc | 2 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc | 58 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_flash_clipboard_impl.h | 33 |
17 files changed, 335 insertions, 127 deletions
diff --git a/chrome/test/ui/ppapi_uitest.cc b/chrome/test/ui/ppapi_uitest.cc index bb46b44..e1af01c 100644 --- a/chrome/test/ui/ppapi_uitest.cc +++ b/chrome/test/ui/ppapi_uitest.cc @@ -274,6 +274,9 @@ TEST_F(OutOfProcessPPAPITest, DISABLED_Fullscreen) { } #endif +TEST_PPAPI_IN_PROCESS(FlashClipboard) +TEST_PPAPI_OUT_OF_PROCESS(FlashClipboard) + #if defined(OS_POSIX) #define MAYBE_DirectoryReader FLAKY_DirectoryReader #else diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 1b5572e..ad855d9 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -121,6 +121,8 @@ 'thunk/ppb_file_system_api.h', 'thunk/ppb_file_system_thunk.cc', 'thunk/ppb_find_thunk.cc', + 'thunk/ppb_flash_clipboard_api.h', + 'thunk/ppb_flash_clipboard_thunk.cc', 'thunk/ppb_flash_fullscreen_thunk.cc', 'thunk/ppb_flash_menu_api.h', 'thunk/ppb_flash_menu_thunk.cc', diff --git a/ppapi/ppapi_tests.gypi b/ppapi/ppapi_tests.gypi index 625a06d..352cfd1 100644 --- a/ppapi/ppapi_tests.gypi +++ b/ppapi/ppapi_tests.gypi @@ -85,23 +85,25 @@ 'tests/test_char_set.h', 'tests/test_core.cc', 'tests/test_core.h', + 'tests/test_cpp_includes.cc', 'tests/test_crypto.cc', 'tests/test_crypto.h', - 'tests/test_cpp_includes.cc', 'tests/test_cursor_control.cc', 'tests/test_cursor_control.h', 'tests/test_directory_reader.cc', 'tests/test_directory_reader.h', - 'tests/test_fullscreen.cc', - 'tests/test_fullscreen.h', - 'tests/test_flash_fullscreen.cc', - 'tests/test_flash_fullscreen.h', 'tests/test_file_io.cc', 'tests/test_file_io.h', 'tests/test_file_ref.cc', 'tests/test_file_ref.h', 'tests/test_file_system.cc', 'tests/test_file_system.h', + 'tests/test_flash_clipboard.cc', + 'tests/test_flash_clipboard.h', + 'tests/test_flash_fullscreen.cc', + 'tests/test_flash_fullscreen.h', + 'tests/test_fullscreen.cc', + 'tests/test_fullscreen.h', 'tests/test_graphics_2d.cc', 'tests/test_graphics_2d.h', 'tests/test_graphics_3d.cc', diff --git a/ppapi/proxy/interface_list.cc b/ppapi/proxy/interface_list.cc index 5f037dd..a11e778 100644 --- a/ppapi/proxy/interface_list.cc +++ b/ppapi/proxy/interface_list.cc @@ -240,7 +240,7 @@ void InterfaceList::AddFlashInterfaces() { AddProxy(API_ID_PPB_FLASH_CLIPBOARD, &ProxyFactory<PPB_Flash_Clipboard_Proxy>); AddPPB(PPB_FLASH_CLIPBOARD_INTERFACE, API_ID_PPB_FLASH_CLIPBOARD, - PPB_Flash_Clipboard_Proxy::GetInterface()); + thunk::GetPPB_Flash_Clipboard_Thunk()); AddProxy(API_ID_PPB_FLASH_FILE_MODULELOCAL, &ProxyFactory<PPB_Flash_File_ModuleLocal_Proxy>); diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.cc b/ppapi/proxy/ppb_flash_clipboard_proxy.cc index e37aff2..b35182b 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.cc +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.cc @@ -9,12 +9,18 @@ #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 || @@ -27,90 +33,66 @@ bool IsValidClipboardFormat(PP_Flash_Clipboard_Format format) { format == PP_FLASH_CLIPBOARD_FORMAT_HTML; } -PP_Bool IsFormatAvailable(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_FALSE; +} // 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( + dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_IsFormatAvailable( API_ID_PPB_FLASH_CLIPBOARD, - instance_id, + instance, static_cast<int>(clipboard_type), static_cast<int>(format), &result)); return PP_FromBool(result); } -PP_Var ReadPlainText(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_MakeUndefined(); - +PP_Var PPB_Flash_Clipboard_Proxy::ReadPlainText( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) { if (!IsValidClipboardType(clipboard_type)) return PP_MakeUndefined(); ReceiveSerializedVarReturnValue result; - dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( - API_ID_PPB_FLASH_CLIPBOARD, instance_id, + dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_ReadPlainText( + API_ID_PPB_FLASH_CLIPBOARD, instance, static_cast<int>(clipboard_type), &result)); - return result.Return(dispatcher); + return result.Return(dispatcher()); } -int32_t WritePlainText(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type, - PP_Var text) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return PP_ERROR_BADARGUMENT; - +int32_t PPB_Flash_Clipboard_Proxy::WritePlainText( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + const PP_Var& text) { if (!IsValidClipboardType(clipboard_type)) return PP_ERROR_BADARGUMENT; - dispatcher->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( + dispatcher()->Send(new PpapiHostMsg_PPBFlashClipboard_WritePlainText( API_ID_PPB_FLASH_CLIPBOARD, - instance_id, + instance, static_cast<int>(clipboard_type), - SerializedVarSendInput(dispatcher, text))); + SerializedVarSendInput(dispatcher(), text))); // Assume success, since it allows us to avoid a sync IPC. return PP_OK; } -const PPB_Flash_Clipboard flash_clipboard_interface = { - &IsFormatAvailable, - &ReadPlainText, - &WritePlainText -}; - -InterfaceProxy* CreateFlashClipboardProxy(Dispatcher* dispatcher) { - return new PPB_Flash_Clipboard_Proxy(dispatcher); -} - -} // namespace - -PPB_Flash_Clipboard_Proxy::PPB_Flash_Clipboard_Proxy(Dispatcher* dispatcher) - : InterfaceProxy(dispatcher), - ppb_flash_clipboard_impl_(NULL) { - if (!dispatcher->IsPlugin()) { - ppb_flash_clipboard_impl_ = static_cast<const PPB_Flash_Clipboard*>( - dispatcher->local_get_interface()(PPB_FLASH_CLIPBOARD_INTERFACE)); - } -} - -PPB_Flash_Clipboard_Proxy::~PPB_Flash_Clipboard_Proxy() { -} - -// static -const PPB_Flash_Clipboard* PPB_Flash_Clipboard_Proxy::GetInterface() { - return &flash_clipboard_interface; -} - bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Clipboard_Proxy, msg) @@ -126,35 +108,47 @@ bool PPB_Flash_Clipboard_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPB_Flash_Clipboard_Proxy::OnMsgIsFormatAvailable( - PP_Instance instance_id, + PP_Instance instance, int clipboard_type, int format, bool* result) { - *result = PP_ToBool(ppb_flash_clipboard_impl_->IsFormatAvailable( - instance_id, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - static_cast<PP_Flash_Clipboard_Format>(format))); + 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::OnMsgReadPlainText( - PP_Instance instance_id, + PP_Instance instance, int clipboard_type, SerializedVarReturnValue result) { - result.Return(dispatcher(), - ppb_flash_clipboard_impl_->ReadPlainText( - instance_id, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); + EnterFlashClipboardNoLock enter(instance, true); + if (enter.succeeded()) { + result.Return(dispatcher(), + enter.functions()->ReadPlainText( + instance, + static_cast<PP_Flash_Clipboard_Type>(clipboard_type))); + } } void PPB_Flash_Clipboard_Proxy::OnMsgWritePlainText( - PP_Instance instance_id, + PP_Instance instance, int clipboard_type, SerializedVarReceiveInput text) { - int32_t result = ppb_flash_clipboard_impl_->WritePlainText( - instance_id, - static_cast<PP_Flash_Clipboard_Type>(clipboard_type), - text.Get(dispatcher())); - LOG_IF(WARNING, result != PP_OK) << "Write to clipboard failed unexpectedly."; + EnterFlashClipboardNoLock enter(instance, true); + if (enter.succeeded()) { + int32_t result = enter.functions()->WritePlainText( + instance, + static_cast<PP_Flash_Clipboard_Type>(clipboard_type), + text.Get(dispatcher())); + DLOG_IF(WARNING, result != PP_OK) + << "Write to clipboard failed unexpectedly."; + } } } // namespace proxy diff --git a/ppapi/proxy/ppb_flash_clipboard_proxy.h b/ppapi/proxy/ppb_flash_clipboard_proxy.h index 79505fe..c337f82 100644 --- a/ppapi/proxy/ppb_flash_clipboard_proxy.h +++ b/ppapi/proxy/ppb_flash_clipboard_proxy.h @@ -7,6 +7,7 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/interface_proxy.h" +#include "ppapi/thunk/ppb_flash_clipboard_api.h" struct PPB_Flash_Clipboard; @@ -16,33 +17,44 @@ namespace proxy { class SerializedVarReceiveInput; class SerializedVarReturnValue; -class PPB_Flash_Clipboard_Proxy : public InterfaceProxy { +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(); - static const PPB_Flash_Clipboard* GetInterface(); + // 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 ReadPlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) OVERRIDE; + virtual int32_t WritePlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + const PP_Var& text) 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_id, + void OnMsgIsFormatAvailable(PP_Instance instance, int clipboard_type, int format, bool* result); - void OnMsgReadPlainText(PP_Instance instance_id, + void OnMsgReadPlainText(PP_Instance instance, int clipboard_type, SerializedVarReturnValue result); - void OnMsgWritePlainText(PP_Instance instance_id, + void OnMsgWritePlainText(PP_Instance instance, int clipboard_type, SerializedVarReceiveInput text); - - // 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_Clipboard* ppb_flash_clipboard_impl_; }; } // namespace proxy diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index e09b893..bbf149a 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -12,6 +12,7 @@ #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/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc new file mode 100644 index 0000000..600dad3 --- /dev/null +++ b/ppapi/tests/test_flash_clipboard.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2011 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/tests/test_flash_clipboard.h" + +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/point.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(FlashClipboard); + +TestFlashClipboard::TestFlashClipboard(TestingInstance* instance) + : TestCase(instance), + clipboard_interface_(NULL) { +} + +bool TestFlashClipboard::Init() { + clipboard_interface_ = static_cast<const PPB_Flash_Clipboard*>( + pp::Module::Get()->GetBrowserInterface(PPB_FLASH_CLIPBOARD_INTERFACE)); + return !!clipboard_interface_; +} + +void TestFlashClipboard::RunTest() { + RUN_TEST(ReadWrite); +} + +std::string TestFlashClipboard::TestReadWrite() { + std::string input_str("Hello, world"); + pp::Var input_var(input_str); + clipboard_interface_->WritePlainText(instance_->pp_instance(), + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + input_var.pp_var()); + + ASSERT_TRUE(clipboard_interface_->IsFormatAvailable( + instance_->pp_instance(), + PP_FLASH_CLIPBOARD_TYPE_STANDARD, + PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT)); + + pp::Var result_var(pp::Var::PassRef(), + clipboard_interface_->ReadPlainText(instance_->pp_instance(), + PP_FLASH_CLIPBOARD_TYPE_STANDARD)); + ASSERT_TRUE(result_var.is_string()); + + std::string result_str = result_var.AsString(); + ASSERT_TRUE(result_str == input_str); + PASS(); +} diff --git a/ppapi/tests/test_flash_clipboard.h b/ppapi/tests/test_flash_clipboard.h new file mode 100644 index 0000000..eacf933 --- /dev/null +++ b/ppapi/tests/test_flash_clipboard.h @@ -0,0 +1,28 @@ +// Copyright (c) 2011 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_TESTS_TEST_FLASH_CLIPBOARD_H_ +#define PPAPI_TESTS_TEST_FLASH_CLIPBOARD_H_ + +#include <string> + +#include "ppapi/c/private/ppb_flash_clipboard.h" +#include "ppapi/tests/test_case.h" +#include "ppapi/tests/test_utils.h" + +class TestFlashClipboard : public TestCase { + public: + explicit TestFlashClipboard(TestingInstance* instance); + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestReadWrite(); + + const PPB_Flash_Clipboard* clipboard_interface_; +}; + +#endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ diff --git a/ppapi/tests/test_flash_fullscreen.h b/ppapi/tests/test_flash_fullscreen.h index c4f2c8c..539a84f 100644 --- a/ppapi/tests/test_flash_fullscreen.h +++ b/ppapi/tests/test_flash_fullscreen.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ -#define PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ +#ifndef PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_ +#define PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_ #include <string> @@ -38,4 +38,4 @@ class TestFlashFullscreen : public TestCase { TestCompletionCallback normal_callback_; }; -#endif // PAPPI_TESTS_TEST_FLASH_FULLSCREEN_H_ +#endif // PPAPI_TESTS_TEST_FLASH_FULLSCREEN_H_ diff --git a/ppapi/thunk/ppb_flash_clipboard_api.h b/ppapi/thunk/ppb_flash_clipboard_api.h new file mode 100644 index 0000000..c91e6a1 --- /dev/null +++ b/ppapi/thunk/ppb_flash_clipboard_api.h @@ -0,0 +1,33 @@ +// Copyright (c) 2011 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 ReadPlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) = 0; + virtual int32_t WritePlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + const PP_Var& text) = 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 new file mode 100644 index 0000000..010aa2f --- /dev/null +++ b/ppapi/thunk/ppb_flash_clipboard_thunk.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2011 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/c/pp_errors.h" +#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" + +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); + if (enter.failed()) + return PP_FALSE; + return enter.functions()->IsFormatAvailable(instance, clipboard_type, format); +} + +PP_Var ReadPlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) { + EnterFlashClipboard enter(instance, true); + if (enter.failed()) + return PP_MakeUndefined(); + return enter.functions()->ReadPlainText(instance, clipboard_type); +} + +int32_t WritePlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + PP_Var text) { + EnterFlashClipboard enter(instance, true); + if (enter.failed()) + return PP_ERROR_NOINTERFACE; + return enter.functions()->WritePlainText(instance, clipboard_type, text); +} + +const PPB_Flash_Clipboard g_ppb_flash_clipboard_thunk = { + &IsFormatAvailable, + &ReadPlainText, + &WritePlainText +}; + +} // namespace + +const PPB_Flash_Clipboard* GetPPB_Flash_Clipboard_Thunk() { + return &g_ppb_flash_clipboard_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 08b6f2d..c197745 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -33,6 +33,7 @@ struct PPB_BufferTrusted; struct PPB_Context3DTrusted_Dev; struct PPB_FileChooserTrusted; struct PPB_FileIOTrusted; +struct PPB_Flash_Clipboard; struct PPB_Flash_Menu; struct PPB_Flash_NetConnector; struct PPB_Flash_TCPSocket; @@ -59,6 +60,7 @@ PPAPI_THUNK_EXPORT const PPB_Context3DTrusted_Dev* PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted* GetPPB_FileChooser_Trusted_Thunk(); PPAPI_THUNK_EXPORT const PPB_FileIOTrusted* GetPPB_FileIOTrusted_Thunk(); +PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard* GetPPB_Flash_Clipboard_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_Thunk(); diff --git a/webkit/plugins/ppapi/host_globals.cc b/webkit/plugins/ppapi/host_globals.cc index a753570..80f538c 100644 --- a/webkit/plugins/ppapi/host_globals.cc +++ b/webkit/plugins/ppapi/host_globals.cc @@ -14,6 +14,7 @@ #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" #include "webkit/plugins/ppapi/ppb_cursor_control_impl.h" +#include "webkit/plugins/ppapi/ppb_flash_clipboard_impl.h" #include "webkit/plugins/ppapi/ppb_font_impl.h" #include "webkit/plugins/ppapi/ppb_text_input_impl.h" #include "webkit/plugins/ppapi/resource_creation_impl.h" @@ -88,6 +89,9 @@ 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 e25b4b0..bdff66f 100644 --- a/webkit/plugins/ppapi/plugin_module.cc +++ b/webkit/plugins/ppapi/plugin_module.cc @@ -273,7 +273,7 @@ const void* GetInterface(const char* name) { if (strcmp(name, PPB_FLASH_INTERFACE) == 0) return PPB_Flash_Impl::GetInterface(); if (strcmp(name, PPB_FLASH_CLIPBOARD_INTERFACE) == 0) - return PPB_Flash_Clipboard_Impl::GetInterface(); + return ::ppapi::thunk::GetPPB_Flash_Clipboard_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 index 9153ae7..da3ea24 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.cc @@ -60,47 +60,53 @@ WebKit::WebClipboard::Format ConvertClipboardFormat( } } -PP_Bool IsFormatAvailable(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type, - PP_Flash_Clipboard_Format format) { - // If you don't give us an instance, we don't give you anything. - PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); - if (!instance) - return PP_FALSE; +} // namespace +PPB_Flash_Clipboard_Impl::PPB_Flash_Clipboard_Impl(PluginInstance* instance) + : instance_(instance) { +} + +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) { WebKit::WebClipboard* web_clipboard = WebKit::webKitPlatformSupport()->clipboard(); if (!web_clipboard) { NOTREACHED(); return PP_FALSE; } - return BoolToPPBool( web_clipboard->isFormatAvailable(ConvertClipboardFormat(format), ConvertClipboardType(clipboard_type))); } -PP_Var ReadPlainText(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type) { - PluginInstance* instance = HostGlobals::Get()->GetInstance(instance_id); - if (!instance) - return PP_MakeNull(); - +PP_Var PPB_Flash_Clipboard_Impl::ReadPlainText( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) { WebKit::WebClipboard* web_clipboard = WebKit::webKitPlatformSupport()->clipboard(); if (!web_clipboard) { NOTREACHED(); return PP_MakeNull(); } - WebKit::WebCString s = web_clipboard->readPlainText(ConvertClipboardType(clipboard_type)).utf8(); - return StringVar::StringToPPVar(instance->module()->pp_module(), s); + return StringVar::StringToPPVar(instance_->module()->pp_module(), s); } -int32_t WritePlainText(PP_Instance instance_id, - PP_Flash_Clipboard_Type clipboard_type, - PP_Var text) { +int32_t PPB_Flash_Clipboard_Impl::WritePlainText( + PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + const PP_Var& text) { StringVar* text_string = StringVar::FromPPVar(text); if (!text_string) return PP_ERROR_BADARGUMENT; @@ -125,19 +131,5 @@ int32_t WritePlainText(PP_Instance instance_id, return PP_OK; } -const PPB_Flash_Clipboard ppb_flash_clipboard = { - &IsFormatAvailable, - &ReadPlainText, - &WritePlainText, -}; - -} // namespace - -// static -const PPB_Flash_Clipboard* - PPB_Flash_Clipboard_Impl::GetInterface() { - return &ppb_flash_clipboard; -} - } // namespace ppapi } // namespace webkit diff --git a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h index 2088595..1c168fe 100644 --- a/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h +++ b/webkit/plugins/ppapi/ppb_flash_clipboard_impl.h @@ -5,14 +5,43 @@ #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 "ppapi/shared_impl/function_group_base.h" +#include "ppapi/thunk/ppb_flash_clipboard_api.h" + struct PPB_Flash_Clipboard; namespace webkit { namespace ppapi { -class PPB_Flash_Clipboard_Impl { +class PluginInstance; + +class PPB_Flash_Clipboard_Impl + : public ::ppapi::FunctionGroupBase, + public ::ppapi::thunk::PPB_Flash_Clipboard_FunctionAPI { public: - static const PPB_Flash_Clipboard* GetInterface(); + 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 ReadPlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type) OVERRIDE; + virtual int32_t WritePlainText(PP_Instance instance, + PP_Flash_Clipboard_Type clipboard_type, + const PP_Var& text) OVERRIDE; + + private: + PluginInstance* instance_; + + DISALLOW_COPY_AND_ASSIGN(PPB_Flash_Clipboard_Impl); }; } // namespace ppapi |