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

Unified Diff: third_party/WebKit/Source/modules/webusb/USB.cpp

Issue 1419213006: Require secure contexts and user gestures to use WebUSB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | 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/webusb/USB.cpp
diff --git a/third_party/WebKit/Source/modules/webusb/USB.cpp b/third_party/WebKit/Source/modules/webusb/USB.cpp
index 213b3aafac20515ab5b5c62d925ec6fb1ae8b177..af7db9038a6d486143eafd36824f0cacad61da16 100644
--- a/third_party/WebKit/Source/modules/webusb/USB.cpp
+++ b/third_party/WebKit/Source/modules/webusb/USB.cpp
@@ -18,6 +18,7 @@
#include "modules/webusb/USBDeviceFilter.h"
#include "modules/webusb/USBDeviceRequestOptions.h"
#include "modules/webusb/USBError.h"
+#include "platform/UserGestureIndicator.h"
#include "public/platform/Platform.h"
#include "public/platform/WebVector.h"
#include "public/platform/modules/webusb/WebUSBClient.h"
@@ -93,6 +94,10 @@ ScriptPromise USB::getDevices(ScriptState* scriptState)
if (!m_client)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
+ String errorMessage;
+ if (!scriptState->executionContext()->isSecureContext(errorMessage))
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, errorMessage));
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
m_client->getDevices(new CallbackPromiseAdapter<DeviceArray, USBError>(resolver));
@@ -105,6 +110,13 @@ ScriptPromise USB::requestDevice(ScriptState* scriptState, const USBDeviceReques
if (!m_client)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
+ String errorMessage;
+ if (!scriptState->executionContext()->isSecureContext(errorMessage))
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, errorMessage));
+
+ if (!UserGestureIndicator::consumeUserGesture())
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "Must be handling a user gesture to show a permission request."));
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698