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 class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<Globa
lFetchImpl>, public WillBeHeapSupplement<LocalDOMWindow>, public WillBeHeapSuppl
ement<WorkerGlobalScope> { |
23 class GlobalFetchImpl final : public NoBaseWillBeGarbageCollectedFinalized<Globa
lFetchImpl<T>>, public WillBeHeapSupplement<T> { | |
24 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); | 23 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); |
25 public: | 24 public: |
26 static GlobalFetchImpl& from(T& supplementable, ExecutionContext* executionC
ontext) | 25 static GlobalFetchImpl& from(LocalDOMWindow& supplementable, ExecutionContex
t* executionContext) |
27 { | 26 { |
28 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSu
pplement<T>::from(supplementable, name())); | 27 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSu
pplement<LocalDOMWindow>::from(supplementable, name())); |
29 if (!supplement) { | 28 if (!supplement) { |
30 supplement = new GlobalFetchImpl(executionContext); | 29 supplement = new GlobalFetchImpl(executionContext); |
31 WillBeHeapSupplement<T>::provideTo(supplementable, name(), adoptPtrW
illBeNoop(supplement)); | 30 WillBeHeapSupplement<LocalDOMWindow>::provideTo(supplementable, name
(), adoptPtrWillBeNoop(supplement)); |
32 } | 31 } |
33 return *supplement; | 32 return *supplement; |
34 } | 33 } |
| 34 |
| 35 static GlobalFetchImpl& from(WorkerGlobalScope& supplementable, ExecutionCon
text* executionContext) |
| 36 { |
| 37 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(WillBeHeapSu
pplement<WorkerGlobalScope>::from(supplementable, name())); |
| 38 if (!supplement) { |
| 39 supplement = new GlobalFetchImpl(executionContext); |
| 40 WillBeHeapSupplement<WorkerGlobalScope>::provideTo(supplementable, n
ame(), adoptPtrWillBeNoop(supplement)); |
| 41 } |
| 42 return *supplement; |
| 43 } |
35 | 44 |
36 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) | 45 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) |
37 { | 46 { |
38 if (m_fetchManager->isStopped()) { | 47 if (m_fetchManager->isStopped()) { |
39 exceptionState.throwTypeError("The global scope is shutting down."); | 48 exceptionState.throwTypeError("The global scope is shutting down."); |
40 return ScriptPromise(); | 49 return ScriptPromise(); |
41 } | 50 } |
42 | 51 |
43 // "Let |r| be the associated request of the result of invoking the | 52 // "Let |r| be the associated request of the result of invoking the |
44 // initial value of Request as constructor with |input| and |init| as | 53 // initial value of Request as constructor with |input| and |init| as |
45 // arguments. If this throws an exception, reject |p| with it." | 54 // arguments. If this throws an exception, reject |p| with it." |
46 Request* r = Request::create(m_stopDetector->executionContext(), input,
init, exceptionState); | 55 Request* r = Request::create(m_stopDetector->executionContext(), input,
init, exceptionState); |
47 if (exceptionState.hadException()) | 56 if (exceptionState.hadException()) |
48 return ScriptPromise(); | 57 return ScriptPromise(); |
49 return m_fetchManager->fetch(scriptState, r->passRequestData()); | 58 return m_fetchManager->fetch(scriptState, r->passRequestData()); |
50 } | 59 } |
51 | 60 |
52 DEFINE_INLINE_VIRTUAL_TRACE() | 61 DEFINE_INLINE_VIRTUAL_TRACE() |
53 { | 62 { |
54 visitor->trace(m_fetchManager); | 63 visitor->trace(m_fetchManager); |
55 visitor->trace(m_stopDetector); | 64 visitor->trace(m_stopDetector); |
56 WillBeHeapSupplement<T>::trace(visitor); | 65 WillBeHeapSupplement<LocalDOMWindow>::trace(visitor); |
| 66 WillBeHeapSupplement<WorkerGlobalScope>::trace(visitor); |
57 } | 67 } |
58 | 68 |
59 private: | 69 private: |
60 class StopDetector final : public NoBaseWillBeGarbageCollectedFinalized<Stop
Detector>, public ActiveDOMObject { | 70 class StopDetector final : public NoBaseWillBeGarbageCollectedFinalized<Stop
Detector>, public ActiveDOMObject { |
61 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StopDetector); | 71 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StopDetector); |
62 public: | 72 public: |
63 static PassOwnPtrWillBeRawPtr<StopDetector> create(ExecutionContext* exe
cutionContext, FetchManager* fetchManager) | 73 static PassOwnPtrWillBeRawPtr<StopDetector> create(ExecutionContext* exe
cutionContext, FetchManager* fetchManager) |
64 { | 74 { |
65 return adoptPtrWillBeNoop(new StopDetector(executionContext, fetchMa
nager)); | 75 return adoptPtrWillBeNoop(new StopDetector(executionContext, fetchMa
nager)); |
66 } | 76 } |
(...skipping 28 matching lines...) Expand all Loading... |
95 | 105 |
96 OwnPtrWillBeMember<FetchManager> m_fetchManager; | 106 OwnPtrWillBeMember<FetchManager> m_fetchManager; |
97 OwnPtrWillBeMember<StopDetector> m_stopDetector; | 107 OwnPtrWillBeMember<StopDetector> m_stopDetector; |
98 }; | 108 }; |
99 | 109 |
100 } // namespace | 110 } // namespace |
101 | 111 |
102 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, DOMWindow& window, co
nst RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState) | 112 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, DOMWindow& window, co
nst RequestInfo& input, const Dictionary& init, ExceptionState& exceptionState) |
103 { | 113 { |
104 UseCounter::count(window.executionContext(), UseCounter::Fetch); | 114 UseCounter::count(window.executionContext(), UseCounter::Fetch); |
105 return GlobalFetchImpl<LocalDOMWindow>::from(toLocalDOMWindow(window), windo
w.executionContext()).fetch(scriptState, input, init, exceptionState); | 115 return GlobalFetchImpl::from(toLocalDOMWindow(window), window.executionConte
xt()).fetch(scriptState, input, init, exceptionState); |
106 } | 116 } |
107 | 117 |
108 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) | 118 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) |
109 { | 119 { |
110 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. | 120 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. |
111 UseCounter::count(worker.executionContext(), UseCounter::Fetch); | 121 UseCounter::count(worker.executionContext(), UseCounter::Fetch); |
112 return GlobalFetchImpl<WorkerGlobalScope>::from(worker, worker.executionCont
ext()).fetch(scriptState, input, init, exceptionState); | 122 return GlobalFetchImpl::from(worker, worker.executionContext()).fetch(script
State, input, init, exceptionState); |
113 } | 123 } |
114 | 124 |
115 } // namespace blink | 125 } // namespace blink |
OLD | NEW |