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

Unified Diff: third_party/WebKit/Source/modules/permissions/Permissions.cpp

Issue 2140583002: Permissions API: take into account that name() can be overridden. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 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/permissions/Permissions.cpp
diff --git a/third_party/WebKit/Source/modules/permissions/Permissions.cpp b/third_party/WebKit/Source/modules/permissions/Permissions.cpp
index a0530be3093ef71ecafdc7deafd483de7a9eab06..a7bcd0bca4cb3f91b811bafd88ee3db6552a944f 100644
--- a/third_party/WebKit/Source/modules/permissions/Permissions.cpp
+++ b/third_party/WebKit/Source/modules/permissions/Permissions.cpp
@@ -31,6 +31,9 @@ namespace blink {
namespace {
+// Websites will be able to run code when `name()` is called, changing the
+// current context. The caller should make sure that no assumption is made
+// after this has been called.
WebPermissionType getPermissionType(ScriptState* scriptState, const Dictionary& rawPermission, const PermissionDescriptor& permission, ExceptionState& exceptionState)
{
const String& name = permission.name();
@@ -106,15 +109,17 @@ WebPermissionClient* Permissions::getClient(ExecutionContext* executionContext)
ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& rawPermission)
{
- WebPermissionClient* client = getClient(scriptState->getExecutionContext());
- if (!client)
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions."));
-
ExceptionState exceptionState(ExceptionState::GetterContext, "query", "Permissions", scriptState->context()->Global(), scriptState->isolate());
Nullable<WebPermissionType> type = parsePermission(scriptState, rawPermission, exceptionState);
if (exceptionState.hadException())
return exceptionState.reject(scriptState);
+ // This must be called after `parsePermission` because the website might
+ // be able to run code.
+ WebPermissionClient* client = getClient(scriptState->getExecutionContext());
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't query permissions."));
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
@@ -128,15 +133,17 @@ ScriptPromise Permissions::query(ScriptState* scriptState, const Dictionary& raw
ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& rawPermission)
{
- WebPermissionClient* client = getClient(scriptState->getExecutionContext());
- if (!client)
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));
-
ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Permissions", scriptState->context()->Global(), scriptState->isolate());
Nullable<WebPermissionType> type = parsePermission(scriptState, rawPermission, exceptionState);
if (exceptionState.hadException())
return exceptionState.reject(scriptState);
+ // This must be called after `parsePermission` because the website might
+ // be able to run code.
+ WebPermissionClient* client = getClient(scriptState->getExecutionContext());
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
@@ -146,15 +153,17 @@ ScriptPromise Permissions::request(ScriptState* scriptState, const Dictionary& r
ScriptPromise Permissions::revoke(ScriptState* scriptState, const Dictionary& rawPermission)
{
- WebPermissionClient* client = getClient(scriptState->getExecutionContext());
- if (!client)
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't revoke permissions."));
-
ExceptionState exceptionState(ExceptionState::GetterContext, "revoke", "Permissions", scriptState->context()->Global(), scriptState->isolate());
Nullable<WebPermissionType> type = parsePermission(scriptState, rawPermission, exceptionState);
if (exceptionState.hadException())
return exceptionState.reject(scriptState);
+ // This must be called after `parsePermission` because the website might
+ // be able to run code.
+ WebPermissionClient* client = getClient(scriptState->getExecutionContext());
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't revoke permissions."));
+
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
@@ -164,10 +173,6 @@ ScriptPromise Permissions::revoke(ScriptState* scriptState, const Dictionary& ra
ScriptPromise Permissions::requestAll(ScriptState* scriptState, const Vector<Dictionary>& rawPermissions)
{
- WebPermissionClient* client = getClient(scriptState->getExecutionContext());
- if (!client)
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));
-
ExceptionState exceptionState(ExceptionState::GetterContext, "request", "Permissions", scriptState->context()->Global(), scriptState->isolate());
std::unique_ptr<Vector<WebPermissionType>> internalPermissions = wrapUnique(new Vector<WebPermissionType>());
std::unique_ptr<Vector<int>> callerIndexToInternalIndex = wrapUnique(new Vector<int>(rawPermissions.size()));
@@ -191,6 +196,12 @@ ScriptPromise Permissions::requestAll(ScriptState* scriptState, const Vector<Dic
callerIndexToInternalIndex->operator[](i) = internalIndex;
}
+ // This must be called after `parsePermission` because the website might
+ // be able to run code.
+ WebPermissionClient* client = getClient(scriptState->getExecutionContext());
+ if (!client)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "In its current state, the global scope can't request permissions."));
+
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