| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "modules/bluetooth/Bluetooth.h" | 5 #include "modules/bluetooth/Bluetooth.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
| 15 #include "modules/bluetooth/BluetoothDevice.h" | 15 #include "modules/bluetooth/BluetoothDevice.h" |
| 16 #include "modules/bluetooth/BluetoothError.h" | 16 #include "modules/bluetooth/BluetoothError.h" |
| 17 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" | 17 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
| 18 #include "modules/bluetooth/BluetoothUUID.h" | 18 #include "modules/bluetooth/BluetoothUUID.h" |
| 19 #include "modules/bluetooth/RequestDeviceOptions.h" | 19 #include "modules/bluetooth/RequestDeviceOptions.h" |
| 20 #include "platform/UserGestureIndicator.h" | 20 #include "platform/UserGestureIndicator.h" |
| 21 #include "public/platform/InterfaceProvider.h" | 21 #include "public/platform/InterfaceProvider.h" |
| 22 #include "public/platform/Platform.h" |
| 22 #include <memory> | 23 #include <memory> |
| 23 #include <utility> | 24 #include <utility> |
| 24 | 25 |
| 25 namespace blink { | 26 namespace blink { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 // Per the Bluetooth Spec: The name is a user-friendly name associated with the | 29 // Per the Bluetooth Spec: The name is a user-friendly name associated with the |
| 29 // device and consists of a maximum of 248 bytes coded according to the UTF-8 | 30 // device and consists of a maximum of 248 bytes coded according to the UTF-8 |
| 30 // standard. | 31 // standard. |
| 31 const size_t kMaxDeviceNameLength = 248; | 32 const size_t kMaxDeviceNameLength = 248; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 if (!UserGestureIndicator::consumeUserGesture()) { | 173 if (!UserGestureIndicator::consumeUserGesture()) { |
| 173 return ScriptPromise::rejectWithDOMException( | 174 return ScriptPromise::rejectWithDOMException( |
| 174 scriptState, | 175 scriptState, |
| 175 DOMException::create( | 176 DOMException::create( |
| 176 SecurityError, | 177 SecurityError, |
| 177 "Must be handling a user gesture to show a permission request.")); | 178 "Must be handling a user gesture to show a permission request.")); |
| 178 } | 179 } |
| 179 | 180 |
| 180 if (!m_service) { | 181 if (!m_service) { |
| 181 InterfaceProvider* interfaceProvider = nullptr; | 182 InterfaceProvider* interfaceProvider = nullptr; |
| 182 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 183 if (context->isDocument()) { |
| 183 if (executionContext->isDocument()) { | 184 Document* document = toDocument(context); |
| 184 Document* document = toDocument(executionContext); | |
| 185 if (document->frame()) | 185 if (document->frame()) |
| 186 interfaceProvider = document->frame()->interfaceProvider(); | 186 interfaceProvider = document->frame()->interfaceProvider(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (interfaceProvider) | 189 if (interfaceProvider) |
| 190 interfaceProvider->getInterface(mojo::MakeRequest(&m_service)); | 190 interfaceProvider->getInterface(mojo::MakeRequest(&m_service)); |
| 191 | 191 |
| 192 if (m_service) { | 192 if (m_service) { |
| 193 // Create an associated interface ptr and pass it to the | 193 // Create an associated interface ptr and pass it to the |
| 194 // WebBluetoothService so that it can send us events without us | 194 // WebBluetoothService so that it can send us events without us |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 // In order to convert the arguments from service names and aliases to just | 207 // In order to convert the arguments from service names and aliases to just |
| 208 // UUIDs, do the following substeps: | 208 // UUIDs, do the following substeps: |
| 209 auto deviceOptions = mojom::blink::WebBluetoothRequestDeviceOptions::New(); | 209 auto deviceOptions = mojom::blink::WebBluetoothRequestDeviceOptions::New(); |
| 210 convertRequestDeviceOptions(options, deviceOptions, exceptionState); | 210 convertRequestDeviceOptions(options, deviceOptions, exceptionState); |
| 211 | 211 |
| 212 if (exceptionState.hadException()) | 212 if (exceptionState.hadException()) |
| 213 return exceptionState.reject(scriptState); | 213 return exceptionState.reject(scriptState); |
| 214 | 214 |
| 215 // Record the eTLD+1 of the frame using the API. |
| 216 Document* document = toDocument(context); |
| 217 Platform::current()->recordRapporURL("Bluetooth.APIUsage.Origin", |
| 218 document->url()); |
| 219 |
| 215 // Subsequent steps are handled in the browser process. | 220 // Subsequent steps are handled in the browser process. |
| 216 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 221 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 217 ScriptPromise promise = resolver->promise(); | 222 ScriptPromise promise = resolver->promise(); |
| 218 | 223 |
| 219 service()->RequestDevice( | 224 service()->RequestDevice( |
| 220 std::move(deviceOptions), | 225 std::move(deviceOptions), |
| 221 convertToBaseCallback(WTF::bind(&Bluetooth::RequestDeviceCallback, | 226 convertToBaseCallback(WTF::bind(&Bluetooth::RequestDeviceCallback, |
| 222 wrapPersistent(this), | 227 wrapPersistent(this), |
| 223 wrapPersistent(resolver)))); | 228 wrapPersistent(resolver)))); |
| 224 return promise; | 229 return promise; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 BluetoothDevice* device = m_deviceInstanceMap.get(id); | 284 BluetoothDevice* device = m_deviceInstanceMap.get(id); |
| 280 if (!device) { | 285 if (!device) { |
| 281 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); | 286 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); |
| 282 auto result = m_deviceInstanceMap.add(id, device); | 287 auto result = m_deviceInstanceMap.add(id, device); |
| 283 DCHECK(result.isNewEntry); | 288 DCHECK(result.isNewEntry); |
| 284 } | 289 } |
| 285 return device; | 290 return device; |
| 286 } | 291 } |
| 287 | 292 |
| 288 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |