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/renderer/pepper/pepper_device_enumeration_host_helper.h" | 5 #include "content/renderer/pepper/pepper_device_enumeration_host_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/host/dispatch_host_message.h" | 13 #include "ppapi/host/dispatch_host_message.h" |
14 #include "ppapi/host/host_message_context.h" | 14 #include "ppapi/host/host_message_context.h" |
15 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
16 #include "ppapi/host/resource_host.h" | 16 #include "ppapi/host/resource_host.h" |
17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
18 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | 18 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
19 | 19 |
20 using ppapi::host::HostMessageContext; | 20 using ppapi::host::HostMessageContext; |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
24 // Makes sure that StopEnumerateDevices() is called for each EnumerateDevices(). | 24 // Makes sure that StopEnumerateDevices() is called for each EnumerateDevices(). |
25 class PepperDeviceEnumerationHostHelper::ScopedRequest | 25 class PepperDeviceEnumerationHostHelper::ScopedRequest |
26 : public base::SupportsWeakPtr<ScopedRequest> { | 26 : public base::SupportsWeakPtr<ScopedRequest> { |
27 public: | 27 public: |
28 // |owner| must outlive this object. | 28 // |owner| must outlive this object. |
29 ScopedRequest( | 29 ScopedRequest(PepperDeviceEnumerationHostHelper* owner, |
30 PepperDeviceEnumerationHostHelper* owner, | 30 const Delegate::EnumerateDevicesCallback& callback) |
31 const Delegate::EnumerateDevicesCallback& callback) | |
32 : owner_(owner), | 31 : owner_(owner), |
33 callback_(callback), | 32 callback_(callback), |
34 requested_(false), | 33 requested_(false), |
35 request_id_(0), | 34 request_id_(0), |
36 sync_call_(false) { | 35 sync_call_(false) { |
37 if (!owner_->document_url_.is_valid()) | 36 if (!owner_->document_url_.is_valid()) |
38 return; | 37 return; |
39 | 38 |
40 requested_ = true; | 39 requested_ = true; |
41 | 40 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 }; | 90 }; |
92 | 91 |
93 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( | 92 PepperDeviceEnumerationHostHelper::PepperDeviceEnumerationHostHelper( |
94 ppapi::host::ResourceHost* resource_host, | 93 ppapi::host::ResourceHost* resource_host, |
95 Delegate* delegate, | 94 Delegate* delegate, |
96 PP_DeviceType_Dev device_type, | 95 PP_DeviceType_Dev device_type, |
97 const GURL& document_url) | 96 const GURL& document_url) |
98 : resource_host_(resource_host), | 97 : resource_host_(resource_host), |
99 delegate_(delegate), | 98 delegate_(delegate), |
100 device_type_(device_type), | 99 device_type_(device_type), |
101 document_url_(document_url) { | 100 document_url_(document_url) {} |
102 } | |
103 | 101 |
104 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() { | 102 PepperDeviceEnumerationHostHelper::~PepperDeviceEnumerationHostHelper() {} |
105 } | |
106 | 103 |
107 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( | 104 bool PepperDeviceEnumerationHostHelper::HandleResourceMessage( |
108 const IPC::Message& msg, | 105 const IPC::Message& msg, |
109 HostMessageContext* context, | 106 HostMessageContext* context, |
110 int32_t* result) { | 107 int32_t* result) { |
111 bool return_value = false; | 108 bool return_value = false; |
112 *result = InternalHandleResourceMessage(msg, context, &return_value); | 109 *result = InternalHandleResourceMessage(msg, context, &return_value); |
113 return return_value; | 110 return return_value; |
114 } | 111 } |
115 | 112 |
116 int32_t PepperDeviceEnumerationHostHelper::InternalHandleResourceMessage( | 113 int32_t PepperDeviceEnumerationHostHelper::InternalHandleResourceMessage( |
117 const IPC::Message& msg, | 114 const IPC::Message& msg, |
118 HostMessageContext* context, | 115 HostMessageContext* context, |
119 bool* handled) { | 116 bool* handled) { |
120 *handled = true; | 117 *handled = true; |
121 IPC_BEGIN_MESSAGE_MAP(PepperDeviceEnumerationHostHelper, msg) | 118 IPC_BEGIN_MESSAGE_MAP(PepperDeviceEnumerationHostHelper, msg) |
122 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 119 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
123 PpapiHostMsg_DeviceEnumeration_EnumerateDevices, OnEnumerateDevices) | 120 PpapiHostMsg_DeviceEnumeration_EnumerateDevices, OnEnumerateDevices) |
124 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 121 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
125 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange, | 122 PpapiHostMsg_DeviceEnumeration_MonitorDeviceChange, OnMonitorDeviceChange) |
126 OnMonitorDeviceChange) | 123 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
127 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 124 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, |
128 PpapiHostMsg_DeviceEnumeration_StopMonitoringDeviceChange, | 125 OnStopMonitoringDeviceChange) |
129 OnStopMonitoringDeviceChange) | |
130 IPC_END_MESSAGE_MAP() | 126 IPC_END_MESSAGE_MAP() |
131 | 127 |
132 *handled = false; | 128 *handled = false; |
133 return PP_ERROR_FAILED; | 129 return PP_ERROR_FAILED; |
134 } | 130 } |
135 | 131 |
136 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( | 132 int32_t PepperDeviceEnumerationHostHelper::OnEnumerateDevices( |
137 HostMessageContext* context) { | 133 HostMessageContext* context) { |
138 if (enumerate_devices_context_) | 134 if (enumerate_devices_context_) |
139 return PP_ERROR_INPROGRESS; | 135 return PP_ERROR_INPROGRESS; |
140 | 136 |
141 enumerate_.reset(new ScopedRequest( | 137 enumerate_.reset(new ScopedRequest( |
142 this, | 138 this, |
143 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, | 139 base::Bind(&PepperDeviceEnumerationHostHelper::OnEnumerateDevicesComplete, |
144 base::Unretained(this)))); | 140 base::Unretained(this)))); |
145 if (!enumerate_->requested()) | 141 if (!enumerate_->requested()) |
146 return PP_ERROR_FAILED; | 142 return PP_ERROR_FAILED; |
147 | 143 |
148 enumerate_devices_context_.reset( | 144 enumerate_devices_context_.reset( |
149 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext())); | 145 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext())); |
150 return PP_OK_COMPLETIONPENDING; | 146 return PP_OK_COMPLETIONPENDING; |
151 } | 147 } |
152 | 148 |
153 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( | 149 int32_t PepperDeviceEnumerationHostHelper::OnMonitorDeviceChange( |
154 HostMessageContext* /* context */, | 150 HostMessageContext* /* context */, |
155 uint32_t callback_id) { | 151 uint32_t callback_id) { |
156 monitor_.reset(new ScopedRequest( | 152 monitor_.reset(new ScopedRequest( |
157 this, | 153 this, |
158 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, | 154 base::Bind(&PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange, |
159 base::Unretained(this), callback_id))); | 155 base::Unretained(this), |
| 156 callback_id))); |
160 | 157 |
161 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; | 158 return monitor_->requested() ? PP_OK : PP_ERROR_FAILED; |
162 } | 159 } |
163 | 160 |
164 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( | 161 int32_t PepperDeviceEnumerationHostHelper::OnStopMonitoringDeviceChange( |
165 HostMessageContext* /* context */) { | 162 HostMessageContext* /* context */) { |
166 monitor_.reset(NULL); | 163 monitor_.reset(NULL); |
167 return PP_OK; | 164 return PP_OK; |
168 } | 165 } |
169 | 166 |
(...skipping 10 matching lines...) Expand all Loading... |
180 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); | 177 PpapiPluginMsg_DeviceEnumeration_EnumerateDevicesReply(devices)); |
181 enumerate_devices_context_.reset(); | 178 enumerate_devices_context_.reset(); |
182 } | 179 } |
183 | 180 |
184 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( | 181 void PepperDeviceEnumerationHostHelper::OnNotifyDeviceChange( |
185 uint32_t callback_id, | 182 uint32_t callback_id, |
186 int /* request_id */, | 183 int /* request_id */, |
187 const std::vector<ppapi::DeviceRefData>& devices) { | 184 const std::vector<ppapi::DeviceRefData>& devices) { |
188 resource_host_->host()->SendUnsolicitedReply( | 185 resource_host_->host()->SendUnsolicitedReply( |
189 resource_host_->pp_resource(), | 186 resource_host_->pp_resource(), |
190 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange( | 187 PpapiPluginMsg_DeviceEnumeration_NotifyDeviceChange(callback_id, |
191 callback_id, | 188 devices)); |
192 devices)); | |
193 } | 189 } |
194 | 190 |
195 } // namespace content | 191 } // namespace content |
OLD | NEW |