diff --git a/.eslintrc.js b/.eslintrc.js index f3b6eedd5275..4631cb0c4222 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -717,7 +717,6 @@ module.exports = { "toolkit/content/tests/chrome/window_preferences3.xhtml", "toolkit/content/tests/chrome/window_preferences_beforeaccept.xhtml", "toolkit/content/tests/chrome/window_preferences_commandretarget.xhtml", - "toolkit/content/tests/chrome/window_preferences_disabled.xhtml", "toolkit/content/tests/chrome/window_preferences_onsyncfrompreference.xhtml", "toolkit/content/tests/chrome/window_subframe_origin.xhtml", "toolkit/content/tests/chrome/window_titlebar.xhtml", diff --git a/browser/components/preferences/dialogs/connection.js b/browser/components/preferences/dialogs/connection.js index faf3081f4dbb..1ab3028d1e13 100644 --- a/browser/components/preferences/dialogs/connection.js +++ b/browser/components/preferences/dialogs/connection.js @@ -187,9 +187,9 @@ var gConnectionsDialog = { // Update http var httpProxyURLPref = Preferences.get("network.proxy.http"); - httpProxyURLPref.updateControlDisabledState(proxyTypePref.value != 1); + httpProxyURLPref.disabled = proxyTypePref.value != 1; var httpProxyPortPref = Preferences.get("network.proxy.http_port"); - httpProxyPortPref.updateControlDisabledState(proxyTypePref.value != 1); + httpProxyPortPref.disabled = proxyTypePref.value != 1; // Now update the other protocols this.updateProtocolPrefs(); @@ -197,14 +197,17 @@ var gConnectionsDialog = { var shareProxiesPref = Preferences.get( "network.proxy.share_proxy_settings" ); - shareProxiesPref.updateControlDisabledState(proxyTypePref.value != 1); + shareProxiesPref.disabled = + proxyTypePref.value != 1 || shareProxiesPref.locked; var autologinProxyPref = Preferences.get("signon.autologin.proxy"); - autologinProxyPref.updateControlDisabledState(proxyTypePref.value == 0); + autologinProxyPref.disabled = + proxyTypePref.value == 0 || autologinProxyPref.locked; var noProxiesPref = Preferences.get("network.proxy.no_proxies_on"); - noProxiesPref.updateControlDisabledState(proxyTypePref.value == 0); + noProxiesPref.disabled = proxyTypePref.value == 0 || noProxiesPref.locked; var autoconfigURLPref = Preferences.get("network.proxy.autoconfig_url"); - autoconfigURLPref.updateControlDisabledState(proxyTypePref.value != 2); + autoconfigURLPref.disabled = + proxyTypePref.value != 2 || autoconfigURLPref.locked; this.updateReloadButton(); @@ -221,10 +224,9 @@ var gConnectionsDialog = { var socksDNSPref = Preferences.get("network.proxy.socks_remote_dns"); var proxyTypePref = Preferences.get("network.proxy.type"); var isDefinitelySocks4 = - proxyTypePref.value == 1 && socksVersionPref.value == 4; - socksDNSPref.updateControlDisabledState( - isDefinitelySocks4 || proxyTypePref.value == 0 - ); + !socksVersionPref.disabled && socksVersionPref.value == 4; + socksDNSPref.disabled = + isDefinitelySocks4 || proxyTypePref.value == 0 || socksDNSPref.locked; return undefined; }, @@ -243,9 +245,8 @@ var gConnectionsDialog = { var disableReloadPref = Preferences.get( "pref.advanced.proxies.disable_button.reload" ); - disableReloadPref.updateControlDisabledState( - proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL - ); + disableReloadPref.disabled = + proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL; }, readProxyType() { @@ -288,15 +289,11 @@ var gConnectionsDialog = { proxyServerURLPref.updateElements(); proxyPortPref.updateElements(); let prefIsShared = proxyPrefs[i] != "socks" && shareProxiesPref.value; - proxyServerURLPref.updateControlDisabledState( - proxyTypePref.value != 1 || prefIsShared - ); - proxyPortPref.updateControlDisabledState( - proxyTypePref.value != 1 || prefIsShared - ); + proxyServerURLPref.disabled = proxyTypePref.value != 1 || prefIsShared; + proxyPortPref.disabled = proxyServerURLPref.disabled; } var socksVersionPref = Preferences.get("network.proxy.socks_version"); - socksVersionPref.updateControlDisabledState(proxyTypePref.value != 1); + socksVersionPref.disabled = proxyTypePref.value != 1; this.updateDNSPref(); return undefined; }, @@ -450,7 +447,7 @@ var gConnectionsDialog = { // called to update checked element property to reflect current pref value let enabled = this.isDnsOverHttpsEnabled(); let uriPref = Preferences.get("network.trr.uri"); - uriPref.updateControlDisabledState(!enabled || this.isDnsOverHttpsLocked()); + uriPref.disabled = !enabled || this.isDnsOverHttpsLocked(); // this is the first signal we get when the prefs are available, so // lazy-init if appropriate if (!this._areTrrPrefsReady) { diff --git a/toolkit/content/preferencesBindings.js b/toolkit/content/preferencesBindings.js index 549b8ff78121..6adb86855339 100644 --- a/toolkit/content/preferencesBindings.js +++ b/toolkit/content/preferencesBindings.js @@ -345,7 +345,7 @@ const Preferences = (window.Preferences = (function() { window.addEventListener("unload", Preferences, { once: true }); class Preference extends EventEmitter { - constructor({ id, type, inverted }) { + constructor({ id, type, inverted, disabled }) { super(); this.on("change", this.onChange.bind(this)); @@ -357,6 +357,7 @@ const Preferences = (window.Preferences = (function() { this.id = id; this.type = type; this.inverted = !!inverted; + this._disabled = !!disabled; // In non-instant apply mode, we must try and use the last saved state // from any previous opens of a child dialog instead of the value from @@ -532,12 +533,16 @@ const Preferences = (window.Preferences = (function() { return Services.prefs.prefIsLocked(this.id); } - updateControlDisabledState(val) { - if (!this.id) { - return; - } + get disabled() { + return this._disabled; + } - val = val || this.locked; + set disabled(val) { + this._disabled = !!val; + + if (!this.id) { + return val; + } const elements = getElementsByAttribute("preference", this.id); for (const element of elements) { @@ -548,6 +553,8 @@ const Preferences = (window.Preferences = (function() { label.disabled = val; } } + + return val; } get hasUserValue() { diff --git a/toolkit/content/tests/chrome/chrome.ini b/toolkit/content/tests/chrome/chrome.ini index abb8a9e46308..08ad0e750197 100644 --- a/toolkit/content/tests/chrome/chrome.ini +++ b/toolkit/content/tests/chrome/chrome.ini @@ -43,7 +43,6 @@ support-files = window_preferences2.xhtml window_preferences3.xhtml window_preferences_commandretarget.xhtml - window_preferences_disabled.xhtml window_screenPosSize.xhtml window_showcaret.xhtml window_subframe_origin.xhtml diff --git a/toolkit/content/tests/chrome/test_preferences.xhtml b/toolkit/content/tests/chrome/test_preferences.xhtml index ad191a445dd0..4ff2998c2bc1 100644 --- a/toolkit/content/tests/chrome/test_preferences.xhtml +++ b/toolkit/content/tests/chrome/test_preferences.xhtml @@ -413,15 +413,6 @@ ok(!GetPreference(aPrefWindow, "tests.static_preference_bool").value, "redirected command bool"); } - function RunCheckDisabled(aPrefWindow) - { - ok(!GetXULElement(aPrefWindow, "disabled_checkbox").disabled, "Checkbox should be enabled"); - GetPreference(aPrefWindow, "tests.disabled_preference_bool").updateControlDisabledState(true); - ok(GetXULElement(aPrefWindow, "disabled_checkbox").disabled, "Checkbox should be disabled"); - GetPreference(aPrefWindow, "tests.locked_preference_bool").updateControlDisabledState(false);; - ok(GetXULElement(aPrefWindow, "locked_checkbox").disabled, "Locked checkbox should stay disabled"); - } - function RunResetPrefTest(aPrefWindow) { // try resetting the prefs to default values @@ -508,21 +499,11 @@ window.docShell.rootTreeItem.domWindow.openDialog("window_preferences_commandretarget.xhtml", "", "modal", RunCheckCommandRedirect, true); } - function RunTestDisabled() - { - // Because this pref is on the default branch and locked, we need to set it before opening the dialog. - const defaultBranch = kPref.getDefaultBranch(""); - defaultBranch.setBoolPref("tests.locked_preference_bool", true); - defaultBranch.lockPref("tests.locked_preference_bool"); - window.docShell.rootTreeItem.domWindow.openDialog("window_preferences_disabled.xhtml", "", "modal", RunCheckDisabled, true); - } - function RunTest() { RunTestInstant(); RunTestNonInstant(); RunTestCommandRedirect(); - RunTestDisabled(); SimpleTest.finish(); } ]]>