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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_gamepad_host.cc

Issue 200873002: Gamepad API: add support for connection events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h" 5 #include "content/browser/renderer_host/pepper/pepper_gamepad_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/gamepad/gamepad_service.h" 8 #include "content/browser/gamepad/gamepad_service.h"
9 #include "content/public/browser/browser_ppapi_host.h" 9 #include "content/public/browser/browser_ppapi_host.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 21 matching lines...) Expand all
32 PP_Resource resource) 32 PP_Resource resource)
33 : ResourceHost(host->GetPpapiHost(), instance, resource), 33 : ResourceHost(host->GetPpapiHost(), instance, resource),
34 browser_ppapi_host_(host), 34 browser_ppapi_host_(host),
35 gamepad_service_(gamepad_service), 35 gamepad_service_(gamepad_service),
36 is_started_(false), 36 is_started_(false),
37 weak_factory_(this) { 37 weak_factory_(this) {
38 } 38 }
39 39
40 PepperGamepadHost::~PepperGamepadHost() { 40 PepperGamepadHost::~PepperGamepadHost() {
41 if (is_started_) 41 if (is_started_)
42 gamepad_service_->RemoveConsumer(); 42 gamepad_service_->RemoveConsumer(this);
43 } 43 }
44 44
45 int32_t PepperGamepadHost::OnResourceMessageReceived( 45 int32_t PepperGamepadHost::OnResourceMessageReceived(
46 const IPC::Message& msg, 46 const IPC::Message& msg,
47 ppapi::host::HostMessageContext* context) { 47 ppapi::host::HostMessageContext* context) {
48 IPC_BEGIN_MESSAGE_MAP(PepperGamepadHost, msg) 48 IPC_BEGIN_MESSAGE_MAP(PepperGamepadHost, msg)
49 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Gamepad_RequestMemory, 49 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Gamepad_RequestMemory,
50 OnRequestMemory) 50 OnRequestMemory)
51 IPC_END_MESSAGE_MAP() 51 IPC_END_MESSAGE_MAP()
52 return PP_ERROR_FAILED; 52 return PP_ERROR_FAILED;
53 } 53 }
54 54
55 int32_t PepperGamepadHost::OnRequestMemory( 55 int32_t PepperGamepadHost::OnRequestMemory(
56 ppapi::host::HostMessageContext* context) { 56 ppapi::host::HostMessageContext* context) {
57 if (is_started_) 57 if (is_started_)
58 return PP_ERROR_FAILED; 58 return PP_ERROR_FAILED;
59 59
60 gamepad_service_->AddConsumer(); 60 gamepad_service_->AddConsumer(this);
61 is_started_ = true; 61 is_started_ = true;
62 62
63 // Don't send the shared memory back until the user has interacted with the 63 // Don't send the shared memory back until the user has interacted with the
64 // gamepad. This is to prevent fingerprinting and matches what the web 64 // gamepad. This is to prevent fingerprinting and matches what the web
65 // platform does. 65 // platform does.
66 gamepad_service_->RegisterForUserGesture( 66 gamepad_service_->RegisterForUserGesture(
67 base::Bind(&PepperGamepadHost::GotUserGesture, 67 base::Bind(&PepperGamepadHost::GotUserGesture,
68 weak_factory_.GetWeakPtr(), 68 weak_factory_.GetWeakPtr(),
69 context->MakeReplyMessageContext())); 69 context->MakeReplyMessageContext()));
70 return PP_OK_COMPLETIONPENDING; 70 return PP_OK_COMPLETIONPENDING;
71 } 71 }
72 72
73 void PepperGamepadHost::GotUserGesture( 73 void PepperGamepadHost::GotUserGesture(
74 const ppapi::host::ReplyMessageContext& context) { 74 const ppapi::host::ReplyMessageContext& context) {
75 base::SharedMemoryHandle handle = 75 base::SharedMemoryHandle handle =
76 gamepad_service_->GetSharedMemoryHandleForProcess( 76 gamepad_service_->GetSharedMemoryHandleForProcess(
77 browser_ppapi_host_->GetPluginProcessHandle()); 77 browser_ppapi_host_->GetPluginProcessHandle());
78 78
79 context.params.AppendHandle(ppapi::proxy::SerializedHandle( 79 context.params.AppendHandle(ppapi::proxy::SerializedHandle(
80 handle, sizeof(ppapi::ContentGamepadHardwareBuffer))); 80 handle, sizeof(ppapi::ContentGamepadHardwareBuffer)));
81 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory()); 81 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory());
82 } 82 }
83 83
84 } // namespace content 84 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/pepper/pepper_gamepad_host.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698