Index: content/browser/renderer_host/pepper/pepper_gamepad_host.cc |
diff --git a/content/browser/renderer_host/pepper/pepper_gamepad_host.cc b/content/browser/renderer_host/pepper/pepper_gamepad_host.cc |
index 0fd3c44d5aa83d1c53b0af3f62e05a826f090710..28f0195b7cd4b7693203eb78eb61c6c51097a1d7 100644 |
--- a/content/browser/renderer_host/pepper/pepper_gamepad_host.cc |
+++ b/content/browser/renderer_host/pepper/pepper_gamepad_host.cc |
@@ -4,9 +4,13 @@ |
#include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" |
+#include "base/bind.h" |
+#include "content/browser/gamepad/gamepad_service.h" |
#include "content/public/browser/browser_ppapi_host.h" |
#include "ppapi/c/pp_errors.h" |
#include "ppapi/host/dispatch_host_message.h" |
+#include "ppapi/host/host_message_context.h" |
+#include "ppapi/host/ppapi_host.h" |
#include "ppapi/proxy/ppapi_messages.h" |
namespace content { |
@@ -15,10 +19,26 @@ PepperGamepadHost::PepperGamepadHost(BrowserPpapiHost* host, |
PP_Instance instance, |
PP_Resource resource) |
: ResourceHost(host->GetPpapiHost(), instance, resource), |
- browser_ppapi_host_(host) { |
+ browser_ppapi_host_(host), |
+ gamepad_service_(GamepadService::GetInstance()), |
+ is_started_(false), |
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
+} |
+ |
+PepperGamepadHost::PepperGamepadHost(GamepadService* gamepad_service, |
+ BrowserPpapiHost* host, |
+ PP_Instance instance, |
+ PP_Resource resource) |
+ : ResourceHost(host->GetPpapiHost(), instance, resource), |
+ browser_ppapi_host_(host), |
+ gamepad_service_(gamepad_service), |
+ is_started_(false), |
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
} |
PepperGamepadHost::~PepperGamepadHost() { |
+ if (is_started_) |
+ gamepad_service_->RemoveConsumer(); |
} |
int32_t PepperGamepadHost::OnResourceMessageReceived( |
@@ -33,7 +53,28 @@ int32_t PepperGamepadHost::OnResourceMessageReceived( |
int32_t PepperGamepadHost::OnMsgRequestMemory( |
ppapi::host::HostMessageContext* context) { |
- return PP_ERROR_FAILED; |
+ if (is_started_) |
+ return PP_ERROR_FAILED; |
+ |
+ gamepad_service_->AddConsumer(); |
+ is_started_ = true; |
+ |
+ // Don't send the shared memory back until the user has interacted with the |
+ // gamepad. This is to prevent fingerprinting and matches what the web |
+ // platform does. |
+ gamepad_service_->RegisterForUserGesture( |
+ base::Bind(&PepperGamepadHost::GotUserGesture, |
+ weak_factory_.GetWeakPtr(), |
+ context->MakeReplyParams())); |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+void PepperGamepadHost::GotUserGesture( |
+ const ppapi::proxy::ResourceMessageReplyParams& params) { |
+ base::SharedMemoryHandle shm = |
raymes
2012/09/05 21:05:57
nit: variable naming. maybe just handle?
|
+ gamepad_service_->GetSharedMemoryHandleForProcess( |
+ browser_ppapi_host_->GetPluginProcessHandle()); |
+ host()->SendReply(params, PpapiPluginMsg_Gamepad_SendMemory(shm)); |
} |
} // namespace content |