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 "content/child/mojo/type_converters.h" |
7 #include "content/child/thread_safe_sender.h" | 8 #include "content/child/thread_safe_sender.h" |
| 9 #include "content/public/common/service_registry.h" |
8 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" | 10 #include "content/renderer/bluetooth/bluetooth_dispatcher.h" |
9 #include "ipc/ipc_message.h" | 11 #include "ipc/ipc_message.h" |
| 12 #include "mojo/public/cpp/bindings/array.h" |
10 | 13 |
11 namespace content { | 14 namespace content { |
12 | 15 |
13 WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender) | 16 WebBluetoothImpl::WebBluetoothImpl(ServiceRegistry* service_registry, |
14 : WebBluetoothImpl(thread_safe_sender, MSG_ROUTING_NONE) {} | 17 ThreadSafeSender* thread_safe_sender, |
15 | |
16 WebBluetoothImpl::WebBluetoothImpl(ThreadSafeSender* thread_safe_sender, | |
17 int frame_routing_id) | 18 int frame_routing_id) |
18 : thread_safe_sender_(thread_safe_sender), | 19 : service_registry_(service_registry), |
| 20 thread_safe_sender_(thread_safe_sender), |
19 frame_routing_id_(frame_routing_id) {} | 21 frame_routing_id_(frame_routing_id) {} |
20 | 22 |
21 WebBluetoothImpl::~WebBluetoothImpl() { | 23 WebBluetoothImpl::~WebBluetoothImpl() { |
22 } | 24 } |
23 | 25 |
24 void WebBluetoothImpl::requestDevice( | 26 void WebBluetoothImpl::requestDevice( |
25 const blink::WebRequestDeviceOptions& options, | 27 const blink::WebRequestDeviceOptions& options, |
26 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { | 28 blink::WebBluetoothRequestDeviceCallbacks* callbacks) { |
27 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); | 29 GetDispatcher()->requestDevice(frame_routing_id_, options, callbacks); |
28 } | 30 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const blink::WebString& characteristic_instance_id, | 67 const blink::WebString& characteristic_instance_id, |
66 blink::WebBluetoothReadValueCallbacks* callbacks) { | 68 blink::WebBluetoothReadValueCallbacks* callbacks) { |
67 GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id, | 69 GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id, |
68 callbacks); | 70 callbacks); |
69 } | 71 } |
70 | 72 |
71 void WebBluetoothImpl::writeValue( | 73 void WebBluetoothImpl::writeValue( |
72 const blink::WebString& characteristic_instance_id, | 74 const blink::WebString& characteristic_instance_id, |
73 const blink::WebVector<uint8_t>& value, | 75 const blink::WebVector<uint8_t>& value, |
74 blink::WebBluetoothWriteValueCallbacks* callbacks) { | 76 blink::WebBluetoothWriteValueCallbacks* callbacks) { |
75 GetDispatcher()->writeValue(frame_routing_id_, characteristic_instance_id, | 77 GetWebBluetoothService().RemoteCharacteristicWriteValue( |
76 value, callbacks); | 78 mojo::String::From(characteristic_instance_id), |
| 79 mojo::Array<uint8_t>::From(value), |
| 80 base::Bind(&WebBluetoothImpl::OnWriteValueComplete, |
| 81 base::Unretained(this), value, |
| 82 base::Passed(make_scoped_ptr(callbacks)))); |
77 } | 83 } |
78 | 84 |
79 void WebBluetoothImpl::startNotifications( | 85 void WebBluetoothImpl::startNotifications( |
80 const blink::WebString& characteristic_instance_id, | 86 const blink::WebString& characteristic_instance_id, |
81 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, | 87 blink::WebBluetoothRemoteGATTCharacteristic* characteristic, |
82 blink::WebBluetoothNotificationsCallbacks* callbacks) { | 88 blink::WebBluetoothNotificationsCallbacks* callbacks) { |
83 GetDispatcher()->startNotifications( | 89 GetDispatcher()->startNotifications( |
84 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); | 90 frame_routing_id_, characteristic_instance_id, characteristic, callbacks); |
85 } | 91 } |
86 | 92 |
(...skipping 12 matching lines...) Expand all Loading... |
99 frame_routing_id_, characteristic_instance_id, characteristic); | 105 frame_routing_id_, characteristic_instance_id, characteristic); |
100 } | 106 } |
101 | 107 |
102 void WebBluetoothImpl::registerCharacteristicObject( | 108 void WebBluetoothImpl::registerCharacteristicObject( |
103 const blink::WebString& characteristic_instance_id, | 109 const blink::WebString& characteristic_instance_id, |
104 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { | 110 blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { |
105 GetDispatcher()->registerCharacteristicObject( | 111 GetDispatcher()->registerCharacteristicObject( |
106 frame_routing_id_, characteristic_instance_id, characteristic); | 112 frame_routing_id_, characteristic_instance_id, characteristic); |
107 } | 113 } |
108 | 114 |
| 115 void WebBluetoothImpl::OnWriteValueComplete( |
| 116 const blink::WebVector<uint8_t>& value, |
| 117 scoped_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
| 118 blink::mojom::WebBluetoothError error) { |
| 119 if (error == blink::mojom::WebBluetoothError::SUCCESS) { |
| 120 callbacks->onSuccess(value); |
| 121 } else { |
| 122 callbacks->onError(error); |
| 123 } |
| 124 } |
| 125 |
109 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { | 126 BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |
110 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( | 127 return BluetoothDispatcher::GetOrCreateThreadSpecificInstance( |
111 thread_safe_sender_.get()); | 128 thread_safe_sender_.get()); |
112 } | 129 } |
113 | 130 |
| 131 blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { |
| 132 if (!web_bluetooth_service_) { |
| 133 service_registry_->ConnectToRemoteService( |
| 134 mojo::GetProxy(&web_bluetooth_service_)); |
| 135 } |
| 136 return *web_bluetooth_service_; |
| 137 } |
| 138 |
114 } // namespace content | 139 } // namespace content |
OLD | NEW |