Bug 1842549 - Remove dom.mutation-events.cssom.disabled pref r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D212588
This commit is contained in:
Gregory Pappas 2024-06-04 18:38:22 +00:00
parent 49e71b90c7
commit e6b70d8c47
6 changed files with 23 additions and 161 deletions

View file

@ -15,7 +15,6 @@
#include "mozilla/dom/MutationEventBinding.h"
#include "mozilla/dom/MutationObservers.h"
#include "mozilla/InternalMutationEvent.h"
#include "mozilla/StaticPrefs_dom.h"
#include "nsDOMCSSDeclaration.h"
#include "nsDOMCSSAttrDeclaration.h"
#include "nsServiceManagerUtils.h"
@ -69,19 +68,8 @@ void nsStyledElement::InlineStyleDeclarationWillChange(
"Should be inside document update!");
bool modification = false;
if (MayHaveStyle()) {
bool needsOldValue = !StaticPrefs::dom_mutation_events_cssom_disabled() &&
nsContentUtils::HasMutationListeners(
this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED, this);
if (!needsOldValue) {
CustomElementDefinition* definition = GetCustomElementDefinition();
if (definition &&
definition->IsInObservedAttributeList(nsGkAtoms::style)) {
needsOldValue = true;
}
}
if (needsOldValue) {
CustomElementDefinition* definition = GetCustomElementDefinition();
if (definition && definition->IsInObservedAttributeList(nsGkAtoms::style)) {
nsAutoString oldValueStr;
modification = GetAttr(nsGkAtoms::style, oldValueStr);
if (modification) {
@ -110,9 +98,8 @@ nsresult nsStyledElement::SetInlineStyleDeclaration(
MOZ_ASSERT(OwnerDoc()->UpdateNestingLevel(),
"Should be inside document update!");
bool hasListeners = !StaticPrefs::dom_mutation_events_cssom_disabled() &&
nsContentUtils::HasMutationListeners(
this, NS_EVENT_BITS_MUTATION_ATTRMODIFIED, this);
// Avoid dispatching mutation events for style attribute changes from CSSOM
const bool hasMutationEventListeners = false;
nsAttrValue attrValue(do_AddRef(&aDeclaration), nullptr);
SetMayHaveStyle();
@ -121,7 +108,7 @@ nsresult nsStyledElement::SetInlineStyleDeclaration(
mozAutoDocUpdate updateBatch(document, true);
return SetAttrAndNotify(kNameSpaceID_None, nsGkAtoms::style, nullptr,
aData.mOldValue.ptrOr(nullptr), attrValue, nullptr,
aData.mModType, hasListeners, true,
aData.mModType, hasMutationEventListeners, true,
kDontCallAfterSetAttr, document, updateBatch);
}

View file

@ -380,8 +380,6 @@ skip-if = [
"http2",
]
["test_bug338679.html"]
["test_bug339494.html"]
["test_bug339494.xhtml"]

View file

@ -1,82 +0,0 @@
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=338679
-->
<head>
<title>Bug 338679: correct reporting of newValue/prevValue in
DOMAttrModified events</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=338679">Bug
338679: correct reporting of newValue/prevValue in
DOMAttrModified events</a>
<div id="test" style="width:20em"></div>
<script>
var testDiv = document.getElementById("test");
var e_new, e_prev = testDiv.getAttribute("style");
var phase, recursive = false;
/* driver */
var tests = [ test_1, test_2, test_3 ];
var i = 0;
function nextTest() {
if (i < tests.length) {
phase = tests[i];
i++;
phase();
} else {
SimpleTest.finish();
}
}
if (SpecialPowers.getBoolPref("dom.mutation-events.cssom.disabled")) {
ok(true, "DOMAttrModified event from CSSOM change is disabled");
} else {
SimpleTest.waitForExplicitFinish();
testDiv.addEventListener("DOMAttrModified", attr_modified);
nextTest();
}
/* event handler */
function attr_modified(ev) {
is(ev.newValue, e_new,
phase.name + (recursive ? " recursive" : "") + ": newValue");
is(ev.prevValue, e_prev,
phase.name + (recursive ? " recursive" : "") + ": prevValue");
e_prev = e_new;
if (!recursive) {
recursive = true;
e_new = "width: 0px;";
testDiv.style.width = "0";
} else {
recursive = false;
setTimeout(nextTest, 0);
}
}
/* tests */
function test_1() {
e_new = "width: auto;";
testDiv.style.width = "auto";
}
function test_2() {
e_new = "width: 15%;";
testDiv.style.width = "15%";
}
function test_3() {
window.getComputedStyle(testDiv).width; // force style resolution
e_new = "width: inherit;";
testDiv.style.width = "inherit";
}
</script>
</body>
</html>

View file

@ -1,52 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<title>Test for Bug 338679 (from bug 1340341)</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<div style=""></div>
<script>
SimpleTest.waitForExplicitFinish();
// Run the test first with mutation events enabled and then disabled.
SpecialPowers.pushPrefEnv(
{ 'set': [['dom.mutation-events.cssom.disabled', false]] },
runTest
);
function runTest(stop) {
let div = document.querySelector('div');
let expectation;
let count = 0;
div.style.color = "red";
div.addEventListener('DOMAttrModified', function(evt) {
count++;
is(evt.prevValue, expectation.prevValue, `Previous value for event ${count}`);
is(evt.newValue, expectation.newValue, `New value for event ${count}`);
});
expectation = { prevValue: 'color: red;', newValue: 'color: green;' };
div.style.color = "green";
expectation = { prevValue: 'color: green;', newValue: '' };
div.style.color = '';
if (SpecialPowers.getBoolPref("dom.mutation-events.cssom.disabled")) {
is(count, 0, "No DOMAttrModified event should be triggered");
} else {
is(count, 2, "DOMAttrModified events should have been triggered");
}
if (!stop) {
div.setAttribute("style", "");
SpecialPowers.pushPrefEnv(
{ 'set': [['dom.mutation-events.cssom.disabled', true]] },
function() {
runTest(true);
SimpleTest.finish();
}
);
}
}
</script>
</body>
<head>
<title>Test for Bug 1460295</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<div></div>
<script>
let div = document.querySelector("div");
let count = 0;
div.addEventListener("DOMAttrModified", function () {
count++;
});
div.style.color = "green";
is(count, 0, "No DOMAttrModified event should be triggered");
</script>
</body>
</html>

View file

@ -3165,15 +3165,6 @@
value: true
mirror: always
# Whether we disable triggering mutation events for changes to style
# attribute via CSSOM.
# NOTE: This preference is used in unit tests. If it is removed or its default
# value changes, please update test_sharedMap_static_prefs.js accordingly.
- name: dom.mutation-events.cssom.disabled
type: bool
value: true
mirror: always
# Limit of location change caused by content scripts in a time span per
# BrowsingContext. This includes calls to History and Location APIs.
- name: dom.navigation.locationChangeRateLimit.count

View file

@ -22,7 +22,7 @@
const PREF1_NAME = "dom.webcomponents.shadowdom.report_usage";
const PREF1_VALUE = false;
const PREF2_NAME = "dom.mutation-events.cssom.disabled";
const PREF2_NAME = "full-screen-api.enabled";
const PREF2_VALUE = true;
const { XPCShellContentUtils } = ChromeUtils.importESModule(