Bug 1188545 - respondWith promise should extend the service worker's lifetime. r=nsm

This commit is contained in:
Catalin Badea 2015-09-30 19:11:03 -04:00
parent 518e55a5ed
commit cce3b797b1
3 changed files with 19 additions and 1 deletions

View File

@ -408,6 +408,9 @@ FetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv)
return;
}
if (!mPromise) {
mPromise = &aArg;
}
nsRefPtr<InternalRequest> ir = mRequest->GetInternalRequest();
mWaitToRespond = true;
nsRefPtr<RespondWithHandler> 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)

View File

@ -55,6 +55,7 @@ class FetchEvent final : public Event
nsRefPtr<Request> mRequest;
nsCString mScriptSpec;
UniquePtr<ServiceWorkerClientInfo> mClientInfo;
nsRefPtr<Promise> mPromise;
bool mIsReload;
bool mWaitToRespond;
protected:
@ -105,6 +106,13 @@ public:
void
RespondWith(Promise& aArg, ErrorResult& aRv);
already_AddRefed<Promise>
GetPromise() const
{
nsRefPtr<Promise> p = mPromise;
return p.forget();
}
already_AddRefed<Promise>
ForwardTo(const nsAString& aUrl);

View File

@ -1068,6 +1068,12 @@ private:
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
}
nsRefPtr<Promise> respondWithPromise = event->GetPromise();
if (respondWithPromise) {
nsRefPtr<KeepAliveHandler> keepAliveHandler =
new KeepAliveHandler(mKeepAliveToken);
respondWithPromise->AppendNativeHandler(keepAliveHandler);
}
return true;
}
};