Pier Angelo Vendrame pushed to branch tor-browser-102.12.0esr-13.0-1 at The Tor Project / Applications / Tor Browser
Commits: 01e38a05 by Henry Wilkes at 2023-06-14T10:04:00+00:00 fixup! Bug 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection
Bug 41848 - Consistently disable the accept/connect button in the bridge dialogs until the user gives some input.
(cherry picked from commit 0d458af9bf952c1b6f4f685e7c1397156ae8b69c) - - - - -
3 changed files:
- browser/components/torpreferences/content/builtinBridgeDialog.jsm - browser/components/torpreferences/content/connectionPane.js - browser/components/torpreferences/content/provideBridgeDialog.jsm
Changes:
===================================== browser/components/torpreferences/content/builtinBridgeDialog.jsm ===================================== @@ -26,6 +26,7 @@ class BuiltinBridgeDialog { constructor(onSubmit) { this.onSubmit = onSubmit; this._acceptButton = null; + this._radioGroup = null; }
_populateXUL(window, dialog) { @@ -36,7 +37,7 @@ class BuiltinBridgeDialog { "#torPreferences-builtinBridge-description" ).textContent = TorStrings.settings.builtinBridgeDescription2;
- const radioGroup = dialog.querySelector( + this._radioGroup = dialog.querySelector( "#torPreferences-builtinBridge-typeSelection" );
@@ -60,13 +61,8 @@ class BuiltinBridgeDialog { TorSettings.bridges.source == TorBridgeSource.BuiltIn ? TorSettings.bridges.builtin_type : null; - if (currentBuiltinType) { - radioGroup.value = currentBuiltinType; - } else { - radioGroup.selectedItem = null; - }
- for (const optionEl of radioGroup.querySelectorAll( + for (const optionEl of this._radioGroup.querySelectorAll( ".builtin-bridges-option" )) { const radio = optionEl.querySelector("radio"); @@ -85,8 +81,15 @@ class BuiltinBridgeDialog { ); }
+ if (currentBuiltinType) { + this._radioGroup.value = currentBuiltinType; + } else { + this._radioGroup.selectedItem = null; + } + + this._radioGroup.addEventListener("select", () => this.onSelectChange()); dialog.addEventListener("dialogaccept", () => { - this.onSubmit(radioGroup.value, TorConnect.canBeginBootstrap); + this.onSubmit(this._radioGroup.value, TorConnect.canBeginBootstrap); }); dialog.addEventListener("dialoghelp", e => { window.top.openTrustedLinkIn( @@ -102,9 +105,15 @@ class BuiltinBridgeDialog { this._acceptButton = dialog.getButton("accept");
Services.obs.addObserver(this, TorConnectTopics.StateChange); + + this.onSelectChange(); this.onAcceptStateChange(); }
+ onSelectChange() { + this._acceptButton.disabled = !this._radioGroup.value; + } + onAcceptStateChange() { this._acceptButton.setAttribute( "label",
===================================== browser/components/torpreferences/content/connectionPane.js ===================================== @@ -1088,14 +1088,9 @@ const gConnectionPane = (function() { onAddBuiltinBridge() { const builtinBridgeDialog = new BuiltinBridgeDialog( (bridgeType, connect) => { - if (!bridgeType) { - TorSettings.bridges.enabled = false; - TorSettings.bridges.builtin_type = ""; - } else { - TorSettings.bridges.enabled = true; - TorSettings.bridges.source = TorBridgeSource.BuiltIn; - TorSettings.bridges.builtin_type = bridgeType; - } + TorSettings.bridges.enabled = true; + TorSettings.bridges.source = TorBridgeSource.BuiltIn; + TorSettings.bridges.builtin_type = bridgeType;
this.saveBridgeSettings(connect); } @@ -1124,15 +1119,9 @@ const gConnectionPane = (function() { onAddBridgeManually() { const provideBridgeDialog = new ProvideBridgeDialog( (aBridgeString, connect) => { - if (aBridgeString) { - TorSettings.bridges.enabled = true; - TorSettings.bridges.source = TorBridgeSource.UserProvided; - TorSettings.bridges.bridge_strings = aBridgeString; - } else { - TorSettings.bridges.enabled = false; - TorSettings.bridges.source = TorBridgeSource.Invalid; - TorSettings.bridges.bridge_strings = ""; - } + TorSettings.bridges.enabled = true; + TorSettings.bridges.source = TorBridgeSource.UserProvided; + TorSettings.bridges.bridge_strings = aBridgeString;
this.saveBridgeSettings(connect); }
===================================== browser/components/torpreferences/content/provideBridgeDialog.jsm ===================================== @@ -56,32 +56,35 @@ class ProvideBridgeDialog { "placeholder", TorStrings.settings.provideBridgePlaceholder ); - this._textarea.addEventListener("input", () => { - this.onAcceptStateChange(); - }); + + this._textarea.addEventListener("input", () => this.onValueChange()); if (TorSettings.bridges.source == TorBridgeSource.UserProvided) { this._textarea.value = TorSettings.bridges.bridge_strings.join("\n"); }
this._dialog.addEventListener("dialogaccept", e => { - let value = this._textarea.value; - if (!value.trim()) { - value = null; - } - this.onSubmit(value, value && TorConnect.canBeginBootstrap); + this.onSubmit(this._textarea.value, TorConnect.canBeginBootstrap); }); this._dialog.addEventListener("dialoghelp", openHelp);
this._acceptButton = this._dialog.getButton("accept");
Services.obs.addObserver(this, TorConnectTopics.StateChange); + + this.onValueChange(); this.onAcceptStateChange(); }
+ onValueChange() { + // TODO: Do some proper value parsing and error reporting. See + // tor-browser#40552. + this._acceptButton.disabled = !this._textarea.value.trim(); + } + onAcceptStateChange() { this._acceptButton.setAttribute( "label", - this._textarea.value.trim() && TorConnect.canBeginBootstrap + TorConnect.canBeginBootstrap ? TorStrings.settings.bridgeButtonConnect : TorStrings.settings.bridgeButtonAccept );
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/commit/01e38a05...
tbb-commits@lists.torproject.org