| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/serviceworkers/GlobalCacheStorage.h" | |
| 7 | |
| 8 #include "core/dom/ExecutionContext.h" | |
| 9 #include "core/frame/LocalDOMWindow.h" | |
| 10 #include "core/frame/UseCounter.h" | |
| 11 #include "core/workers/WorkerGlobalScope.h" | |
| 12 #include "modules/serviceworkers/CacheStorage.h" | |
| 13 #include "platform/Supplementable.h" | |
| 14 #include "platform/heap/Handle.h" | |
| 15 #include "platform/weborigin/DatabaseIdentifier.h" | |
| 16 #include "public/platform/Platform.h" | |
| 17 | |
| 18 namespace blink { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 template <typename T> | |
| 23 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { | |
| 24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); | |
| 25 public: | |
| 26 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) | |
| 27 { | |
| 28 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl*
>(WillBeHeapSupplement<T>::from(supplementable, name())); | |
| 29 if (!supplement) { | |
| 30 supplement = new GlobalCacheStorageImpl(); | |
| 31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); | |
| 32 } | |
| 33 return *supplement; | |
| 34 } | |
| 35 | |
| 36 CacheStorage* caches(ExecutionContext* context, ExceptionState& exceptionSta
te) | |
| 37 { | |
| 38 if (!context->securityOrigin()->canAccessCacheStorage()) { | |
| 39 if (context->securityContext().isSandboxed(SandboxOrigin)) | |
| 40 exceptionState.throwSecurityError("Cache storage is disabled bec
ause the context is sandboxed and lacks the 'allow-same-origin' flag."); | |
| 41 else if (context->url().protocolIs("data")) | |
| 42 exceptionState.throwSecurityError("Cache storage is disabled ins
ide 'data:' URLs."); | |
| 43 else | |
| 44 exceptionState.throwSecurityError("Access to cache storage is de
nied."); | |
| 45 return nullptr; | |
| 46 } | |
| 47 | |
| 48 if (!m_caches) { | |
| 49 String identifier = createDatabaseIdentifierFromSecurityOrigin(conte
xt->securityOrigin()); | |
| 50 ASSERT(!identifier.isEmpty()); | |
| 51 m_caches = CacheStorage::create(Platform::current()->cacheStorage(id
entifier)); | |
| 52 } | |
| 53 return m_caches; | |
| 54 } | |
| 55 | |
| 56 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 57 { | |
| 58 visitor->trace(m_caches); | |
| 59 WillBeHeapSupplement<T>::trace(visitor); | |
| 60 } | |
| 61 | |
| 62 private: | |
| 63 GlobalCacheStorageImpl() | |
| 64 { | |
| 65 } | |
| 66 | |
| 67 static const char* name() { return "CacheStorage"; } | |
| 68 | |
| 69 PersistentWillBeMember<CacheStorage> m_caches; | |
| 70 }; | |
| 71 | |
| 72 } // namespace | |
| 73 | |
| 74 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce
ptionState) | |
| 75 { | |
| 76 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(window.executionContext(), exceptionState); | |
| 77 } | |
| 78 | |
| 79 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) | |
| 80 { | |
| 81 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker.executionContext(), exceptionState); | |
| 82 } | |
| 83 | |
| 84 } // namespace blink | |
| OLD | NEW |