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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/GlobalCacheStorage.h" | 6 #include "modules/serviceworkers/GlobalCacheStorage.h" |
7 | 7 |
| 8 #include "core/dom/ExecutionContext.h" |
8 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
9 #include "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
10 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
11 #include "modules/serviceworkers/CacheStorage.h" | 12 #include "modules/serviceworkers/CacheStorage.h" |
12 #include "platform/Supplementable.h" | 13 #include "platform/Supplementable.h" |
13 #include "platform/heap/Handle.h" | 14 #include "platform/heap/Handle.h" |
14 #include "platform/weborigin/DatabaseIdentifier.h" | 15 #include "platform/weborigin/DatabaseIdentifier.h" |
15 #include "public/platform/Platform.h" | 16 #include "public/platform/Platform.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 template <typename T> | 22 template <typename T> |
22 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { | 23 class GlobalCacheStorageImpl final : public NoBaseWillBeGarbageCollectedFinalize
d<GlobalCacheStorageImpl<T>>, public WillBeHeapSupplement<T> { |
23 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); | 24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalCacheStorageImpl); |
24 public: | 25 public: |
25 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) | 26 static GlobalCacheStorageImpl& from(T& supplementable, ExecutionContext* exe
cutionContext) |
26 { | 27 { |
27 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl*
>(WillBeHeapSupplement<T>::from(supplementable, name())); | 28 GlobalCacheStorageImpl* supplement = static_cast<GlobalCacheStorageImpl*
>(WillBeHeapSupplement<T>::from(supplementable, name())); |
28 if (!supplement) { | 29 if (!supplement) { |
29 supplement = new GlobalCacheStorageImpl(); | 30 supplement = new GlobalCacheStorageImpl(); |
30 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); | 31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); |
31 } | 32 } |
32 return *supplement; | 33 return *supplement; |
33 } | 34 } |
34 | 35 |
35 CacheStorage* caches(ScriptState* scriptState, ExceptionState& exceptionStat
e) | 36 CacheStorage* caches(ExecutionContext* context, ExceptionState& exceptionSta
te) |
36 { | 37 { |
37 ExecutionContext* context = scriptState->executionContext(); | |
38 if (!context->securityOrigin()->canAccessCacheStorage()) { | 38 if (!context->securityOrigin()->canAccessCacheStorage()) { |
39 if (context->securityContext().isSandboxed(SandboxOrigin)) | 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."); | 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")) | 41 else if (context->url().protocolIs("data")) |
42 exceptionState.throwSecurityError("Cache storage is disabled ins
ide 'data:' URLs."); | 42 exceptionState.throwSecurityError("Cache storage is disabled ins
ide 'data:' URLs."); |
43 else | 43 else |
44 exceptionState.throwSecurityError("Access to cache storage is de
nied."); | 44 exceptionState.throwSecurityError("Access to cache storage is de
nied."); |
45 return nullptr; | 45 return nullptr; |
46 } | 46 } |
47 | 47 |
(...skipping 16 matching lines...) Expand all Loading... |
64 { | 64 { |
65 } | 65 } |
66 | 66 |
67 static const char* name() { return "CacheStorage"; } | 67 static const char* name() { return "CacheStorage"; } |
68 | 68 |
69 PersistentWillBeMember<CacheStorage> m_caches; | 69 PersistentWillBeMember<CacheStorage> m_caches; |
70 }; | 70 }; |
71 | 71 |
72 } // namespace | 72 } // namespace |
73 | 73 |
74 CacheStorage* GlobalCacheStorage::caches(ScriptState* scriptState, DOMWindow& wi
ndow, ExceptionState& exceptionState) | 74 CacheStorage* GlobalCacheStorage::caches(DOMWindow& window, ExceptionState& exce
ptionState) |
75 { | 75 { |
76 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(scriptState, exceptionState); | 76 return GlobalCacheStorageImpl<LocalDOMWindow>::from(toLocalDOMWindow(window)
, window.executionContext()).caches(window.executionContext(), exceptionState); |
77 } | 77 } |
78 | 78 |
79 CacheStorage* GlobalCacheStorage::caches(ScriptState* scriptState, WorkerGlobalS
cope& worker, ExceptionState& exceptionState) | 79 CacheStorage* GlobalCacheStorage::caches(WorkerGlobalScope& worker, ExceptionSta
te& exceptionState) |
80 { | 80 { |
81 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(scriptState, exceptionState); | 81 return GlobalCacheStorageImpl<WorkerGlobalScope>::from(worker, worker.execut
ionContext()).caches(worker.executionContext(), exceptionState); |
82 } | 82 } |
83 | 83 |
84 } // namespace blink | 84 } // namespace blink |
OLD | NEW |