Chromium Code Reviews| 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/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 9 #include "modules/EventModulesNames.h" | 10 #include "modules/EventModulesNames.h" |
| 11 #include "modules/background_fetch/BackgroundFetchBridge.h" | |
| 10 #include "modules/background_fetch/BackgroundFetchSettledRequest.h" | 12 #include "modules/background_fetch/BackgroundFetchSettledRequest.h" |
| 11 #include "modules/background_fetch/BackgroundFetchedEventInit.h" | 13 #include "modules/background_fetch/BackgroundFetchedEventInit.h" |
| 12 | 14 |
| 13 namespace blink { | 15 namespace blink { |
| 14 | 16 |
| 15 BackgroundFetchedEvent::BackgroundFetchedEvent( | 17 BackgroundFetchedEvent::BackgroundFetchedEvent( |
| 16 const AtomicString& type, | 18 const AtomicString& type, |
| 17 const BackgroundFetchedEventInit& init) | 19 const BackgroundFetchedEventInit& init, |
| 20 ServiceWorkerRegistration* registration) | |
| 18 : BackgroundFetchEvent(type, init), | 21 : BackgroundFetchEvent(type, init), |
| 19 m_completedFetches(init.completedFetches()) {} | 22 m_completedFetches(init.completedFetches()), |
| 23 m_registration(registration) {} | |
| 20 | 24 |
| 21 BackgroundFetchedEvent::~BackgroundFetchedEvent() = default; | 25 BackgroundFetchedEvent::~BackgroundFetchedEvent() = default; |
| 22 | 26 |
| 23 HeapVector<Member<BackgroundFetchSettledRequest>> | 27 HeapVector<Member<BackgroundFetchSettledRequest>> |
| 24 BackgroundFetchedEvent::completedFetches() const { | 28 BackgroundFetchedEvent::completedFetches() const { |
| 25 return m_completedFetches; | 29 return m_completedFetches; |
| 26 } | 30 } |
| 27 | 31 |
| 28 ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState, | 32 ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState, |
| 29 String title) { | 33 const String& title) { |
| 30 return ScriptPromise::rejectWithDOMException( | 34 if (!m_registration) { |
| 31 scriptState, | 35 // Return a Promise that will never settle when a developer calls this |
| 32 DOMException::create(NotSupportedError, "Not implemented yet.")); | 36 // method on a BackgroundFetchedEvent instance they created themselves. |
| 37 return ScriptPromise(); | |
| 38 } | |
| 39 | |
| 40 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | |
| 41 ScriptPromise promise = resolver->promise(); | |
| 42 | |
| 43 BackgroundFetchBridge::from(m_registration) | |
| 44 ->updateUI(tag(), title, | |
| 45 WTF::bind(&BackgroundFetchedEvent::didUpdateUI, | |
| 46 wrapPersistent(this), wrapPersistent(resolver))); | |
| 47 | |
| 48 return promise; | |
| 49 } | |
| 50 | |
| 51 void BackgroundFetchedEvent::didUpdateUI( | |
| 52 ScriptPromiseResolver* resolver, | |
| 53 mojom::blink::BackgroundFetchError error) { | |
| 54 switch (error) { | |
| 55 case mojom::blink::BackgroundFetchError::NONE: | |
| 56 resolver->resolve(); | |
|
dcheng
2017/03/16 07:14:08
Nit: this still ends up in the NOTREACHED(), shoul
Peter Beverloo
2017/03/16 16:26:55
Done.
| |
| 57 break; | |
| 58 case mojom::blink::BackgroundFetchError::DUPLICATED_TAG: | |
| 59 // Not applicable for this callback. | |
| 60 break; | |
| 61 } | |
| 62 | |
| 63 NOTREACHED(); | |
| 33 } | 64 } |
| 34 | 65 |
| 35 const AtomicString& BackgroundFetchedEvent::interfaceName() const { | 66 const AtomicString& BackgroundFetchedEvent::interfaceName() const { |
| 36 return EventNames::BackgroundFetchedEvent; | 67 return EventNames::BackgroundFetchedEvent; |
| 37 } | 68 } |
| 38 | 69 |
| 39 DEFINE_TRACE(BackgroundFetchedEvent) { | 70 DEFINE_TRACE(BackgroundFetchedEvent) { |
| 40 visitor->trace(m_completedFetches); | 71 visitor->trace(m_completedFetches); |
| 72 visitor->trace(m_registration); | |
| 41 BackgroundFetchEvent::trace(visitor); | 73 BackgroundFetchEvent::trace(visitor); |
| 42 } | 74 } |
| 43 | 75 |
| 44 } // namespace blink | 76 } // namespace blink |
| OLD | NEW |