diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-15 16:54:32 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-15 16:54:32 +0000 |
commit | f20b56d0897f3026064c32593174414aeb107990 (patch) | |
tree | 7179b28874b2f465d1707494333bd462fbfc2589 /ppapi | |
parent | 0829e5e2575130a1e6d6ff0b3062a6e32700cf19 (diff) | |
download | chromium_src-f20b56d0897f3026064c32593174414aeb107990.zip chromium_src-f20b56d0897f3026064c32593174414aeb107990.tar.gz chromium_src-f20b56d0897f3026064c32593174414aeb107990.tar.bz2 |
Implement flash menu and net connector resources using the API/thunk model.
Write thunk for image data trusted.
BUG=none
TEST=ppapi ui tests
Review URL: http://codereview.chromium.org/7149026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/ppapi_shared.gypi | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_buffer_proxy.cc | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_menu_proxy.cc | 154 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_menu_proxy.h | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_net_connector_proxy.cc | 311 | ||||
-rw-r--r-- | ppapi/proxy/ppb_flash_net_connector_proxy.h | 5 | ||||
-rw-r--r-- | ppapi/proxy/ppb_image_data_proxy.cc | 7 | ||||
-rw-r--r-- | ppapi/proxy/ppb_image_data_proxy.h | 11 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 13 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 3 | ||||
-rw-r--r-- | ppapi/shared_impl/resource_object_base.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/enter.h | 2 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_menu_api.h | 23 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_menu_thunk.cc | 54 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_net_connector_api.h | 31 | ||||
-rw-r--r-- | ppapi/thunk/ppb_flash_net_connector_thunk.cc | 72 | ||||
-rw-r--r-- | ppapi/thunk/ppb_image_data_api.h | 3 | ||||
-rw-r--r-- | ppapi/thunk/ppb_image_data_trusted_thunk.cc | 35 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 4 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 6 |
20 files changed, 507 insertions, 241 deletions
diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 3fc24be..3367183 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -78,12 +78,17 @@ 'thunk/ppb_file_system_thunk.cc', 'thunk/ppb_find_api.h', 'thunk/ppb_find_thunk.cc', + 'thunk/ppb_flash_menu_api.h', + 'thunk/ppb_flash_menu_thunk.cc', + 'thunk/ppb_flash_net_connector_api.h', + 'thunk/ppb_flash_net_connector_thunk.cc', 'thunk/ppb_font_api.h', 'thunk/ppb_font_thunk.cc', 'thunk/ppb_graphics_2d_api.h', 'thunk/ppb_graphics_2d_thunk.cc', 'thunk/ppb_image_data_api.h', 'thunk/ppb_image_data_thunk.cc', + 'thunk/ppb_image_data_trusted_thunk.cc', 'thunk/thunk.h', ], 'conditions': [ diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index ec4b1ea..2e2ee90 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -44,7 +44,7 @@ class Buffer : public ppapi::thunk::PPB_Buffer_API, // Resource overrides. virtual Buffer* AsBuffer() OVERRIDE; - // ResourceObjectBase overries. + // ResourceObjectBase overrides. virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; // PPB_Buffer_API implementation. diff --git a/ppapi/proxy/ppb_flash_menu_proxy.cc b/ppapi/proxy/ppb_flash_menu_proxy.cc index 505ea5d..70262b1 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.cc +++ b/ppapi/proxy/ppb_flash_menu_proxy.cc @@ -6,29 +6,34 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash_menu.h" +#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_menu_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::EnterFunctionNoLock; +using ppapi::thunk::PPB_Flash_Menu_API; +using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { -class FlashMenu : public PluginResource { +class FlashMenu : public PPB_Flash_Menu_API, public PluginResource { public: - explicit FlashMenu(const HostResource& resource) - : PluginResource(resource), - callback_(PP_BlockUntilComplete()), - selected_id_ptr_(NULL) { - } + explicit FlashMenu(const HostResource& resource); + virtual ~FlashMenu(); - virtual ~FlashMenu() {} + // ResourceObjectBase overrides. + virtual PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE; - // Resource overrides. - virtual FlashMenu* AsFlashMenu() { return this; } + // PPB_Flash_Menu_API implementation. + virtual int32_t Show(const PP_Point* location, + int32_t* selected_id, + PP_CompletionCallback callback) OVERRIDE; - int32_t* selected_id_ptr() const { return selected_id_ptr_; } - void set_selected_id_ptr(int32_t* ptr) { selected_id_ptr_ = ptr; } - - PP_CompletionCallback callback() const { return callback_; } - void set_callback(PP_CompletionCallback cb) { callback_ = cb; } + void ShowACK(int32_t selected_id, int32_t result); private: PP_CompletionCallback callback_; @@ -37,60 +42,39 @@ class FlashMenu : public PluginResource { DISALLOW_COPY_AND_ASSIGN(FlashMenu); }; -namespace { - -PP_Resource Create(PP_Instance instance_id, const PP_Flash_Menu* menu_data) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return 0; - - HostResource result; - pp::proxy::SerializedFlashMenu serialized_menu; - if (!serialized_menu.SetPPMenu(menu_data)) - return 0; - - dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Create( - INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result)); - if (result.is_null()) - return 0; - - linked_ptr<FlashMenu> menu(new FlashMenu(result)); - return PluginResourceTracker::GetInstance()->AddResource(menu); +FlashMenu::FlashMenu(const HostResource& resource) + : PluginResource(resource), + callback_(PP_BlockUntilComplete()), + selected_id_ptr_(NULL) { } -PP_Bool IsFlashMenu(PP_Resource resource) { - return BoolToPPBool(!!PluginResource::GetAs<FlashMenu>(resource)); +FlashMenu::~FlashMenu() { } -int32_t Show(PP_Resource menu_id, - const PP_Point* location, - int32_t* selected_id, - PP_CompletionCallback callback) { - FlashMenu* object = PluginResource::GetAs<FlashMenu>(menu_id); - if (!object) - return PP_ERROR_BADRESOURCE; - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - object->instance()); - if (!dispatcher) - return PP_ERROR_FAILED; +PPB_Flash_Menu_API* FlashMenu::AsPPB_Flash_Menu_API() { + return this; +} - if (object->callback().func) +int32_t FlashMenu::Show(const struct PP_Point* location, + int32_t* selected_id, + struct PP_CompletionCallback callback) { + if (callback_.func) return PP_ERROR_INPROGRESS; - object->set_selected_id_ptr(selected_id); - object->set_callback(callback); - - dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Show( - INTERFACE_ID_PPB_FLASH_MENU, object->host_resource(), *location)); + selected_id_ptr_ = selected_id; + callback_ = callback; + GetDispatcher()->Send(new PpapiHostMsg_PPBFlashMenu_Show( + INTERFACE_ID_PPB_FLASH_MENU, host_resource(), *location)); return PP_OK_COMPLETIONPENDING; } -const PPB_Flash_Menu flash_menu_interface = { - &Create, - &IsFlashMenu, - &Show, -}; +void FlashMenu::ShowACK(int32_t selected_id, int32_t result) { + *selected_id_ptr_ = selected_id; + PP_RunAndClearCompletionCallback(&callback_, result); +} + +namespace { InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher, const void* target_interface) { @@ -108,9 +92,10 @@ PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher, PPB_Flash_Menu_Proxy::~PPB_Flash_Menu_Proxy() { } +// static const InterfaceProxy::Info* PPB_Flash_Menu_Proxy::GetInfo() { static const Info info = { - &flash_menu_interface, + ppapi::thunk::GetPPB_Flash_Menu_Thunk(), PPB_FLASH_MENU_INTERFACE, INTERFACE_ID_PPB_FLASH_MENU, true, @@ -119,6 +104,28 @@ const InterfaceProxy::Info* PPB_Flash_Menu_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Flash_Menu_Proxy::CreateProxyResource( + PP_Instance instance_id, + const PP_Flash_Menu* menu_data) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); + if (!dispatcher) + return 0; + + HostResource result; + pp::proxy::SerializedFlashMenu serialized_menu; + if (!serialized_menu.SetPPMenu(menu_data)) + return 0; + + dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Create( + INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result)); + if (result.is_null()) + return 0; + + linked_ptr<FlashMenu> menu(new FlashMenu(result)); + return PluginResourceTracker::GetInstance()->AddResource(menu); +} + bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Menu_Proxy, msg) @@ -135,12 +142,15 @@ bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) { return handled; } -void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance_id, +void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance, const SerializedFlashMenu& menu_data, HostResource* result) { - PP_Resource resource = ppb_flash_menu_target()->Create(instance_id, - menu_data.pp_menu()); - result->SetHostResource(instance_id, resource); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); + if (enter.succeeded()) { + result->SetHostResource( + instance, + enter.functions()->CreateFlashMenu(instance, menu_data.pp_menu())); + } } struct PPB_Flash_Menu_Proxy::ShowRequest { @@ -154,11 +164,14 @@ void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu, request->menu = menu; CompletionCallback callback = callback_factory_.NewCallback( &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request); - int32_t result = ppb_flash_menu_target()->Show( - menu.host_resource(), - &location, - &request->selected_id, - callback.pp_completion_callback()); + + EnterHostFromHostResource<PPB_Flash_Menu_API> enter(menu); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) { + result = enter.object()->Show(&location, + &request->selected_id, + callback.pp_completion_callback()); + } if (result != PP_OK_COMPLETIONPENDING) { // There was some error, so we won't get a callback. We need to now issue // the ACK to the plugin so that it hears about the error. This will also @@ -181,12 +194,7 @@ void PPB_Flash_Menu_Proxy::OnMsgShowACK(const HostResource& menu, return; } - // Be careful to make the callback NULL before issuing the callback since the - // plugin might want to show the menu again from within the callback. - PP_CompletionCallback callback = object->callback(); - object->set_callback(PP_BlockUntilComplete()); - *(object->selected_id_ptr()) = selected_id; - PP_RunCompletionCallback(&callback, result); + object->ShowACK(selected_id, result); } void PPB_Flash_Menu_Proxy::SendShowACKToPlugin( diff --git a/ppapi/proxy/ppb_flash_menu_proxy.h b/ppapi/proxy/ppb_flash_menu_proxy.h index 1684bac..d999905 100644 --- a/ppapi/proxy/ppb_flash_menu_proxy.h +++ b/ppapi/proxy/ppb_flash_menu_proxy.h @@ -25,9 +25,8 @@ class PPB_Flash_Menu_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_Flash_Menu* ppb_flash_menu_target() const { - return static_cast<const PPB_Flash_Menu*>(target_interface()); - } + static PP_Resource CreateProxyResource(PP_Instance instance_id, + const PP_Flash_Menu* menu_data); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.cc b/ppapi/proxy/ppb_flash_net_connector_proxy.cc index 2874dae..8a5aa41 100644 --- a/ppapi/proxy/ppb_flash_net_connector_proxy.cc +++ b/ppapi/proxy/ppb_flash_net_connector_proxy.cc @@ -8,10 +8,19 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_flash_net_connector.h" +#include "ppapi/proxy/enter_proxy.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/serialized_var.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_net_connector_api.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" + +using ppapi::thunk::EnterFunctionNoLock; +using ppapi::thunk::PPB_Flash_NetConnector_API; +using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { @@ -39,169 +48,147 @@ class AbortCallbackTask : public Task { PP_CompletionCallback callback_; }; -class FlashNetConnector : public PluginResource { +class FlashNetConnector : public PPB_Flash_NetConnector_API, + public PluginResource { public: - FlashNetConnector(const HostResource& resource) - : PluginResource(resource), - callback_(PP_BlockUntilComplete()), - local_addr_out_(NULL), - remote_addr_out_(NULL) { - } - ~FlashNetConnector() { - if (callback_.func) { - MessageLoop::current()->PostTask(FROM_HERE, - new AbortCallbackTask(callback_)); - } - } - - // Resource overrides. - virtual FlashNetConnector* AsFlashNetConnector() { - return this; - } - - bool HasCallback() const { - return callback_.func != NULL; - } - - void SetCallback(const PP_CompletionCallback& callback, - PP_FileHandle* socket_out, - PP_Flash_NetAddress* local_addr_out, - PP_Flash_NetAddress* remote_addr_out) { - callback_ = callback; - socket_out_ = socket_out; - local_addr_out_ = local_addr_out; - remote_addr_out_ = remote_addr_out; - } + explicit FlashNetConnector(const HostResource& resource); + virtual ~FlashNetConnector(); + + // ResourceObjectBase overrides. + virtual PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE; + + // PPB_Flash_NetConnector_API implementation. + virtual int32_t ConnectTcp(const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) OVERRIDE; + virtual int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) OVERRIDE; void ConnectComplete(int32_t result, base::PlatformFile file, const std::string& local_addr_as_string, - const std::string& remote_addr_as_string) { - if (!callback_.func) { - base::ClosePlatformFile(file); - return; - } - - *socket_out_ = static_cast<PP_FileHandle>(file); - StringToNetAddress(local_addr_as_string, local_addr_out_); - StringToNetAddress(remote_addr_as_string, remote_addr_out_); - - PP_RunAndClearCompletionCallback(&callback_, result); - } + const std::string& remote_addr_as_string); private: + // Backend for both ConnectTcp and ConnectTcpAddress. To keep things generic, + // the message is passed in (on error, it's deleted). + int32_t ConnectWithMessage(IPC::Message* msg, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback); + PP_CompletionCallback callback_; PP_FileHandle* socket_out_; PP_Flash_NetAddress* local_addr_out_; PP_Flash_NetAddress* remote_addr_out_; }; -// Contains the data that the host interface will write to so we can send it -// to the plugin. This is created when a request is initiated, and deleted in -// the callback handler. -struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo { - ConnectCallbackInfo(const HostResource& r) : resource(r), handle(0) { - local_addr.size = 0; - remote_addr.size = 0; - } +FlashNetConnector::FlashNetConnector(const HostResource& resource) + : PluginResource(resource), + callback_(PP_BlockUntilComplete()), + local_addr_out_(NULL), + remote_addr_out_(NULL) { +} - HostResource resource; +FlashNetConnector::~FlashNetConnector() { + if (callback_.func) { + MessageLoop::current()->PostTask(FROM_HERE, + new AbortCallbackTask(callback_)); + } +} - PP_FileHandle handle; - PP_Flash_NetAddress local_addr; - PP_Flash_NetAddress remote_addr; -}; +PPB_Flash_NetConnector_API* FlashNetConnector::AsPPB_Flash_NetConnector_API() { + return this; +} -namespace { +int32_t FlashNetConnector::ConnectTcp( + const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + return ConnectWithMessage( + new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp( + INTERFACE_ID_PPB_FLASH_NETCONNECTOR, host_resource(), host, port), + socket_out, local_addr_out, remote_addr_out, callback); +} -PP_Resource Create(PP_Instance instance_id) { - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return 0; +int32_t FlashNetConnector::ConnectTcpAddress( + const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + return ConnectWithMessage( + new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress( + INTERFACE_ID_PPB_FLASH_NETCONNECTOR, + host_resource(), NetAddressToString(*addr)), + socket_out, local_addr_out, remote_addr_out, callback); +} - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create( - INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance_id, &result)); - if (result.is_null()) - return 0; +void FlashNetConnector::ConnectComplete( + int32_t result, + base::PlatformFile file, + const std::string& local_addr_as_string, + const std::string& remote_addr_as_string) { + if (!callback_.func) { + base::ClosePlatformFile(file); + return; + } - linked_ptr<FlashNetConnector> object(new FlashNetConnector(result)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} + *socket_out_ = static_cast<PP_FileHandle>(file); + StringToNetAddress(local_addr_as_string, local_addr_out_); + StringToNetAddress(remote_addr_as_string, remote_addr_out_); -PP_Bool IsFlashNetConnector(PP_Resource resource_id) { - FlashNetConnector* object = - PluginResource::GetAs<FlashNetConnector>(resource_id); - return BoolToPPBool(!!object); + PP_RunAndClearCompletionCallback(&callback_, result); } -// Backend for both ConnectTcp and ConnectTcpAddress. To keep things generic, -// the message is passed in (on error, it's deleted). -int32_t ConnectWithMessage(FlashNetConnector* object, - IPC::Message* msg, - PP_FileHandle* socket_out, - struct PP_Flash_NetAddress* local_addr_out, - struct PP_Flash_NetAddress* remote_addr_out, - struct PP_CompletionCallback callback) { +int32_t FlashNetConnector::ConnectWithMessage( + IPC::Message* msg, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { scoped_ptr<IPC::Message> msg_deletor(msg); - if (object->HasCallback()) + if (callback_.func != NULL) return PP_ERROR_INPROGRESS; // Can only have one pending request. // Send the request, it will call us back via ConnectACK. - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( - object->instance()); - if (!dispatcher) - return PP_ERROR_BADARGUMENT; - dispatcher->Send(msg_deletor.release()); + GetDispatcher()->Send(msg_deletor.release()); - object->SetCallback(callback, socket_out, local_addr_out, remote_addr_out); + callback_ = callback; + socket_out_ = socket_out; + local_addr_out_ = local_addr_out; + remote_addr_out_ = remote_addr_out; return PP_OK_COMPLETIONPENDING; } -int32_t ConnectTcp(PP_Resource connector_id, - const char* host, - uint16_t port, - PP_FileHandle* socket_out, - struct PP_Flash_NetAddress* local_addr_out, - struct PP_Flash_NetAddress* remote_addr_out, - struct PP_CompletionCallback callback) { - FlashNetConnector* object = - PluginResource::GetAs<FlashNetConnector>(connector_id); - if (!object) - return PP_ERROR_BADARGUMENT; - return ConnectWithMessage( - object, - new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp( - INTERFACE_ID_PPB_FLASH_NETCONNECTOR, - object->host_resource(), host, port), - socket_out, local_addr_out, remote_addr_out, callback); -} +// Contains the data that the host interface will write to so we can send it +// to the plugin. This is created when a request is initiated, and deleted in +// the callback handler. +struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo { + ConnectCallbackInfo(const HostResource& r) : resource(r), handle(0) { + local_addr.size = 0; + remote_addr.size = 0; + } -int32_t ConnectTcpAddress(PP_Resource connector_id, - const struct PP_Flash_NetAddress* addr, - PP_FileHandle* socket_out, - struct PP_Flash_NetAddress* local_addr_out, - struct PP_Flash_NetAddress* remote_addr_out, - struct PP_CompletionCallback callback) { - FlashNetConnector* object = - PluginResource::GetAs<FlashNetConnector>(connector_id); - if (!object) - return PP_ERROR_BADARGUMENT; - return ConnectWithMessage( - object, - new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress( - INTERFACE_ID_PPB_FLASH_NETCONNECTOR, - object->host_resource(), NetAddressToString(*addr)), - socket_out, local_addr_out, remote_addr_out, callback); -} + HostResource resource; -const PPB_Flash_NetConnector flash_netconnector_interface = { - &Create, - &IsFlashNetConnector, - &ConnectTcp, - &ConnectTcpAddress + PP_FileHandle handle; + PP_Flash_NetAddress local_addr; + PP_Flash_NetAddress remote_addr; }; +namespace { + InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher, const void* target_interface) { return new PPB_Flash_NetConnector_Proxy(dispatcher, target_interface); @@ -221,7 +208,7 @@ PPB_Flash_NetConnector_Proxy::~PPB_Flash_NetConnector_Proxy() { // static const InterfaceProxy::Info* PPB_Flash_NetConnector_Proxy::GetInfo() { static const Info info = { - &flash_netconnector_interface, + ppapi::thunk::GetPPB_Flash_NetConnector_Thunk(), PPB_FLASH_NETCONNECTOR_INTERFACE, INTERFACE_ID_PPB_FLASH_NETCONNECTOR, false, @@ -230,6 +217,23 @@ const InterfaceProxy::Info* PPB_Flash_NetConnector_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Flash_NetConnector_Proxy::CreateProxyResource( + PP_Instance instance) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create( + INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance, &result)); + if (result.is_null()) + return 0; + + linked_ptr<FlashNetConnector> object(new FlashNetConnector(result)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg) @@ -246,11 +250,14 @@ bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { return handled; } -void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance_id, +void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance, HostResource* result) { - result->SetHostResource( - instance_id, - ppb_flash_net_connector_target()->Create(instance_id)); + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true); + if (enter.succeeded()) { + result->SetHostResource( + instance, + enter.functions()->CreateFlashNetConnector(instance)); + } } void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp( @@ -261,10 +268,13 @@ void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp( CompletionCallback callback = callback_factory_.NewCallback( &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); - int32_t result = ppb_flash_net_connector_target()->ConnectTcp( - resource.host_resource(), host.c_str(), port, - &info->handle, &info->local_addr, &info->remote_addr, - callback.pp_completion_callback()); + EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) { + result = enter.object()->ConnectTcp( + host.c_str(), port, &info->handle, &info->local_addr, + &info->remote_addr, callback.pp_completion_callback()); + } if (result != PP_OK_COMPLETIONPENDING) OnCompleteCallbackInHost(result, info); } @@ -279,10 +289,13 @@ void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress( PP_Flash_NetAddress net_address; StringToNetAddress(net_address_as_string, &net_address); - int32_t result = ppb_flash_net_connector_target()->ConnectTcpAddress( - resource.host_resource(), &net_address, - &info->handle, &info->local_addr, &info->remote_addr, - callback.pp_completion_callback()); + EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); + int32_t result = PP_ERROR_BADRESOURCE; + if (enter.succeeded()) { + result = enter.object()->ConnectTcpAddress( + &net_address, &info->handle, &info->local_addr, &info->remote_addr, + callback.pp_completion_callback()); + } if (result != PP_OK_COMPLETIONPENDING) OnCompleteCallbackInHost(result, info); } @@ -296,20 +309,12 @@ void PPB_Flash_NetConnector_Proxy::OnMsgConnectACK( base::PlatformFile platform_file = IPC::PlatformFileForTransitToPlatformFile(handle); - PP_Resource plugin_resource = - PluginResourceTracker::GetInstance()->PluginResourceForHostResource( - host_resource); - if (!plugin_resource) { - base::ClosePlatformFile(platform_file); - return; - } - FlashNetConnector* object = - PluginResource::GetAs<FlashNetConnector>(plugin_resource); - if (!object) { + EnterPluginFromHostResource<PPB_Flash_NetConnector_API> enter(host_resource); + if (enter.failed()) { base::ClosePlatformFile(platform_file); return; } - + FlashNetConnector* object = static_cast<FlashNetConnector*>(enter.object()); object->ConnectComplete(result, platform_file, load_addr_as_string, remote_addr_as_string); } diff --git a/ppapi/proxy/ppb_flash_net_connector_proxy.h b/ppapi/proxy/ppb_flash_net_connector_proxy.h index aced8f8..67647c2 100644 --- a/ppapi/proxy/ppb_flash_net_connector_proxy.h +++ b/ppapi/proxy/ppb_flash_net_connector_proxy.h @@ -27,10 +27,7 @@ class PPB_Flash_NetConnector_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_Flash_NetConnector* ppb_flash_net_connector_target() const { - return reinterpret_cast<const PPB_Flash_NetConnector*>( - target_interface()); - } + static PP_Resource CreateProxyResource(PP_Instance instance); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index 2d8e7f9..18f9e02 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -109,6 +109,13 @@ void ImageData::Unmap() { // We need to add a method to TransportDIB to release the handles. } +int32_t ImageData::GetSharedMemory(int* /* handle */, + uint32_t* /* byte_count */) { + // Not supported in the proxy (this method is for actually implementing the + // proxy in the host). + return PP_ERROR_NOACCESS; +} + #if defined(OS_WIN) const ImageHandle ImageData::NullHandle = NULL; #elif defined(OS_MACOSX) diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 366b6b4..23cf442 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -55,15 +55,16 @@ class ImageData : public PluginResource, virtual ~ImageData(); // ResourceObjectBase overrides. - virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API(); + virtual ::ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; // Resource overrides. - virtual ImageData* AsImageData(); + virtual ImageData* AsImageData() OVERRIDE; // PPB_ImageData API. - virtual PP_Bool Describe(PP_ImageDataDesc* desc); - virtual void* Map(); - virtual void Unmap(); + virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE; + virtual void* Map() OVERRIDE; + virtual void Unmap() OVERRIDE; + virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; skia::PlatformCanvas* mapped_canvas() const { return mapped_canvas_.get(); } diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 8d26528..36b9300 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -19,6 +19,8 @@ #include "ppapi/proxy/ppb_file_chooser_proxy.h" #include "ppapi/proxy/ppb_file_ref_proxy.h" #include "ppapi/proxy/ppb_file_system_proxy.h" +#include "ppapi/proxy/ppb_flash_menu_proxy.h" +#include "ppapi/proxy/ppb_flash_net_connector_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" @@ -103,6 +105,17 @@ PP_Resource ResourceCreationProxy::CreateFileSystem( return PPB_FileSystem_Proxy::CreateProxyResource(instance, type); } +PP_Resource ResourceCreationProxy::CreateFlashMenu( + PP_Instance instance, + const PP_Flash_Menu* menu_data) { + return PPB_Flash_Menu_Proxy::CreateProxyResource(instance, menu_data); +} + +PP_Resource ResourceCreationProxy::CreateFlashNetConnector( + PP_Instance instance) { + return PPB_Flash_NetConnector_Proxy::CreateProxyResource(instance); +} + PP_Resource ResourceCreationProxy::CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) { diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 501e70b..b95916e 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -52,6 +52,9 @@ class ResourceCreationProxy : public ::ppapi::FunctionGroupBase, const char* path) OVERRIDE; virtual PP_Resource CreateFileSystem(PP_Instance instance, PP_FileSystemType_Dev type) OVERRIDE; + virtual PP_Resource CreateFlashMenu(PP_Instance instance, + const PP_Flash_Menu* menu_data) OVERRIDE; + virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) OVERRIDE; diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h index 464d477..86b6338 100644 --- a/ppapi/shared_impl/resource_object_base.h +++ b/ppapi/shared_impl/resource_object_base.h @@ -20,6 +20,8 @@ F(PPB_FileRef_API) \ F(PPB_FileSystem_API) \ F(PPB_Find_API) \ + F(PPB_Flash_Menu_API) \ + F(PPB_Flash_NetConnector_API) \ F(PPB_Font_API) \ F(PPB_Graphics2D_API) \ F(PPB_ImageData_API) diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index dc06381..ea2fc82 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -52,11 +52,9 @@ class EnterFunction { bool succeeded() const { return !!functions_; } bool failed() const { return !functions_; } - PP_Instance instance() const { return instance_; } FunctionsT* functions() { return functions_; } private: - PP_Instance instance_; FunctionsT* functions_; DISALLOW_COPY_AND_ASSIGN(EnterFunction); diff --git a/ppapi/thunk/ppb_flash_menu_api.h b/ppapi/thunk/ppb_flash_menu_api.h new file mode 100644 index 0000000..24ef1f2 --- /dev/null +++ b/ppapi/thunk/ppb_flash_menu_api.h @@ -0,0 +1,23 @@ +// 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_MENU_API_H_ +#define PPAPI_THUNK_PPB_FLASH_MENU_API_H_ + +#include "ppapi/c/private/ppb_flash_menu.h" + +namespace ppapi { +namespace thunk { + +class PPB_Flash_Menu_API { + public: + virtual int32_t Show(const PP_Point* location, + int32_t* selected_id, + PP_CompletionCallback callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FLASH_MENU_API_H_ diff --git a/ppapi/thunk/ppb_flash_menu_thunk.cc b/ppapi/thunk/ppb_flash_menu_thunk.cc new file mode 100644 index 0000000..f24ff72 --- /dev/null +++ b/ppapi/thunk/ppb_flash_menu_thunk.cc @@ -0,0 +1,54 @@ +// 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/private/ppb_flash_menu.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_menu_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, const PP_Flash_Menu* menu_data) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateFlashMenu(instance, menu_data); +} + +PP_Bool IsFlashMenu(PP_Resource resource) { + EnterResource<PPB_Flash_Menu_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t Show(PP_Resource resource, + const PP_Point* location, + int32_t* selected_id, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_Menu_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->Show(location, selected_id, callback); +} + +const PPB_Flash_Menu g_ppb_flash_menu_thunk = { + &Create, + &IsFlashMenu, + &Show +}; + +} // namespace + +const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk() { + return &g_ppb_flash_menu_thunk; +} + +} // namespace thunk +} // namespace ppapi + diff --git a/ppapi/thunk/ppb_flash_net_connector_api.h b/ppapi/thunk/ppb_flash_net_connector_api.h new file mode 100644 index 0000000..5a17d0f --- /dev/null +++ b/ppapi/thunk/ppb_flash_net_connector_api.h @@ -0,0 +1,31 @@ +// 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_NET_CONNECTOR_API_H_ +#define PPAPI_THUNK_PPB_FLASH_NET_CONNECTOR_API_H_ + +#include "ppapi/c/private/ppb_flash_net_connector.h" + +namespace ppapi { +namespace thunk { + +class PPB_Flash_NetConnector_API { + public: + virtual int32_t ConnectTcp(const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) = 0; + virtual int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_FLASH_NET_CONNECTOR_API_H_ diff --git a/ppapi/thunk/ppb_flash_net_connector_thunk.cc b/ppapi/thunk/ppb_flash_net_connector_thunk.cc new file mode 100644 index 0000000..e0bb05c --- /dev/null +++ b/ppapi/thunk/ppb_flash_net_connector_thunk.cc @@ -0,0 +1,72 @@ +// 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/private/ppb_flash_net_connector.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_flash_net_connector_api.h" +#include "ppapi/thunk/resource_creation_api.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()->CreateFlashNetConnector(instance); +} + +PP_Bool IsFlashNetConnector(PP_Resource resource) { + EnterResource<PPB_Flash_NetConnector_API> enter(resource, false); + return PP_FromBool(enter.succeeded()); +} + +int32_t ConnectTcp(PP_Resource resource, + const char* host, + uint16_t port, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->ConnectTcp(host, port, socket_out, local_addr_out, + remote_addr_out, callback); +} + +int32_t ConnectTcpAddress(PP_Resource resource, + const PP_Flash_NetAddress* addr, + PP_FileHandle* socket_out, + PP_Flash_NetAddress* local_addr_out, + PP_Flash_NetAddress* remote_addr_out, + PP_CompletionCallback callback) { + EnterResource<PPB_Flash_NetConnector_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->ConnectTcpAddress(addr, socket_out, local_addr_out, + remote_addr_out, callback); +} + +const PPB_Flash_NetConnector g_ppb_flash_net_connector_thunk = { + &Create, + &IsFlashNetConnector, + &ConnectTcp, + &ConnectTcpAddress +}; + +} // namespace + +const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_Thunk() { + return &g_ppb_flash_net_connector_thunk; +} + +} // namespace thunk +} // namespace ppapi + diff --git a/ppapi/thunk/ppb_image_data_api.h b/ppapi/thunk/ppb_image_data_api.h index cce38b29..c0703402 100644 --- a/ppapi/thunk/ppb_image_data_api.h +++ b/ppapi/thunk/ppb_image_data_api.h @@ -16,6 +16,9 @@ class PPB_ImageData_API { virtual PP_Bool Describe(PP_ImageDataDesc* desc) = 0; virtual void* Map() = 0; virtual void Unmap() = 0; + + // Trusted inteface. + virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) = 0; }; } // namespace thunk diff --git a/ppapi/thunk/ppb_image_data_trusted_thunk.cc b/ppapi/thunk/ppb_image_data_trusted_thunk.cc new file mode 100644 index 0000000..d477e2b --- /dev/null +++ b/ppapi/thunk/ppb_image_data_trusted_thunk.cc @@ -0,0 +1,35 @@ +// 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/trusted/ppb_image_data_trusted.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_image_data_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +int32_t GetSharedMemory(PP_Resource resource, + int* handle, + uint32_t* byte_count) { + EnterResource<PPB_ImageData_API> enter(resource, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetSharedMemory(handle, byte_count); +} + +const PPB_ImageDataTrusted g_ppb_image_data_trusted_thunk = { + &GetSharedMemory +}; + +} // namespace + +const PPB_ImageDataTrusted* GetPPB_ImageDataTrusted_Thunk() { + return &g_ppb_image_data_trusted_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index efb0150..cbaf92e 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -15,6 +15,7 @@ #include "ppapi/c/ppb_image_data.h" #include "ppapi/proxy/interface_id.h" +struct PP_Flash_Menu; struct PP_FontDescription_Dev; struct PP_Size; @@ -50,6 +51,9 @@ class ResourceCreationAPI { const char* path) = 0; virtual PP_Resource CreateFileSystem(PP_Instance instance, PP_FileSystemType_Dev type) = 0; + virtual PP_Resource CreateFlashMenu(PP_Instance instance, + const PP_Flash_Menu* menu_data) = 0; + virtual PP_Resource CreateFlashNetConnector(PP_Instance instance) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( PP_Instance instance, diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 4d0dcf7..78b1b80 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -20,9 +20,12 @@ struct PPB_FileIOTrusted_Dev; struct PPB_FileRef_Dev; struct PPB_FileSystem_Dev; struct PPB_Find_Dev; +struct PPB_Flash_Menu; +struct PPB_Flash_NetConnector; struct PPB_Font_Dev; struct PPB_Graphics2D; struct PPB_ImageData; +struct PPB_ImageDataTrusted; namespace ppapi { namespace thunk { @@ -42,9 +45,12 @@ const PPB_FileIOTrusted_Dev* GetPPB_FileIOTrusted_Thunk(); const PPB_FileRef_Dev* GetPPB_FileRef_Thunk(); const PPB_FileSystem_Dev* GetPPB_FileSystem_Thunk(); const PPB_Find_Dev* GetPPB_Find_Thunk(); +const PPB_Flash_Menu* GetPPB_Flash_Menu_Thunk(); +const PPB_Flash_NetConnector* GetPPB_Flash_NetConnector_Thunk(); const PPB_Font_Dev* GetPPB_Font_Thunk(); const PPB_Graphics2D* GetPPB_Graphics2D_Thunk(); const PPB_ImageData* GetPPB_ImageData_Thunk(); +const PPB_ImageDataTrusted* GetPPB_ImageDataTrusted_Thunk(); } // namespace thunk } // namespace ppapi |