OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/background_fetch/BackgroundFetchedEvent.h" | 5 #include "modules/background_fetch/BackgroundFetchedEvent.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "modules/EventModulesNames.h" | 10 #include "modules/EventModulesNames.h" |
11 #include "modules/background_fetch/BackgroundFetchBridge.h" | 11 #include "modules/background_fetch/BackgroundFetchBridge.h" |
12 #include "modules/background_fetch/BackgroundFetchSettledFetch.h" | 12 #include "modules/background_fetch/BackgroundFetchSettledFetch.h" |
13 #include "modules/background_fetch/BackgroundFetchedEventInit.h" | 13 #include "modules/background_fetch/BackgroundFetchedEventInit.h" |
| 14 #include "modules/fetch/Request.h" |
| 15 #include "modules/fetch/Response.h" |
| 16 #include "public/platform/modules/background_fetch/WebBackgroundFetchSettledFetc
h.h" |
14 | 17 |
15 namespace blink { | 18 namespace blink { |
16 | 19 |
17 BackgroundFetchedEvent::BackgroundFetchedEvent( | 20 BackgroundFetchedEvent::BackgroundFetchedEvent( |
18 const AtomicString& type, | 21 const AtomicString& type, |
19 const BackgroundFetchedEventInit& init, | 22 const BackgroundFetchedEventInit& initializer) |
| 23 : BackgroundFetchEvent(type, initializer, nullptr /* observer */), |
| 24 m_fetches(initializer.fetches()) {} |
| 25 |
| 26 BackgroundFetchedEvent::BackgroundFetchedEvent( |
| 27 const AtomicString& type, |
| 28 const BackgroundFetchedEventInit& initializer, |
| 29 const WebVector<WebBackgroundFetchSettledFetch>& fetches, |
| 30 ScriptState* scriptState, |
| 31 WaitUntilObserver* observer, |
20 ServiceWorkerRegistration* registration) | 32 ServiceWorkerRegistration* registration) |
21 : BackgroundFetchEvent(type, init, nullptr /* observer */), | 33 : BackgroundFetchEvent(type, initializer, observer), |
22 m_fetches(init.fetches()), | 34 m_fetches(initializer.fetches()), |
23 m_registration(registration) {} | 35 m_registration(registration) { |
| 36 m_fetches.reserveInitialCapacity(fetches.size()); |
| 37 for (const WebBackgroundFetchSettledFetch& fetch : fetches) { |
| 38 auto* settledFetch = BackgroundFetchSettledFetch::create( |
| 39 Request::create(scriptState, fetch.request), |
| 40 Response::create(scriptState, fetch.response)); |
| 41 |
| 42 m_fetches.push_back(settledFetch); |
| 43 } |
| 44 } |
24 | 45 |
25 BackgroundFetchedEvent::~BackgroundFetchedEvent() = default; | 46 BackgroundFetchedEvent::~BackgroundFetchedEvent() = default; |
26 | 47 |
27 HeapVector<Member<BackgroundFetchSettledFetch>> | 48 HeapVector<Member<BackgroundFetchSettledFetch>> |
28 BackgroundFetchedEvent::fetches() const { | 49 BackgroundFetchedEvent::fetches() const { |
29 return m_fetches; | 50 return m_fetches; |
30 } | 51 } |
31 | 52 |
32 ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState, | 53 ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState, |
33 const String& title) { | 54 const String& title) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 return EventNames::BackgroundFetchedEvent; | 89 return EventNames::BackgroundFetchedEvent; |
69 } | 90 } |
70 | 91 |
71 DEFINE_TRACE(BackgroundFetchedEvent) { | 92 DEFINE_TRACE(BackgroundFetchedEvent) { |
72 visitor->trace(m_fetches); | 93 visitor->trace(m_fetches); |
73 visitor->trace(m_registration); | 94 visitor->trace(m_registration); |
74 BackgroundFetchEvent::trace(visitor); | 95 BackgroundFetchEvent::trace(visitor); |
75 } | 96 } |
76 | 97 |
77 } // namespace blink | 98 } // namespace blink |
OLD | NEW |