OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bluetooth/web_bluetooth_impl.h" | 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/optional.h" | 12 #include "base/optional.h" |
13 #include "content/child/mojo/type_converters.h" | 13 #include "content/child/mojo/type_converters.h" |
14 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
15 #include "content/public/common/service_registry.h" | |
16 #include "content/renderer/bluetooth/bluetooth_type_converters.h" | 15 #include "content/renderer/bluetooth/bluetooth_type_converters.h" |
17 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" |
18 #include "mojo/public/cpp/bindings/array.h" | 17 #include "mojo/public/cpp/bindings/array.h" |
| 18 #include "services/shell/public/cpp/interface_provider.h" |
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" | 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" |
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" | 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" |
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" | 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" |
22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" |
23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" | 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" |
24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" | 24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry) | 28 WebBluetoothImpl::WebBluetoothImpl(shell::InterfaceProvider* remote_interfaces) |
29 : service_registry_(service_registry), binding_(this) {} | 29 : remote_interfaces_(remote_interfaces), binding_(this) {} |
30 | 30 |
31 WebBluetoothImpl::~WebBluetoothImpl() { | 31 WebBluetoothImpl::~WebBluetoothImpl() { |
32 } | 32 } |
33 | 33 |
34 void WebBluetoothImpl::requestDevice( | 34 void WebBluetoothImpl::requestDevice( |
35 const blink::WebRequestDeviceOptions& options, | 35 const blink::WebRequestDeviceOptions& options, |
36 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 36 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
37 GetWebBluetoothService().RequestDevice( | 37 GetWebBluetoothService().RequestDevice( |
38 blink::mojom::WebBluetoothRequestDeviceOptions::From(options), | 38 blink::mojom::WebBluetoothRequestDeviceOptions::From(options), |
39 base::Bind(&WebBluetoothImpl::OnRequestDeviceComplete, | 39 base::Bind(&WebBluetoothImpl::OnRequestDeviceComplete, |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 const std::string& characteristic_instance_id, | 291 const std::string& characteristic_instance_id, |
292 const std::vector<uint8_t>& value) { | 292 const std::vector<uint8_t>& value) { |
293 auto active_iter = active_characteristics_.find(characteristic_instance_id); | 293 auto active_iter = active_characteristics_.find(characteristic_instance_id); |
294 if (active_iter != active_characteristics_.end()) { | 294 if (active_iter != active_characteristics_.end()) { |
295 active_iter->second->dispatchCharacteristicValueChanged(value); | 295 active_iter->second->dispatchCharacteristicValueChanged(value); |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { | 299 blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { |
300 if (!web_bluetooth_service_) { | 300 if (!web_bluetooth_service_) { |
301 service_registry_->ConnectToRemoteService( | 301 remote_interfaces_->GetInterface(mojo::GetProxy(&web_bluetooth_service_)); |
302 mojo::GetProxy(&web_bluetooth_service_)); | |
303 // Create an associated interface ptr and pass it to the WebBluetoothService | 302 // Create an associated interface ptr and pass it to the WebBluetoothService |
304 // so that it can send us events without us prompting. | 303 // so that it can send us events without us prompting. |
305 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 304 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
306 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 305 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
307 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 306 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
308 } | 307 } |
309 return *web_bluetooth_service_; | 308 return *web_bluetooth_service_; |
310 } | 309 } |
311 | 310 |
312 } // namespace content | 311 } // namespace content |
OLD | NEW |