OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/bluetooth/web_bluetooth_service_impl.h" | 5 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" |
6 | 6 |
7 #include "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "content/browser/bluetooth/bluetooth_blacklist.h" | 8 #include "content/browser/bluetooth/bluetooth_blacklist.h" |
9 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" | 9 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 characteristic_instance_id, mojo::Array<uint8_t>(std::move(value))); | 126 characteristic_instance_id, mojo::Array<uint8_t>(std::move(value))); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 void WebBluetoothServiceImpl::SetClient( | 130 void WebBluetoothServiceImpl::SetClient( |
131 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { | 131 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { |
132 DCHECK(!client_.get()); | 132 DCHECK(!client_.get()); |
133 client_.Bind(std::move(client)); | 133 client_.Bind(std::move(client)); |
134 } | 134 } |
135 | 135 |
136 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | |
137 const mojo::String& characteristic_instance_id, | |
138 const RemoteCharacteristicReadValueCallback& callback) { | |
139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
140 RecordWebBluetoothFunctionCall( | |
141 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | |
142 | |
143 const CacheQueryResult query_result = | |
144 GetBluetoothDispatcherHost()->QueryCacheForCharacteristic( | |
145 GetOrigin(), characteristic_instance_id); | |
146 | |
147 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | |
148 return; | |
149 } | |
150 | |
151 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | |
152 RecordCharacteristicReadValueOutcome(query_result.outcome); | |
153 callback.Run(query_result.GetWebError(), nullptr /* value */); | |
154 return; | |
155 } | |
156 | |
157 if (BluetoothBlacklist::Get().IsExcludedFromReads( | |
158 query_result.characteristic->GetUUID())) { | |
159 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | |
160 callback.Run(blink::mojom::WebBluetoothError::BLACKLISTED_READ, | |
161 nullptr /* value */); | |
162 return; | |
163 } | |
164 | |
165 query_result.characteristic->ReadRemoteCharacteristic( | |
166 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | |
167 weak_ptr_factory_.GetWeakPtr(), callback), | |
168 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | |
169 weak_ptr_factory_.GetWeakPtr(), callback)); | |
170 } | |
171 | |
136 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( | 172 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( |
137 const mojo::String& characteristic_instance_id, | 173 const mojo::String& characteristic_instance_id, |
138 mojo::Array<uint8_t> value, | 174 mojo::Array<uint8_t> value, |
139 const RemoteCharacteristicWriteValueCallback& callback) { | 175 const RemoteCharacteristicWriteValueCallback& callback) { |
140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 176 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
141 RecordWebBluetoothFunctionCall( | 177 RecordWebBluetoothFunctionCall( |
142 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); | 178 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); |
143 | 179 |
144 // We perform the length check on the renderer side. So if we | 180 // We perform the length check on the renderer side. So if we |
145 // get a value with length > 512, we can assume it's a hostile | 181 // get a value with length > 512, we can assume it's a hostile |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 // If the frame hasn't subscribed to notifications before we just | 285 // If the frame hasn't subscribed to notifications before we just |
250 // run the callback. | 286 // run the callback. |
251 callback.Run(); | 287 callback.Run(); |
252 return; | 288 return; |
253 } | 289 } |
254 notify_session_iter->second->Stop(base::Bind( | 290 notify_session_iter->second->Stop(base::Bind( |
255 &WebBluetoothServiceImpl::OnStopNotifySessionComplete, | 291 &WebBluetoothServiceImpl::OnStopNotifySessionComplete, |
256 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); | 292 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); |
257 } | 293 } |
258 | 294 |
295 void WebBluetoothServiceImpl::OnReadValueSuccess( | |
296 const RemoteCharacteristicReadValueCallback& callback, | |
297 const std::vector<uint8_t>& value) { | |
298 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
299 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); | |
300 callback.Run(blink::mojom::WebBluetoothError::SUCCESS, | |
301 mojo::Array<uint8_t>::From(value)); | |
Jeffrey Yasskin
2016/04/15 20:59:35
Do the by-value and move thing again here. (The ca
ortuno
2016/04/15 21:34:07
I tried but OnReadValueSuccess needs to be a Value
Jeffrey Yasskin
2016/04/15 21:38:52
That's a good reason. We should eventually fix tha
| |
302 } | |
303 | |
304 void WebBluetoothServiceImpl::OnReadValueFailed( | |
305 const RemoteCharacteristicReadValueCallback& callback, | |
306 device::BluetoothGattService::GattErrorCode error_code) { | |
307 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
308 callback.Run(TranslateGATTErrorAndRecord( | |
309 error_code, UMAGATTOperation::CHARACTERISTIC_READ), | |
310 nullptr /* value */); | |
311 } | |
312 | |
259 void WebBluetoothServiceImpl::OnWriteValueSuccess( | 313 void WebBluetoothServiceImpl::OnWriteValueSuccess( |
260 const RemoteCharacteristicWriteValueCallback& callback) { | 314 const RemoteCharacteristicWriteValueCallback& callback) { |
261 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 315 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
262 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 316 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
263 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 317 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); |
264 } | 318 } |
265 | 319 |
266 void WebBluetoothServiceImpl::OnWriteValueFailed( | 320 void WebBluetoothServiceImpl::OnWriteValueFailed( |
267 const RemoteCharacteristicWriteValueCallback& callback, | 321 const RemoteCharacteristicWriteValueCallback& callback, |
268 device::BluetoothGattService::GattErrorCode error_code) { | 322 device::BluetoothGattService::GattErrorCode error_code) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 bad_message::BadMessageReason reason) { | 368 bad_message::BadMessageReason reason) { |
315 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); | 369 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); |
316 binding_.Close(); | 370 binding_.Close(); |
317 } | 371 } |
318 | 372 |
319 url::Origin WebBluetoothServiceImpl::GetOrigin() { | 373 url::Origin WebBluetoothServiceImpl::GetOrigin() { |
320 return render_frame_host_->GetLastCommittedOrigin(); | 374 return render_frame_host_->GetLastCommittedOrigin(); |
321 } | 375 } |
322 | 376 |
323 } // namespace content | 377 } // namespace content |
OLD | NEW |