Backed out changeset da4b797fcefa (bug 1650162) for bc failures on browser_protocol_ask_dialog.js. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2020-07-16 03:52:12 +03:00
Родитель 916bf4d67b
Коммит 765f7688bf
2 изменённых файлов: 5 добавлений и 138 удалений

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

@ -984,25 +984,16 @@ nsExternalHelperAppService::LoadURI(nsIURI* aURI,
// Also allow this load if the target is a toplevel BC and contains a
// non-web-controlled about:blank document
if (bc->IsTop() && !bc->HadOriginalOpener() && wgp) {
if (bc->IsTop() && !bc->HadOriginalOpener()) {
RefPtr<nsIURI> uri = wgp->GetDocumentURI();
foundAccessibleFrame =
uri && uri->GetSpecOrDefault().EqualsLiteral("about:blank");
}
while (!foundAccessibleFrame) {
if (wgp) {
foundAccessibleFrame =
aTriggeringPrincipal->Subsumes(wgp->DocumentPrincipal());
}
// We have to get the parent via the bc, because there may not
// be a window global for the innermost bc; see bug 1650162.
BrowsingContext* parent = bc->GetParent();
if (!parent) {
break;
}
bc = parent;
wgp = parent->Canonical()->GetCurrentWindowGlobal();
while (wgp && !foundAccessibleFrame) {
foundAccessibleFrame =
aTriggeringPrincipal->Subsumes(wgp->DocumentPrincipal());
wgp = wgp->GetParentWindowContext();
}
if (!foundAccessibleFrame) {
return NS_OK; // deny the load.

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

@ -38,30 +38,10 @@ add_task(async function setup() {
let previousHandling = mailHandlerInfo.alwaysAskBeforeHandling;
mailHandlerInfo.alwaysAskBeforeHandling = true;
// Create a dummy web mail handler so we always know the mailto: protocol.
// Without this, the test fails on VMs without a default mailto: handler,
// because no dialog is ever shown, as we ignore subframe navigations to
// protocols that cannot be handled.
let dummy = Cc["@mozilla.org/uriloader/web-handler-app;1"].createInstance(
Ci.nsIWebHandlerApp
);
dummy.name = "Handler 1";
dummy.uriTemplate = "https://example.com/first/%s";
mailHandlerInfo.possibleApplicationHandlers.appendElement(dummy);
gHandlerService.store(mailHandlerInfo);
registerCleanupFunction(() => {
// Re-add the original protocol handlers:
let mailHandlers = mailHandlerInfo.possibleApplicationHandlers;
for (let i = handlers.Count() - 1; i >= 0; i--) {
try {
// See if this is a web handler. If it is, it'll throw, otherwise,
// we will remove it.
mailHandlers.queryElementAt(i, Ci.nsIWebHandlerApp);
mailHandlers.removeElementAt(i);
} catch (ex) {}
}
for (let h of gOldMailHandlers) {
mailHandlers.appendElement(h);
}
@ -244,107 +224,3 @@ add_task(async function test_multiple_dialogs() {
await dialogClosedPromise;
ok(dialog.closed, "The dialog should have been closed again.");
});
/**
* Check that navigating invisible frames to external-proto URLs
* is handled correctly.
*/
add_task(async function invisible_iframes() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"https://example.com/"
);
// Ensure we notice the dialog opening:
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
let frame = content.document.createElement("iframe");
frame.style.display = "none";
frame.src = "mailto:help@example.com";
content.document.body.append(frame);
});
let dialog = await dialogWindowPromise;
is(
dialog.document.location.href,
CONTENT_HANDLING_URL,
"Dialog opens as expected"
);
// Close the dialog:
let dialogClosedPromise = BrowserTestUtils.domWindowClosed(dialog);
dialog.close();
await dialogClosedPromise;
gBrowser.removeTab(tab);
});
/**
* Check that nested iframes are handled correctly.
*/
add_task(async function nested_iframes() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
"https://example.com/"
);
// Ensure we notice the dialog opening:
let dialogWindowPromise = BrowserTestUtils.domWindowOpenedAndLoaded();
info("Constructing top frame");
await SpecialPowers.spawn(tab.linkedBrowser, [], function() {
let frame = content.document.createElement("iframe");
frame.src = "https://example.org/"; // cross-origin frame.
content.document.body.prepend(frame);
content.eval(
`window.addEventListener("message", e => e.source.location = "mailto:help@example.com");`
);
});
let parentBC = tab.linkedBrowser.browsingContext;
info("Waiting for top frame to exist");
await TestUtils.waitForCondition(
() => parentBC.children[0]?.currentWindowGlobal
);
info("Creating innermost frame");
await SpecialPowers.spawn(parentBC.children[0], [], async function() {
let { document } = content;
if (
document.readyState != "complete" ||
document.URL != "https://example.org/"
) {
await ContentTaskUtils.waitForEvent(
content,
"load",
true,
() => content.document.URL == "https://example.org/"
);
}
let innerFrame = content.document.createElement("iframe");
let frameLoaded = ContentTaskUtils.waitForEvent(innerFrame, "load", true);
content.document.body.prepend(innerFrame);
await frameLoaded;
});
info("Posting event from innermost frame");
await SpecialPowers.spawn(
parentBC.children[0].children[0],
[],
async function() {
// Top browsing context needs reference to the innermost, which is cross origin.
content.eval("top.postMessage('hello', '*')");
}
);
let dialog = await dialogWindowPromise;
is(
dialog.document.location.href,
CONTENT_HANDLING_URL,
"Dialog opens as expected"
);
// Close the dialog:
let dialogClosedPromise = BrowserTestUtils.domWindowClosed(dialog);
dialog.close();
await dialogClosedPromise;
gBrowser.removeTab(tab);
});