Bug 1934246 - Get rid of dom.popup.experimental; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D242688
This commit is contained in:
Edgar Chen
2025-03-24 16:15:49 +00:00
parent 2e21dda1b5
commit c111b0a57c
8 changed files with 26 additions and 182 deletions

View File

@@ -116,10 +116,8 @@ void nsCoreUtils::DispatchClickEvent(XULTreeElement* aTree, int32_t aRowIndex,
int32_t cnvdY = presContext->CSSPixelsToDevPixels(tcY + int32_t(rect.y) + 1) +
presContext->AppUnitsToDevPixels(offset.y);
if (StaticPrefs::dom_popup_experimental()) {
// This isn't needed once bug 1924790 is fixed.
tcElm->OwnerDoc()->NotifyUserGestureActivation();
}
// This isn't needed once bug 1924790 is fixed.
tcElm->OwnerDoc()->NotifyUserGestureActivation();
// XUL is just desktop, so there is no real reason for senfing touch events.
DispatchMouseEvent(eMouseDown, cnvdX, cnvdY, tcElm, tcFrame, presShell,

View File

@@ -2573,10 +2573,9 @@ void LocalAccessible::DispatchClickEvent(uint32_t aActionIndex) const {
nsCoreUtils::DispatchTouchEvent(eTouchStart, x, y, mContent, frame, presShell,
widget);
if (StaticPrefs::dom_popup_experimental()) {
// This isn't needed once bug 1924790 is fixed.
mContent->OwnerDoc()->NotifyUserGestureActivation();
}
// This isn't needed once bug 1924790 is fixed.
mContent->OwnerDoc()->NotifyUserGestureActivation();
nsCoreUtils::DispatchMouseEvent(eMouseDown, x, y, mContent, frame, presShell,
widget);
nsCoreUtils::DispatchTouchEvent(eTouchEnd, x, y, mContent, frame, presShell,

View File

@@ -2284,8 +2284,8 @@ PopupBlocker::PopupControlState BrowsingContext::RevisePopupAbuseLevel(
case PopupBlocker::openAllowed:
break;
case PopupBlocker::openBlocked:
if (IsPopupAllowed() || (StaticPrefs::dom_popup_experimental() && doc &&
doc->HasValidTransientUserGestureActivation())) {
if (IsPopupAllowed() ||
(doc && doc->HasValidTransientUserGestureActivation())) {
// Go down one state enum step:
// openBlocked (2) -> openControlled (1)
abuse = PopupBlocker::openControlled;

View File

@@ -11,8 +11,6 @@
<div id="target" style="width: 50px; height: 50px; background: green"></div>
<script>
var experimental = false;
function sendMouseEvent(element, eventName, button, listenEventName, handler) {
let needToCheckHandler = false;
let handlerIsCalled = false;
@@ -61,31 +59,7 @@ const MIDDLE_BUTTON = 1;
const RIGHT_BUTTON = 2;
let target = document.getElementById("target");
async function beginTest() {
if (!experimental) {
info("NOT EXPERIMENTAL");
await SpecialPowers.pushPrefEnv({
set: [
["dom.popup.experimental", false]
],
});
} else {
info("EXPERIMENTAL");
await SpecialPowers.pushPrefEnv({
set: [
["dom.popup.experimental", true],
],
});
}
}
async function endTest() {
await SpecialPowers.popPrefEnv();
}
async function testMouseDownUpMove() {
await beginTest();
// Left button
sendMouseEvent(target, "mousedown", LEFT_BUTTON, "mousedown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", LEFT_BUTTON, "mousemove", checkBlockOpenPopup);
@@ -97,28 +71,18 @@ async function testMouseDownUpMove() {
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "mouseup", checkBlockOpenPopup);
// Right button
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "mousedown", experimental ?
checkAllowOpenPopup :
checkBlockOpenPopup);
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "mousedown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "mousemove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "mouseup", checkBlockOpenPopup);
await endTest();
}
async function testMouseClick() {
await beginTest();
// Left button
sendMouseEvent(target, "mousedown", LEFT_BUTTON);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "click", checkAllowOpenPopup);
await endTest();
}
async function testMouseAuxclick() {
await beginTest();
// Middle button
sendMouseEvent(target, "mousedown", MIDDLE_BUTTON);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "auxclick", checkAllowOpenPopup);
@@ -126,20 +90,12 @@ async function testMouseAuxclick() {
// Right button
sendMouseEvent(target, "mousedown", RIGHT_BUTTON);
sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "auxclick", checkAllowOpenPopup);
await endTest();
}
add_task(testMouseDownUpMove);
add_task(testMouseClick);
add_task(testMouseAuxclick);
add_task(() => experimental = true);
add_task(testMouseDownUpMove);
add_task(testMouseClick);
add_task(testMouseAuxclick);
</script>
</body>
</html>

View File

@@ -11,8 +11,6 @@
<div id="target" style="width: 50px; height: 50px; background: green"></div>
<script>
let experimental = false;
function sendMouseEvent(element, eventName, button, listenEventName, handler) {
let needToCheckHandler = false;
let handlerIsCalled = false;
@@ -62,132 +60,69 @@
const RIGHT_BUTTON = 2;
let target = document.getElementById("target");
async function beginTest() {
if (!experimental) {
info("NOT EXPERIMENTAL");
await SpecialPowers.pushPrefEnv({
set: [
["dom.popup.experimental", false]
],
});
} else {
info("EXPERIMENTAL");
// This is a rather fragile test when experimental pref isn't enabled.
// Use default prefs in experimental case.
SpecialPowers.wrap(document).clearUserGestureActivation();
await SpecialPowers.pushPrefEnv({
set: [
["dom.popup.experimental", true],
// Enable popup blocker
["dom.disable_open_during_load", true],
],
});
}
}
async function endTest() {
await SpecialPowers.popPrefEnv();
}
async function testPointerEventDefault() {
await beginTest();
// By default, only allow opening popup in the pointerup listener.
// Left button
sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkBlockOpenPopup);
// Middle button
sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkBlockOpenPopup);
// Right button
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", experimental ?
checkAllowOpenPopup :
checkBlockOpenPopup);
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup);
await endTest();
};
async function testPointerEventAddPointerDownToPref() {
await beginTest();
// Adding pointerdown to preference
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events",
"pointerdown pointerup"]]});
// Left button
sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkBlockOpenPopup);
// Middle button
sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkBlockOpenPopup);
// Right button
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", experimental ?
checkAllowOpenPopup :
checkBlockOpenPopup);
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup);
await SpecialPowers.popPrefEnv();
await endTest();
}
async function testPointerEventAddPointerMoveToPref() {
await beginTest();
// Adding pointermove to preference should have no effect.
await SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events",
"pointerdown pointerup pointermove"]]});
// Left button
sendMouseEvent(target, "mousedown", LEFT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", LEFT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", LEFT_BUTTON, "pointerup", checkBlockOpenPopup);
// Middle button
sendMouseEvent(target, "mousedown", MIDDLE_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", MIDDLE_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", experimental ?
checkBlockOpenPopup :
checkAllowOpenPopup);
sendMouseEvent(target, "mouseup", MIDDLE_BUTTON, "pointerup", checkBlockOpenPopup);
// Right button
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", experimental ?
checkAllowOpenPopup :
checkBlockOpenPopup);
sendMouseEvent(target, "mousedown", RIGHT_BUTTON, "pointerdown", checkAllowOpenPopup);
sendMouseEvent(target, "mousemove", RIGHT_BUTTON, "pointermove", checkBlockOpenPopup);
sendMouseEvent(target, "mouseup", RIGHT_BUTTON, "pointerup", checkBlockOpenPopup);
await SpecialPowers.popPrefEnv();
await endTest();
}
add_task(testPointerEventDefault);
add_task(testPointerEventAddPointerDownToPref);
add_task(testPointerEventAddPointerMoveToPref);
add_task(() => experimental = true);
add_task(testPointerEventDefault);
add_task(testPointerEventAddPointerDownToPref);
add_task(testPointerEventAddPointerMoveToPref);
</script>
</body>
</html>

