Browse Source

Bug 20614: Add links to Tor Browser User Manual

Arthur Edelstein 3 years ago
parent
commit
8a5dc8c510

+ 8 - 1
src/chrome/content/aboutTor/aboutTor.xhtml

@@ -241,7 +241,14 @@ window.addEventListener("pageshow", function() {
     <div class="bubble">
       <h1>&aboutTor.whatnextQuestion.label;</h1>
       <p>&aboutTor.whatnextAnswer.label;</p>
-      <a class="tips" href="&aboutTor.whatnext.link;">&aboutTor.whatnext.label;</a>
+      <ul>
+        <li class="showForManual">
+          <a href="&aboutTor.torbrowser_user_manual.link;">
+            &aboutTor.torbrowser_user_manual.label;
+          </a>
+        </li>
+        <li><a href="&aboutTor.whatnext.link;">&aboutTor.whatnext.label;</a></li>
+      </ul>
     </div>
 
     <div class="bubble">

+ 10 - 1
src/chrome/content/menu-overlay.xul

@@ -1,9 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?> <!-- -*- Mode: HTML -*- -->
 
-<!-- Bug 18905: Hide unused help menu items -->
+<!DOCTYPE overlay SYSTEM "chrome://torbutton/locale/torbutton.dtd">
+
 <overlay id="torbutton-menu-overlay"
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <menupopup id="menu_HelpPopup">
+    <!-- Bug 18905: Hide unused help menu items -->
     <menuitem id="menu_openHelp" removeelement="true"/>
     <menuitem id="menu_openTour" removeelement="true"/>
     <menuitem id="healthReport" removeelement="true"/>
@@ -14,5 +16,12 @@
     <!-- dummy elements to avoid 'getElementById' errors -->
     <box id="menu_HelpPopup_reportPhishingtoolmenu"/>
     <box id="menu_HelpPopup_reportPhishingErrortoolmenu"/>
+    <!-- Add Tor Browser manual link -->
+    <menuitem name="torBrowserUserManual"
+              id="torBrowserUserManual"
+              position="1"
+              label="&torbutton.torbrowser_user_manual.label;"
+              accesskey="&torbutton.torbrowser_user_manual.accesskey;"
+              oncommand="torbutton_open_torbrowser_user_manual()" />
   </menupopup>
 </overlay>

+ 39 - 7
src/chrome/content/torbutton.js

@@ -12,6 +12,7 @@ let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
 let { showDialog } = 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 { bindPrefAndInit } = Cu.import("resource://torbutton/modules/utils.js", {});
 
 const k_tb_last_browser_version_pref = "extensions.torbutton.lastBrowserVersion";
 const k_tb_browser_update_needed_pref = "extensions.torbutton.updateNeeded";
@@ -200,7 +201,7 @@ var torbutton_tor_check_observer = {
 
         // Update all open about:tor pages. If the user does not have an
         // about:tor page open in the front most window, open one.
-        if (torbutton_update_all_abouttor_pages(undefined, false) < 1) {
+        if (torbutton_update_all_abouttor_pages(undefined, undefined, false) < 1) {
           var wm = Cc["@mozilla.org/appshell/window-mediator;1"]
               .getService(Components.interfaces.nsIWindowMediator);
           var win = wm.getMostRecentWindow("navigator:browser");
@@ -360,7 +361,7 @@ function torbutton_init() {
 
     // Detect toolbar customization and update arrow on about:tor pages.
     window.addEventListener("aftercustomization", function() {
-      torbutton_update_all_abouttor_pages(undefined, undefined);
+      torbutton_update_all_abouttor_pages(undefined, undefined, undefined);
     }, false);
     
     //setting up context menu
@@ -399,6 +400,8 @@ function torbutton_init() {
 
     quantizeBrowserSize(window, 100, 100);
 
+    torbutton_init_user_manual_links();
+
     torbutton_log(3, 'init completed');
 }
 
@@ -565,7 +568,7 @@ function torbutton_notify_if_update_needed() {
     setOrClearAttribute(btn, "tbUpdateNeeded", updateNeeded);
 
     // Update all open about:tor pages.
-    torbutton_update_all_abouttor_pages(updateNeeded, undefined);
+    torbutton_update_all_abouttor_pages(updateNeeded, undefined, undefined);
 
     // Make the "check for update" menu item bold if an update is needed.
     var item = document.getElementById("torbutton-checkForUpdate");
@@ -594,9 +597,11 @@ function torbutton_check_for_update() {
 
 // Pass undefined for a parameter to have this function determine it.
 // Returns a count of open pages that were updated,
-function torbutton_update_all_abouttor_pages(aUpdateNeeded, aTorIsOn) {
+function torbutton_update_all_abouttor_pages(aUpdateNeeded, aShowManual, aTorIsOn) {
   if (aUpdateNeeded === undefined)
     aUpdateNeeded = torbutton_update_is_needed();
+  if (aShowManual === undefined)
+    aShowManual = torbutton_show_torbrowser_manual();
   if (aTorIsOn === undefined)
     aTorIsOn = torbutton_tor_check_ok();
 
@@ -607,7 +612,7 @@ function torbutton_update_all_abouttor_pages(aUpdateNeeded, aTorIsOn) {
     for (var tab = tabs[0]; tab != null; tab = tab.nextSibling) {
       try {
         let doc = tabBrowser.getBrowserForTab(tab).contentDocument;
-        if (torbutton_update_abouttor_doc(doc, aTorIsOn, aUpdateNeeded))
+        if (torbutton_update_abouttor_doc(doc, aTorIsOn, aShowManual, aUpdateNeeded))
           ++count;
       } catch(e) {}
     }
@@ -617,7 +622,7 @@ function torbutton_update_all_abouttor_pages(aUpdateNeeded, aTorIsOn) {
 }
 
 // Returns true if aDoc is an about:tor page.
-function torbutton_update_abouttor_doc(aDoc, aTorOn, aUpdateNeeded) {
+function torbutton_update_abouttor_doc(aDoc, aTorOn, aShowManual, aUpdateNeeded) {
   var isAboutTor = torbutton_is_abouttor_doc(aDoc);
   if (isAboutTor) {
     if (aTorOn)
@@ -625,6 +630,11 @@ function torbutton_update_abouttor_doc(aDoc, aTorOn, aUpdateNeeded) {
     else
       aDoc.body.removeAttribute("toron");
 
+    if (aShowManual)
+      aDoc.body.setAttribute("showmanual", "yes");
+    else
+      aDoc.body.removeAttribute("showmanual");
+
     if (aUpdateNeeded)
       aDoc.body.setAttribute("torNeedsUpdate", "yes"); 
     else
@@ -739,8 +749,9 @@ function torbutton_on_abouttor_load(aDoc) {
 
     // Show correct Tor on/off and "update needed" status.
     let torOn = torbutton_tor_check_ok();
+    let showManual = torbutton_show_torbrowser_manual();
     let needsUpdate = torbutton_update_is_needed();
-    torbutton_update_abouttor_doc(aDoc, torOn, needsUpdate);
+    torbutton_update_abouttor_doc(aDoc, torOn, showManual, needsUpdate);
 
     aDoc.defaultView.addEventListener("resize",
                       function() { torbutton_update_abouttor_arrow(aDoc); },
@@ -2437,5 +2448,26 @@ function torbutton_update_noscript_button()
   }, 0);
 }
 
+// Opens the Tor Browser User Manual in a new tab
+function torbutton_open_torbrowser_user_manual() {
+  gBrowser.selectedTab = gBrowser.addTab("https://tb-manual.torproject.org");
+}
+
+// Returns true if we should show the tor browser manual.
+function torbutton_show_torbrowser_manual() {
+  let locale = torbutton_get_general_useragent_locale();
+  return locale.startsWith("en");
+}
+
+// Makes sure the tem 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.
+function torbutton_init_user_manual_links() {
+  let menuitem = document.getElementById("torBrowserUserManual");
+  bindPrefAndInit("general.useragent.locale", val => {
+    menuitem.hidden = !torbutton_show_torbrowser_manual();
+    torbutton_update_all_abouttor_pages(undefined, undefined, undefined);
+  });
+}
 
 //vim:set ts=4

+ 2 - 0
src/chrome/locale/en/aboutTor.dtd

@@ -32,6 +32,8 @@
 <!ENTITY aboutTor.whatnextAnswer.label "Tor is NOT all you need to browse anonymously! You may need to change some of your browsing habits to ensure your identity stays safe.">
 <!ENTITY aboutTor.whatnext.label "Tips On Staying Anonymous »">
 <!ENTITY aboutTor.whatnext.link "https://www.torproject.org/download/download.html.en#warning">
+<!ENTITY aboutTor.torbrowser_user_manual.label "Tor Browser User Manual »">
+<!ENTITY aboutTor.torbrowser_user_manual.link "https://tb-manual.torproject.org">
 <!ENTITY aboutTor.helpInfo1.label "You Can Help!">
 <!ENTITY aboutTor.helpInfo2.label "There are many ways you can help make the Tor Network faster and stronger:">
 <!ENTITY aboutTor.helpInfo3.label "Run a Tor Relay Node »">

+ 2 - 0
src/chrome/locale/en/torbutton.dtd

@@ -59,3 +59,5 @@
 <!ENTITY torbutton.prefs.sec_webfonts_desc "Some fonts and icons may display incorrectly.">
 <!ENTITY torbutton.prefs.sec_webfonts_desc_tooltip "Website-provided font files are blocked.">
 <!ENTITY torbutton.circuit_display.title "Tor circuit for this site">
+<!ENTITY torbutton.torbrowser_user_manual.label "Tor Browser User Manual">
+<!ENTITY torbutton.torbrowser_user_manual.accesskey "M">

+ 4 - 0
src/chrome/skin/aboutTor.css

@@ -132,6 +132,10 @@ body[toron] .top h1 {
   color: #600060;
 }
 
+body:not([showmanual]) .showForManual {
+  display: none;
+}
+
 div.hideIfTorIsUpToDate,
 body .top div.hideIfTorIsUpToDate h1 {
   color: black;