Skip to content

Commit

Permalink
Bug 1557754 - Don't allow locked preferences to be enabled. r=Gijs
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaply committed Apr 24, 2020
1 parent a900e2d commit 5bdeae5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ 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",
Expand Down
39 changes: 21 additions & 18 deletions browser/components/preferences/dialogs/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,24 @@ var gConnectionsDialog = {

// Update http
var httpProxyURLPref = Preferences.get("network.proxy.http");
httpProxyURLPref.disabled = proxyTypePref.value != 1;
httpProxyURLPref.updateControlDisabledState(proxyTypePref.value != 1);
var httpProxyPortPref = Preferences.get("network.proxy.http_port");
httpProxyPortPref.disabled = proxyTypePref.value != 1;
httpProxyPortPref.updateControlDisabledState(proxyTypePref.value != 1);

// Now update the other protocols
this.updateProtocolPrefs();

var shareProxiesPref = Preferences.get(
"network.proxy.share_proxy_settings"
);
shareProxiesPref.disabled =
proxyTypePref.value != 1 || shareProxiesPref.locked;
shareProxiesPref.updateControlDisabledState(proxyTypePref.value != 1);
var autologinProxyPref = Preferences.get("signon.autologin.proxy");
autologinProxyPref.disabled =
proxyTypePref.value == 0 || autologinProxyPref.locked;
autologinProxyPref.updateControlDisabledState(proxyTypePref.value == 0);
var noProxiesPref = Preferences.get("network.proxy.no_proxies_on");
noProxiesPref.disabled = proxyTypePref.value == 0 || noProxiesPref.locked;
noProxiesPref.updateControlDisabledState(proxyTypePref.value == 0);

var autoconfigURLPref = Preferences.get("network.proxy.autoconfig_url");
autoconfigURLPref.disabled =
proxyTypePref.value != 2 || autoconfigURLPref.locked;
autoconfigURLPref.updateControlDisabledState(proxyTypePref.value != 2);

this.updateReloadButton();

Expand All @@ -224,9 +221,10 @@ var gConnectionsDialog = {
var socksDNSPref = Preferences.get("network.proxy.socks_remote_dns");
var proxyTypePref = Preferences.get("network.proxy.type");
var isDefinitelySocks4 =
!socksVersionPref.disabled && socksVersionPref.value == 4;
socksDNSPref.disabled =
isDefinitelySocks4 || proxyTypePref.value == 0 || socksDNSPref.locked;
proxyTypePref.value == 1 && socksVersionPref.value == 4;
socksDNSPref.updateControlDisabledState(
isDefinitelySocks4 || proxyTypePref.value == 0
);
return undefined;
},

Expand All @@ -245,8 +243,9 @@ var gConnectionsDialog = {
var disableReloadPref = Preferences.get(
"pref.advanced.proxies.disable_button.reload"
);
disableReloadPref.disabled =
proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL;
disableReloadPref.updateControlDisabledState(
proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL
);
},

readProxyType() {
Expand Down Expand Up @@ -289,11 +288,15 @@ var gConnectionsDialog = {
proxyServerURLPref.updateElements();
proxyPortPref.updateElements();
let prefIsShared = proxyPrefs[i] != "socks" && shareProxiesPref.value;
proxyServerURLPref.disabled = proxyTypePref.value != 1 || prefIsShared;
proxyPortPref.disabled = proxyServerURLPref.disabled;
proxyServerURLPref.updateControlDisabledState(
proxyTypePref.value != 1 || prefIsShared
);
proxyPortPref.updateControlDisabledState(
proxyTypePref.value != 1 || prefIsShared
);
}
var socksVersionPref = Preferences.get("network.proxy.socks_version");
socksVersionPref.disabled = proxyTypePref.value != 1;
socksVersionPref.updateControlDisabledState(proxyTypePref.value != 1);
this.updateDNSPref();
return undefined;
},
Expand Down Expand Up @@ -447,7 +450,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.disabled = !enabled || this.isDnsOverHttpsLocked();
uriPref.updateControlDisabledState(!enabled || this.isDnsOverHttpsLocked());
// this is the first signal we get when the prefs are available, so
// lazy-init if appropriate
if (!this._areTrrPrefsReady) {
Expand Down
17 changes: 5 additions & 12 deletions toolkit/content/preferencesBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ const Preferences = (window.Preferences = (function() {
window.addEventListener("unload", Preferences, { once: true });

class Preference extends EventEmitter {
constructor({ id, type, inverted, disabled }) {
constructor({ id, type, inverted }) {
super();
this.on("change", this.onChange.bind(this));

Expand All @@ -357,7 +357,6 @@ 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
Expand Down Expand Up @@ -533,17 +532,13 @@ const Preferences = (window.Preferences = (function() {
return Services.prefs.prefIsLocked(this.id);
}

get disabled() {
return this._disabled;
}

set disabled(val) {
this._disabled = !!val;

updateControlDisabledState(val) {
if (!this.id) {
return val;
return;
}

val = val || this.locked;

const elements = getElementsByAttribute("preference", this.id);
for (const element of elements) {
element.disabled = val;
Expand All @@ -553,8 +548,6 @@ const Preferences = (window.Preferences = (function() {
label.disabled = val;
}
}

return val;
}

get hasUserValue() {
Expand Down
1 change: 1 addition & 0 deletions toolkit/content/tests/chrome/chrome.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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
Expand Down
19 changes: 19 additions & 0 deletions toolkit/content/tests/chrome/test_preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@
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
Expand Down Expand Up @@ -499,11 +508,21 @@
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();
}
]]>
Expand Down

0 comments on commit 5bdeae5

Please sign in to comment.