[tbb-commits] [torbutton/master] Bug 9387: Version 0.3 of the Security Slider.

gk at torproject.org gk at torproject.org
Tue Dec 2 20:36:34 UTC 2014


commit 6f3904e16b829715b230d927f29d2cf02f1e4964
Author: Georg Koppen <gk at torproject.org>
Date:   Mon Dec 1 15:36:51 2014 +0000

    Bug 9387: Version 0.3 of the Security Slider.
    
    It contains the following, small improvements:
      * custom settings are not overwritten on restart/New Identity
      * the custom checkbox is disabled and not hidden anymore by default
      * the security level can be chosen by clicking on the respective
        description
---
 src/chrome/content/preferences.js  |   20 ++++++++++++--------
 src/chrome/content/preferences.xul |   19 +++++++++++--------
 src/chrome/content/torbutton.js    |    9 ++++++---
 3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 20a6c9f..75937eb 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -194,7 +194,7 @@ function torbutton_prefs_init(doc) {
     // non-responding. We need to handle |movetoclick| as well.
     sec_slider.setAttribute("movetoclick", !custom_values);
     sec_custom.checked = custom_values;
-    sec_custom.collapsed = !custom_values;
+    sec_custom.disabled = !custom_values;
 
     torbutton_prefs_set_field_attributes(doc);
 }
@@ -447,14 +447,18 @@ function torbutton_prefs_reset_defaults() {
     prefService.savePrefFile(null);
 }
 
-function torbutton_toggle_slider(doc) {
+function torbutton_toggle_slider(doc, pos) {
     let slider = doc.getElementById("torbutton_sec_slider");
-    if (doc.getElementById("torbutton_sec_custom").checked) {
-        slider.disabled = true;
-        slider.setAttribute("movetoclick", false);
+    // onclick is active even if the element it belongs to is disabled.
+    if (pos && !slider.disabled) {
+        slider.value = pos;
     } else {
-        slider.disabled = false;
-        slider.setAttribute("movetoclick", true);
+        if (doc.getElementById("torbutton_sec_custom").checked) {
+            slider.disabled = true;
+            slider.setAttribute("movetoclick", false);
+        } else {
+            slider.disabled = false;
+            slider.setAttribute("movetoclick", true);
+        }
     }
 }
-
diff --git a/src/chrome/content/preferences.xul b/src/chrome/content/preferences.xul
index 7c5633b..cb5f1ab 100644
--- a/src/chrome/content/preferences.xul
+++ b/src/chrome/content/preferences.xul
@@ -97,7 +97,7 @@
                       <radiogroup align="center" orient="horizontal" id="torbutton_socksGroup">
                           <radio id="torbutton_socksv4"
                                 label="&torbutton.prefs.socks_vfour;"/>
-                          <radio id="torbutton_socksv5" 
+                          <radio id="torbutton_socksv5"
                                 label="&torbutton.prefs.socks_vfive;"/>
                       </radiogroup>
                     </row>
@@ -129,8 +129,7 @@
         oncommand="torbutton_prefs_set_field_attributes(document)"/>
 
         </radiogroup>
-       
-        
+
         <hbox>
          <spacer flex="1"/>
          <button id="torbutton_testSettings"
@@ -162,22 +161,26 @@
             </vbox>
             <vbox height="200">
               <hbox flex="1" align="center">
-                <description id="torbutton_sec_low">
+                <description id="torbutton_sec_low"
+                             onclick="torbutton_toggle_slider(document, 1);">
                   &torbutton.prefs.sec_low;
                 </description>
               </hbox>
               <hbox flex="1" align="center">
-                <description id="torbutton_sec_med_low">
+                <description id="torbutton_sec_med_low"
+                             onclick="torbutton_toggle_slider(document, 2);">
                   &torbutton.prefs.sec_med_low;
                 </description>
               </hbox>
               <hbox flex="1" align="center">
-                <description id="torbutton_sec_med_high">
+                <description id="torbutton_sec_med_high"
+                             onclick="torbutton_toggle_slider(document, 3);">
                   &torbutton.prefs.sec_med_high;
                 </description>
               </hbox>
               <hbox flex="1" align="center">
-                <description id="torbutton_sec_high">
+                <description id="torbutton_sec_high"
+                             onclick="torbutton_toggle_slider(document, 4);">
                   &torbutton.prefs.sec_high;
                 </description>
               </hbox>
@@ -185,7 +188,7 @@
           </hbox>
           <hbox>
             <checkbox id="torbutton_sec_custom" flex="1"
-                      oncommand="torbutton_toggle_slider(document);"
+                      oncommand="torbutton_toggle_slider(document, 0);"
                       label="&torbutton.prefs.sec_custom;"/>
           </hbox>
         </groupbox>
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index da39864..2ba4159 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -552,8 +552,11 @@ function torbutton_init() {
 
     // initialize preferences before we start our prefs observer
     torbutton_init_prefs();
-    // set some important security prefs according to the chosen security level
-    torbutton_update_security_slider();
+    // Set some important security prefs according to the chosen security level
+    // if there are no custom settings to respect.
+    if (!m_tb_prefs.getBoolPref("extensions.torbutton.security_custom")) {
+      torbutton_update_security_slider();
+    }
 
     // set panel style from preferences
     torbutton_set_panel_style();
@@ -562,7 +565,7 @@ function torbutton_init() {
     torbutton_init_toolbutton();
 
     torbutton_log(1, 'registering pref observer');
-    torbutton_window_pref_observer.register(); 
+    torbutton_window_pref_observer.register();
 
     torbutton_log(1, "registering Tor check observer");
     torbutton_tor_check_observer.register();





More information about the tbb-commits mailing list