Bug 1134330 - Mark fetch events as reloads appropriately. r=smaug

This commit is contained in:
Josh Matthews 2015-03-23 13:36:44 -04:00
parent 18e5cd874b
commit 9eb14e014e
5 changed files with 36 additions and 12 deletions

View File

@ -13995,7 +13995,8 @@ nsDocShell::ChannelIntercepted(nsIInterceptedChannel* aChannel)
}
}
return swm->DispatchFetchEvent(doc, aChannel);
bool isReload = mLoadType & LOAD_CMD_RELOAD;
return swm->DispatchFetchEvent(doc, aChannel, isReload);
}
NS_IMETHODIMP

View File

@ -19,7 +19,7 @@ interface nsIServiceWorkerUnregisterCallback : nsISupports
[noscript] void UnregisterFailed();
};
[builtinclass, uuid(706c3e6b-c9d2-4857-893d-4b4845fec48f)]
[builtinclass, uuid(e4c8baa5-237a-4bf6-82d4-ea06eb4b76ba)]
interface nsIServiceWorkerManager : nsISupports
{
/**
@ -59,7 +59,8 @@ interface nsIServiceWorkerManager : nsISupports
bool isControlled(in nsIDocument aDocument);
// Cause a fetch event to be dispatched to the worker global associated with the given document.
void dispatchFetchEvent(in nsIDocument aDoc, in nsIInterceptedChannel aChannel);
void dispatchFetchEvent(in nsIDocument aDoc, in nsIInterceptedChannel aChannel,
in boolean aIsReload);
// aTarget MUST be a ServiceWorkerRegistration.
[noscript] void AddRegistrationEventListener(in DOMString aScope, in nsIDOMEventTarget aTarget);

View File

@ -2135,11 +2135,13 @@ public:
FetchEventRunnable(WorkerPrivate* aWorkerPrivate,
nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
nsMainThreadPtrHandle<ServiceWorker>& aServiceWorker,
nsAutoPtr<ServiceWorkerClientInfo>& aClientInfo)
nsAutoPtr<ServiceWorkerClientInfo>& aClientInfo,
bool aIsReload)
: WorkerRunnable(aWorkerPrivate, WorkerThreadModifyBusyCount)
, mInterceptedChannel(aChannel)
, mServiceWorker(aServiceWorker)
, mClientInfo(aClientInfo)
, mIsReload(aIsReload)
{
MOZ_ASSERT(aWorkerPrivate);
}
@ -2178,9 +2180,6 @@ public:
rv = channel->GetLoadFlags(&loadFlags);
NS_ENSURE_SUCCESS(rv, rv);
//TODO(jdm): we should probably include reload-ness in the loadinfo or as a separate load flag
mIsReload = false;
rv = httpChannel->VisitRequestHeaders(this);
NS_ENSURE_SUCCESS(rv, rv);
@ -2280,7 +2279,8 @@ private:
NS_IMPL_ISUPPORTS_INHERITED(FetchEventRunnable, WorkerRunnable, nsIHttpHeaderVisitor)
NS_IMETHODIMP
ServiceWorkerManager::DispatchFetchEvent(nsIDocument* aDoc, nsIInterceptedChannel* aChannel)
ServiceWorkerManager::DispatchFetchEvent(nsIDocument* aDoc, nsIInterceptedChannel* aChannel,
bool aIsReload)
{
MOZ_ASSERT(aChannel);
nsCOMPtr<nsISupports> serviceWorker;
@ -2330,7 +2330,7 @@ ServiceWorkerManager::DispatchFetchEvent(nsIDocument* aDoc, nsIInterceptedChanne
// clientInfo is null if we don't have a controlled document
nsRefPtr<FetchEventRunnable> event =
new FetchEventRunnable(sw->GetWorkerPrivate(), handle, serviceWorkerHandle, clientInfo);
new FetchEventRunnable(sw->GetWorkerPrivate(), handle, serviceWorkerHandle, clientInfo, aIsReload);
rv = event->Init();
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -1,3 +1,5 @@
var seenIndex = false;
onfetch = function(ev) {
if (ev.request.url.contains("synthesized.txt")) {
ev.respondWith(Promise.resolve(
@ -115,4 +117,18 @@ onfetch = function(ev) {
});
}));
}
else if (ev.request.url.contains("index.html")) {
if (seenIndex) {
var body = "<script>" +
"opener.postMessage({status: 'ok', result: " + ev.isReload + "," +
"message: 'reload status should be indicated'}, '*');" +
"opener.postMessage({status: 'done'}, '*');" +
"</script>";
ev.respondWith(new Response(body, {headers: {'Content-Type': 'text/html'}}));
} else {
seenIndex = true;
ev.respondWith(fetch(ev.request.url));
}
}
}

View File

@ -27,13 +27,19 @@
function testController() {
var p = new Promise(function(resolve, reject) {
var reloaded = false;
window.onmessage = function(e) {
if (e.data.status == "ok") {
ok(e.data.result, e.data.message);
} else if (e.data.status == "done") {
window.onmessage = null;
w.close();
resolve();
if (reloaded) {
window.onmessage = null;
w.close();
resolve();
} else {
w.location.reload();
reloaded = true;
}
}
}
});