| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/GlobalCacheStorage.h" | 5 #include "modules/cachestorage/GlobalCacheStorage.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
| 10 #include "core/workers/WorkerGlobalScope.h" | 10 #include "core/workers/WorkerGlobalScope.h" |
| 11 #include "modules/cachestorage/CacheStorage.h" | 11 #include "modules/cachestorage/CacheStorage.h" |
| 12 #include "platform/Supplementable.h" | 12 #include "platform/Supplementable.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/Platform.h" |
| 15 #include "public/platform/WebSecurityOrigin.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 template <typename T> | 21 template <typename T> |
| 22 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { | 22 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { |
| 23 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); | 23 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); |
| 24 public: | 24 public: |
| 25 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) | 25 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 if (context->securityContext().isSandboxed(SandboxOrigin)) | 45 if (context->securityContext().isSandboxed(SandboxOrigin)) |
| 46 exceptionState.throwSecurityError("Cache storage is disabled bec
ause the context is sandboxed and lacks the 'allow-same-origin' flag."); | 46 exceptionState.throwSecurityError("Cache storage is disabled bec
ause the context is sandboxed and lacks the 'allow-same-origin' flag."); |
| 47 else if (context->url().protocolIs("data")) | 47 else if (context->url().protocolIs("data")) |
| 48 exceptionState.throwSecurityError("Cache storage is disabled ins
ide 'data:' URLs."); | 48 exceptionState.throwSecurityError("Cache storage is disabled ins
ide 'data:' URLs."); |
| 49 else | 49 else |
| 50 exceptionState.throwSecurityError("Access to cache storage is de
nied."); | 50 exceptionState.throwSecurityError("Access to cache storage is de
nied."); |
| 51 return nullptr; | 51 return nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 if (!m_caches) { | 54 if (!m_caches) { |
| 55 String identifier = createDatabaseIdentifierFromSecurityOrigin(conte
xt->securityOrigin()); | 55 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet
chingScope), Platform::current()->cacheStorage(WebSecurityOrigin(context->securi
tyOrigin()))); |
| 56 ASSERT(!identifier.isEmpty()); | |
| 57 m_caches = CacheStorage::create(GlobalFetch::ScopedFetcher::from(fet
chingScope), Platform::current()->cacheStorage(identifier)); | |
| 58 } | 56 } |
| 59 return m_caches; | 57 return m_caches; |
| 60 } | 58 } |
| 61 | 59 |
| 62 // Promptly dispose of associated CacheStorage. | 60 // Promptly dispose of associated CacheStorage. |
| 63 EAGERLY_FINALIZE(); | 61 EAGERLY_FINALIZE(); |
| 64 DEFINE_INLINE_VIRTUAL_TRACE() | 62 DEFINE_INLINE_VIRTUAL_TRACE() |
| 65 { | 63 { |
| 66 visitor->trace(m_caches); | 64 visitor->trace(m_caches); |
| 67 WillBeHeapSupplement<T>::trace(visitor); | 65 WillBeHeapSupplement<T>::trace(visitor); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 { | 81 { |
| 84 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(toLocalDOMWindow(window), exceptionState); | 82 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(toLocalDOMWindow(window), exceptionState); |
| 85 } | 83 } |
| 86 | 84 |
| 87 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) | 85 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) |
| 88 { | 86 { |
| 89 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker, exceptionState); | 87 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker, exceptionState); |
| 90 } | 88 } |
| 91 | 89 |
| 92 } // namespace blink | 90 } // namespace blink |
| OLD | NEW |