diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 19:54:30 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 19:54:30 +0000 |
commit | f511881bed1a46d2110f36e6b60e28f2b306b935 (patch) | |
tree | 58d69490432a1176a56ee2c0bdd6dd8016162e46 | |
parent | 5d67452f563f0d6eddc932dd67f7e84579b77831 (diff) | |
download | chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.zip chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.gz chromium_src-f511881bed1a46d2110f36e6b60e28f2b306b935.tar.bz2 |
Add a skeleton gamepad resource.
This implements the skeleton of the gamepad resource for the IPC proxy. It is not actually hooked up. Hooking it up will require moving some gamepad lock code to a shared location.
This also hooks up the browser message routing for implementing resource hosts in the browser process.
BUG=
Review URL: https://chromiumcodereview.appspot.com/10824272
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153265 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 338 insertions, 40 deletions
diff --git a/content/browser/ppapi_plugin_process_host.cc b/content/browser/ppapi_plugin_process_host.cc index 6ca4235..7da9abd 100644 --- a/content/browser/ppapi_plugin_process_host.cc +++ b/content/browser/ppapi_plugin_process_host.cc @@ -127,13 +127,14 @@ PpapiPluginProcessHost::PpapiPluginProcessHost( host_resolver); ppapi::PpapiPermissions permissions(info.permissions); - host_impl_.reset(new content::BrowserPpapiHostImpl(this, permissions)); + host_impl_ = new content::BrowserPpapiHostImpl(this, permissions); file_filter_ = new PepperTrustedFileMessageFilter( process_->GetData().id, info.name, profile_data_directory); process_->GetHost()->AddFilter(filter_.get()); process_->GetHost()->AddFilter(file_filter_.get()); + process_->GetHost()->AddFilter(host_impl_.get()); } PpapiPluginProcessHost::PpapiPluginProcessHost() diff --git a/content/browser/ppapi_plugin_process_host.h b/content/browser/ppapi_plugin_process_host.h index 871666d..de57b52 100644 --- a/content/browser/ppapi_plugin_process_host.h +++ b/content/browser/ppapi_plugin_process_host.h @@ -124,7 +124,7 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate, // Handles most requests from the plugin. May be NULL. scoped_refptr<PepperMessageFilter> filter_; - scoped_ptr<content::BrowserPpapiHostImpl> host_impl_; + scoped_refptr<content::BrowserPpapiHostImpl> host_impl_; // Handles filesystem requests from flash plugins. May be NULL. scoped_refptr<PepperFileMessageFilter> file_filter_; diff --git a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h index 2bedbda..062755a 100644 --- a/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h +++ b/content/browser/renderer_host/pepper/browser_ppapi_host_impl.h @@ -9,7 +9,7 @@ #include "base/compiler_specific.h" #include "content/browser/renderer_host/pepper/content_browser_pepper_host_factory.h" #include "content/public/browser/browser_ppapi_host.h" -#include "ipc/ipc_listener.h" +#include "ipc/ipc_channel_proxy.h" #include "ppapi/host/ppapi_host.h" namespace IPC { @@ -18,19 +18,21 @@ class Sender; namespace content { -class BrowserPpapiHostImpl : public BrowserPpapiHost, public IPC::Listener { +class BrowserPpapiHostImpl : public BrowserPpapiHost, + public IPC::ChannelProxy::MessageFilter { public: BrowserPpapiHostImpl(IPC::Sender* sender, const ppapi::PpapiPermissions& permissions); - virtual ~BrowserPpapiHostImpl(); - // IPC::Listener. + // IPC::ChannelProxy::MessageFilter. virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; // BrowserPpapiHost. virtual ppapi::host::PpapiHost* GetPpapiHost() OVERRIDE; private: + virtual ~BrowserPpapiHostImpl(); + ContentBrowserPepperHostFactory host_factory_; ppapi::host::PpapiHost ppapi_host_; diff --git a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc index fbe5e6d..d5e7e98 100644 --- a/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc +++ b/content/browser/renderer_host/pepper/content_browser_pepper_host_factory.cc @@ -4,6 +4,8 @@ #include "content/browser/renderer_host/pepper/content_browser_pepper_host_factory.h" +#include "content/browser/renderer_host/pepper/browser_ppapi_host_impl.h" +#include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" #include "ppapi/host/resource_host.h" #include "ppapi/proxy/ppapi_messages.h" @@ -24,7 +26,21 @@ scoped_ptr<ResourceHost> ContentBrowserPepperHostFactory::CreateResourceHost( const ppapi::proxy::ResourceMessageCallParams& params, PP_Instance instance, const IPC::Message& message) { - // TODO(brettw) implement hosts here. + DCHECK(host == host_->GetPpapiHost()); + + // Make sure the plugin is giving us a valid instance for this resource. + /* TODO(brettw) make this work. The browser should be aware of all valid + instances. + if (!host_->IsValidInstance(instance)) + return scoped_ptr<ResourceHost>(); + */ + + // Public interfaces with no permissions required. + switch (message.type()) { + case PpapiHostMsg_Gamepad_Create::ID: + return scoped_ptr<ResourceHost>(new PepperGamepadHost( + host_, instance, params.pp_resource())); + } return scoped_ptr<ResourceHost>(); } diff --git a/content/browser/renderer_host/pepper/pepper_gamepad_host.cc b/content/browser/renderer_host/pepper/pepper_gamepad_host.cc new file mode 100644 index 0000000..0fd3c44 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_gamepad_host.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" + +#include "content/public/browser/browser_ppapi_host.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/host/dispatch_host_message.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace content { + +PepperGamepadHost::PepperGamepadHost(BrowserPpapiHost* host, + PP_Instance instance, + PP_Resource resource) + : ResourceHost(host->GetPpapiHost(), instance, resource), + browser_ppapi_host_(host) { +} + +PepperGamepadHost::~PepperGamepadHost() { +} + +int32_t PepperGamepadHost::OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) { + IPC_BEGIN_MESSAGE_MAP(PepperGamepadHost, msg) + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Gamepad_RequestMemory, + OnMsgRequestMemory) + IPC_END_MESSAGE_MAP() + return PP_ERROR_FAILED; +} + +int32_t PepperGamepadHost::OnMsgRequestMemory( + ppapi::host::HostMessageContext* context) { + return PP_ERROR_FAILED; +} + +} // namespace content diff --git a/content/browser/renderer_host/pepper/pepper_gamepad_host.h b/content/browser/renderer_host/pepper/pepper_gamepad_host.h new file mode 100644 index 0000000..a47d053 --- /dev/null +++ b/content/browser/renderer_host/pepper/pepper_gamepad_host.h @@ -0,0 +1,37 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_GAMEPAD_HOST_H_ +#define CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_GAMEPAD_HOST_H_ + +#include "base/compiler_specific.h" +#include "content/common/content_export.h" +#include "ppapi/host/resource_host.h" + +namespace content { + +class BrowserPpapiHost; + +class CONTENT_EXPORT PepperGamepadHost : public ppapi::host::ResourceHost { + public: + PepperGamepadHost(BrowserPpapiHost* host, + PP_Instance instance, + PP_Resource resource); + virtual ~PepperGamepadHost(); + + virtual int32_t OnResourceMessageReceived( + const IPC::Message& msg, + ppapi::host::HostMessageContext* context) OVERRIDE; + + private: + int32_t OnMsgRequestMemory(ppapi::host::HostMessageContext* context); + + BrowserPpapiHost* browser_ppapi_host_; + + DISALLOW_COPY_AND_ASSIGN(PepperGamepadHost); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_PEPPER_GAMEPAD_HOST_H_ diff --git a/content/content_browser.gypi b/content/content_browser.gypi index efc8ab9..f65ba6b 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -613,6 +613,8 @@ 'browser/renderer_host/pepper/content_browser_pepper_host_factory.h', 'browser/renderer_host/pepper/pepper_file_message_filter.cc', 'browser/renderer_host/pepper/pepper_file_message_filter.h', + 'browser/renderer_host/pepper/pepper_gamepad_host.cc', + 'browser/renderer_host/pepper/pepper_gamepad_host.h', 'browser/renderer_host/pepper/pepper_lookup_request.h', 'browser/renderer_host/pepper/pepper_message_filter.cc', 'browser/renderer_host/pepper/pepper_message_filter.h', diff --git a/ppapi/host/dispatch_host_message.h b/ppapi/host/dispatch_host_message.h index 070b746..9a3fae5 100644 --- a/ppapi/host/dispatch_host_message.h +++ b/ppapi/host/dispatch_host_message.h @@ -61,20 +61,28 @@ inline int32_t DispatchResourceCall(ObjT* obj, Method method, return (obj->*method)(context, arg.a, arg.b, arg.c, arg.d, arg.e); } +// Note that this only works for message with 1 or more parameters. For +// 0-parameter messages you need to use the _0 version below (since there are +// no Params in the message). #define PPAPI_DISPATCH_HOST_RESOURCE_CALL(msg_class, member_func) \ case msg_class::ID: { \ - TRACK_RUN_IN_IPC_HANDLER(member_func); \ - msg_class::Schema::Param p; \ - if (msg_class::Read(&ipc_message__, &p)) { \ - return ppapi::host::DispatchResourceCall( \ - this, \ - &_IpcMessageHandlerClass::member_func, \ - context, p); \ - } else { \ - return PP_ERROR_FAILED; \ - } \ - } \ - break; + TRACK_RUN_IN_IPC_HANDLER(member_func); \ + msg_class::Schema::Param p; \ + if (msg_class::Read(&ipc_message__, &p)) { \ + return ppapi::host::DispatchResourceCall( \ + this, \ + &_IpcMessageHandlerClass::member_func, \ + context, p); \ + } \ + return PP_ERROR_FAILED; \ + } + +#define PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(msg_class, member_func) \ + case msg_class::ID: { \ + TRACK_RUN_IN_IPC_HANDLER(member_func); \ + return member_func(context); \ + } + } // namespace host } // namespace ppapi diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index ca15e63..6bf1d88 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -27,6 +27,8 @@ 'proxy/enter_proxy.h', 'proxy/file_chooser_resource.cc', 'proxy/file_chooser_resource.h', + 'proxy/gamepad_resource.cc', + 'proxy/gamepad_resource.h', 'proxy/host_dispatcher.cc', 'proxy/host_dispatcher.h', 'proxy/host_var_serialization_rules.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 1c186b5..06f6e00 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -170,6 +170,7 @@ 'thunk/ppb_flash_message_loop_thunk.cc', 'thunk/ppb_flash_thunk.cc', 'thunk/ppb_fullscreen_thunk.cc', + 'thunk/ppb_gamepad_api.h', 'thunk/ppb_gamepad_thunk.cc', 'thunk/ppb_gles_chromium_texture_mapping_thunk.cc', 'thunk/ppb_graphics_2d_api.h', diff --git a/ppapi/proxy/gamepad_resource.cc b/ppapi/proxy/gamepad_resource.cc new file mode 100644 index 0000000..21ee02d --- /dev/null +++ b/ppapi/proxy/gamepad_resource.cc @@ -0,0 +1,58 @@ +// 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/gamepad_resource.h" + +#include <string.h> + +#include "ppapi/c/ppb_gamepad.h" +#include "ppapi/proxy/dispatch_reply_message.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace ppapi { +namespace proxy { + +GamepadResource::GamepadResource(Connection connection, PP_Instance instance) + : PluginResource(connection, instance), + buffer_(NULL) { + SendCreateToBrowser(PpapiHostMsg_Gamepad_Create()); + CallBrowser(PpapiHostMsg_Gamepad_RequestMemory()); +} + +GamepadResource::~GamepadResource() { +} + +void GamepadResource::Sample(PP_GamepadsSampleData* data) { + if (!buffer_) { + // Browser hasn't sent back our shared memory, give the plugin gamepad + // data corresponding to "not connected". + memset(data, 0, sizeof(PP_GamepadsSampleData)); + } else { + memcpy(data, buffer_, sizeof(PP_GamepadsSampleData)); + } +} + +void GamepadResource::OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) { + IPC_BEGIN_MESSAGE_MAP(GamepadResource, msg) + PPAPI_DISPATCH_RESOURCE_REPLY(PpapiPluginMsg_Gamepad_SendMemory, + OnPluginMsgSendMemory) + IPC_END_MESSAGE_MAP() +} + +void GamepadResource::OnPluginMsgSendMemory( + const ResourceMessageReplyParams& params, + base::SharedMemoryHandle shared_memory_handle) { + /* TODO(brettw) implement this when we have shared gamepad code. It would be + something like this: + shared_memory_.reset( + new base::SharedMemory(shared_memory_handle, true)); + CHECK(shared_memory_->Map(sizeof(GamepadHardwareBuffer))); + void *memory = shared_memory_->memory(); + // Use the memory... + */ +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/gamepad_resource.h b/ppapi/proxy/gamepad_resource.h new file mode 100644 index 0000000..61d66b0 --- /dev/null +++ b/ppapi/proxy/gamepad_resource.h @@ -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. + +#ifndef PPAPI_PROXY_GAMEPAD_RESOURCE_H_ +#define PPAPI_PROXY_GAMEPAD_RESOURCE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "base/shared_memory.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_proxy_export.h" +#include "ppapi/thunk/ppb_gamepad_api.h" + +struct PP_GamepadsSampleData; + +namespace base { +class SharedMemory; +} + +namespace ppapi { +namespace proxy { + +// This class is a bit weird. It isn't a true resource from the plugin's +// perspective. But we need to make requests to the browser and get replies. +// It's more convenient to do this as a resource, so the instance just +// maintains an internal lazily instantiated copy of this resource. +class PPAPI_PROXY_EXPORT GamepadResource + : public PluginResource, + public thunk::PPB_Gamepad_API { + public: + GamepadResource(Connection connection, PP_Instance instance); + virtual ~GamepadResource(); + + // PPB_Gamepad_API. + virtual void Sample(PP_GamepadsSampleData* data) OVERRIDE; + + private: + // PluginResource override. + virtual void OnReplyReceived(const ResourceMessageReplyParams& params, + const IPC::Message& msg) OVERRIDE; + + void OnPluginMsgSendMemory(const ResourceMessageReplyParams& params, + base::SharedMemoryHandle shared_memory_handle); + + scoped_ptr<base::SharedMemory> shared_memory_; + void* buffer_; + + DISALLOW_COPY_AND_ASSIGN(GamepadResource); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_GAMEPAD_RESOURCE_H_ diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 4c50653..0e406db 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -14,6 +14,7 @@ #include "base/debug/trace_event.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppp_instance.h" +#include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/interface_list.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_message_filter.h" diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 5cf1967..ba46464 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -34,6 +34,7 @@ class ResourceCreationAPI; namespace proxy { +class GamepadResource; class ResourceMessageReplyParams; // Used to keep track of per-instance data. @@ -48,6 +49,9 @@ struct InstanceData { // When non-NULL, indicates the callback to execute when mouse lock is lost. scoped_refptr<TrackedCallback> mouse_lock_callback; + // Lazily created the first time the plugin requests gamepad data. + scoped_refptr<GamepadResource> gamepad_resource; + // Calls to |RequestSurroundingText()| are done by posted tasks. Track whether // a) a task is pending, to avoid redundant calls, and b) whether we should // actually call |RequestSurroundingText()|, to avoid stale calls (i.e., diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index f35b3e8..a5a9cfb 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1530,3 +1530,9 @@ IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileChooser_Show, std::vector<std::string> /* accept_mime_types */) IPC_MESSAGE_CONTROL1(PpapiPluginMsg_FileChooser_ShowReply, std::vector<ppapi::PPB_FileRef_CreateInfo> /* files */) + +// Gamepad. +IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_Create) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_Gamepad_RequestMemory) +IPC_MESSAGE_CONTROL1(PpapiPluginMsg_Gamepad_SendMemory, + base::SharedMemoryHandle /* handle */) diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index e9eaf35..01fae69 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -14,6 +14,7 @@ #include "ppapi/c/private/pp_content_decryptor.h" #include "ppapi/proxy/content_decryptor_private_serializer.h" #include "ppapi/proxy/enter_proxy.h" +#include "ppapi/proxy/gamepad_resource.h" #include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_proxy_delegate.h" @@ -314,9 +315,20 @@ thunk::PPB_Flash_API* PPB_Instance_Proxy::GetFlashAPI() { return static_cast<PPB_Flash_Proxy*>(ip); } -void PPB_Instance_Proxy::SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) { - NOTIMPLEMENTED(); +thunk::PPB_Gamepad_API* PPB_Instance_Proxy::GetGamepadAPI( + PP_Instance instance) { + InstanceData* data = static_cast<PluginDispatcher*>(dispatcher())-> + GetInstanceData(instance); + if (!data) + return NULL; + + if (!data->gamepad_resource.get()) { + Connection connection( + PluginGlobals::Get()->plugin_proxy_delegate()->GetBrowserSender(), + dispatcher()); + data->gamepad_resource = new GamepadResource(connection, instance); + } + return data->gamepad_resource.get(); } int32_t PPB_Instance_Proxy::RequestInputEvents(PP_Instance instance, diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index 9da6659..b2503a4 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -69,8 +69,7 @@ class PPB_Instance_Proxy : public InterfaceProxy, virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; virtual thunk::PPB_Flash_API* GetFlashAPI() OVERRIDE; - virtual void SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) OVERRIDE; + virtual thunk::PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; virtual int32_t RequestFilteringInputEvents(PP_Instance instance, diff --git a/ppapi/thunk/ppb_gamepad_api.h b/ppapi/thunk/ppb_gamepad_api.h new file mode 100644 index 0000000..ee7199a --- /dev/null +++ b/ppapi/thunk/ppb_gamepad_api.h @@ -0,0 +1,25 @@ +// 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_GAMEPAD_API_H_ +#define PPAPI_THUNK_PPB_GAMEPAD_API_H_ + +#include "ppapi/thunk/ppapi_thunk_export.h" + +struct PP_GamepadsSampleData; + +namespace ppapi { +namespace thunk { + +class PPAPI_THUNK_EXPORT PPB_Gamepad_API { + public: + virtual ~PPB_Gamepad_API() {} + + virtual void Sample(PP_GamepadsSampleData* data) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_PPB_GAMEPAD_API_H_ diff --git a/ppapi/thunk/ppb_gamepad_thunk.cc b/ppapi/thunk/ppb_gamepad_thunk.cc index 61b3195..3aeedb5 100644 --- a/ppapi/thunk/ppb_gamepad_thunk.cc +++ b/ppapi/thunk/ppb_gamepad_thunk.cc @@ -2,9 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string.h> + #include "ppapi/c/ppb_gamepad.h" #include "ppapi/thunk/thunk.h" #include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_gamepad_api.h" #include "ppapi/thunk/ppb_instance_api.h" #include "ppapi/thunk/resource_creation_api.h" @@ -15,9 +18,15 @@ namespace { void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) { EnterInstance enter(instance); - if (enter.failed()) - return; - enter.functions()->SampleGamepads(instance, data); + if (enter.succeeded()) { + PPB_Gamepad_API* api = enter.functions()->GetGamepadAPI(instance); + if (api) { + api->Sample(data); + return; + } + } + // Failure, zero out. + memset(data, 0, sizeof(PP_GamepadsSampleData)); } const PPB_Gamepad g_ppb_gamepad_thunk = { diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index 10868dd..ef80609 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -37,6 +37,7 @@ struct ViewData; namespace thunk { class PPB_Flash_API; +class PPB_Gamepad_API; class PPB_Instance_API { public: @@ -90,8 +91,7 @@ class PPB_Instance_API { virtual PPB_Flash_API* GetFlashAPI() = 0; // Gamepad. - virtual void SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) = 0; + virtual PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) = 0; // InputEvent. virtual int32_t RequestInputEvents(PP_Instance instance, diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index 1137890..aa17478 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -333,6 +333,16 @@ PluginInstance* PluginInstance::Create(PluginDelegate* delegate, return new PluginInstance(delegate, module, ppp_instance_combined); } +PluginInstance::GamepadImpl::GamepadImpl(PluginDelegate* delegate) + : delegate_(delegate) { +} + +void PluginInstance::GamepadImpl::Sample(PP_GamepadsSampleData* data) { + WebKit::WebGamepads webkit_data; + delegate_->SampleGamepads(&webkit_data); + ConvertWebKitGamepadData(webkit_data, data); +} + PluginInstance::PluginInstance( PluginDelegate* delegate, PluginModule* module, @@ -360,6 +370,7 @@ PluginInstance::PluginInstance( plugin_zoom_interface_(NULL), checked_for_plugin_input_event_interface_(false), checked_for_plugin_messaging_interface_(false), + gamepad_impl_(delegate), plugin_print_interface_(NULL), plugin_graphics_3d_interface_(NULL), always_on_top_(false), @@ -1551,13 +1562,6 @@ bool PluginInstance::IsRectTopmost(const gfx::Rect& rect) { #endif } -void PluginInstance::SampleGamepads(PP_Instance instance, - PP_GamepadsSampleData* data) { - WebKit::WebGamepads webkit_data; - delegate()->SampleGamepads(&webkit_data); - ConvertWebKitGamepadData(webkit_data, data); -} - bool PluginInstance::IsViewAccelerated() { if (!container_) return false; @@ -2085,6 +2089,11 @@ PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { return &flash_impl_; } +::ppapi::thunk::PPB_Gamepad_API* PluginInstance::GetGamepadAPI( + PP_Instance /* instance */) { + return &gamepad_impl_; +} + int32_t PluginInstance::RequestInputEvents(PP_Instance instance, uint32_t event_classes) { input_event_mask_ |= event_classes; diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index 89c5be1..a136460 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -40,6 +40,7 @@ #include "ppapi/c/private/ppp_instance_private.h" #include "ppapi/shared_impl/ppb_instance_shared.h" #include "ppapi/shared_impl/ppb_view_shared.h" +#include "ppapi/thunk/ppb_gamepad_api.h" #include "ppapi/thunk/resource_creation_api.h" #include "ppapi/shared_impl/tracked_callback.h" #include "third_party/skia/include/core/SkRefCnt.h" @@ -320,10 +321,6 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : bool from_user_action); bool IsRectTopmost(const gfx::Rect& rect); - // Implementation of PPB_Gamepad. - void SampleGamepads(PP_Instance instance, PP_GamepadsSampleData* data) - OVERRIDE; - // Implementation of PPP_Messaging. void HandleMessage(PP_Var message); @@ -379,6 +376,8 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : virtual PP_Bool GetScreenSize(PP_Instance instance, PP_Size* size) OVERRIDE; virtual ::ppapi::thunk::PPB_Flash_API* GetFlashAPI() OVERRIDE; + virtual ::ppapi::thunk::PPB_Gamepad_API* GetGamepadAPI(PP_Instance instance) + OVERRIDE; virtual int32_t RequestInputEvents(PP_Instance instance, uint32_t event_classes) OVERRIDE; virtual int32_t RequestFilteringInputEvents(PP_Instance instance, @@ -462,6 +461,16 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : bool ResetAsProxied(); private: + // Implements PPB_Gamepad_API. This is just to avoid having an excessive + // number of interfaces implemented by PluginInstance. + class GamepadImpl : public ::ppapi::thunk::PPB_Gamepad_API { + public: + GamepadImpl(PluginDelegate* delegate); + virtual void Sample(PP_GamepadsSampleData* data) OVERRIDE; + private: + PluginDelegate* delegate_; + }; + // See the static Create functions above for creating PluginInstance objects. // This constructor is private so that we can hide the PPP_Instance_Combined // details while still having 1 constructor to maintain for member @@ -642,6 +651,8 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : std::vector<PP_PrintPageNumberRange_Dev> ranges_; #endif // OS_LINUX || OS_WIN + GamepadImpl gamepad_impl_; + // The plugin print interface. const PPP_Printing_Dev* plugin_print_interface_; |