diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 09:19:17 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 09:19:17 +0000 |
commit | cd2af395e8429a30bcee9e7ad7ec9f4b680c924d (patch) | |
tree | acdc2fa6ef032a0c88b2a2f7729e15ae07a73254 /ppapi/thunk | |
parent | befff0575c078d9353e48a125575b429e4b8b5f1 (diff) | |
download | chromium_src-cd2af395e8429a30bcee9e7ad7ec9f4b680c924d.zip chromium_src-cd2af395e8429a30bcee9e7ad7ec9f4b680c924d.tar.gz chromium_src-cd2af395e8429a30bcee9e7ad7ec9f4b680c924d.tar.bz2 |
Introduce PPB_Flash_MessageLoop interface for Pepper Flash.
Comparing with PPB_Flash.RunMessageLoop/QuitMessageLoop, this new interface avoids leaking nested message loops. If Quit() is not called to balance the call to Run(), the outermost message loop will be quitted when the resource is destroyed.
BUG=109340
TEST=test_flash_message_loop.{h,cc}
Review URL: http://codereview.chromium.org/9188045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/thunk')
-rw-r--r-- | ppapi/thunk/ppb_flash_message_loop_api.h | 32 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_message_loop_thunk.cc | 56 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 1 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 3 |
4 files changed, 92 insertions, 0 deletions
diff --git a/ppapi/thunk/ppb_flash_message_loop_api.h b/ppapi/thunk/ppb_flash_message_loop_api.h new file mode 100644 index 0000000..618eace --- /dev/null +++ b/ppapi/thunk/ppb_flash_message_loop_api.h @@ -0,0 +1,32 @@ +// 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_MESSAGE_LOOP_API_H_ +#define PPAPI_THUNK_PPB_FLASH_MESSAGE_LOOP_API_H_ + +#include "base/callback_forward.h" +#include "ppapi/c/private/ppb_flash_message_loop.h" + +namespace ppapi { +namespace thunk { + +class PPB_Flash_MessageLoop_API { + public: + virtual ~PPB_Flash_MessageLoop_API() {} + + virtual int32_t Run() = 0; + virtual void Quit() = 0; + + // This is used by the proxy at the host side to call into the implementation. + // |callback| is called when the message loop is signaled to quit but before + // the method returns. + typedef base::Callback<void (int32_t)> RunFromHostProxyCallback; + virtual void RunFromHostProxy( + const RunFromHostProxyCallback& callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FLASH_MESSAGE_LOOP_API_H_ diff --git a/ppapi/thunk/ppb_flash_message_loop_thunk.cc b/ppapi/thunk/ppb_flash_message_loop_thunk.cc new file mode 100644 index 0000000..8fc4258 --- /dev/null +++ b/ppapi/thunk/ppb_flash_message_loop_thunk.cc @@ -0,0 +1,56 @@ +// 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/c/pp_bool.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_message_loop_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFlashMessageLoop(instance); +} + +PP_Bool IsFlashMessageLoop(PP_Resource resource) { + EnterResource<PPB_Flash_MessageLoop_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Run(PP_Resource resource) { + EnterResource<PPB_Flash_MessageLoop_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Run(); +} + +void Quit(PP_Resource resource) { + EnterResource<PPB_Flash_MessageLoop_API> enter(resource, true); + if (enter.succeeded()) + enter.object()->Quit(); +} + +const PPB_Flash_MessageLoop g_ppb_flash_message_loop_thunk = { + &Create, + &IsFlashMessageLoop, + &Run, + &Quit +}; + +} // namespace + +const PPB_Flash_MessageLoop_0_1* GetPPB_Flash_MessageLoop_0_1_Thunk() { + return &g_ppb_flash_message_loop_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index 7d895d8..ccfe7a59 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -69,6 +69,7 @@ class ResourceCreationAPI { PP_FileSystemType type) = 0; virtual PP_Resource CreateFlashMenu(PP_Instance instance, const PP_Flash_Menu* menu_data) = 0; + virtual PP_Resource CreateFlashMessageLoop(PP_Instance instance) = 0; virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index c2394f2..703ab02 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -8,6 +8,7 @@ #include "ppapi/c/ppb_graphics_3d.h" #include "ppapi/c/private/ppb_flash_clipboard.h" #include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/c/private/ppb_flash_message_loop.h" #include "ppapi/c/private/ppb_flash_net_connector.h" #include "ppapi/c/private/ppb_flash_fullscreen.h" #include "ppapi/c/private/ppb_instance_private.h" @@ -60,6 +61,8 @@ PPAPI_THUNK_EXPORT const PPB_FileChooserTrusted_0_5* PPAPI_THUNK_EXPORT const PPB_Flash_Clipboard_3_0* GetPPB_Flash_Clipboard_3_0_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_Menu_0_2* GetPPB_Flash_Menu_0_2_Thunk(); +PPAPI_THUNK_EXPORT const PPB_Flash_MessageLoop_0_1* + GetPPB_Flash_MessageLoop_0_1_Thunk(); PPAPI_THUNK_EXPORT const PPB_Flash_NetConnector_0_2* GetPPB_Flash_NetConnector_0_2_Thunk(); PPAPI_THUNK_EXPORT const PPB_Graphics3DTrusted_1_0* |