| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 return; | 122 return; |
| 123 optionalServices.append(validatedOptionalService); | 123 optionalServices.append(validatedOptionalService); |
| 124 } | 124 } |
| 125 result.optionalServices.assign(optionalServices); | 125 result.optionalServices.assign(optionalServices); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi
ce | 129 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi
ce |
| 130 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe
viceOptions& options, ExceptionState& exceptionState) | 130 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe
viceOptions& options, ExceptionState& exceptionState) |
| 131 { | 131 { |
| 132 // By adding the "OriginTrialEnabled" extended binding, we enable the | |
| 133 // requestDevice function on all platforms for whitelisted domains. Since we | |
| 134 // only support Chrome OS and Android for this experiment we reject any | |
| 135 // promises from other platforms unless they have the enable-web-bluetooth | |
| 136 // flag on. | |
| 137 #if !OS(CHROMEOS) && !OS(ANDROID) | |
| 138 if (!RuntimeEnabledFeatures::webBluetoothEnabled()) { | |
| 139 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")); | |
| 140 } | |
| 141 #endif | |
| 142 | |
| 143 // 1. If the incumbent settings object is not a secure context, reject promi
se with a SecurityError and abort these steps. | 132 // 1. If the incumbent settings object is not a secure context, reject promi
se with a SecurityError and abort these steps. |
| 144 String errorMessage; | 133 String errorMessage; |
| 145 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { | 134 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
| 146 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 135 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
| 147 } | 136 } |
| 148 | 137 |
| 149 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. | 138 // 2. If the algorithm is not allowed to show a popup, reject promise with a
SecurityError and abort these steps. |
| 150 if (!UserGestureIndicator::consumeUserGesture()) { | 139 if (!UserGestureIndicator::consumeUserGesture()) { |
| 151 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); | 140 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, "Must be handling a user gesture to show a permission requ
est.")); |
| 152 } | 141 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 163 | 152 |
| 164 // Subsequent steps are handled in the browser process. | 153 // Subsequent steps are handled in the browser process. |
| 165 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 154 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 166 ScriptPromise promise = resolver->promise(); | 155 ScriptPromise promise = resolver->promise(); |
| 167 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); | 156 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); |
| 168 return promise; | 157 return promise; |
| 169 | 158 |
| 170 } | 159 } |
| 171 | 160 |
| 172 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |