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

Unified Diff: Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp

Issue 1044203004: [Storage] Cache storage inspection on all the frames! (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 9 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/serviceworkers/InspectorServiceWorkerCacheAgent.cpp
diff --git a/Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp b/Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp
index f05db4438ca3e496554b4c3414bb883a95de6c5d..94396053a89db583691d3bdc0fb11256aa8db644 100644
--- a/Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp
+++ b/Source/modules/serviceworkers/InspectorServiceWorkerCacheAgent.cpp
@@ -5,8 +5,15 @@
#include "config.h"
#include "modules/serviceworkers/InspectorServiceWorkerCacheAgent.h"
+#include "bindings/core/v8/ScriptState.h"
#include "core/InspectorBackendDispatcher.h"
#include "core/InspectorTypeBuilder.h"
+#include "core/dom/Document.h"
+#include "core/frame/DOMWindow.h"
+#include "core/frame/LocalFrame.h"
+#include "core/page/Page.h"
+#include "modules/serviceworkers/CacheStorage.h"
+#include "modules/serviceworkers/GlobalCacheStorage.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h"
#include "platform/JSONValues.h"
@@ -32,26 +39,57 @@
#include <algorithm>
using blink::TypeBuilder::Array;
-using blink::TypeBuilder::ServiceWorkerCache::DataEntry;
+using blink::TypeBuilder::CacheStorage::DataEntry;
-typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::DeleteCacheCallback DeleteCacheCallback;
-typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::RequestCacheNamesCallback RequestCacheNamesCallback;
-typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::RequestEntriesCallback RequestEntriesCallback;
+typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::DeleteCacheCallback DeleteCacheCallback;
+typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestCacheNamesCallback RequestCacheNamesCallback;
+typedef blink::InspectorBackendDispatcher::CacheStorageCommandHandler::RequestEntriesCallback RequestEntriesCallback;
typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback;
namespace blink {
namespace {
-PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorString, ServiceWorkerGlobalScope* globalScope)
+LocalFrame* findFrameWithSecurityOrigin(Page* page, const String& securityOrigin)
{
- String identifier = createDatabaseIdentifierFromSecurityOrigin(globalScope->securityOrigin());
- OwnPtr<WebServiceWorkerCacheStorage> caches = adoptPtr(Platform::current()->cacheStorage(identifier));
- if (!caches) {
- *errorString = "Cache Storage not available in global scope.";
+ for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ if (!frame->isLocalFrame())
+ continue;
+ RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()->securityOrigin();
+ if (documentOrigin->toRawString() == securityOrigin)
+ return toLocalFrame(frame);
+ }
+ return 0;
+}
+
+static DOMWindow* assertWindow(ErrorString* errorString, LocalFrame* frame)
horo 2015/04/01 03:39:07 remove "static"
dmurph 2015/04/02 20:59:03 Done.
+{
+ DOMWindow* window = frame ? frame->domWindow() : 0;
+
+ if (!window)
+ *errorString = "No window for given frame found.";
+
+ return window;
+}
+
+WebServiceWorkerCacheStorage* assertCacheStorage(ErrorString* errorString, ScriptState* state, DOMWindow& window)
+{
+ TrackExceptionState exceptionState;
+ CacheStorage* cache = GlobalCacheStorage::caches(state, window, exceptionState);
+ if (exceptionState.hadException()) {
+ *errorString = "Exception while retrieving Cache Storage.";
+ return nullptr;
+ }
+ if (!cache) {
+ *errorString = "Cache Storage not available.";
return nullptr;
}
- return caches.release();
+ WebServiceWorkerCacheStorage* webCache = cache->webCacheStorage();
+ if (!webCache) {
+ *errorString = "Web cache not found on Cache Storage.";
+ return nullptr;
+ }
+ return webCache;
}
CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error)
@@ -290,9 +328,9 @@ private:
} // namespace
-InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorkerGlobalScope* scope)
- : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent, InspectorFrontend::ServiceWorkerCache>("ServiceWorkerCache")
- , m_globalScope(scope)
+InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(Page* page)
+ : InspectorBaseAgent<InspectorServiceWorkerCacheAgent, InspectorFrontend::CacheStorage>("CacheStorage")
+ , m_page(page)
{
}
@@ -303,9 +341,16 @@ DEFINE_TRACE(InspectorServiceWorkerCacheAgent)
InspectorBaseAgent::trace(visitor);
}
-void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorString, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback)
+void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorString, const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback)
{
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope);
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
pfeldman 2015/04/01 07:01:09 This one is important: going into the frame, throu
dmurph 2015/04/02 20:59:03 I think I understand what you mean. I removed scr
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ ScriptState* scriptState = ScriptState::forMainWorld(frame);
+ WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, scriptState, *window);
if (!cache) {
callback->sendFailure(*errorString);
return;
@@ -313,10 +358,16 @@ void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin
cache->dispatchKeys(new RequestCacheNames(callback));
}
-
-void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString, const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback)
+void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString, const String& securityOrigin, const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback)
{
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope);
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ ScriptState* scriptState = ScriptState::forMainWorld(frame);
+ WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, scriptState, *window);
if (!cache) {
callback->sendFailure(*errorString);
return;
@@ -328,9 +379,16 @@ void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString,
cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString(cacheName));
}
-void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, const String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback)
+void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, const String& securityOrigin, const String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback)
{
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope);
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ ScriptState* scriptState = ScriptState::forMainWorld(frame);
+ WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, scriptState, *window);
if (!cache) {
callback->sendFailure(*errorString);
return;

Powered by Google App Engine
This is Rietveld 408576698