| Index: third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
|
| diff --git a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
|
| index d5cc50da50f26fc97d8016b63f06b37a45a91a44..3551dbe69457edbdc4634f9f4b4e486765e4fc68 100644
|
| --- a/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
|
| +++ b/third_party/WebKit/Source/modules/background_fetch/BackgroundFetchedEvent.cpp
|
| @@ -4,9 +4,11 @@
|
|
|
| #include "modules/background_fetch/BackgroundFetchedEvent.h"
|
|
|
| +#include "bindings/core/v8/ScriptPromiseResolver.h"
|
| #include "bindings/core/v8/ScriptState.h"
|
| #include "core/dom/DOMException.h"
|
| #include "modules/EventModulesNames.h"
|
| +#include "modules/background_fetch/BackgroundFetchBridge.h"
|
| #include "modules/background_fetch/BackgroundFetchSettledRequest.h"
|
| #include "modules/background_fetch/BackgroundFetchedEventInit.h"
|
|
|
| @@ -14,9 +16,11 @@ namespace blink {
|
|
|
| BackgroundFetchedEvent::BackgroundFetchedEvent(
|
| const AtomicString& type,
|
| - const BackgroundFetchedEventInit& init)
|
| + const BackgroundFetchedEventInit& init,
|
| + ServiceWorkerRegistration* registration)
|
| : BackgroundFetchEvent(type, init),
|
| - m_completedFetches(init.completedFetches()) {}
|
| + m_completedFetches(init.completedFetches()),
|
| + m_registration(registration) {}
|
|
|
| BackgroundFetchedEvent::~BackgroundFetchedEvent() = default;
|
|
|
| @@ -26,10 +30,37 @@ BackgroundFetchedEvent::completedFetches() const {
|
| }
|
|
|
| ScriptPromise BackgroundFetchedEvent::updateUI(ScriptState* scriptState,
|
| - String title) {
|
| - return ScriptPromise::rejectWithDOMException(
|
| - scriptState,
|
| - DOMException::create(NotSupportedError, "Not implemented yet."));
|
| + const String& title) {
|
| + if (!m_registration) {
|
| + // Return a Promise that will never settle when a developer calls this
|
| + // method on a BackgroundFetchedEvent instance they created themselves.
|
| + return ScriptPromise();
|
| + }
|
| +
|
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| + ScriptPromise promise = resolver->promise();
|
| +
|
| + BackgroundFetchBridge::from(m_registration)
|
| + ->updateUI(tag(), title,
|
| + WTF::bind(&BackgroundFetchedEvent::didUpdateUI,
|
| + wrapPersistent(this), wrapPersistent(resolver)));
|
| +
|
| + return promise;
|
| +}
|
| +
|
| +void BackgroundFetchedEvent::didUpdateUI(
|
| + ScriptPromiseResolver* resolver,
|
| + mojom::blink::BackgroundFetchError error) {
|
| + switch (error) {
|
| + case mojom::blink::BackgroundFetchError::NONE:
|
| + resolver->resolve();
|
| + return;
|
| + case mojom::blink::BackgroundFetchError::DUPLICATED_TAG:
|
| + // Not applicable for this callback.
|
| + break;
|
| + }
|
| +
|
| + NOTREACHED();
|
| }
|
|
|
| const AtomicString& BackgroundFetchedEvent::interfaceName() const {
|
| @@ -38,6 +69,7 @@ const AtomicString& BackgroundFetchedEvent::interfaceName() const {
|
|
|
| DEFINE_TRACE(BackgroundFetchedEvent) {
|
| visitor->trace(m_completedFetches);
|
| + visitor->trace(m_registration);
|
| BackgroundFetchEvent::trace(visitor);
|
| }
|
|
|
|
|