OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/InspectorServiceWorkerCacheAgent.h" | 6 #include "modules/serviceworkers/InspectorServiceWorkerCacheAgent.h" |
7 | 7 |
8 #include "core/InspectorBackendDispatcher.h" | 8 #include "core/InspectorBackendDispatcher.h" |
9 #include "core/InspectorTypeBuilder.h" | 9 #include "core/InspectorTypeBuilder.h" |
10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" | 10 #include "modules/serviceworkers/ServiceWorkerGlobalScope.h" |
11 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 11 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
12 #include "platform/JSONValues.h" | 12 #include "platform/JSONValues.h" |
13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 #include "platform/weborigin/DatabaseIdentifier.h" |
| 15 #include "public/platform/Platform.h" |
14 #include "public/platform/WebServiceWorkerCache.h" | 16 #include "public/platform/WebServiceWorkerCache.h" |
15 #include "public/platform/WebServiceWorkerCacheError.h" | 17 #include "public/platform/WebServiceWorkerCacheError.h" |
16 #include "public/platform/WebServiceWorkerCacheStorage.h" | 18 #include "public/platform/WebServiceWorkerCacheStorage.h" |
17 #include "public/platform/WebServiceWorkerRequest.h" | 19 #include "public/platform/WebServiceWorkerRequest.h" |
18 #include "public/platform/WebServiceWorkerResponse.h" | 20 #include "public/platform/WebServiceWorkerResponse.h" |
19 #include "public/platform/WebString.h" | 21 #include "public/platform/WebString.h" |
20 #include "public/platform/WebURL.h" | 22 #include "public/platform/WebURL.h" |
21 #include "public/platform/WebVector.h" | 23 #include "public/platform/WebVector.h" |
22 #include "wtf/Noncopyable.h" | 24 #include "wtf/Noncopyable.h" |
23 #include "wtf/OwnPtr.h" | 25 #include "wtf/OwnPtr.h" |
(...skipping 10 matching lines...) Expand all Loading... |
34 | 36 |
35 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Del
eteCacheCallback DeleteCacheCallback; | 37 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Del
eteCacheCallback DeleteCacheCallback; |
36 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req
uestCacheNamesCallback RequestCacheNamesCallback; | 38 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req
uestCacheNamesCallback RequestCacheNamesCallback; |
37 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req
uestEntriesCallback RequestEntriesCallback; | 39 typedef blink::InspectorBackendDispatcher::ServiceWorkerCacheCommandHandler::Req
uestEntriesCallback RequestEntriesCallback; |
38 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; | 40 typedef blink::InspectorBackendDispatcher::CallbackBase RequestCallback; |
39 | 41 |
40 namespace blink { | 42 namespace blink { |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 WebServiceWorkerCacheStorage* assertCacheStorage(ErrorString* errorString, Servi
ceWorkerGlobalScope* globalScope) | 46 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt
ring, ServiceWorkerGlobalScope* globalScope) |
45 { | 47 { |
46 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(globalScope); | 48 String identifier = createDatabaseIdentifierFromSecurityOrigin(globalScope->
securityOrigin()); |
47 if (!client) { | 49 OwnPtr<WebServiceWorkerCacheStorage> caches = adoptPtr(Platform::current()->
cacheStorage(identifier)); |
48 *errorString = "Could not find service worker global scope."; | 50 if (!caches) { |
| 51 *errorString = "Cache Storage not available in global scope."; |
49 return nullptr; | 52 return nullptr; |
50 } | 53 } |
51 WebServiceWorkerCacheStorage* cache = client->cacheStorage(); | 54 return caches.release(); |
52 if (!cache) { | |
53 *errorString = "Cache not available on service worker global client."; | |
54 return nullptr; | |
55 } | |
56 return cache; | |
57 } | 55 } |
58 | 56 |
59 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) | 57 CString serviceWorkerCacheErrorString(WebServiceWorkerCacheError* error) |
60 { | 58 { |
61 switch (*error) { | 59 switch (*error) { |
62 case WebServiceWorkerCacheErrorNotImplemented: | 60 case WebServiceWorkerCacheErrorNotImplemented: |
63 return CString("not implemented."); | 61 return CString("not implemented."); |
64 break; | 62 break; |
65 case WebServiceWorkerCacheErrorNotFound: | 63 case WebServiceWorkerCacheErrorNotFound: |
66 return CString("not found."); | 64 return CString("not found."); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 298 |
301 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { } | 299 InspectorServiceWorkerCacheAgent::~InspectorServiceWorkerCacheAgent() { } |
302 | 300 |
303 DEFINE_TRACE(InspectorServiceWorkerCacheAgent) | 301 DEFINE_TRACE(InspectorServiceWorkerCacheAgent) |
304 { | 302 { |
305 InspectorBaseAgent::trace(visitor); | 303 InspectorBaseAgent::trace(visitor); |
306 } | 304 } |
307 | 305 |
308 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin
g, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) | 306 void InspectorServiceWorkerCacheAgent::requestCacheNames(ErrorString* errorStrin
g, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> callback) |
309 { | 307 { |
310 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, m_glob
alScope); | 308 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString,
m_globalScope); |
311 if (!cache) { | 309 if (!cache) { |
312 callback->sendFailure(*errorString); | 310 callback->sendFailure(*errorString); |
313 return; | 311 return; |
314 } | 312 } |
315 cache->dispatchKeys(new RequestCacheNames(callback)); | 313 cache->dispatchKeys(new RequestCacheNames(callback)); |
316 } | 314 } |
317 | 315 |
318 | 316 |
319 void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString,
const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<Req
uestEntriesCallback> callback) | 317 void InspectorServiceWorkerCacheAgent::requestEntries(ErrorString* errorString,
const String& cacheName, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<Req
uestEntriesCallback> callback) |
320 { | 318 { |
321 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, m_glob
alScope); | 319 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString,
m_globalScope); |
322 if (!cache) { | 320 if (!cache) { |
323 callback->sendFailure(*errorString); | 321 callback->sendFailure(*errorString); |
324 return; | 322 return; |
325 } | 323 } |
326 DataRequestParams params; | 324 DataRequestParams params; |
327 params.cacheName = cacheName; | 325 params.cacheName = cacheName; |
328 params.pageSize = pageSize; | 326 params.pageSize = pageSize; |
329 params.skipCount = skipCount; | 327 params.skipCount = skipCount; |
330 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString(
cacheName)); | 328 cache->dispatchOpen(new GetCacheForRequestData(params, callback), WebString(
cacheName)); |
331 } | 329 } |
332 | 330 |
333 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con
st String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) | 331 void InspectorServiceWorkerCacheAgent::deleteCache(ErrorString* errorString, con
st String& cacheName, PassRefPtrWillBeRawPtr<DeleteCacheCallback> callback) |
334 { | 332 { |
335 WebServiceWorkerCacheStorage* cache = assertCacheStorage(errorString, m_glob
alScope); | 333 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString,
m_globalScope); |
336 if (!cache) { | 334 if (!cache) { |
337 callback->sendFailure(*errorString); | 335 callback->sendFailure(*errorString); |
338 return; | 336 return; |
339 } | 337 } |
340 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); | 338 cache->dispatchDelete(new DeleteCache(callback), WebString(cacheName)); |
341 } | 339 } |
342 | 340 |
343 } // namespace blink | 341 } // namespace blink |
OLD | NEW |