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 | 132 // TODO(https://crbug.com/584113) Enable Web Bluetooth Experiment. |
133 // requestDevice function on all platforms for whitelisted domains. Since we | 133 // Restore this logic when re-enabling the experiment: |
134 // only support Chrome OS and Android for this experiment we reject any | 134 // |
135 // promises from other platforms unless they have the enable-web-bluetooth | 135 // By adding the "OriginTrialEnabled" extended binding, we enable the |
136 // flag on. | 136 // requestDevice function on all platforms for whitelisted domains. Since we |
137 #if !OS(CHROMEOS) && !OS(ANDROID) | 137 // only support Chrome OS and Android for this experiment we reject any |
| 138 // promises from other platforms unless they have the enable-web-bluetooth |
| 139 // flag on. |
| 140 #if 0 // !OS(CHROMEOS) && !OS(ANDROID) |
138 if (!RuntimeEnabledFeatures::webBluetoothEnabled()) { | 141 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")); | 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")); |
140 } | 143 } |
141 #endif | 144 #endif |
142 | 145 |
143 // 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. |
144 String errorMessage; | 147 String errorMessage; |
145 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { | 148 if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) { |
146 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); | 149 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(SecurityError, errorMessage)); |
147 } | 150 } |
(...skipping 15 matching lines...) Expand all Loading... |
163 | 166 |
164 // Subsequent steps are handled in the browser process. | 167 // Subsequent steps are handled in the browser process. |
165 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
166 ScriptPromise promise = resolver->promise(); | 169 ScriptPromise promise = resolver->promise(); |
167 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); | 170 webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<Bluetooth
Device, BluetoothError>(resolver)); |
168 return promise; | 171 return promise; |
169 | 172 |
170 } | 173 } |
171 | 174 |
172 } // namespace blink | 175 } // namespace blink |
OLD | NEW |