[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torbutton/master] Bug 26884 - Part 1: Move show_torbrowser_manual and



commit 5b5931efdf9d8d8bc018d5c02abb14d4e379e160
Author: Igor Oliveira <igt0@xxxxxxxxxxxxxx>
Date:   Tue Jul 31 17:03:02 2018 -0300

    Bug 26884 - Part 1: Move show_torbrowser_manual and
    get_general_useragent_locale to utils
    
    On Desktop, show_torbrowser_manual is a torbutton.js method and it
    is called by other components using the window.opener.
    
    However, on mobile, the security settings is opened in a tab instead
    of a modal. Thus the window.opener is nil.
    
    This patch moves the show_torbrowser_manual to util.js allowing it
    to be accessible from anywhere.
---
 src/chrome/content/aboutTor/aboutTor-content.js |  4 +--
 src/chrome/content/preferences.js               |  4 +--
 src/chrome/content/tor-circuit-display.js       |  4 +--
 src/chrome/content/torbutton.js                 | 33 ++++---------------------
 src/modules/utils.js                            | 10 +++++++-
 5 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/src/chrome/content/aboutTor/aboutTor-content.js b/src/chrome/content/aboutTor/aboutTor-content.js
index c2e26c8c..ae20505e 100644
--- a/src/chrome/content/aboutTor/aboutTor-content.js
+++ b/src/chrome/content/aboutTor/aboutTor-content.js
@@ -18,7 +18,7 @@ var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 
 Cu.import("resource://gre/modules/Services.jsm");
