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/fetch/GlobalFetch.h" | 6 #include "modules/fetch/GlobalFetch.h" |
7 | 7 |
8 #include "core/dom/ActiveDOMObject.h" | 8 #include "core/dom/ActiveDOMObject.h" |
9 #include "core/frame/LocalDOMWindow.h" | 9 #include "core/frame/LocalDOMWindow.h" |
10 #include "core/frame/UseCounter.h" | 10 #include "core/frame/UseCounter.h" |
11 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
12 #include "modules/fetch/FetchManager.h" | 12 #include "modules/fetch/FetchManager.h" |
13 #include "modules/fetch/Request.h" | 13 #include "modules/fetch/Request.h" |
14 #include "platform/Supplementable.h" | 14 #include "platform/Supplementable.h" |
15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
16 #include "wtf/OwnPtr.h" | 16 #include "wtf/OwnPtr.h" |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 template <typename T> | 22 template <typename T> |
23 class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<Globa
lFetchImpl<T>>, public GlobalFetch::ScopedFetcher, public WillBeHeapSupplement<T
> { | 23 class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<Globa
lFetchImpl<T>>, public GlobalFetch::ScopedFetcher, public WillBeHeapSupplement<T
> { |
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); | 24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); |
25 public: | 25 public: |
26 static WeakPtr<ScopedFetcher> from(T& supplementable, ExecutionContext* exec
utionContext) | 26 static WeakPtrWillBeRawPtr<ScopedFetcher> from(T& supplementable, ExecutionC
ontext* executionContext) |
27 { | 27 { |
28 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSu
pplement<T>::from(supplementable, name())); | 28 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSu
pplement<T>::from(supplementable, supplementName())); |
29 if (!supplement) { | 29 if (!supplement) { |
30 supplement = new GlobalFetchImpl(executionContext); | 30 supplement = new GlobalFetchImpl(executionContext); |
31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); | 31 WillBeHeapSupplement<T>::provideTo(supplementable, supplementName(),
adoptPtrWillBeNoop(supplement)); |
32 } | 32 } |
| 33 #if ENABLE(OILPAN) |
| 34 return supplement; |
| 35 #else |
33 return supplement->m_weakFactory.createWeakPtr(); | 36 return supplement->m_weakFactory.createWeakPtr(); |
| 37 #endif |
34 } | 38 } |
35 | 39 |
36 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) override | 40 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) override |
37 { | 41 { |
38 if (m_fetchManager->isStopped()) { | 42 if (m_fetchManager->isStopped()) { |
39 exceptionState.throwTypeError("The global scope is shutting down."); | 43 exceptionState.throwTypeError("The global scope is shutting down."); |
40 return ScriptPromise(); | 44 return ScriptPromise(); |
41 } | 45 } |
42 | 46 |
43 // "Let |r| be the associated request of the result of invoking the | 47 // "Let |r| be the associated request of the result of invoking the |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 87 } |
84 | 88 |
85 // Having a raw pointer is safe, because |m_fetchManager| is owned by | 89 // Having a raw pointer is safe, because |m_fetchManager| is owned by |
86 // the owner of this object. | 90 // the owner of this object. |
87 RawPtrWillBeMember<FetchManager> m_fetchManager; | 91 RawPtrWillBeMember<FetchManager> m_fetchManager; |
88 }; | 92 }; |
89 | 93 |
90 explicit GlobalFetchImpl(ExecutionContext* executionContext) | 94 explicit GlobalFetchImpl(ExecutionContext* executionContext) |
91 : m_fetchManager(FetchManager::create(executionContext)) | 95 : m_fetchManager(FetchManager::create(executionContext)) |
92 , m_stopDetector(StopDetector::create(executionContext, m_fetchManager.g
et())) | 96 , m_stopDetector(StopDetector::create(executionContext, m_fetchManager.g
et())) |
| 97 #if !ENABLE(OILPAN) |
93 , m_weakFactory(this) | 98 , m_weakFactory(this) |
| 99 #endif |
94 { | 100 { |
95 } | 101 } |
96 static const char* name() { return "GlobalFetch"; } | 102 static const char* supplementName() { return "GlobalFetch"; } |
97 | 103 |
98 OwnPtrWillBeMember<FetchManager> m_fetchManager; | 104 OwnPtrWillBeMember<FetchManager> m_fetchManager; |
99 OwnPtrWillBeMember<StopDetector> m_stopDetector; | 105 OwnPtrWillBeMember<StopDetector> m_stopDetector; |
| 106 #if !ENABLE(OILPAN) |
100 WeakPtrFactory<ScopedFetcher> m_weakFactory; | 107 WeakPtrFactory<ScopedFetcher> m_weakFactory; |
| 108 #endif |
101 }; | 109 }; |
102 | 110 |
103 } // namespace | 111 } // namespace |
104 | 112 |
105 GlobalFetch::ScopedFetcher::~ScopedFetcher() | 113 GlobalFetch::ScopedFetcher::~ScopedFetcher() |
106 { | 114 { |
107 } | 115 } |
108 | 116 |
109 WeakPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(DOMWindow&
window) | 117 WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from
(DOMWindow& window) |
110 { | 118 { |
111 return GlobalFetchImpl<LocalDOMWindow>::from(toLocalDOMWindow(window), windo
w.executionContext()); | 119 return GlobalFetchImpl<LocalDOMWindow>::from(toLocalDOMWindow(window), windo
w.executionContext()); |
112 } | 120 } |
113 | 121 |
114 WeakPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(WorkerGloba
lScope& worker) | 122 WeakPtrWillBeRawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from
(WorkerGlobalScope& worker) |
115 { | 123 { |
116 return GlobalFetchImpl<WorkerGlobalScope>::from(worker, worker.executionCont
ext()); | 124 return GlobalFetchImpl<WorkerGlobalScope>::from(worker, worker.executionCont
ext()); |
117 } | 125 } |
118 | 126 |
119 DEFINE_TRACE(GlobalFetch::ScopedFetcher) | 127 DEFINE_TRACE(GlobalFetch::ScopedFetcher) |
120 { | 128 { |
121 } | 129 } |
122 | 130 |
123 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, DOMWindow& window, co
nst RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState) | 131 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, DOMWindow& window, co
nst RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState) |
124 { | 132 { |
125 UseCounter::count(window.executionContext(), UseCounter::Fetch); | 133 UseCounter::count(window.executionContext(), UseCounter::Fetch); |
126 return ScopedFetcher::from(window)->fetch(scriptState, input, init, exceptio
nState); | 134 return ScopedFetcher::from(window)->fetch(scriptState, input, init, exceptio
nState); |
127 } | 135 } |
128 | 136 |
129 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) | 137 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) |
130 { | 138 { |
131 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. | 139 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. |
132 UseCounter::count(worker.executionContext(), UseCounter::Fetch); | 140 UseCounter::count(worker.executionContext(), UseCounter::Fetch); |
133 return ScopedFetcher::from(worker)->fetch(scriptState, input, init, exceptio
nState); | 141 return ScopedFetcher::from(worker)->fetch(scriptState, input, init, exceptio
nState); |
134 } | 142 } |
135 | 143 |
136 } // namespace blink | 144 } // namespace blink |
OLD | NEW |