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/cachestorage/InspectorCacheStorageAgent.h" | 6 #include "modules/cachestorage/InspectorCacheStorageAgent.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 "platform/JSONValues.h" | 10 #include "platform/JSONValues.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return false; | 63 return false; |
64 } | 64 } |
65 *securityOrigin = id.substring(0, pipe); | 65 *securityOrigin = id.substring(0, pipe); |
66 *cacheName = id.substring(pipe + 1); | 66 *cacheName = id.substring(pipe + 1); |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt
ring, const String& securityOrigin) | 70 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorage(ErrorString* errorSt
ring, const String& securityOrigin) |
71 { | 71 { |
72 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security
Origin); | 72 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security
Origin); |
| 73 |
| 74 // Cache Storage API is restricted to trustworthy origins. |
| 75 if (!secOrigin->isPotentiallyTrustworthy(*errorString)) |
| 76 return nullptr; |
| 77 |
73 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get
()); | 78 String identifier = createDatabaseIdentifierFromSecurityOrigin(secOrigin.get
()); |
74 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c
acheStorage(identifier)); | 79 OwnPtr<WebServiceWorkerCacheStorage> cache = adoptPtr(Platform::current()->c
acheStorage(identifier)); |
75 if (!cache) | 80 if (!cache) |
76 *errorString = "Could not find cache storage."; | 81 *errorString = "Could not find cache storage."; |
77 return cache.release(); | 82 return cache.release(); |
78 } | 83 } |
79 | 84 |
80 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr
ing* errorString, const String& cacheId, String* cacheName) | 85 PassOwnPtr<WebServiceWorkerCacheStorage> assertCacheStorageAndNameForId(ErrorStr
ing* errorString, const String& cacheId, String* cacheName) |
81 { | 86 { |
82 String securityOrigin; | 87 String securityOrigin; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 406 |
402 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { } | 407 InspectorCacheStorageAgent::~InspectorCacheStorageAgent() { } |
403 | 408 |
404 DEFINE_TRACE(InspectorCacheStorageAgent) | 409 DEFINE_TRACE(InspectorCacheStorageAgent) |
405 { | 410 { |
406 InspectorBaseAgent::trace(visitor); | 411 InspectorBaseAgent::trace(visitor); |
407 } | 412 } |
408 | 413 |
409 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con
st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> cal
lback) | 414 void InspectorCacheStorageAgent::requestCacheNames(ErrorString* errorString, con
st String& securityOrigin, PassRefPtrWillBeRawPtr<RequestCacheNamesCallback> cal
lback) |
410 { | 415 { |
| 416 RefPtr<SecurityOrigin> secOrigin = SecurityOrigin::createFromString(security
Origin); |
| 417 |
| 418 // Cache Storage API is restricted to trustworthy origins. |
| 419 String ignoredMessage; |
| 420 if (!secOrigin->isPotentiallyTrustworthy(ignoredMessage)) { |
| 421 // Don't treat this as an error, just don't attempt to open and enumerat
e the caches. |
| 422 callback->sendSuccess(Array<TypeBuilder::CacheStorage::Cache>::create())
; |
| 423 return; |
| 424 } |
| 425 |
411 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString,
securityOrigin); | 426 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorage(errorString,
securityOrigin); |
412 if (!cache) { | 427 if (!cache) { |
413 callback->sendFailure(*errorString); | 428 callback->sendFailure(*errorString); |
414 return; | 429 return; |
415 } | 430 } |
416 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); | 431 cache->dispatchKeys(new RequestCacheNames(securityOrigin, callback)); |
417 } | 432 } |
418 | 433 |
419 void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const
String& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntr
iesCallback> callback) | 434 void InspectorCacheStorageAgent::requestEntries(ErrorString* errorString, const
String& cacheId, int skipCount, int pageSize, PassRefPtrWillBeRawPtr<RequestEntr
iesCallback> callback) |
420 { | 435 { |
(...skipping 27 matching lines...) Expand all Loading... |
448 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); | 463 OwnPtr<WebServiceWorkerCacheStorage> cache = assertCacheStorageAndNameForId(
errorString, cacheId, &cacheName); |
449 if (!cache) { | 464 if (!cache) { |
450 callback->sendFailure(*errorString); | 465 callback->sendFailure(*errorString); |
451 return; | 466 return; |
452 } | 467 } |
453 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); | 468 cache->dispatchOpen(new GetCacheForDeleteEntry(request, cacheName, callback)
, WebString(cacheName)); |
454 } | 469 } |
455 | 470 |
456 | 471 |
457 } // namespace blink | 472 } // namespace blink |
OLD | NEW |