Bug 1495583 - Add a button to restore the default value for network.trr.uri preference. r=flod,jaws

This adds a button to the preferences UI to restore the default value for network.trr.uri preference.

Differential Revision: https://phabricator.services.mozilla.com/D7359

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Erica Wright 2018-10-12 21:34:50 +00:00
parent 16de201664
commit d3826b0a61
5 changed files with 57 additions and 18 deletions

View File

@ -35,6 +35,7 @@ Preferences.addAll([
{ id: "network.proxy.backup.socks_port", type: "int" },
{ id: "network.trr.mode", type: "int" },
{ id: "network.trr.uri", type: "string" },
{ id: "network.trr.custom_uri", "type": "string" },
]);
window.addEventListener("DOMContentLoaded", () => {
@ -42,6 +43,7 @@ window.addEventListener("DOMContentLoaded", () => {
gConnectionsDialog.proxyTypeChanged.bind(gConnectionsDialog));
Preferences.get("network.proxy.socks_version").on("change",
gConnectionsDialog.updateDNSPref.bind(gConnectionsDialog));
gConnectionsDialog.initDnsOverHttpsUI();
document
.getElementById("disableProxyExtension")
@ -54,6 +56,10 @@ window.addEventListener("DOMContentLoaded", () => {
var gConnectionsDialog = {
beforeAccept() {
if (document.getElementById("customDnsOverHttpsUrlRadio").selected) {
Services.prefs.setStringPref("network.trr.uri", document.getElementById("customDnsOverHttpsInput").value);
}
var proxyTypePref = Preferences.get("network.proxy.type");
if (proxyTypePref.value == 2) {
this.doAutoconfigURLFixup();
@ -303,11 +309,25 @@ var gConnectionsDialog = {
return trrModeCheckbox.checked ? 2 : 0;
},
writeDnsOverHttpsUri() {
// called to update pref with user input
let input = document.getElementById("networkDnsOverHttpsUrl");
let uriString = input.value.trim();
// turn an empty string into `undefined` to clear the pref back to the default
return uriString.length ? uriString : undefined;
updateDnsOverHttpsUI() {
// Disable the custom url input box if the parent checkbox and custom radio button attached to it is not selected.
// Disable the custom radio button if the parent checkbox is not selected.
let parentCheckbox = document.getElementById("networkDnsOverHttps");
let customDnsOverHttpsUrlRadio = document.getElementById("customDnsOverHttpsUrlRadio");
let customDnsOverHttpsInput = document.getElementById("customDnsOverHttpsInput");
customDnsOverHttpsInput.disabled = !parentCheckbox.checked || !customDnsOverHttpsUrlRadio.selected;
customDnsOverHttpsUrlRadio.disabled = !parentCheckbox.checked;
},
initDnsOverHttpsUI() {
let defaultDnsOverHttpsUrlRadio = document.getElementById("defaultDnsOverHttpsUrlRadio");
let defaultPrefUrl = Preferences.get("network.trr.uri").defaultValue;
document.l10n.setAttributes(defaultDnsOverHttpsUrlRadio, "connection-dns-over-https-url-default", {
url: defaultPrefUrl,
});
defaultDnsOverHttpsUrlRadio.value = defaultPrefUrl;
let radioGroup = document.getElementById("DnsOverHttpsUrlRadioGroup");
radioGroup.selectedIndex = Preferences.get("network.trr.uri").hasUserValue ? 1 : 0;
this.updateDnsOverHttpsUI();
},
};

View File

@ -154,14 +154,23 @@
data-l10n-id="connection-dns-over-https"
preference="network.trr.mode"
onsyncfrompreference="return gConnectionsDialog.readDnsOverHttpsMode();"
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode()" />
<hbox class="indent" flex="1" align="center">
<label control="networkDnsOverHttpsUrl" data-l10n-id="connection-dns-over-https-url"
data-l10n-attrs="tooltiptext"/>
<textbox id="networkDnsOverHttpsUrl" flex="1" preference="network.trr.uri"
placeholder="https://doh.example.com/dns-query"
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsUri()" />
</hbox>
onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode();"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<vbox class="indent" flex="1">
<radiogroup id="DnsOverHttpsUrlRadioGroup" orient="vertical">
<radio id="defaultDnsOverHttpsUrlRadio"
data-l10n-id="connection-dns-over-https-url-default"
preference="network.trr.uri"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<hbox>
<radio id="customDnsOverHttpsUrlRadio"
data-l10n-id="connection-dns-over-https-url-custom"
oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
<textbox id="customDnsOverHttpsInput" flex="1" preference="network.trr.custom_uri"/>
</hbox>
</radiogroup>
</vbox>
<separator/>
</vbox>
</dialog>

View File

@ -705,7 +705,8 @@
connection-proxy-autologin.label,
connection-proxy-socks-remote-dns.label,
connection-dns-over-https,
connection-dns-over-https-url
connection-dns-over-https-url-custom,
connection-dns-over-https-url-default,
" />
</hbox>
</hbox>

View File

@ -86,6 +86,14 @@ connection-dns-over-https =
.label = Enable DNS over HTTPS
.accesskey = b
connection-dns-over-https-url = URL
# Variables:
# $url (String) - URL for the DNS over HTTPS provider
connection-dns-over-https-url-default =
.label = Use default ({ $url })
.accesskey = U
.tooltiptext = URL for resolving DNS over HTTPS
.tooltiptext = Use the default URL for resolving DNS over HTTPS
connection-dns-over-https-url-custom =
.label = Custom
.accesskey = C
.tooltiptext = Enter your preferred URL for resolving DNS over HTTPS

View File

@ -5433,9 +5433,10 @@ pref("network.captive-portal-service.enabled", false);
// 0 - default off, 1 - race, 2 TRR first, 3 TRR only, 4 shadow, 5 off by choice
pref("network.trr.mode", 0);
// DNS-over-HTTP service to use, must be HTTPS://
pref("network.trr.uri", "");
pref("network.trr.uri", "https://mozilla.cloudflare-dns.com/dns-query");
// credentials to pass to DOH end-point
pref("network.trr.credentials", "");
pref("network.trr.custom_uri", "");
// Wait for captive portal confirmation before enabling TRR
#if defined(ANDROID)
// On Android, the captive portal is handled by the OS itself