Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp

Issue 2080553002: bluetooth: Enable Web Bluetooth in Origin Trials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Rebase and fix bindings Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
iclelland 2016/06/24 18:36:32 nit: MacOS
ortuno 2016/06/24 19:16:33 I think it's macOS, like in iOS O_O. https://9to5m
iclelland 2016/06/24 19:46:35 Maybe --or Mac OS X, or MacOSX, or just 'OS X' ;)
ortuno 2016/06/27 20:22:42 Ah I guess we are not using the new name yet. I'll
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698