Bug 1538516 - Resolve the Promise returned by fetch() later during page loads, r=baku

The patch depends on https://bugzilla.mozilla.org/show_bug.cgi?id=1558215

Depends on D34366

Differential Revision: https://phabricator.services.mozilla.com/D34367

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Olli Pettay 2019-06-12 18:37:49 +00:00
Родитель f2f19ca465
Коммит 7004df09e8
1 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -540,6 +540,21 @@ already_AddRefed<Promise> FetchRequest(nsIGlobalObject* aGlobal,
return p.forget();
}
class ResolveFetchPromise : public Runnable {
public:
ResolveFetchPromise(Promise* aPromise, Response* aResponse)
: Runnable("ResolveFetchPromise"),
mPromise(aPromise),
mResponse(aResponse) {}
NS_IMETHOD Run() {
mPromise->MaybeResolve(mResponse);
return NS_OK;
}
RefPtr<Promise> mPromise;
RefPtr<Response> mResponse;
};
void MainThreadFetchResolver::OnResponseAvailableInternal(
InternalResponse* aResponse) {
NS_ASSERT_OWNINGTHREAD(MainThreadFetchResolver);
@ -552,7 +567,15 @@ void MainThreadFetchResolver::OnResponseAvailableInternal(
nsCOMPtr<nsIGlobalObject> go = mPromise->GetParentObject();
mResponse = new Response(go, aResponse, mSignalImpl);
mPromise->MaybeResolve(mResponse);
nsCOMPtr<nsPIDOMWindowInner> inner = do_QueryInterface(go);
nsPIDOMWindowInner* topLevel =
inner ? inner->GetWindowForDeprioritizedLoadRunner() : nullptr;
if (topLevel) {
topLevel->AddDeprioritizedLoadRunner(
new ResolveFetchPromise(mPromise, mResponse));
} else {
mPromise->MaybeResolve(mResponse);
}
} else {
if (mFetchObserver) {
mFetchObserver->SetState(FetchState::Errored);