Bug 1506355 - Port bug 1495583: Add a button to restore the default value for the network.trr.uri preference. r=mkmelin
authorRichard Marti <richard.marti@gmail.com>
Sat, 10 Nov 2018 13:20:42 +0100
changeset 33690 37233a992def692093f85e6b88860bc500869634
parent 33689 856dd9d687bd3089751b4aae08a5a2f07fd18586
child 33691 e1449ad9e4d66904616aef96031d48f9f4a9fc6d
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersmkmelin
bugs1506355, 1495583
Bug 1506355 - Port bug 1495583: Add a button to restore the default value for the network.trr.uri preference. r=mkmelin
mail/components/preferences/connection.js
mail/components/preferences/connection.xul
mail/locales/en-US/chrome/messenger/preferences/connection.dtd
--- a/mail/components/preferences/connection.js
+++ b/mail/components/preferences/connection.js
@@ -2,16 +2,20 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var gConnectionsDialog = {
   beforeAccept() {
+    if (document.getElementById("customDnsOverHttpsUrlRadio").selected) {
+      Services.prefs.setStringPref("network.trr.uri", document.getElementById("customDnsOverHttpsInput").value);
+    }
+
     var proxyTypePref = document.getElementById("network.proxy.type");
     if (proxyTypePref.value == 2) {
       this.doAutoconfigURLFixup();
       return true;
     }
 
     if (proxyTypePref.value != 1)
       return true;
@@ -179,21 +183,29 @@ 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 input = document.getElementById("networkDnsOverHttpsUrl");
-    input.placeholder = document.getElementById("network.trr.uri").defaultValue;
+    let defaultDnsOverHttpsUrlRadio = document.getElementById("defaultDnsOverHttpsUrlRadio");
+    let defaultPrefUrl = document.getElementById("network.trr.uri").defaultValue;
+    document.getElementById("defaultDnsOverHttpsUrlLabel").setAttribute("value", "(" + defaultPrefUrl + ")");
+    defaultDnsOverHttpsUrlRadio.value = defaultPrefUrl;
+    let radioGroup = document.getElementById("DnsOverHttpsUrlRadioGroup");
+    radioGroup.selectedIndex = document.getElementById("network.trr.uri").hasUserValue ? 1 : 0;
+    this.updateDnsOverHttpsUI();
   },
 };
--- a/mail/components/preferences/connection.xul
+++ b/mail/components/preferences/connection.xul
@@ -44,16 +44,17 @@
 
       <preference id="network.proxy.backup.ssl"          name="network.proxy.backup.ssl"          type="string"/>
       <preference id="network.proxy.backup.ssl_port"     name="network.proxy.backup.ssl_port"     type="int"/>
       <preference id="network.proxy.backup.socks"        name="network.proxy.backup.socks"        type="string"/>
       <preference id="network.proxy.backup.socks_port"   name="network.proxy.backup.socks_port"   type="int"/>
       <preference id="network.proxy.socks_remote_dns"    name="network.proxy.socks_remote_dns"    type="bool"/>
       <preference id="network.trr.mode"                  name="network.trr.mode"                  type="int"/>
       <preference id="network.trr.uri"                   name="network.trr.uri"                   type="string"/>
+      <preference id="network.trr.custom_uri"            name="network.trr.custom_uri"            type="string"/>
       <preference id="signon.autologin.proxy"            name="signon.autologin.proxy"            type="bool"/>
     </preferences>
 
     <script type="application/javascript" src="chrome://messenger/content/preferences/connection.js"/>
 
     <groupbox>
       <caption>&proxyTitle.label;</caption>
 
@@ -162,22 +163,36 @@
               preference="network.proxy.socks_remote_dns"
               label="&socksRemoteDNS.label;"
               accesskey="&socksRemoteDNS.accesskey;"/>
     <checkbox id="networkDnsOverHttps"
               label="&dnsOverHttps.label;"
               accesskey="&dnsOverHttps.accesskey;"
               preference="network.trr.mode"
               onsyncfrompreference="return gConnectionsDialog.readDnsOverHttpsMode();"
-              onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode()"/>
-    <hbox class="indent" flex="1" align="center">
-      <label control="networkDnsOverHttpsUrl"
-             label="&dnsOverHttpsUrl.label;"
-             accesskey="&dnsOverHttpsUrl.accesskey;"
-             tooltiptext="&dnsOverHttpsUrl.tooltip;"/>
-      <textbox id="networkDnsOverHttpsUrl"
-               flex="1"
-               preference="network.trr.uri"
-               onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsUri()"/>
-    </hbox>
+              onsynctopreference="return gConnectionsDialog.writeDnsOverHttpsMode();"
+              oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
+    <vbox class="indent" flex="1">
+      <radiogroup id="DnsOverHttpsUrlRadioGroup" orient="vertical">
+        <hbox>
+          <radio id="defaultDnsOverHttpsUrlRadio"
+                 label="&dnsOverHttpsUrlDefault.label;"
+                 accesskey="&dnsOverHttpsUrlDefault.accesskey;"
+                 tooltiptext="&dnsOverHttpsUrlDefault.tooltip;"
+                 preference="network.trr.uri"
+                 oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
+          <label id="defaultDnsOverHttpsUrlLabel"/>
+        </hbox>
+        <hbox>
+          <radio id="customDnsOverHttpsUrlRadio"
+                 label="&dnsOverHttpsUrlCustom.label;"
+                 accesskey="&dnsOverHttpsUrlCustom.accesskey;"
+                 tooltiptext="&dnsOverHttpsUrlCustom.tooltip;"
+                 oncommand="gConnectionsDialog.updateDnsOverHttpsUI();"/>
+          <textbox id="customDnsOverHttpsInput"
+                   flex="1"
+                   preference="network.trr.custom_uri"/>
+        </hbox>
+      </radiogroup>
+    </vbox>
     <separator/>
   </prefpane>
 </prefwindow>
--- a/mail/locales/en-US/chrome/messenger/preferences/connection.dtd
+++ b/mail/locales/en-US/chrome/messenger/preferences/connection.dtd
@@ -42,11 +42,14 @@
 <!ENTITY  shareproxy.accesskey          "x">
 <!ENTITY  autologinproxy.label          "Do not prompt for authentication if password is saved">
 <!ENTITY  autologinproxy.accesskey      "i">
 <!ENTITY  autologinproxy.tooltip        "This option silently authenticates you to proxies when you have saved credentials for them. You will be prompted if authentication fails.">
 <!ENTITY  socksRemoteDNS.label          "Proxy DNS when using SOCKS v5">
 <!ENTITY  socksRemoteDNS.accesskey      "d">
 <!ENTITY  dnsOverHttps.label            "Enable DNS over HTTPS">
 <!ENTITY  dnsOverHttps.accesskey        "b">
-<!ENTITY  dnsOverHttpsUrl.label         "URL">
-<!ENTITY  dnsOverHttpsUrl.accesskey     "R">
-<!ENTITY  dnsOverHttpsUrl.tooltip       "URL for resolving DNS over HTTPS">
+<!ENTITY  dnsOverHttpsUrlDefault.label     "Use default">
+<!ENTITY  dnsOverHttpsUrlDefault.accesskey "l">
+<!ENTITY  dnsOverHttpsUrlDefault.tooltip   "Use the default URL for resolving DNS over HTTPS">
+<!ENTITY  dnsOverHttpsUrlCustom.label      "Custom">
+<!ENTITY  dnsOverHttpsUrlCustom.accesskey  "t">
+<!ENTITY  dnsOverHttpsUrlCustom.tooltip    "Enter your preferred URL for resolving DNS over HTTPS">