| 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" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // promises from other platforms unless they have the enable-web-bluetooth | 138 // promises from other platforms unless they have the enable-web-bluetooth |
| 139 // flag on. | 139 // flag on. |
| 140 #if 0 // !OS(CHROMEOS) && !OS(ANDROID) | 140 #if 0 // !OS(CHROMEOS) && !OS(ANDROID) |
| 141 if (!RuntimeEnabledFeatures::webBluetoothEnabled()) { | 141 if (!RuntimeEnabledFeatures::webBluetoothEnabled()) { |
| 142 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "Web Bluetooth is not enabled on this platform. To fin
d out how to enable it and the current implementation status visit https://goo.g
l/HKa2If")); | 142 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError, "Web Bluetooth is not enabled on this platform. To fin
d out how to enable it and the current implementation status visit https://goo.g
l/HKa2If")); |
| 143 } | 143 } |
| 144 #endif | 144 #endif |
| 145 | 145 |
| 146 // 1. If the incumbent settings object is not a secure context, reject promi
se with a SecurityError and abort these steps. | 146 // 1. If the incumbent settings object is not a secure context, reject promi
se with a SecurityError and abort these steps. |
| 147 String errorMessage; | 147 String errorMessage; |
| 148 if (!scriptState->executionContext()->isSecureContext(errorMessage)) { | 148 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
| 149 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 149 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. | 152 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. |
| 153 if (!UserGestureIndicator::consumeUserGesture()) { | 153 if (!UserGestureIndicator::consumeUserGesture()) { |
| 154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); | 154 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); |
| 155 } | 155 } |
| 156 | 156 |
| 157 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); | 157 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); |
| 158 if (!webbluetooth) | 158 if (!webbluetooth) |
| 159 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 159 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
| 160 | 160 |
| 161 // 3. In order to convert the arguments from service names and aliases to ju
st UUIDs, do the following substeps: | 161 // 3. In order to convert the arguments from service names and aliases to ju
st UUIDs, do the following substeps: |
| 162 WebRequestDeviceOptions webOptions; | 162 WebRequestDeviceOptions webOptions; |
| 163 convertRequestDeviceOptions(options, webOptions, exceptionState); | 163 convertRequestDeviceOptions(options, webOptions, exceptionState); |
| 164 if (exceptionState.hadException()) | 164 if (exceptionState.hadException()) |
| 165 return exceptionState.reject(scriptState); | 165 return exceptionState.reject(scriptState); |
| 166 | 166 |
| 167 // Subsequent steps are handled in the browser process. | 167 // Subsequent steps are handled in the browser process. |
| 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 169 ScriptPromise promise = resolver->promise(); | 169 ScriptPromise promise = resolver->promise(); |
| 170 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); | 170 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); |
| 171 return promise; | 171 return promise; |
| 172 | 172 |
| 173 } | 173 } |
| 174 | 174 |
| 175 } // namespace blink | 175 } // namespace blink |
| OLD | NEW |