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