Bug 1704651 - Wait for the right load in ClientOpenWindow. r=asuth

With fission+BFCache, we get a notification for the initial document,
and that fails the same-origin check (because about:blank isn't
same-origin with the opener) so we resolve the promise with null
rather than returning a client.

Instead, wait for the right load to arrive if the top level window
global is the initial document.

Differential Revision: https://phabricator.services.mozilla.com/D112072
This commit is contained in:
Emilio Cobos Álvarez 2021-04-15 12:11:02 +00:00
Родитель 8695079145
Коммит 0677a9ec85
2 изменённых файлов: 15 добавлений и 4 удалений

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

@ -83,8 +83,10 @@ class WebProgressListener final : public nsIWebProgressListener,
// Our caller keeps a strong reference, so it is safe to remove the listener
// from the BrowsingContext's nsIWebProgress.
auto RemoveListener = [&] {
nsCOMPtr<nsIWebProgress> webProgress = browsingContext->GetWebProgress();
webProgress->RemoveProgressListener(this);
};
RefPtr<dom::WindowGlobalParent> wgp =
browsingContext->GetCurrentWindowGlobal();
@ -93,9 +95,18 @@ class WebProgressListener final : public nsIWebProgressListener,
rv.ThrowInvalidStateError("Unable to open window");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
RemoveListener();
return NS_OK;
}
if (NS_WARN_IF(wgp->IsInitialDocument())) {
// This is the load of the initial document, which is not the document we
// care about for the purposes of checking same-originness of the URL.
return NS_OK;
}
RemoveListener();
// Check same origin. If the origins do not match, resolve with null (per
// step 7.2.7.1 of the openWindow spec).
nsCOMPtr<nsIScriptSecurityManager> securityManager =
@ -104,7 +115,7 @@ class WebProgressListener final : public nsIWebProgressListener,
wgp->DocumentPrincipal()->OriginAttributesRef().mPrivateBrowsingId > 0;
nsresult rv = securityManager->CheckSameOriginURI(
wgp->GetDocumentURI(), mBaseURI, false, isPrivateWin);
if (NS_FAILED(rv)) {
if (NS_WARN_IF(NS_FAILED(rv))) {
mPromise->Resolve(CopyableErrorResult(), __func__);
mPromise = nullptr;
return NS_OK;

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

@ -25,7 +25,7 @@ function testForUrl(url, throwType, clientProperties, resultsArray) {
} else if (clientProperties) {
resultsArray.push({
result: e instanceof WindowClient,
message: "openWindow should resolve to a WindowClient",
message: `openWindow should resolve to a WindowClient for url ${url}, got ${e}`,
});
resultsArray.push({
result: e.url == clientProperties.url,