Bug 1495583 - Add a button to restore the default value for network.trr.uri preference. r=flod,jaws
☠☠ backed out by 4e77c1c74676 ☠ ☠
authorErica Wright <ewright@mozilla.com>
Fri, 12 Oct 2018 21:34:50 +0000
changeset 499399 74a98c04cd54385d99b2a49842df0a9f14846bf4
parent 499398 a58d921ba5a1899c3127d6c93ff569846921e9a8
child 499400 0bad7b51e301e52d3887745546c569c0db412f3b
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflod, jaws
bugs1495583
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
browser/components/preferences/connection.js
browser/components/preferences/connection.xul
browser/components/preferences/in-content/main.xul
browser/locales/en-US/browser/preferences/connection.ftl
modules/libpref/init/all.js
--- a/browser/components/preferences/connection.js
+++ b/browser/components/preferences/connection.js
@@ -30,35 +30,41 @@ Preferences.addAll([
   { id: "network.proxy.backup.ftp", type: "string" },
   { id: "network.proxy.backup.ftp_port", type: "int" },
   { id: "network.proxy.backup.ssl", type: "string" },
   { id: "network.proxy.backup.ssl_port", type: "int" },
   { id: "network.proxy.backup.socks", type: "string" },
   { 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", () => {
   Preferences.get("network.proxy.type").on("change",
     gConnectionsDialog.proxyTypeChanged.bind(gConnectionsDialog));
   Preferences.get("network.proxy.socks_version").on("change",
     gConnectionsDialog.updateDNSPref.bind(gConnectionsDialog));
+  gConnectionsDialog.initDnsOverHttpsUI();
 
   document
     .getElementById("disableProxyExtension")
     .addEventListener(
       "command", makeDisableControllingExtension(
         PREF_SETTING_TYPE, PROXY_KEY).bind(gConnectionsDialog));
   gConnectionsDialog.updateProxySettingsUI();
   initializeProxyUI(gConnectionsDialog);
 }, { once: true, capture: true });
 
 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();
       return true;
     }
 
     if (proxyTypePref.value != 1)
       return true;
@@ -298,16 +304,30 @@ var gConnectionsDialog = {
 
   writeDnsOverHttpsMode() {
     // called to update pref with user change
     let trrModeCheckbox = document.getElementById("networkDnsOverHttps");
     // we treat checked/enabled as mode 2
     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();
   },
 };
--- a/browser/components/preferences/connection.xul
+++ b/browser/components/preferences/connection.xul
@@ -149,19 +149,28 @@
               preference="signon.autologin.proxy" />
     <checkbox id="networkProxySOCKSRemoteDNS"
               preference="network.proxy.socks_remote_dns"
               data-l10n-id="connection-proxy-socks-remote-dns" />
     <checkbox id="networkDnsOverHttps"
               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>
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -700,13 +700,14 @@
                 connection-proxy-noproxy,
                 connection-proxy-noproxy-desc,
                 connection-proxy-http-share.label,
                 connection-proxy-autotype.label,
                 connection-proxy-reload.label,
                 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>
 </groupbox>
--- a/browser/locales/en-US/browser/preferences/connection.ftl
+++ b/browser/locales/en-US/browser/preferences/connection.ftl
@@ -81,11 +81,19 @@ connection-proxy-autologin =
 connection-proxy-socks-remote-dns =
     .label = Proxy DNS when using SOCKS v5
     .accesskey = D
 
 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
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5428,19 +5428,20 @@ pref("network.captive-portal-service.max
 // Every 10 checks, the delay is increased by a factor of 5
 pref("network.captive-portal-service.backoffFactor", "5.0");
 pref("network.captive-portal-service.enabled", false);
 
 // DNS Trusted Recursive Resolver
 // 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
 pref("network.trr.wait-for-portal", false);
 #else
 pref("network.trr.wait-for-portal", true);
 #endif
 // Allow RFC1918 address in responses?