Issue #1629 - Part 3: Implement behind preference.

This is not very "clean," and is mostly done in the same sloppy way as Emilio did it because that's basically the only way you can do it. Note well that this does NOT actually turn off everything I've done in a clean fashion like ifdefs would. For instance, the Explicitly Enabled flag is still present, but is now always false because the only condition that can set it true is behind the pref and therefore inert when this pref is off. Also, because the arguments of SetDisabled have changed, my modifications to SetMozDisabled must be present regardless of whether the pref is on or off. What I have done is turn off the actual reflection of the disabled attribute in Disabled and SetDisabled, as well as in AfterSetAttr.

However, turning the pref off seems to restore more or less our old behavior, though there may be subtle differences unlike with an ifdef since this is, unfortunately, not an exact science and I can only turn off changes that happen within individual functions and not changes in how functions interact with each other.
pull/24/head
athenian200 2 years ago committed by Roy Tam
parent 6835425e20
commit 42d14af9a3
  1. 25
      dom/html/HTMLLinkElement.cpp
  2. 8
      modules/libpref/init/all.js

@ -33,6 +33,8 @@
#define LINK_ELEMENT_FLAG_BIT(n_) \
NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
#define LINK_DISABLED Preferences::GetBool("dom.link.disabled_attribute.enabled", true)
// Link element specific bits
enum {
// Indicates that a DNS Prefetch has been requested from this Link element.
@ -92,10 +94,13 @@ NS_INTERFACE_TABLE_TAIL_INHERITING(nsGenericHTMLElement)
NS_IMPL_ELEMENT_CLONE(HTMLLinkElement)
bool
HTMLLinkElement::Disabled() const
{
return GetBoolAttr(nsGkAtoms::disabled);
if (LINK_DISABLED) {
return GetBoolAttr(nsGkAtoms::disabled);
}
StyleSheet* ss = GetSheet();
return ss && ss->Disabled();
@ -110,8 +115,10 @@ HTMLLinkElement::GetMozDisabled(bool* aDisabled)
void
HTMLLinkElement::SetDisabled(bool aDisabled, ErrorResult& aRv)
{
{
if (LINK_DISABLED) {
return SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aRv);
}
if (StyleSheet* ss = GetSheet()) {
ss->SetDisabled(aDisabled);
@ -123,7 +130,7 @@ HTMLLinkElement::SetMozDisabled(bool aDisabled)
{
ErrorResult rv;
SetDisabled(aDisabled, rv);
return rv.StealNSResult();
return rv.StealNSResult();
}
NS_IMPL_STRING_ATTR(HTMLLinkElement, Charset, charset)
@ -375,7 +382,7 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled)) {
(LINK_DISABLED && aName == nsGkAtoms::disabled))) {
bool dropSheet = false;
if (aName == nsGkAtoms::rel) {
nsAutoString value;
@ -403,12 +410,12 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
(aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled));
(LINK_DISABLED && aName == nsGkAtoms::disabled)));
}
} else {
// If the disabled attribute is removed from a link element, the
// stylesheet may be explicitly enabled.
if (aNameSpaceID == kNameSpaceID_None) {
if (aNameSpaceID == kNameSpaceID_None && LINK_DISABLED) {
if (aName == nsGkAtoms::disabled) {
mExplicitlyEnabled = true;
}
@ -419,7 +426,7 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type ||
aName == nsGkAtoms::disabled) {
(LINK_DISABLED && aName == nsGkAtoms::disabled)) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
}
if (aName == nsGkAtoms::href ||
@ -530,6 +537,8 @@ HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
return;
}
if (LINK_DISABLED) {
// Is the link disabled?
if (Disabled()) {
return;
@ -540,6 +549,8 @@ HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
*aIsExplicitlyEnabled = true;
}
}
nsAutoString title;
GetAttr(kNameSpaceID_None, nsGkAtoms::title, title);
title.CompressWhitespace();

@ -1185,6 +1185,14 @@ pref("dom.storage.default_quota", 5120);
pref("dom.send_after_paint_to_content", false);
// Whether the disabled attribute in HTMLLinkElement disables the sheet loading
// altogether, or forwards to the inner stylesheet method without attribute
// reflection.
//
// Historical behavior is the second, the first is being discussed at:
// https://github.com/whatwg/html/issues/3840
pref("dom.link.disabled_attribute.enabled", true);
// Timeout clamp in ms for timeouts we clamp
pref("dom.min_timeout_value", 4);
// And for background windows

Loading…
Cancel
Save