-let { bindPrefAndInit } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { bindPrefAndInit, show_torbrowser_manual } = Cu.import("resource://torbutton/modules/utils.js", {});
 
 
 var AboutTorListener = {
@@ -89,7 +89,7 @@ var AboutTorListener = {
     else
       body.removeAttribute("toron");
 
-    if (aData.showManual)
+    if (show_torbrowser_manual())
       body.setAttribute("showmanual", "yes");
     else
       body.removeAttribute("showmanual");
diff --git a/src/chrome/content/preferences.js b/src/chrome/content/preferences.js
index 36c8818c..81668d6e 100644
--- a/src/chrome/content/preferences.js
+++ b/src/chrome/content/preferences.js
@@ -5,7 +5,7 @@ let { utils: Cu } = Components;
 let { getBoolPref, getIntPref, setBoolPref, setIntPref, getCharPref } =
     Cu.import("resource://gre/modules/Services.jsm", {}).Services.prefs;
 
-let { getLocale } =
+let { getLocale, show_torbrowser_manual } =
     Cu.import("resource://torbutton/modules/utils.js", {});
 
 // Description elements have the follow names.
@@ -67,7 +67,7 @@ function torbutton_save_security_settings() {
 // Help Menu and on about:tor: if we have the manual available for a locale,
 // let's show the "Learn more"-link, otherwise hide it.
 function torbutton_set_learn_more_links() {
-  let show_manual = window.opener.torbutton_show_torbrowser_manual();
+  let show_manual = show_torbrowser_manual();
   let locale = ""
   if (show_manual) {
     locale = getLocale();
diff --git a/src/chrome/content/tor-circuit-display.js b/src/chrome/content/tor-circuit-display.js
index 7b12db08..fe6b51c1 100644
--- a/src/chrome/content/tor-circuit-display.js
+++ b/src/chrome/content/tor-circuit-display.js
@@ -33,7 +33,7 @@ Cu.import("resource://gre/modules/Services.jsm");
 let { controller } = Cu.import("resource://torbutton/modules/tor-control-port.js", {});
 
 // Utility functions
-let { bindPrefAndInit, observe } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { bindPrefAndInit, observe, getLocale } = Cu.import("resource://torbutton/modules/utils.js", {});
 
 // Make the TorButton logger available.
 let logger = Cc["@torproject.org/torbutton-logger;1"]
@@ -381,7 +381,7 @@ let setupGuardNote = function () {
   let guardNoteString = uiString("guard_note");
   let learnMoreString = uiString("learn_more");
   let [noteBefore, name, noteAfter] = guardNoteString.split(/[\[\]]/);
-  let localeCode = torbutton_get_general_useragent_locale();
+  let localeCode = getLocale();
   appendHtml(guardNote,
              ["div", {},
               noteBefore, ["span", {class: "circuit-guard-name"}, name],
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 134f10da..b4e6ed18 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -8,8 +8,8 @@
 //       http://kb.mozillazine.org/Links_to_local_pages_don%27t_work
 
 let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
-let { showDialog } = Cu.import("resource://torbutton/modules/utils.js", {});
-let { getLocale, unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { showDialog, show_torbrowser_manual } = Cu.import("resource://torbutton/modules/utils.js", {});
+let { unescapeTorString } = Cu.import("resource://torbutton/modules/utils.js", {});
 let SecurityPrefs = Cu.import("resource://torbutton/modules/security-prefs.js", {});
 let NoScriptControl = Cu.import("resource://torbutton/modules/noscript-control.js", {});
 let { bindPrefAndInit, observe } = Cu.import("resource://torbutton/modules/utils.js", {});
@@ -435,8 +435,7 @@ var torbutton_abouttor_message_handler = {
   // not working.
   get chromeData() {
     return {
-      torOn: torbutton_tor_check_ok(),
-      showManual: torbutton_show_torbrowser_manual()
+      torOn: torbutton_tor_check_ok()
     };
   }
 };
@@ -730,21 +729,6 @@ function torbutton_update_toolbutton()
                             torbutton_get_property_string(tooltipKey));
 }
 
-// Bug 1506 P3: Support code for language+uagent spoofing
-function torbutton_get_general_useragent_locale() {
-   try {
-        const locale = getLocale();
-        if (/chrome:\/\//.test(locale)) {
-            return m_tb_prefs.getComplexValue("intl.locale.requested",
-                       Components.interfaces.nsIPrefLocalizedString).data;
-        }
-        return locale;
-    } catch(err) {
-        torbutton_log(4, "Error while getting locale" + err);
-        return 'en-US';
-    }
-}
-
 // Bug 1506 P4: Control port interaction. Needed for New Identity.
 function torbutton_socket_readline(input) {
   var str = "";
@@ -2213,20 +2197,13 @@ function torbutton_update_noscript_button()
   }, 0);
 }
 
-// Returns true if we should show the tor browser manual.
-function torbutton_show_torbrowser_manual() {
-  let availableLocales = ["de", "en", "es", "fr", "nl", "pt", "tr", "vi", "zh"];
-  let shortLocale = torbutton_get_general_useragent_locale().substring(0, 2);
-  return availableLocales.indexOf(shortLocale) >= 0;
-}
-
 // Makes sure the item in the Help Menu and the link in about:tor
 // for the Tor Browser User Manual are only visible when
-// torbutton_show_torbrowser_manual() returns true.
+// show_torbrowser_manual() returns true.
 function torbutton_init_user_manual_links() {
   let menuitem = document.getElementById("torBrowserUserManual");
   bindPrefAndInit("intl.locale.requested", val => {
-    menuitem.hidden = !torbutton_show_torbrowser_manual();
+    menuitem.hidden = !show_torbrowser_manual();
     torbutton_abouttor_message_handler.updateAllOpenPages();
   });
 }
diff --git a/src/modules/utils.js b/src/modules/utils.js
index 0a2649dd..5af071ec 100644
--- a/src/modules/utils.js
+++ b/src/modules/utils.js
@@ -205,6 +205,14 @@ var unescapeTorString = function(str) {
   return _torControl._strUnescape(str);
 };
 
+// Returns true if we should show the tor browser manual.
+var show_torbrowser_manual = () => {
+  let availableLocales = ["de", "en", "es", "fr", "nl", "pt", "tr", "vi", "zh"];
+  let shortLocale = getLocale().substring(0, 2);
+  return availableLocales.indexOf(shortLocale) >= 0;
+}
+
+
 // Export utility functions for external use.
 let EXPORTED_SYMBOLS = ["bindPref", "bindPrefAndInit", "getEnv", "getLocale",
-                        "getPrefValue", "observe", "showDialog", "unescapeTorString"];
+                        "getPrefValue", "observe", "showDialog", "show_torbrowser_manual", "unescapeTorString"];



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits