OLD | NEW |
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/public/browser/browser_ppapi_host.h" | 8 #include "content/public/browser/browser_ppapi_host.h" |
9 #include "device/gamepad/gamepad_service.h" | 9 #include "device/gamepad/gamepad_service.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/host/dispatch_host_message.h" | 11 #include "ppapi/host/dispatch_host_message.h" |
12 #include "ppapi/host/host_message_context.h" | 12 #include "ppapi/host/host_message_context.h" |
13 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 14 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/shared_impl/ppb_gamepad_shared.h" | 15 #include "ppapi/shared_impl/ppb_gamepad_shared.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 PepperGamepadHost::PepperGamepadHost(BrowserPpapiHost* host, | 19 PepperGamepadHost::PepperGamepadHost(BrowserPpapiHost* host, |
20 PP_Instance instance, | 20 PP_Instance instance, |
21 PP_Resource resource) | 21 PP_Resource resource) |
22 : ResourceHost(host->GetPpapiHost(), instance, resource), | 22 : ResourceHost(host->GetPpapiHost(), instance, resource), |
23 browser_ppapi_host_(host), | |
24 gamepad_service_(device::GamepadService::GetInstance()), | 23 gamepad_service_(device::GamepadService::GetInstance()), |
25 is_started_(false), | 24 is_started_(false), |
26 weak_factory_(this) {} | 25 weak_factory_(this) {} |
27 | 26 |
28 PepperGamepadHost::PepperGamepadHost(device::GamepadService* gamepad_service, | 27 PepperGamepadHost::PepperGamepadHost(device::GamepadService* gamepad_service, |
29 BrowserPpapiHost* host, | 28 BrowserPpapiHost* host, |
30 PP_Instance instance, | 29 PP_Instance instance, |
31 PP_Resource resource) | 30 PP_Resource resource) |
32 : ResourceHost(host->GetPpapiHost(), instance, resource), | 31 : ResourceHost(host->GetPpapiHost(), instance, resource), |
33 browser_ppapi_host_(host), | |
34 gamepad_service_(gamepad_service), | 32 gamepad_service_(gamepad_service), |
35 is_started_(false), | 33 is_started_(false), |
36 weak_factory_(this) {} | 34 weak_factory_(this) {} |
37 | 35 |
38 PepperGamepadHost::~PepperGamepadHost() { | 36 PepperGamepadHost::~PepperGamepadHost() { |
39 if (is_started_) | 37 if (is_started_) |
40 gamepad_service_->RemoveConsumer(this); | 38 gamepad_service_->RemoveConsumer(this); |
41 } | 39 } |
42 | 40 |
43 int32_t PepperGamepadHost::OnResourceMessageReceived( | 41 int32_t PepperGamepadHost::OnResourceMessageReceived( |
(...skipping 20 matching lines...) Expand all Loading... |
64 gamepad_service_->RegisterForUserGesture( | 62 gamepad_service_->RegisterForUserGesture( |
65 base::Bind(&PepperGamepadHost::GotUserGesture, | 63 base::Bind(&PepperGamepadHost::GotUserGesture, |
66 weak_factory_.GetWeakPtr(), | 64 weak_factory_.GetWeakPtr(), |
67 context->MakeReplyMessageContext())); | 65 context->MakeReplyMessageContext())); |
68 return PP_OK_COMPLETIONPENDING; | 66 return PP_OK_COMPLETIONPENDING; |
69 } | 67 } |
70 | 68 |
71 void PepperGamepadHost::GotUserGesture( | 69 void PepperGamepadHost::GotUserGesture( |
72 const ppapi::host::ReplyMessageContext& context) { | 70 const ppapi::host::ReplyMessageContext& context) { |
73 base::SharedMemoryHandle handle = | 71 base::SharedMemoryHandle handle = |
74 gamepad_service_->GetSharedMemoryHandleForProcess( | 72 gamepad_service_->DuplicateSharedMemoryHandle(); |
75 browser_ppapi_host_->GetPluginProcess().Handle()); | |
76 | 73 |
77 context.params.AppendHandle(ppapi::proxy::SerializedHandle( | 74 context.params.AppendHandle(ppapi::proxy::SerializedHandle( |
78 handle, sizeof(ppapi::ContentGamepadHardwareBuffer))); | 75 handle, sizeof(ppapi::ContentGamepadHardwareBuffer))); |
79 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory()); | 76 host()->SendReply(context, PpapiPluginMsg_Gamepad_SendMemory()); |
80 } | 77 } |
81 | 78 |
82 } // namespace content | 79 } // namespace content |
OLD | NEW |