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

Unified Diff: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp

Issue 1177983007: Cache Storage: restrict access to secure origins (Blink-side) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Factor out common checks Created 5 years, 6 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: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp
diff --git a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp
index 21b4884a681c1c1b8302ba6d07d7fefaed71d71a..dc380ed07e64029a0b2a9f19f9a1e970de678d1d 100644
--- a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp
+++ b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp
@@ -7,6 +7,10 @@
#include "core/InspectorBackendDispatcher.h"
#include "core/InspectorTypeBuilder.h"
+#include "core/dom/Document.h"
+#include "core/dom/ExecutionContext.h"
+#include "core/frame/Frame.h"
+#include "core/page/Page.h"
#include "platform/JSONValues.h"
#include "platform/heap/Handle.h"
#include "platform/weborigin/DatabaseIdentifier.h"
@@ -66,25 +70,6 @@ bool parseCacheId(ErrorString* errorString, const String& id, String* securityOr
return true;
}
-PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorString, const String& securityOrigin)
-{
- RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(securityOrigin);
- String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get());
- OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->cacheStorage(identifier));
- if (!cache)
- *errorString = "Could not find cache storage.";
- return cache.release();
-}
-
-PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorString* errorString, const String& cacheId, String* cacheName)
-{
- String securityOrigin;
- if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName)) {
- return nullptr;
- }
- return assertCacheStorage(errorString, securityOrigin);
-}
-
CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error)
{
switch (*error) {
@@ -392,8 +377,9 @@ private:
} // namespace
-InspectorCacheStorageAgent::InspectorCacheStorageAgent()
+InspectorCacheStorageAgent::InspectorCacheStorageAgent(Page* page)
: InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheStorage>("CacheStorage")
+ , m_page(page)
{
}
@@ -451,5 +437,41 @@ void InspectorCacheStorageAgent::deleteEntry(ErrorString* errorString, const Str
cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback), WebString(cacheName));
}
+ExecutionContext* InspectorCacheStorageAgent::assertExecutionContextForOrigin(ErrorString* error, SecurityOrigin* origin)
+{
+ for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ if (!frame->isLocalFrame())
+ continue;
+ LocalFrame* localFrame = toLocalFrame(frame);
+ if (localFrame->document() && localFrame->document()->securityOrigin()->isSameSchemeHostPort(origin))
+ return localFrame->document();
+ }
+
+ *error = "No frame is available for the request";
+ return 0;
+}
+
+PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCacheStorage(ErrorString* errorString, const String& securityOrigin)
+{
+ RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(securityOrigin);
+ ExecutionContext* executionContext = assertExecutionContextForOrigin(errorString, secOrigin.get());
+ if (!executionContext || !executionContext->isPrivilegedContext(*errorString))
jsbell 2015/06/19 20:32:40 This should call a public static on CacheStorage r
+ return nullptr;
+
+ String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get());
+ OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->cacheStorage(identifier));
+ if (!cache)
+ *errorString = "Could not find cache storage.";
+ return cache.release();
+}
+
+PassOwnPtr<WebServiceWorkerCacheStorage> InspectorCacheStorageAgent::assertCacheStorageAndNameForId(ErrorString* errorString, const String& cacheId, String* cacheName)
+{
+ String securityOrigin;
+ if (!parseCacheId(errorString, cacheId, &securityOrigin, cacheName))
+ return nullptr;
+ return assertCacheStorage(errorString, securityOrigin);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698