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

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

Issue 2437943002: Ship WebBluetooth out of origin trial (Closed)
Patch Set: address more comments Created 4 years, 1 month 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"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/inspector/ConsoleMessage.h"
13 #include "core/origin_trials/OriginTrialContext.h"
14 #include "core/origin_trials/OriginTrials.h"
15 #include "modules/bluetooth/BluetoothDevice.h" 12 #include "modules/bluetooth/BluetoothDevice.h"
16 #include "modules/bluetooth/BluetoothError.h" 13 #include "modules/bluetooth/BluetoothError.h"
17 #include "modules/bluetooth/BluetoothSupplement.h" 14 #include "modules/bluetooth/BluetoothSupplement.h"
18 #include "modules/bluetooth/BluetoothUUID.h" 15 #include "modules/bluetooth/BluetoothUUID.h"
19 #include "modules/bluetooth/RequestDeviceOptions.h" 16 #include "modules/bluetooth/RequestDeviceOptions.h"
20 #include "platform/RuntimeEnabledFeatures.h"
21 #include "platform/UserGestureIndicator.h" 17 #include "platform/UserGestureIndicator.h"
22 #include "public/platform/modules/bluetooth/WebBluetooth.h" 18 #include "public/platform/modules/bluetooth/WebBluetooth.h"
23 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h" 19 #include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h"
24 20
25 namespace blink { 21 namespace blink {
26 22
27 namespace { 23 namespace {
28 // A device name can never be longer than 29 bytes. A adv packet is at most 24 // A device name can never be longer than 29 bytes. A adv packet is at most
29 // 31 bytes long. The length and identifier of the length field take 2 bytes. 25 // 31 bytes long. The length and identifier of the length field take 2 bytes.
30 // That least 29 bytes for the name. 26 // That least 29 bytes for the name.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 optionalServices.append(validatedOptionalService); 130 optionalServices.append(validatedOptionalService);
135 } 131 }
136 result.optionalServices.assign(optionalServices); 132 result.optionalServices.assign(optionalServices);
137 } 133 }
138 } 134 }
139 135
140 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi ce 136 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevi ce
141 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, 137 ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState,
142 const RequestDeviceOptions& options, 138 const RequestDeviceOptions& options,
143 ExceptionState& exceptionState) { 139 ExceptionState& exceptionState) {
144 // By adding the "OriginTrialEnabled" extended binding, we enable the
145 // requestDevice function on all platforms for websites that contain an
146 // origin trial token. Since we only support Chrome OS, Android and MacOS
147 // for this experiment we reject any promises from other platforms unless
148 // they have the enable-web-bluetooth flag on.
149 #if !OS(CHROMEOS) && !OS(ANDROID) && !OS(MACOSX)
150 if (!RuntimeEnabledFeatures::webBluetoothEnabled()) {
151 return ScriptPromise::rejectWithDOMException(
152 scriptState, DOMException::create(
153 NotSupportedError,
154 "Web Bluetooth is not enabled on this platform. To "
155 "find out how to enable it and the current "
156 "implementation status visit https://goo.gl/HKa2If"));
157 }
158 #endif
159
160 // Promote use of Origin Trials
161 // * When not being run on an origin trial.
162 // * Only once for the lifetime of this Bluetooth object, to avoid being
163 // a nuisance and too verbose in the console. Reloading a page will reset
164 // and the message can be shown again.
165 ExecutionContext* context = scriptState->getExecutionContext(); 140 ExecutionContext* context = scriptState->getExecutionContext();
166 OriginTrialContext* originTrials = OriginTrialContext::from(
167 context, OriginTrialContext::DontCreateIfNotExists);
168 bool originTrialActiveForThisPage =
169 originTrials && originTrials->isTrialEnabled("WebBluetooth");
170
171 if (!originTrialActiveForThisPage && !promotedOriginTrial) {
172 promotedOriginTrial = true;
173 context->addConsoleMessage(
174 ConsoleMessage::create(JSMessageSource, InfoMessageLevel,
175 "Web Bluetooth is available as an Origin Trial: "
176 "https://bit.ly/WebBluetoothOriginTrial"));
177 }
178 141
179 // 1. If the incumbent settings object is not a secure context, reject promise 142 // 1. If the incumbent settings object is not a secure context, reject promise
180 // with a SecurityError and abort these steps. 143 // with a SecurityError and abort these steps.
181 String errorMessage; 144 String errorMessage;
182 if (!context->isSecureContext(errorMessage)) { 145 if (!context->isSecureContext(errorMessage)) {
183 return ScriptPromise::rejectWithDOMException( 146 return ScriptPromise::rejectWithDOMException(
184 scriptState, DOMException::create(SecurityError, errorMessage)); 147 scriptState, DOMException::create(SecurityError, errorMessage));
185 } 148 }
186 149
187 // 2. If the algorithm is not allowed to show a popup, reject promise with a 150 // 2. If the algorithm is not allowed to show a popup, reject promise with a
(...skipping 22 matching lines...) Expand all
210 // Subsequent steps are handled in the browser process. 173 // Subsequent steps are handled in the browser process.
211 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); 174 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
212 ScriptPromise promise = resolver->promise(); 175 ScriptPromise promise = resolver->promise();
213 webbluetooth->requestDevice( 176 webbluetooth->requestDevice(
214 webOptions, 177 webOptions,
215 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver)); 178 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver));
216 return promise; 179 return promise;
217 } 180 }
218 181
219 } // namespace blink 182 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/Bluetooth.h ('k') | third_party/WebKit/Source/modules/bluetooth/Bluetooth.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698