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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 originTrials && originTrials->isFeatureEnabled("WebBluetooth"); | 169 originTrials && originTrials->isFeatureEnabled("WebBluetooth"); |
170 | 170 |
171 if (!originTrialActiveForThisPage && !promotedOriginTrial) { | 171 if (!originTrialActiveForThisPage && !promotedOriginTrial) { |
172 promotedOriginTrial = true; | 172 promotedOriginTrial = true; |
173 context->addConsoleMessage( | 173 context->addConsoleMessage( |
174 ConsoleMessage::create(JSMessageSource, InfoMessageLevel, | 174 ConsoleMessage::create(JSMessageSource, InfoMessageLevel, |
175 "Web Bluetooth is available as an Origin Trial: " | 175 "Web Bluetooth is available as an Origin Trial: " |
176 "https://bit.ly/WebBluetoothOriginTrial")); | 176 "https://bit.ly/WebBluetoothOriginTrial")); |
177 } | 177 } |
178 | 178 |
179 // 1. If the incumbent settings object is not a secure context, reject promise
with a SecurityError and abort these steps. | 179 // 1. If the incumbent settings object is not a secure context, reject promise |
| 180 // with a SecurityError and abort these steps. |
180 String errorMessage; | 181 String errorMessage; |
181 if (!context->isSecureContext(errorMessage)) { | 182 if (!context->isSecureContext(errorMessage)) { |
182 return ScriptPromise::rejectWithDOMException( | 183 return ScriptPromise::rejectWithDOMException( |
183 scriptState, DOMException::create(SecurityError, errorMessage)); | 184 scriptState, DOMException::create(SecurityError, errorMessage)); |
184 } | 185 } |
185 | 186 |
186 // 2. If the algorithm is not allowed to show a popup, reject promise with a S
ecurityError and abort these steps. | 187 // 2. If the algorithm is not allowed to show a popup, reject promise with a |
| 188 // SecurityError and abort these steps. |
187 if (!UserGestureIndicator::consumeUserGesture()) { | 189 if (!UserGestureIndicator::consumeUserGesture()) { |
188 return ScriptPromise::rejectWithDOMException( | 190 return ScriptPromise::rejectWithDOMException( |
189 scriptState, | 191 scriptState, |
190 DOMException::create( | 192 DOMException::create( |
191 SecurityError, | 193 SecurityError, |
192 "Must be handling a user gesture to show a permission request.")); | 194 "Must be handling a user gesture to show a permission request.")); |
193 } | 195 } |
194 | 196 |
195 WebBluetooth* webbluetooth = | 197 WebBluetooth* webbluetooth = |
196 BluetoothSupplement::fromScriptState(scriptState); | 198 BluetoothSupplement::fromScriptState(scriptState); |
197 if (!webbluetooth) | 199 if (!webbluetooth) |
198 return ScriptPromise::rejectWithDOMException( | 200 return ScriptPromise::rejectWithDOMException( |
199 scriptState, DOMException::create(NotSupportedError)); | 201 scriptState, DOMException::create(NotSupportedError)); |
200 | 202 |
201 // 3. In order to convert the arguments from service names and aliases to just
UUIDs, do the following substeps: | 203 // 3. In order to convert the arguments from service names and aliases to just |
| 204 // UUIDs, do the following substeps: |
202 WebRequestDeviceOptions webOptions; | 205 WebRequestDeviceOptions webOptions; |
203 convertRequestDeviceOptions(options, webOptions, exceptionState); | 206 convertRequestDeviceOptions(options, webOptions, exceptionState); |
204 if (exceptionState.hadException()) | 207 if (exceptionState.hadException()) |
205 return exceptionState.reject(scriptState); | 208 return exceptionState.reject(scriptState); |
206 | 209 |
207 // Subsequent steps are handled in the browser process. | 210 // Subsequent steps are handled in the browser process. |
208 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 211 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
209 ScriptPromise promise = resolver->promise(); | 212 ScriptPromise promise = resolver->promise(); |
210 webbluetooth->requestDevice( | 213 webbluetooth->requestDevice( |
211 webOptions, | 214 webOptions, |
212 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver)); | 215 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver)); |
213 return promise; | 216 return promise; |
214 } | 217 } |
215 | 218 |
216 } // namespace blink | 219 } // namespace blink |
OLD | NEW |