| 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 "modules/cachestorage/CacheStorage.h" | 5 #include "modules/cachestorage/CacheStorage.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
| 11 #include "core/inspector/ConsoleMessage.h" | 11 #include "core/inspector/ConsoleMessage.h" |
| 12 #include "modules/cachestorage/CacheStorageError.h" | 12 #include "modules/cachestorage/CacheStorageError.h" |
| 13 #include "modules/fetch/Request.h" | 13 #include "modules/fetch/Request.h" |
| 14 #include "modules/fetch/Response.h" | 14 #include "modules/fetch/Response.h" |
| 15 #include "platform/RuntimeEnabledFeatures.h" | |
| 16 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" | 15 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheError.h" |
| 17 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" | 16 #include "public/platform/modules/serviceworker/WebServiceWorkerCacheStorage.h" |
| 18 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
| 19 #include <memory> | 18 #include <memory> |
| 20 | 19 |
| 21 namespace blink { | 20 namespace blink { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 DOMException* createNoImplementationException() | 24 DOMException* createNoImplementationException() |
| 26 { | 25 { |
| 27 return DOMException::create(NotSupportedError, "No CacheStorage implementati
on provided."); | 26 return DOMException::create(NotSupportedError, "No CacheStorage implementati
on provided."); |
| 28 } | 27 } |
| 29 | 28 |
| 30 bool commonChecks(ScriptState* scriptState, ExceptionState& exceptionState) | 29 bool commonChecks(ScriptState* scriptState, ExceptionState& exceptionState) |
| 31 { | 30 { |
| 32 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 31 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 33 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 32 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 34 if (!executionContext) | 33 if (!executionContext) |
| 35 return false; | 34 return false; |
| 36 | 35 |
| 37 String errorMessage; | 36 String errorMessage; |
| 38 if (!executionContext->isSecureContext(errorMessage)) { | 37 if (!executionContext->isSecureContext(errorMessage)) { |
| 39 exceptionState.throwSecurityError(errorMessage); | 38 exceptionState.throwSecurityError(errorMessage); |
| 40 return false; | 39 return false; |
| 41 } | 40 } |
| 42 return true; | 41 return true; |
| 43 } | 42 } |
| 44 | 43 |
| 45 void checkCacheQueryOptions(const CacheQueryOptions& options, ExecutionContext*
context) | |
| 46 { | |
| 47 if (!RuntimeEnabledFeatures::cacheIgnoreSearchOptionEnabled() && options.ign
oreSearch()) | |
| 48 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "Cache.match() does not support 'ignoreSearch' option yet. See h
ttp://crbug.com/520784")); | |
| 49 if (options.ignoreMethod()) | |
| 50 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "Cache.match() does not support 'ignoreMethod' option yet. See h
ttp://crbug.com/482256")); | |
| 51 if (options.ignoreVary()) | |
| 52 context->addConsoleMessage(ConsoleMessage::create(JSMessageSource, Warni
ngMessageLevel, "Cache.match() does not support 'ignoreVary' option yet. See htt
p://crbug.com/499216")); | |
| 53 } | |
| 54 | |
| 55 } // namespace | 44 } // namespace |
| 56 | 45 |
| 57 // FIXME: Consider using CallbackPromiseAdapter. | 46 // FIXME: Consider using CallbackPromiseAdapter. |
| 58 class CacheStorage::Callbacks final : public WebServiceWorkerCacheStorage::Cache
StorageCallbacks { | 47 class CacheStorage::Callbacks final : public WebServiceWorkerCacheStorage::Cache
StorageCallbacks { |
| 59 WTF_MAKE_NONCOPYABLE(Callbacks); | 48 WTF_MAKE_NONCOPYABLE(Callbacks); |
| 60 public: | 49 public: |
| 61 explicit Callbacks(ScriptPromiseResolver* resolver) | 50 explicit Callbacks(ScriptPromiseResolver* resolver) |
| 62 : m_resolver(resolver) { } | 51 : m_resolver(resolver) { } |
| 63 ~Callbacks() override { } | 52 ~Callbacks() override { } |
| 64 | 53 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 Request* newRequest = Request::create(scriptState, request.getAsUSVString(),
exceptionState); | 297 Request* newRequest = Request::create(scriptState, request.getAsUSVString(),
exceptionState); |
| 309 if (exceptionState.hadException()) | 298 if (exceptionState.hadException()) |
| 310 return ScriptPromise(); | 299 return ScriptPromise(); |
| 311 return matchImpl(scriptState, newRequest, options); | 300 return matchImpl(scriptState, newRequest, options); |
| 312 } | 301 } |
| 313 | 302 |
| 314 ScriptPromise CacheStorage::matchImpl(ScriptState* scriptState, const Request* r
equest, const CacheQueryOptions& options) | 303 ScriptPromise CacheStorage::matchImpl(ScriptState* scriptState, const Request* r
equest, const CacheQueryOptions& options) |
| 315 { | 304 { |
| 316 WebServiceWorkerRequest webRequest; | 305 WebServiceWorkerRequest webRequest; |
| 317 request->populateWebServiceWorkerRequest(webRequest); | 306 request->populateWebServiceWorkerRequest(webRequest); |
| 318 checkCacheQueryOptions(options, scriptState->getExecutionContext()); | |
| 319 | 307 |
| 320 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 308 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 321 const ScriptPromise promise = resolver->promise(); | 309 const ScriptPromise promise = resolver->promise(); |
| 322 | 310 |
| 323 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { | 311 if (request->method() != HTTPNames::GET && !options.ignoreMethod()) { |
| 324 resolver->resolve(); | 312 resolver->resolve(); |
| 325 return promise; | 313 return promise; |
| 326 } | 314 } |
| 327 | 315 |
| 328 if (m_webCacheStorage) | 316 if (m_webCacheStorage) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 348 m_webCacheStorage.reset(); | 336 m_webCacheStorage.reset(); |
| 349 } | 337 } |
| 350 | 338 |
| 351 DEFINE_TRACE(CacheStorage) | 339 DEFINE_TRACE(CacheStorage) |
| 352 { | 340 { |
| 353 visitor->trace(m_scopedFetcher); | 341 visitor->trace(m_scopedFetcher); |
| 354 visitor->trace(m_nameToCacheMap); | 342 visitor->trace(m_nameToCacheMap); |
| 355 } | 343 } |
| 356 | 344 |
| 357 } // namespace blink | 345 } // namespace blink |
| OLD | NEW |