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

Unified Diff: third_party/WebKit/Source/modules/quota/StorageManager.cpp

Issue 2692633002: Use [SecureContext] for navigator.storage (Closed)
Patch Set: TypeError and rebased tests Created 3 years, 10 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
Index: third_party/WebKit/Source/modules/quota/StorageManager.cpp
diff --git a/third_party/WebKit/Source/modules/quota/StorageManager.cpp b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
index 2830ea3e66798d6857bea3b36829d6824a5ff90e..0341f5fc4e1f9488145bf36f302cac15bb76dfa0 100644
--- a/third_party/WebKit/Source/modules/quota/StorageManager.cpp
+++ b/third_party/WebKit/Source/modules/quota/StorageManager.cpp
@@ -24,6 +24,9 @@ using mojom::blink::PermissionStatus;
namespace {
+const char uniqueOriginErrorMessage[] =
+ "The operation is not supported in this context.";
+
class EstimateCallbacks final : public StorageQuotaCallbacks {
WTF_MAKE_NONCOPYABLE(EstimateCallbacks);
@@ -60,19 +63,14 @@ ScriptPromise StorageManager::persist(ScriptState* scriptState) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
ExecutionContext* executionContext = scriptState->getExecutionContext();
+ DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL
SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin();
- // TODO(dgrogan): Is the isUnique() check covered by the later
- // isSecureContext() check? If so, maybe remove it. Write a test if it
- // stays.
if (securityOrigin->isUnique()) {
- resolver->reject(DOMException::create(NotSupportedError));
- return promise;
- }
- String errorMessage;
- if (!executionContext->isSecureContext(errorMessage)) {
- resolver->reject(DOMException::create(SecurityError, errorMessage));
+ resolver->reject(V8ThrowException::createTypeError(
+ scriptState->isolate(), uniqueOriginErrorMessage));
return promise;
}
+
ASSERT(executionContext->isDocument());
PermissionService* permissionService =
getPermissionService(scriptState->getExecutionContext());
@@ -96,6 +94,15 @@ ScriptPromise StorageManager::persist(ScriptState* scriptState) {
ScriptPromise StorageManager::persisted(ScriptState* scriptState) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
+ ExecutionContext* executionContext = scriptState->getExecutionContext();
+ DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL
+ SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin();
+ if (securityOrigin->isUnique()) {
+ resolver->reject(V8ThrowException::createTypeError(
+ scriptState->isolate(), uniqueOriginErrorMessage));
+ return promise;
+ }
+
PermissionService* permissionService =
getPermissionService(scriptState->getExecutionContext());
if (!permissionService) {
@@ -117,15 +124,11 @@ ScriptPromise StorageManager::estimate(ScriptState* scriptState) {
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
ExecutionContext* executionContext = scriptState->getExecutionContext();
+ DCHECK(executionContext->isSecureContext()); // [SecureContext] in IDL
SecurityOrigin* securityOrigin = executionContext->getSecurityOrigin();
if (securityOrigin->isUnique()) {
- resolver->reject(DOMException::create(NotSupportedError));
- return promise;
- }
- // IDL has: [SecureContext]
- String errorMessage;
- if (!executionContext->isSecureContext(errorMessage)) {
- resolver->reject(DOMException::create(SecurityError, errorMessage));
+ resolver->reject(V8ThrowException::createTypeError(
+ scriptState->isolate(), uniqueOriginErrorMessage));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698