Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Unified Diff: content/browser/renderer_host/pepper/pepper_gamepad_host.cc

Issue 10912062: Implement the gamepad API in the IPC proxy (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a3cd89011d69436f2c87bd82b3efbac041fc4f28 100644
--- a/content/browser/renderer_host/pepper/pepper_gamepad_host.cc
+++ b/content/browser/renderer_host/pepper/pepper_gamepad_host.cc
@@ -4,10 +4,15 @@
#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"
+#include "ppapi/shared_impl/ppb_gamepad_shared.h"
namespace content {
@@ -15,10 +20,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 +54,34 @@ 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& in_params) {
+ base::SharedMemoryHandle handle =
+ gamepad_service_->GetSharedMemoryHandleForProcess(
+ browser_ppapi_host_->GetPluginProcessHandle());
+
+ // The shared memory handle is sent in the params struct, so we have to make
+ // a copy to mutate it.
+ ppapi::proxy::ResourceMessageReplyParams params = in_params;
+ params.AppendHandle(ppapi::proxy::SerializedHandle(
+ handle, sizeof(ppapi::ContentGamepadHardwareBuffer)));
+ host()->SendReply(params, PpapiPluginMsg_Gamepad_SendMemory());
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698