Commit b06e759e authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1685056 - For an initial, same-origin iframe, consume activation on the...

Bug 1685056 - For an initial, same-origin iframe, consume activation on the parent page for multiple-popup blocking. r=edgar, a=jcristau

Sadness. Test times out without the fix.

Differential Revision: https://phabricator.services.mozilla.com/D101378
parent c3518f7e
......@@ -5759,12 +5759,33 @@ PopupBlocker::PopupControlState nsGlobalWindowOuter::RevisePopupAbuseLevel(
}
}
// HACK: Some pages using bogus library + UA sniffing call window.open() from
// a blank iframe, only on Firefox, see bug 1685056.
//
// This is a hack-around to preserve behavior in that particular and specific
// case, by consuming activation on the parent document, so we don't care
// about the InProcessParent bits not being fission-safe or what not.
auto ConsumeTransientUserActivationForMultiplePopupBlocking = [&]() -> bool {
if (mDoc->ConsumeTransientUserGestureActivation()) {
return true;
}
if (!mDoc->IsInitialDocument()) {
return false;
}
Document* parentDoc = mDoc->GetInProcessParentDocument();
if (!parentDoc ||
!parentDoc->NodePrincipal()->Equals(mDoc->NodePrincipal())) {
return false;
}
return parentDoc->ConsumeTransientUserGestureActivation();
};
// If this popup is allowed, let's block any other for this event, forcing
// PopupBlocker::openBlocked state.
if ((abuse == PopupBlocker::openAllowed ||
abuse == PopupBlocker::openControlled) &&
StaticPrefs::dom_block_multiple_popups() && !IsPopupAllowed() &&
!mDoc->ConsumeTransientUserGestureActivation()) {
!ConsumeTransientUserActivationForMultiplePopupBlocking()) {
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, "DOM"_ns, mDoc,
nsContentUtils::eDOM_PROPERTIES,
"MultiplePopupsBlockedNoUserActivation");
......
......@@ -5,6 +5,7 @@
<button onclick="openNestedPopups();" id="openNestedPopups">open tested popups</button>
<button onclick="openPopupAndClick();" id="openPopupAndClick">open popups and click</button>
<button onclick="closeAllWindows();" id="closeAllWindows">close all windows</button>
<button onclick="openPopupInFrame();" id="openPopupInFrame">open popup in frame</button>
<input type="text" id="input" />
<script>
let windows = [];
......@@ -29,6 +30,14 @@ function openPopupAndClick() {
}
}
function openPopupInFrame() {
let iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);
windows.push(iframe.contentWindow.open('empty.html', '_blank', 'width=100,height=100'));
iframe.remove();
}
function closeAllWindows() {
windows.forEach(w => {
try {
......
......@@ -532,3 +532,44 @@ add_task(async _ => {
BrowserTestUtils.removeTab(tab);
});
add_task(async function test_bug_1685056() {
info(
"window.open() from a blank iframe window during an event dispatched at the parent page: window should be allowed"
);
await SpecialPowers.pushPrefEnv({
set: [
["dom.block_multiple_popups", true],
["dom.disable_open_during_load", true],
],
});
let tab = BrowserTestUtils.addTab(
gBrowser,
TEST_DOMAIN + TEST_PATH + "browser_multiple_popups.html"
);
gBrowser.selectedTab = tab;
let browser = gBrowser.getBrowserForTab(tab);
await BrowserTestUtils.browserLoaded(browser);
let obs = new WindowObserver(1);
await BrowserTestUtils.synthesizeMouseAtCenter(
"#openPopupInFrame",
{},
tab.linkedBrowser
);
await obs;
ok(true, "We had 1 popup.");
await BrowserTestUtils.synthesizeMouseAtCenter(
"#closeAllWindows",
{},
tab.linkedBrowser
);
BrowserTestUtils.removeTab(tab);
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment