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

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: Cleanup, re-adding SWGlobalScope support, tested for pages and SW's 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..ef5d4bdcfe5d2a91abac3c75a8d5bfdb25508d76 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,77 @@
#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)
pfeldman 2015/04/02 21:18:58 Sorry, did I miss a reply here? I was suggesting t
{
- 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;
+}
+
+DOMWindow* assertWindow(ErrorString* errorString, LocalFrame* frame)
pfeldman 2015/04/02 21:18:58 And this method
+{
+ DOMWindow* window = frame ? frame->domWindow() : 0;
+
+ if (!window)
+ *errorString = "No window for given frame found.";
+
+ return window;
+}
+
+WebServiceWorkerCacheStorage* assertCacheStorage(ErrorString* errorString, DOMWindow& window)
+{
+ TrackExceptionState exceptionState;
pfeldman 2015/04/02 21:18:58 And go straight to WebServiceWorkerCacheStorage he
dmurph 2015/04/02 23:23:18 Ah. So calling Platform::current()->cacheStorage(
+ CacheStorage* cache = GlobalCacheStorage::caches(window, exceptionState);
+ if (exceptionState.hadException()) {
+ *errorString = "Exception while retrieving Cache Storage.";
+ return nullptr;
+ }
+ if (!cache) {
+ *errorString = "Cache Storage not available.";
+ return nullptr;
+ }
+ WebServiceWorkerCacheStorage* webCache = cache->webCacheStorage();
+ if (!webCache) {
+ *errorString = "Web cache not found on Cache Storage.";
+ return nullptr;
+ }
+ return webCache;
+}
+
+WebServiceWorkerCacheStorage* assertCacheStorage(ErrorString* errorString, WorkerGlobalScope& scope)
+{
+ TrackExceptionState exceptionState;
+ CacheStorage* cache = GlobalCacheStorage::caches(scope, exceptionState);
+ if (exceptionState.hadException()) {
+ *errorString = "Exception while retrieving Cache Storage.";
return nullptr;
}
- return caches.release();
+ if (!cache) {
+ *errorString = "Cache Storage not available.";
+ return nullptr;
+ }
+ WebServiceWorkerCacheStorage* webCache = cache->webCacheStorage();
+ if (!webCache) {
+ *errorString = "Web cache not found on Cache Storage.";
+ return nullptr;
+ }
+ return webCache;
}
CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error)
@@ -290,12 +348,21 @@ private:
} // namespace
+InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(Page* page)
+ : InspectorBaseAgent<InspectorServiceWorkerCacheAgent, InspectorFrontend::CacheStorage>("CacheStorage")
+ , m_page(page)
+ , m_serviceWorkerGlobalScope(nullptr)
+{
+}
+
InspectorServiceWorkerCacheAgent::InspectorServiceWorkerCacheAgent(ServiceWorkerGlobalScope* scope)
- : InspectorBaseAgent<blink::InspectorServiceWorkerCacheAgent, InspectorFrontend::ServiceWorkerCache>("ServiceWorkerCache")
- , m_globalScope(scope)
+ : InspectorBaseAgent<InspectorServiceWorkerCacheAgent, InspectorFrontend::CacheStorage>("CacheStorage")
+ , m_page(nullptr)
+ , m_serviceWorkerGlobalScope(scope)
{
}
+
InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { }
DEFINE_TRACE(InspectorServiceWorkerCacheAgent)
@@ -303,9 +370,20 @@ 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);
+ WebServiceWorkerCacheStorage* cache;
+ if (!m_serviceWorkerGlobalScope) {
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ cache = assertCacheStorage(errorString, *window);
+ } else {
+ cache = assertCacheStorage(errorString, *m_serviceWorkerGlobalScope);
+ }
if (!cache) {
callback->sendFailure(*errorString);
return;
@@ -313,10 +391,20 @@ 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);
+ WebServiceWorkerCacheStorage* cache;
+ if (!m_serviceWorkerGlobalScope) {
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ cache = assertCacheStorage(errorString, *window);
+ } else {
+ cache = assertCacheStorage(errorString, *m_serviceWorkerGlobalScope);
+ }
if (!cache) {
callback->sendFailure(*errorString);
return;
@@ -328,9 +416,20 @@ 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);
+ WebServiceWorkerCacheStorage* cache;
+ if (!m_serviceWorkerGlobalScope) {
+ LocalFrame* frame = findFrameWithSecurityOrigin(m_page, securityOrigin);
+ DOMWindow* window = assertWindow(errorString, frame);
+ if (!window) {
+ callback->sendFailure(*errorString);
+ return;
+ }
+ cache = assertCacheStorage(errorString, *window);
+ } else {
+ cache = assertCacheStorage(errorString, *m_serviceWorkerGlobalScope);
+ }
if (!cache) {
callback->sendFailure(*errorString);
return;

Powered by Google App Engine
This is Rietveld 408576698