mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1278778 - Show JS stack traces of Fetch requests in Netmonitor r=bkelly
This commit is contained in:
parent
14183e306e
commit
b57da2dc12
@ -40,12 +40,19 @@ const EXPECTED_REQUESTS = [
|
||||
causeUri: CAUSE_URL,
|
||||
hasStack: { fn: "performXhrRequest", file: CAUSE_FILE_NAME, line: 22 }
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
url: EXAMPLE_URL + "fetch_request",
|
||||
causeType: "fetch",
|
||||
causeUri: CAUSE_URL,
|
||||
hasStack: { fn: "performFetchRequest", file: CAUSE_FILE_NAME, line: 26 }
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
url: EXAMPLE_URL + "beacon_request",
|
||||
causeType: "beacon",
|
||||
causeUri: CAUSE_URL,
|
||||
hasStack: { fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 26 }
|
||||
hasStack: { fn: "performBeaconRequest", file: CAUSE_FILE_NAME, line: 30 }
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -22,11 +22,16 @@
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function performFetchRequest() {
|
||||
fetch("fetch_request");
|
||||
}
|
||||
|
||||
function performBeaconRequest() {
|
||||
navigator.sendBeacon("beacon_request");
|
||||
}
|
||||
|
||||
performXhrRequest();
|
||||
performFetchRequest();
|
||||
performBeaconRequest();
|
||||
</script>
|
||||
</body>
|
||||
|
@ -124,23 +124,29 @@ public:
|
||||
Run()
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
RefPtr<FetchDriver> fetch;
|
||||
RefPtr<PromiseWorkerProxy> proxy = mResolver->mPromiseProxy;
|
||||
MutexAutoLock lock(proxy->Lock());
|
||||
if (proxy->CleanedUp()) {
|
||||
NS_WARNING("Aborting Fetch because worker already shut down");
|
||||
return NS_OK;
|
||||
|
||||
{
|
||||
// Acquire the proxy mutex while getting data from the WorkerPrivate...
|
||||
MutexAutoLock lock(proxy->Lock());
|
||||
if (proxy->CleanedUp()) {
|
||||
NS_WARNING("Aborting Fetch because worker already shut down");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = proxy->GetWorkerPrivate()->GetPrincipal();
|
||||
MOZ_ASSERT(principal);
|
||||
nsCOMPtr<nsILoadGroup> loadGroup = proxy->GetWorkerPrivate()->GetLoadGroup();
|
||||
MOZ_ASSERT(loadGroup);
|
||||
fetch = new FetchDriver(mRequest, principal, loadGroup);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal = proxy->GetWorkerPrivate()->GetPrincipal();
|
||||
MOZ_ASSERT(principal);
|
||||
nsCOMPtr<nsILoadGroup> loadGroup = proxy->GetWorkerPrivate()->GetLoadGroup();
|
||||
MOZ_ASSERT(loadGroup);
|
||||
RefPtr<FetchDriver> fetch = new FetchDriver(mRequest, principal, loadGroup);
|
||||
nsresult rv = fetch->Fetch(mResolver);
|
||||
// Right now we only support async fetch, which should never directly fail.
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
// ...but release it before calling Fetch, because mResolver's callback can
|
||||
// be called synchronously and they want the mutex, too.
|
||||
fetch->Fetch(mResolver);
|
||||
|
||||
// FetchDriver::Fetch never directly fails
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
@ -83,20 +83,12 @@ FetchDriver::Fetch(FetchDriverObserver* aObserver)
|
||||
MOZ_RELEASE_ASSERT(!mRequest->IsSynchronous(),
|
||||
"Synchronous fetch not supported");
|
||||
|
||||
return NS_DispatchToCurrentThread(NewRunnableMethod(this, &FetchDriver::ContinueFetch));
|
||||
}
|
||||
|
||||
nsresult
|
||||
FetchDriver::ContinueFetch()
|
||||
{
|
||||
workers::AssertIsOnMainThread();
|
||||
|
||||
nsresult rv = HttpFetch();
|
||||
if (NS_FAILED(rv)) {
|
||||
if (NS_FAILED(HttpFetch())) {
|
||||
FailWithNetworkError();
|
||||
}
|
||||
|
||||
return rv;
|
||||
// Any failure is handled by FailWithNetworkError notifying the aObserver.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This function implements the "HTTP Fetch" algorithm from the Fetch spec.
|
||||
|
@ -27,6 +27,11 @@ namespace dom {
|
||||
class InternalRequest;
|
||||
class InternalResponse;
|
||||
|
||||
/**
|
||||
* Provides callbacks to be called when response is available or on error.
|
||||
* Implemenations usually resolve or reject the promise returned from fetch().
|
||||
* The callbacks can be called synchronously or asynchronously from FetchDriver::Fetch.
|
||||
*/
|
||||
class FetchDriverObserver
|
||||
{
|
||||
public:
|
||||
@ -92,7 +97,6 @@ private:
|
||||
FetchDriver& operator=(const FetchDriver&) = delete;
|
||||
~FetchDriver();
|
||||
|
||||
nsresult ContinueFetch();
|
||||
nsresult HttpFetch();
|
||||
// Returns the filtered response sent to the observer.
|
||||
already_AddRefed<InternalResponse>
|
||||
|
Loading…
Reference in New Issue
Block a user