Bug 1426253 P2 Use nsIDocument::GetClientInfo() where possible. r=asuth

This commit is contained in:
Ben Kelly 2017-12-20 10:53:18 -05:00
Родитель aa417857ba
Коммит 7c2e00408e
3 изменённых файлов: 19 добавлений и 37 удалений

Просмотреть файл

@ -80,15 +80,8 @@ public:
return NS_OK;
}
nsPIDOMWindowInner* innerWindow = doc->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) {
mPromise->Reject(NS_ERROR_FAILURE, __func__);
mPromise = nullptr;
return NS_OK;
}
Maybe<ClientInfo> info = innerWindow->GetClientInfo();
Maybe<ClientState> state = innerWindow->GetClientState();
Maybe<ClientInfo> info(doc->GetClientInfo());
Maybe<ClientState> state(doc->GetClientState());
if (NS_WARN_IF(info.isNothing() || state.isNothing())) {
mPromise->Reject(NS_ERROR_FAILURE, __func__);

Просмотреть файл

@ -2372,16 +2372,13 @@ ServiceWorkerManager::StartControllingADocument(ServiceWorkerRegistrationInfo* a
// document here, our goal is to move ServiceWorkerManager to a separate
// process. Using the ClientHandle supports this remote operation.
ServiceWorkerInfo* activeWorker = aRegistration->GetActive();
nsPIDOMWindowInner* innerWindow = aDoc->GetInnerWindow();
if (activeWorker && innerWindow) {
Maybe<ClientInfo> clientInfo = innerWindow->GetClientInfo();
if (clientInfo.isSome()) {
Maybe<ClientInfo> clientInfo = aDoc->GetClientInfo();
if (activeWorker && clientInfo.isSome()) {
RefPtr<ClientHandle> clientHandle =
ClientManager::CreateHandle(clientInfo.ref(),
SystemGroup::EventTargetFor(TaskCategory::Other));
ref = Move(clientHandle->Control(activeWorker->Descriptor()));
}
}
Telemetry::Accumulate(Telemetry::SERVICE_WORKER_CONTROLLED_DOCUMENTS, 1);
return Move(ref);
@ -3273,7 +3270,7 @@ ServiceWorkerManager::UpdateClientControllers(ServiceWorkerRegistrationInfo* aRe
RefPtr<ServiceWorkerInfo> activeWorker = aRegistration->GetActive();
MOZ_DIAGNOSTIC_ASSERT(activeWorker);
AutoTArray<nsCOMPtr<nsPIDOMWindowInner>, 16> innerWindows;
AutoTArray<nsCOMPtr<nsIDocument>, 16> docList;
for (auto iter = mControlledDocuments.Iter(); !iter.Done(); iter.Next()) {
if (iter.UserData() != aRegistration) {
continue;
@ -3284,25 +3281,21 @@ ServiceWorkerManager::UpdateClientControllers(ServiceWorkerRegistrationInfo* aRe
continue;
}
nsPIDOMWindowInner* innerWindow = doc->GetInnerWindow();
if (NS_WARN_IF(!innerWindow)) {
continue;
}
innerWindows.AppendElement(innerWindow);
docList.AppendElement(doc.forget());
}
// Fire event after iterating mControlledDocuments is done to prevent
// modification by reentering from the event handlers during iteration.
for (auto& innerWindow : innerWindows) {
Maybe<ClientInfo> clientInfo = innerWindow->GetClientInfo();
if (clientInfo.isSome()) {
for (auto& doc : docList) {
Maybe<ClientInfo> clientInfo = doc->GetClientInfo();
if (clientInfo.isNothing()) {
continue;
}
RefPtr<ClientHandle> clientHandle =
ClientManager::CreateHandle(clientInfo.ref(),
innerWindow->EventTargetFor(TaskCategory::Other));
SystemGroup::EventTargetFor(TaskCategory::Other));
clientHandle->Control(activeWorker->Descriptor());
}
}
}
already_AddRefed<ServiceWorkerRegistrationInfo>

Просмотреть файл

@ -117,11 +117,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
// Ensure that all network requests for a window client have the ClientInfo
// properly set.
// TODO: The ClientInfo is not set properly for worker initiated requests yet.
nsCOMPtr<nsPIDOMWindowInner> contextInner =
aLoadingContext->OwnerDoc()->GetInnerWindow();
if (contextInner) {
mClientInfo = contextInner->GetClientInfo();
}
mClientInfo = aLoadingContext->OwnerDoc()->GetClientInfo();
nsCOMPtr<nsPIDOMWindowOuter> contextOuter = aLoadingContext->OwnerDoc()->GetWindow();
if (contextOuter) {