diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 436750babc7b..04d57bdde49f 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -408,6 +408,9 @@ FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv) return; } + if (!mPromise) { + mPromise = &aArg; + } nsRefPtr ir = mRequest->GetInternalRequest(); mWaitToRespond = true; nsRefPtr handler = @@ -440,7 +443,8 @@ NS_IMPL_RELEASE_INHERITED(FetchEvent, Event) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FetchEvent) NS_INTERFACE_MAP_END_INHERITING(Event) -NS_IMPL_CYCLE_COLLECTION_INHERITED(FetchEvent, Event, mRequest, mClient) +NS_IMPL_CYCLE_COLLECTION_INHERITED(FetchEvent, Event, mRequest, mClient, + mPromise) ExtendableEvent::ExtendableEvent(EventTarget* aOwner) : Event(aOwner, nullptr, nullptr) diff --git a/dom/workers/ServiceWorkerEvents.h b/dom/workers/ServiceWorkerEvents.h index dd8847f825c5..51e9d691bcbc 100644 --- a/dom/workers/ServiceWorkerEvents.h +++ b/dom/workers/ServiceWorkerEvents.h @@ -55,6 +55,7 @@ class FetchEvent final : public Event nsRefPtr mRequest; nsCString mScriptSpec; UniquePtr mClientInfo; + nsRefPtr mPromise; bool mIsReload; bool mWaitToRespond; protected: @@ -105,6 +106,13 @@ public: void RespondWith(Promise& aArg, ErrorResult& aRv); + already_AddRefed + GetPromise() const + { + nsRefPtr p = mPromise; + return p.forget(); + } + already_AddRefed ForwardTo(const nsAString& aUrl); diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index f0da36002202..f6f3f3b5622d 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -1068,6 +1068,12 @@ private: MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable))); } + nsRefPtr respondWithPromise = event->GetPromise(); + if (respondWithPromise) { + nsRefPtr keepAliveHandler = + new KeepAliveHandler(mKeepAliveToken); + respondWithPromise->AppendNativeHandler(keepAliveHandler); + } return true; } };