View File

@@ -26,9 +26,6 @@ add_setup(async function() {
]);
await new Promise(resolve => SimpleTest.waitForFocus(resolve));
// Set popup preferences.
await SpecialPowers.pushPrefEnv({ set: [["dom.popup.experimental", true]] });
});
const LEFT_BUTTON = 0;

View File

@@ -1052,9 +1052,6 @@ nsresult EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
SetClickCount(mouseEvent, aStatus);
break;
}
if (!StaticPrefs::dom_popup_experimental()) {
NotifyTargetUserActivation(aEvent, aTargetContent);
}
break;
}
case eMouseUp: {
@@ -1137,14 +1134,8 @@ nsresult EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
PointerEventHandler::UpdateActivePointerState(mouseEvent,
aTargetContent);
PointerEventHandler::ImplicitlyCapturePointer(aTargetFrame, aEvent);
if (StaticPrefs::dom_popup_experimental()) {
// https://html.spec.whatwg.org/multipage/interaction.html#activation-triggering-input-event
if (mouseEvent->mInputSource ==
MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
NotifyTargetUserActivation(aEvent, aTargetContent);
}
} else if (mouseEvent->mInputSource !=
MouseEvent_Binding::MOZ_SOURCE_TOUCH) {
// https://html.spec.whatwg.org/multipage/interaction.html#activation-triggering-input-event
if (mouseEvent->mInputSource == MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
NotifyTargetUserActivation(aEvent, aTargetContent);
}
@@ -1179,8 +1170,7 @@ nsresult EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
case ePointerUp:
LightDismissOpenPopovers(aEvent, aTargetContent);
GenerateMouseEnterExit(mouseEvent);
if (StaticPrefs::dom_popup_experimental() &&
mouseEvent->mInputSource != MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
if (mouseEvent->mInputSource != MouseEvent_Binding::MOZ_SOURCE_MOUSE) {
NotifyTargetUserActivation(aEvent, aTargetContent);
}
break;
@@ -1367,11 +1357,6 @@ nsresult EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
case eTouchStart:
SetGestureDownPoint(aEvent->AsTouchEvent());
break;
case eTouchEnd:
if (!StaticPrefs::dom_popup_experimental()) {
NotifyTargetUserActivation(aEvent, aTargetContent);
}
break;
default:
break;
}
@@ -1385,15 +1370,8 @@ nsresult EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
// The modifiers associated with the user activation is used for controlling
// where the `window.open` is opened into.
static bool CanReflectModifiersToUserActivation(WidgetInputEvent* aEvent) {
if (StaticPrefs::dom_popup_experimental()) {
MOZ_ASSERT(aEvent->mMessage == eKeyDown ||
aEvent->mMessage == ePointerDown ||
aEvent->mMessage == ePointerUp);
} else {
MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == eMouseDown ||
aEvent->mMessage == ePointerDown ||
aEvent->mMessage == eTouchEnd);
}
MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == ePointerDown ||
aEvent->mMessage == ePointerUp);
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
if (keyEvent) {
@@ -1446,11 +1424,7 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
// Do not treat the click on scrollbar as a user interaction with the web
// content.
if (StaticPrefs::dom_user_activation_ignore_scrollbars() &&
((StaticPrefs::dom_popup_experimental() &&
(aEvent->mMessage == ePointerDown || aEvent->mMessage == ePointerUp)) ||
(!StaticPrefs::dom_popup_experimental() &&
(aEvent->mMessage == eMouseDown ||
aEvent->mMessage == ePointerDown))) &&
(aEvent->mMessage == ePointerDown || aEvent->mMessage == ePointerUp) &&
aTargetContent->IsInNativeAnonymousSubtree()) {
nsIContent* current = aTargetContent;
do {
@@ -1465,17 +1439,8 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
} while (current);
}
#ifdef DEBUG
if (StaticPrefs::dom_popup_experimental()) {
MOZ_ASSERT(aEvent->mMessage == eKeyDown ||
aEvent->mMessage == ePointerDown ||
aEvent->mMessage == ePointerUp);
} else {
MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == eMouseDown ||
aEvent->mMessage == ePointerDown ||
aEvent->mMessage == eTouchEnd);
}
#endif
MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == ePointerDown ||
aEvent->mMessage == ePointerUp);
UserActivation::Modifiers modifiers;
if (WidgetInputEvent* inputEvent = aEvent->AsInputEvent()) {

View File

@@ -2469,13 +2469,7 @@
value: -1
mirror: always
# Enable experimental popup blocker changes.
- name: dom.popup.experimental
type: bool
value: true
mirror: always
# Enable CacheAPI in private browsing mode with encryption
# Enable CacheAPI in private browsing mode with encryption
- name: dom.cache.privateBrowsing.enabled
type: RelaxedAtomicBool
value: true