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 "modules/fetch/GlobalFetch.h" | 5 #include "modules/fetch/GlobalFetch.h" |
6 | 6 |
7 #include "core/frame/LocalDOMWindow.h" | 7 #include "core/frame/LocalDOMWindow.h" |
8 #include "core/frame/UseCounter.h" | 8 #include "core/frame/UseCounter.h" |
9 #include "core/workers/WorkerGlobalScope.h" | 9 #include "core/workers/WorkerGlobalScope.h" |
10 #include "modules/fetch/FetchManager.h" | 10 #include "modules/fetch/FetchManager.h" |
11 #include "modules/fetch/Request.h" | 11 #include "modules/fetch/Request.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 "wtf/OwnPtr.h" | 14 #include "wtf/OwnPtr.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 template <typename T> | 20 template <typename T> |
21 class GlobalFetchImpl final : public GarbageCollectedFinalized<GlobalFetchImpl<T
>>, public GlobalFetch::ScopedFetcher, public HeapSupplement<T> { | 21 class GlobalFetchImpl final : public GarbageCollectedFinalized<GlobalFetchImpl<T
>>, public GlobalFetch::ScopedFetcher, public Supplement<T> { |
22 USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); | 22 USING_GARBAGE_COLLECTED_MIXIN(GlobalFetchImpl); |
23 public: | 23 public: |
24 static RawPtr<ScopedFetcher> from(T& supplementable, ExecutionContext* execu
tionContext) | 24 static RawPtr<ScopedFetcher> from(T& supplementable, ExecutionContext* execu
tionContext) |
25 { | 25 { |
26 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(HeapSuppleme
nt<T>::from(supplementable, supplementName())); | 26 GlobalFetchImpl* supplement = static_cast<GlobalFetchImpl*>(Supplement<T
>::from(supplementable, supplementName())); |
27 if (!supplement) { | 27 if (!supplement) { |
28 supplement = new GlobalFetchImpl(executionContext); | 28 supplement = new GlobalFetchImpl(executionContext); |
29 HeapSupplement<T>::provideTo(supplementable, supplementName(), suppl
ement); | 29 Supplement<T>::provideTo(supplementable, supplementName(), supplemen
t); |
30 } | 30 } |
31 #if ENABLE(OILPAN) | |
32 return supplement; | 31 return supplement; |
33 #else | |
34 return supplement->m_weakFactory.createWeakPtr(); | |
35 #endif | |
36 } | 32 } |
37 | 33 |
38 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) override | 34 ScriptPromise fetch(ScriptState* scriptState, const RequestInfo& input, cons
t Dictionary& init, ExceptionState& exceptionState) override |
39 { | 35 { |
40 if (m_fetchManager->isStopped()) { | 36 if (m_fetchManager->isStopped()) { |
41 exceptionState.throwTypeError("The global scope is shutting down."); | 37 exceptionState.throwTypeError("The global scope is shutting down."); |
42 return ScriptPromise(); | 38 return ScriptPromise(); |
43 } | 39 } |
44 | 40 |
45 // "Let |r| be the associated request of the result of invoking the | 41 // "Let |r| be the associated request of the result of invoking the |
46 // initial value of Request as constructor with |input| and |init| as | 42 // initial value of Request as constructor with |input| and |init| as |
47 // arguments. If this throws an exception, reject |p| with it." | 43 // arguments. If this throws an exception, reject |p| with it." |
48 Request* r = Request::create(scriptState, input, init, exceptionState); | 44 Request* r = Request::create(scriptState, input, init, exceptionState); |
49 if (exceptionState.hadException()) | 45 if (exceptionState.hadException()) |
50 return ScriptPromise(); | 46 return ScriptPromise(); |
51 return m_fetchManager->fetch(scriptState, r->passRequestData()); | 47 return m_fetchManager->fetch(scriptState, r->passRequestData()); |
52 } | 48 } |
53 | 49 |
54 DEFINE_INLINE_VIRTUAL_TRACE() | 50 DEFINE_INLINE_VIRTUAL_TRACE() |
55 { | 51 { |
56 visitor->trace(m_fetchManager); | 52 visitor->trace(m_fetchManager); |
57 ScopedFetcher::trace(visitor); | 53 ScopedFetcher::trace(visitor); |
58 HeapSupplement<T>::trace(visitor); | 54 Supplement<T>::trace(visitor); |
59 } | 55 } |
60 | 56 |
61 private: | 57 private: |
62 explicit GlobalFetchImpl(ExecutionContext* executionContext) | 58 explicit GlobalFetchImpl(ExecutionContext* executionContext) |
63 : m_fetchManager(FetchManager::create(executionContext)) | 59 : m_fetchManager(FetchManager::create(executionContext)) |
64 #if !ENABLE(OILPAN) | |
65 , m_weakFactory(this) | |
66 #endif | |
67 { | 60 { |
68 } | 61 } |
| 62 |
69 static const char* supplementName() { return "GlobalFetch"; } | 63 static const char* supplementName() { return "GlobalFetch"; } |
70 | 64 |
71 Member<FetchManager> m_fetchManager; | 65 Member<FetchManager> m_fetchManager; |
72 #if !ENABLE(OILPAN) | |
73 WeakPtrFactory<ScopedFetcher> m_weakFactory; | |
74 #endif | |
75 }; | 66 }; |
76 | 67 |
77 } // namespace | 68 } // namespace |
78 | 69 |
79 GlobalFetch::ScopedFetcher::~ScopedFetcher() | 70 GlobalFetch::ScopedFetcher::~ScopedFetcher() |
80 { | 71 { |
81 } | 72 } |
82 | 73 |
83 RawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(DOMWindow& w
indow) | 74 RawPtr<GlobalFetch::ScopedFetcher> GlobalFetch::ScopedFetcher::from(DOMWindow& w
indow) |
84 { | 75 { |
(...skipping 16 matching lines...) Expand all Loading... |
101 } | 92 } |
102 | 93 |
103 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) | 94 ScriptPromise GlobalFetch::fetch(ScriptState* scriptState, WorkerGlobalScope& wo
rker, const RequestInfo& input, const Dictionary& init, ExceptionState& exceptio
nState) |
104 { | 95 { |
105 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. | 96 // Note that UseCounter doesn't work with SharedWorker or ServiceWorker. |
106 UseCounter::count(worker.getExecutionContext(), UseCounter::Fetch); | 97 UseCounter::count(worker.getExecutionContext(), UseCounter::Fetch); |
107 return ScopedFetcher::from(worker)->fetch(scriptState, input, init, exceptio
nState); | 98 return ScopedFetcher::from(worker)->fetch(scriptState, input, init, exceptio
nState); |
108 } | 99 } |
109 | 100 |
110 } // namespace blink | 101 } // namespace blink |
OLD | NEW |