summaryrefslogtreecommitdiffstats
path: root/dom/fetch/FetchDriver.cpp
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-06-10 21:51:44 +0000
committerwolfbeast <mcwerewolf@wolfbeast.com>2020-06-13 11:51:41 +0200
commita04d67dd12d4999b28e74744150770482a3c5a3d (patch)
treedcbb29403e938f6b14140d15e9077c6188ca81c8 /dom/fetch/FetchDriver.cpp
parent9e2da53a02356244c5dc0a3e7b7ec916740d3d51 (diff)
downloadUXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar
UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.gz
UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.lz
UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.tar.xz
UXP-a04d67dd12d4999b28e74744150770482a3c5a3d.zip
Issue #1587 - Part 3: Hook FetchSignal up to the Fetch API
Diffstat (limited to 'dom/fetch/FetchDriver.cpp')
-rw-r--r--dom/fetch/FetchDriver.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp
index 6294b0dc5..448ec64cd 100644
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -67,7 +67,7 @@ FetchDriver::~FetchDriver()
}
nsresult
-FetchDriver::Fetch(FetchDriverObserver* aObserver)
+FetchDriver::Fetch(FetchSignal* aSignal, FetchDriverObserver* aObserver)
{
workers::AssertIsOnMainThread();
#ifdef DEBUG
@@ -90,6 +90,18 @@ FetchDriver::Fetch(FetchDriverObserver* aObserver)
}
mRequest->SetPrincipalInfo(Move(principalInfo));
+
+ // If the signal is aborted, it's time to inform the observer and terminate
+ // the operation.
+ if (aSignal) {
+ if (aSignal->Aborted()) {
+ Aborted();
+ return NS_OK;
+ }
+
+ Follow(aSignal);
+ }
+
if (NS_FAILED(HttpFetch())) {
FailWithNetworkError();
}
@@ -114,11 +126,7 @@ FetchDriver::HttpFetch()
nsAutoCString url;
mRequest->GetURL(url);
nsCOMPtr<nsIURI> uri;
- rv = NS_NewURI(getter_AddRefs(uri),
- url,
- nullptr,
- nullptr,
- ios);
+ rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, nullptr, ios);
NS_ENSURE_SUCCESS(rv, rv);
// Unsafe requests aren't allowed with when using no-core mode.
@@ -380,6 +388,8 @@ FetchDriver::HttpFetch()
NS_ENSURE_SUCCESS(rv, rv);
// Step 4 onwards of "HTTP Fetch" is handled internally by Necko.
+
+ mChannel = chan;
return NS_OK;
}
already_AddRefed<InternalResponse>
@@ -433,9 +443,11 @@ FetchDriver::FailWithNetworkError()
#ifdef DEBUG
mResponseAvailableCalled = true;
#endif
- mObserver->OnResponseEnd();
+ mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking);
mObserver = nullptr;
}
+
+ mChannel = nullptr;
}
namespace {
@@ -777,10 +789,11 @@ FetchDriver::OnStopRequest(nsIRequest* aRequest,
#endif
}
- mObserver->OnResponseEnd();
+ mObserver->OnResponseEnd(FetchDriverObserver::eByNetworking);
mObserver = nullptr;
}
+ mChannel = nullptr;
return NS_OK;
}
@@ -921,5 +934,21 @@ FetchDriver::SetRequestHeaders(nsIHttpChannel* aChannel) const
}
}
+void FetchDriver::Aborted()
+{
+ if (mObserver) {
+#ifdef DEBUG
+ mResponseAvailableCalled = true;
+#endif
+ mObserver->OnResponseEnd(FetchDriverObserver::eAborted);
+ mObserver = nullptr;
+ }
+
+ if (mChannel) {
+ mChannel->Cancel(NS_BINDING_ABORTED);
+ mChannel = nullptr;
+ }
+}
+
} // namespace dom
} // namespace mozilla