Bug 1423412 P1 Actually mark window/worker ClientSource objects controlled when loaded with a controlling service worker. r=baku r=jld

This commit is contained in:
Ben Kelly
2017-12-05 20:45:22 -05:00
parent 01cf3d8a39
commit 1928345b3c
16 changed files with 213 additions and 3 deletions

View File

@@ -3450,6 +3450,32 @@ nsDocShell::MaybeCreateInitialClientSource(nsIPrincipal* aPrincipal)
// If the client is actually used this will cause ClientSource to force
// the creation of the initial about:blank by calling nsDocShell::GetDocument().
mInitialClientSource->DocShellExecutionReady(this);
// Next, check to see if the parent is controlled.
nsCOMPtr<nsIDocShell> parent = GetParentDocshell();
nsPIDOMWindowOuter* parentOuter = parent ? parent->GetWindow() : nullptr;
nsPIDOMWindowInner* parentInner =
parentOuter ? parentOuter->GetCurrentInnerWindow() : nullptr;
if (!parentInner) {
return;
}
Maybe<ServiceWorkerDescriptor> controller(parentInner->GetController());
if (controller.isNothing()) {
return;
}
// If the parent is controlled then propagate that controller to the
// initial about:blank client as well. This will set the controller
// in the ClientManagerService in the parent.
RefPtr<ClientHandle> handle =
ClientManager::CreateHandle(mInitialClientSource->Info(),
parentInner->EventTargetFor(TaskCategory::Other));
handle->Control(controller.ref());
// Also mark the ClientSource as controlled directly in case script
// immediately accesses navigator.serviceWorker.controller.
mInitialClientSource->SetController(controller.ref());
}
Maybe<ClientInfo>