Bug 1278778 - Show JS stack traces of Fetch requests in Netmonitor r=bkelly

This commit is contained in:
Jarda Snajdr 2016-06-14 04:08:00 +01:00
parent 14183e306e
commit b57da2dc12
5 changed files with 41 additions and 27 deletions

View File

@ -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 }
},
];

View File

@ -22,11 +22,16 @@
xhr.send();
}
function performFetchRequest() {
fetch("fetch_request");
}
function performBeaconRequest() {
navigator.sendBeacon("beacon_request");
}
performXhrRequest();
performFetchRequest();
performBeaconRequest();
</script>
</body>

View File

@ -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;
}
};

View File

@ -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.

View File

@ -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>