Bug 1389303 - [1.3] Call OnStart/OnStop callbacks on successful URI load in the external protocol channel. r=mcmanus

This commit is contained in:
Eugen Sawin 2017-08-16 15:45:27 +02:00
Родитель b1e9bcda7b
Коммит 456f394895
1 изменённых файлов: 14 добавлений и 5 удалений

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

@ -71,6 +71,7 @@ private:
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsILoadInfo> mLoadInfo;
nsCOMPtr<nsIStreamListener> mListener;
};
NS_IMPL_ADDREF(nsExtProtocolChannel)
@ -175,16 +176,23 @@ nsresult nsExtProtocolChannel::OpenURL()
}
rv = extProtService->LoadURI(mUrl, aggCallbacks);
if (NS_SUCCEEDED(rv)) {
// despite success, we need to abort this channel, at the very least
// to make it clear to the caller that no on{Start,Stop}Request
// should be expected.
rv = NS_ERROR_NO_CONTENT;
if (NS_SUCCEEDED(rv) && mListener) {
RefPtr<nsExtProtocolChannel> self = this;
nsCOMPtr<nsIStreamListener> listener = mListener;
MessageLoop::current()->PostTask(
NS_NewRunnableFunction(
"nsExtProtocolChannel::OpenURL",
[self, listener]() {
listener->OnStartRequest(self, nullptr);
listener->OnStopRequest(self, nullptr, self->mStatus);
}));
}
}
finish:
mCallbacks = nullptr;
mListener = nullptr;
return rv;
}
@ -218,6 +226,7 @@ NS_IMETHODIMP nsExtProtocolChannel::AsyncOpen(nsIStreamListener *listener, nsISu
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED);
mWasOpened = true;
mListener = listener;
return OpenURL();
}