Differential Revision: https://phabricator.services.mozilla.com/D89110
This commit is contained in:
Kershaw Chang 2020-09-09 12:57:32 +00:00
Родитель ba273047b5
Коммит 9959ea65a6
1 изменённых файлов: 13 добавлений и 5 удалений

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

@ -867,7 +867,9 @@ already_AddRefed<InternalResponse> FetchDriver::BeginAndGetFilteredResponse(
MOZ_ASSERT(filteredResponse); MOZ_ASSERT(filteredResponse);
MOZ_ASSERT(mObserver); MOZ_ASSERT(mObserver);
if (!ShouldCheckSRI(*mRequest, *filteredResponse)) { if (!ShouldCheckSRI(*mRequest, *filteredResponse)) {
mObserver->OnResponseAvailable(filteredResponse); // Need to keep mObserver alive.
RefPtr<FetchDriverObserver> observer = mObserver;
observer->OnResponseAvailable(filteredResponse);
#ifdef DEBUG #ifdef DEBUG
mResponseAvailableCalled = true; mResponseAvailableCalled = true;
#endif #endif
@ -880,7 +882,9 @@ void FetchDriver::FailWithNetworkError(nsresult rv) {
AssertIsOnMainThread(); AssertIsOnMainThread();
RefPtr<InternalResponse> error = InternalResponse::NetworkError(rv); RefPtr<InternalResponse> error = InternalResponse::NetworkError(rv);
if (mObserver) { if (mObserver) {
mObserver->OnResponseAvailable(error); // Need to keep mObserver alive.
RefPtr<FetchDriverObserver> observer = mObserver;
observer->OnResponseAvailable(error);
#ifdef DEBUG #ifdef DEBUG
mResponseAvailableCalled = true; mResponseAvailableCalled = true;
#endif #endif
@ -1263,10 +1267,12 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest, nsIInputStream* aInputStream,
if (mNeedToObserveOnDataAvailable) { if (mNeedToObserveOnDataAvailable) {
mNeedToObserveOnDataAvailable = false; mNeedToObserveOnDataAvailable = false;
if (mObserver) { if (mObserver) {
// Need to keep mObserver alive.
RefPtr<FetchDriverObserver> observer = mObserver;
if (NS_IsMainThread()) { if (NS_IsMainThread()) {
mObserver->OnDataAvailable(); observer->OnDataAvailable();
} else { } else {
RefPtr<Runnable> runnable = new DataAvailableRunnable(mObserver); RefPtr<Runnable> runnable = new DataAvailableRunnable(observer);
nsresult rv = mMainThreadEventTarget->Dispatch(runnable.forget(), nsresult rv = mMainThreadEventTarget->Dispatch(runnable.forget(),
NS_DISPATCH_NORMAL); NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -1401,7 +1407,9 @@ void FetchDriver::FinishOnStopRequest(
// From "Main Fetch" step 19.1, 19.2: Process response. // From "Main Fetch" step 19.1, 19.2: Process response.
if (ShouldCheckSRI(*mRequest, *mResponse)) { if (ShouldCheckSRI(*mRequest, *mResponse)) {
MOZ_ASSERT(mResponse); MOZ_ASSERT(mResponse);
mObserver->OnResponseAvailable(mResponse); // Need to keep mObserver alive.
RefPtr<FetchDriverObserver> observer = mObserver;
observer->OnResponseAvailable(mResponse);
#ifdef DEBUG #ifdef DEBUG
mResponseAvailableCalled = true; mResponseAvailableCalled = true;
#endif #endif