Index: Source/modules/cachestorage/CacheStorage.cpp |
diff --git a/Source/modules/cachestorage/CacheStorage.cpp b/Source/modules/cachestorage/CacheStorage.cpp |
index 4961a3fa425ef4fa40a96aa96f7531f7b8449511..9c8e9300ecc69fc578b97292539a0439c65fa69d 100644 |
--- a/Source/modules/cachestorage/CacheStorage.cpp |
+++ b/Source/modules/cachestorage/CacheStorage.cpp |
@@ -193,6 +193,18 @@ ScriptPromise CacheStorage::open(ScriptState* scriptState, const String& cacheNa |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
const ScriptPromise promise = resolver->promise(); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ // FIXME: May be null due to worker termination: http://crbug.com/413518. |
+ if (!executionContext) |
+ return ScriptPromise(); |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
+ String errorMessage; |
+ if (!executionContext->isPrivilegedContext(errorMessage)) { |
+ resolver->reject(DOMException::create(SecurityError, errorMessage)); |
+ return promise; |
+ } |
+ |
if (m_nameToCacheMap.contains(cacheName)) { |
Cache* cache = m_nameToCacheMap.find(cacheName)->value; |
resolver->resolve(cache); |
@@ -212,6 +224,18 @@ ScriptPromise CacheStorage::has(ScriptState* scriptState, const String& cacheNam |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
const ScriptPromise promise = resolver->promise(); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ // FIXME: May be null due to worker termination: http://crbug.com/413518. |
+ if (!executionContext) |
+ return ScriptPromise(); |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
+ String errorMessage; |
+ if (!executionContext->isPrivilegedContext(errorMessage)) { |
+ resolver->reject(DOMException::create(SecurityError, errorMessage)); |
+ return promise; |
+ } |
+ |
if (m_nameToCacheMap.contains(cacheName)) { |
resolver->resolve(true); |
return promise; |
@@ -230,6 +254,18 @@ ScriptPromise CacheStorage::deleteFunction(ScriptState* scriptState, const Strin |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
const ScriptPromise promise = resolver->promise(); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ // FIXME: May be null due to worker termination: http://crbug.com/413518. |
+ if (!executionContext) |
+ return ScriptPromise(); |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
+ String errorMessage; |
+ if (!executionContext->isPrivilegedContext(errorMessage)) { |
+ resolver->reject(DOMException::create(SecurityError, errorMessage)); |
+ return promise; |
+ } |
+ |
if (m_webCacheStorage) |
m_webCacheStorage->dispatchDelete(new DeleteCallbacks(cacheName, this, resolver), cacheName); |
else |
@@ -243,6 +279,18 @@ ScriptPromise CacheStorage::keys(ScriptState* scriptState) |
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
const ScriptPromise promise = resolver->promise(); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ // FIXME: May be null due to worker termination: http://crbug.com/413518. |
+ if (!executionContext) |
+ return ScriptPromise(); |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
+ String errorMessage; |
+ if (!executionContext->isPrivilegedContext(errorMessage)) { |
+ resolver->reject(DOMException::create(SecurityError, errorMessage)); |
+ return promise; |
+ } |
Mike West
2015/06/18 19:54:57
Nit: It might be reasonable to extract this repeat
|
+ |
if (m_webCacheStorage) |
m_webCacheStorage->dispatchKeys(new KeysCallbacks(resolver)); |
else |
@@ -255,6 +303,18 @@ ScriptPromise CacheStorage::match(ScriptState* scriptState, const RequestInfo& r |
{ |
ASSERT(!request.isNull()); |
+ ExecutionContext* executionContext = scriptState->executionContext(); |
+ // FIXME: May be null due to worker termination: http://crbug.com/413518. |
+ if (!executionContext) |
+ return ScriptPromise(); |
+ |
+ RefPtr<SecurityOrigin> documentOrigin = executionContext->securityOrigin(); |
+ String errorMessage; |
+ if (!executionContext->isPrivilegedContext(errorMessage)) { |
+ exceptionState.throwSecurityError(errorMessage); |
+ return ScriptPromise(); |
+ } |
+ |
if (request.isRequest()) |
return matchImpl(scriptState, request.getAsRequest(), options); |
Request* newRequest = Request::create(scriptState, request.getAsUSVString(), exceptionState); |