Index: Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
diff --git a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
index 61899800186c60f29cfcda7a8121e926331dd769..091a3ed88184d4cb8bef1b07a3e51ed6f3416559 100644 |
--- a/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
+++ b/Source/modules/cachestorage/InspectorCacheStorageAgent.cpp |
@@ -7,10 +7,10 @@ |
#include "core/InspectorBackendDispatcher.h" |
#include "core/InspectorTypeBuilder.h" |
-#include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
#include "platform/JSONValues.h" |
#include "platform/heap/Handle.h" |
#include "platform/weborigin/DatabaseIdentifier.h" |
+#include "platform/weborigin/SecurityOrigin.h" |
#include "public/platform/Platform.h" |
#include "public/platform/WebServiceWorkerCache.h" |
#include "public/platform/WebServiceWorkerCacheError.h" |
@@ -31,26 +31,26 @@ |
#include <algorithm> |
using blink::TypeBuilder::Array; |
-using blink::TypeBuilder::ServiceWorkerCache::DataEntry; |
+using blink::TypeBuilder::CacheStorage::CacheId; |
+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) |
+PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorString, 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."; |
- return nullptr; |
- } |
- return caches.release(); |
+ RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(securityOrigin); |
+ String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get()); |
+ WebServiceWorkerCacheStorage* cache = Platform::current()->cacheStorage(identifier); |
+ if (!cache) |
+ *errorString = "Could not find cache storage."; |
+ return adoptPtr(cache); |
} |
CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) |
@@ -76,8 +76,9 @@ class RequestCacheNames |
WTF_MAKE_NONCOPYABLE(RequestCacheNames); |
public: |
- RequestCacheNames(PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
- : m_callback(callback) |
+ RequestCacheNames(const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
+ : m_securityOrigin(securityOrigin) |
+ , m_callback(callback) |
{ |
} |
@@ -85,9 +86,12 @@ public: |
void onSuccess(WebVector<WebString>* caches) |
{ |
- RefPtr<TypeBuilder::Array<String>> array = TypeBuilder::Array<String>::create(); |
+ RefPtr<Array<CacheId>> array = Array<CacheId>::create(); |
for (size_t i = 0; i < caches->size(); i++) { |
- array->addItem(String((*caches)[i])); |
+ RefPtr<CacheId> entry = CacheId::create() |
+ .setSecurityOrigin(m_securityOrigin) |
+ .setCacheName(String((*caches)[i])); |
+ array->addItem(entry); |
} |
m_callback->sendSuccess(array); |
} |
@@ -98,6 +102,7 @@ public: |
} |
private: |
+ String m_securityOrigin; |
RefPtrWillBePersistent<RequestCacheNamesCallback> m_callback; |
}; |
@@ -152,7 +157,7 @@ public: |
m_responses.remove(m_params.pageSize, m_responses.size() - m_params.pageSize); |
hasMore = true; |
} |
- RefPtr<TypeBuilder::Array<DataEntry>> array = TypeBuilder::Array<DataEntry>::create(); |
+ RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
for (const auto& requestResponse : m_responses) { |
RefPtr<DataEntry> entry = DataEntry::create() |
.setRequest(JSONString::create(requestResponse.request)->toJSONString()) |
@@ -215,6 +220,11 @@ public: |
void onSuccess(WebVector<WebServiceWorkerRequest>* requests) |
{ |
+ if (requests->isEmpty()) { |
+ RefPtr<Array<DataEntry>> array = Array<DataEntry>::create(); |
+ m_callback->sendSuccess(array, false); |
+ return; |
+ } |
RefPtr<ResponsesAccumulator> accumulator = adoptRef(new ResponsesAccumulator(requests->size(), m_params, m_callback)); |
for (size_t i = 0; i < requests->size(); i++) { |
@@ -289,9 +299,8 @@ private: |
} // namespace |
-InspectorCacheStorageAgent::InspectorCacheStorageAgent(ServiceWorkerGlobalScope* scope) |
- : InspectorBaseAgent<blink::InspectorCacheStorageAgent, InspectorFrontend::ServiceWorkerCache>("ServiceWorkerCache") |
- , m_globalScope(scope) |
+InspectorCacheStorageAgent::InspectorCacheStorageAgent() |
+ : InspectorBaseAgent<InspectorCacheStorageAgent, InspectorFrontend::CacheStorage>("CacheStorage") |
{ |
} |
@@ -302,20 +311,25 @@ DEFINE_TRACE(InspectorCacheStorageAgent) |
InspectorBaseAgent::trace(visitor); |
} |
-void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
+void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, const String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
{ |
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
+ OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
if (!cache) { |
callback->sendFailure(*errorString); |
return; |
} |
- cache->dispatchKeys(new RequestCacheNames(callback)); |
+ cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); |
} |
- |
-void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
+void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const RefPtr<JSONObject>& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntriesCallback> callback) |
{ |
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
+ String securityOrigin, cacheName; |
+ if (!cacheId->getString("securityOrigin", &securityOrigin) || !cacheId->getString("cacheName", &cacheName)) { |
+ *errorString = "Could not read cacheId"; |
+ callback->sendFailure(*errorString); |
+ return; |
+ } |
+ OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
if (!cache) { |
callback->sendFailure(*errorString); |
return; |
@@ -327,9 +341,15 @@ void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const |
cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString(cacheName)); |
} |
-void InspectorCacheStorageAgent::deleteCache(ErrorString* errorString, const String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
+void InspectorCacheStorageAgent::deleteCache(ErrorString* errorString, const RefPtr<JSONObject>& cacheId, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
{ |
- OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, m_globalScope); |
+ String securityOrigin, cacheName; |
+ if (!cacheId->getString("securityOrigin", &securityOrigin) || !cacheId->getString("cacheName", &cacheName)) { |
+ *errorString = "Could not read cacheId"; |
+ callback->sendFailure(*errorString); |
+ return; |
+ } |
+ OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString, securityOrigin); |
if (!cache) { |
callback->sendFailure(*errorString); |
return; |