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

Unified Diff: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp

Issue 2215073002: bluetooth: Suggest Origin Trial in console. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/Bluetooth.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp b/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp
index d7cbeecba4ab21e41d182cc596b400430dc70a03..912ea0ed9ed1ac63056c67ab12733b43a411a2b9 100644
--- a/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp
@@ -9,6 +9,9 @@
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"
+#include "core/inspector/ConsoleMessage.h"
+#include "core/origin_trials/OriginTrialContext.h"
+#include "core/origin_trials/OriginTrials.h"
#include "modules/bluetooth/BluetoothDevice.h"
#include "modules/bluetooth/BluetoothError.h"
#include "modules/bluetooth/BluetoothSupplement.h"
@@ -130,7 +133,6 @@ static void convertRequestDeviceOptions(const RequestDeviceOptions& options, Web
// https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevice
ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDeviceOptions& options, ExceptionState& exceptionState)
{
-
// By adding the "OriginTrialEnabled" extended binding, we enable the
// requestDevice function on all platforms for websites that contain an
// origin trial token. Since we only support Chrome OS, Android and MacOS
@@ -142,9 +144,24 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDe
}
#endif
+ // Promote use of Origin Trials
+ // * When not being run on an origin trial.
+ // * Only once for the lifetime of this Bluetooth object, to avoid being
+ // a nuisance and too verbose in the console. Reloading a page will reset
+ // and the message can be shown again.
+ ExecutionContext* context = scriptState->getExecutionContext();
+ OriginTrialContext* originTrials = OriginTrialContext::from(context, OriginTrialContext::DontCreateIfNotExists);
+ bool originTrialActiveForThisPage = originTrials && originTrials->isFeatureEnabled("WebBluetooth");
+
+ if (!originTrialActiveForThisPage && !promotedOriginTrial) {
+ promotedOriginTrial = true;
+ context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, InfoMessageLevel,
+ "Web Bluetooth is available as an Origin Trial: https://bit.ly/WebBluetoothOriginTrial"));
+ }
+
// 1. If the incumbent settings object is not a secure context, reject promise with a SecurityError and abort these steps.
String errorMessage;
- if (!scriptState->getExecutionContext()->isSecureContext(errorMessage)) {
+ if (!context->isSecureContext(errorMessage)) {
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, errorMessage));
}
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/Bluetooth.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698