[tbb-commits] [tor-browser/tor-browser-78.6.0esr-10.0-1] Bug 10760: Integrate TorButton to TorBrowser core

sysrqb at torproject.org sysrqb at torproject.org
Wed Dec 9 17:17:02 UTC 2020


commit 2d9dde9a6c50221d8c13271343688d5ca9079197
Author: Alex Catarineu <acat at torproject.org>
Date:   Wed Feb 19 23:05:08 2020 +0100

    Bug 10760: Integrate TorButton to TorBrowser core
    
    Because of the non-restartless nature of Torbutton, it required
    a two-stage installation process. On mobile, it was a problem,
    because it was not loading when the user opened the browser for
    the first time.
    
    Moving it to tor-browser and making it a system extension allows it
    to load when the user opens the browser for first time.
    
    Additionally, this patch also fixes Bug 27611.
    
    Bug 26321: New Circuit and New Identity menu items
    
    Bug 14392: Make about:tor behave like other initial pages.
    
    Bug 25013: Add torbutton as a tor-browser submodule
---
 .gitmodules                                        |  3 ++
 browser/base/content/aboutDialog.xhtml             | 38 +++++++++++------
 browser/base/content/browser-doctype.inc           |  6 +++
 browser/base/content/browser-menubar.inc           | 49 ++++++++++++++++------
 browser/base/content/browser-sets.inc              |  2 +
 browser/base/content/browser.js                    |  1 +
 browser/base/content/browser.xhtml                 |  9 ++++
 .../controlcenter/content/identityPanel.inc.xhtml  | 17 ++++++++
 .../customizableui/content/panelUI.inc.xhtml       | 17 +++++++-
 browser/installer/package-manifest.in              |  2 +
 docshell/base/nsAboutRedirector.cpp                |  6 ++-
 docshell/build/components.conf                     |  1 +
 mobile/android/installer/package-manifest.in       |  4 ++
 toolkit/moz.build                                  |  1 +
 .../mozapps/extensions/internal/XPIProvider.jsm    |  9 ++++
 toolkit/torproject/torbutton                       |  1 +
 .../lib/environments/browser-window.js             |  6 ++-
 17 files changed, 142 insertions(+), 30 deletions(-)

diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000000..2f03bd8e22df
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "toolkit/torproject/torbutton"]
+	path = toolkit/torproject/torbutton
+	url = https://git.torproject.org/torbutton.git
diff --git a/browser/base/content/aboutDialog.xhtml b/browser/base/content/aboutDialog.xhtml
index 69cbf846bbef..5274cbc02831 100644
--- a/browser/base/content/aboutDialog.xhtml
+++ b/browser/base/content/aboutDialog.xhtml
@@ -7,11 +7,11 @@
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/content/aboutDialog.css" type="text/css"?>
 <?xml-stylesheet href="chrome://branding/content/aboutDialog.css" type="text/css"?>
+<?xml-stylesheet href="chrome://torbutton/skin/aboutDialog.css" type="text/css"?>
 
+<!-- We need to include the localization DTDs until we migrate to Fluent -->
 <!DOCTYPE window [
-#ifdef XP_MACOSX
 #include browser-doctype.inc
-#endif
 ]>
 
 <window xmlns:html="http://www.w3.org/1999/xhtml"
@@ -28,7 +28,7 @@
         data-l10n-id="aboutDialog-title"
 #endif
         role="dialog"
-        aria-describedby="version distribution distributionId communityDesc contributeDesc trademark"
+        aria-describedby="version distribution distributionId projectDesc helpDesc trademark trademarkTor"
         >
 #ifdef XP_MACOSX
 #include macWindow.inc.xhtml
@@ -132,24 +132,36 @@
               <label is="text-link" useoriginprincipal="true" href="about:credits" data-l10n-name="community-exp-creditsLink"></label>
             </description>
           </vbox>
-          <description class="text-blurb" id="communityDesc" data-l10n-id="community-2">
-            <label is="text-link" href="http://www.mozilla.org/" data-l10n-name="community-mozillaLink"></label>
-            <label is="text-link" useoriginprincipal="true" href="about:credits" data-l10n-name="community-creditsLink"></label>
+          <!-- Keep communityDesc and contributeDesc to avoid JS errors trying to hide them -->
+          <description class="text-blurb" id="communityDesc" data-l10n-id="community-2" hidden="true"></description>
+          <description class="text-blurb" id="contributeDesc" data-l10n-id="helpus" hidden="true"></description>
+          <description class="text-blurb" id="projectDesc">
+            &project.start;
+            <label is="text-link" href="https://www.torproject.org/">
+              &project.tpoLink;
+            </label>&project.end;
           </description>
-          <description class="text-blurb" id="contributeDesc" data-l10n-id="helpus">
-            <label is="text-link" href="https://donate.mozilla.org/?utm_source=firefox&utm_medium=referral&utm_campaign=firefox_about&utm_content=firefox_about" data-l10n-name="helpus-donateLink"></label>
-            <label is="text-link" href="http://www.mozilla.org/contribute/" data-l10n-name="helpus-getInvolvedLink"></label>
+          <description class="text-blurb" id="helpDesc">
+            &help.start;
+            <label is="text-link" href="https://donate.torproject.org/">
+              &help.donateLink;
+            </label>
+            &help.or;
+            <label is="text-link" href="https://community.torproject.org/">
+              &help.getInvolvedLink;
+            </label>&help.end;
           </description>
         </vbox>
       </vbox>
     </hbox>
     <vbox id="bottomBox">
-      <hbox pack="center">
-        <label is="text-link" class="bottom-link" useoriginprincipal="true" href="about:license" data-l10n-id="bottomLinks-license"></label>
-        <label is="text-link" class="bottom-link" useoriginprincipal="true" href="about:rights" data-l10n-id="bottomLinks-rights"></label>
-        <label is="text-link" class="bottom-link" href="https://www.mozilla.org/privacy/" data-l10n-id="bottomLinks-privacy"></label>
+      <hbox id="newBottom" pack="center" position="1">
+        <label is="text-link" class="bottom-link" href="https://support.torproject.org/">&bottomLinks.questions;</label>
+        <label is="text-link" class="bottom-link" href="https://community.torproject.org/relay/">&bottomLinks.grow;</label>
+        <label is="text-link" class="bottom-link" useoriginprincipal="true" href="about:license">&bottomLinks.license;</label>
       </hbox>
       <description id="trademark" data-l10n-id="trademarkInfo"></description>
+      <description id="trademarkTor">&tor.TrademarkStatement;</description>
     </vbox>
   </vbox>
 
diff --git a/browser/base/content/browser-doctype.inc b/browser/base/content/browser-doctype.inc
index 9aa278773158..48cf6cd3eda0 100644
--- a/browser/base/content/browser-doctype.inc
+++ b/browser/base/content/browser-doctype.inc
@@ -14,3 +14,9 @@
 %syncBrandDTD;
 <!ENTITY % brandingsDTD SYSTEM "chrome://browser/locale/brandings.dtd">
 %brandingsDTD;
+<!ENTITY % torbuttonDTD SYSTEM "chrome://torbutton/locale/torbutton.dtd">
+%torbuttonDTD;
+<!ENTITY % aboutTorDTD SYSTEM "chrome://torbutton/locale/aboutTor.dtd">
+%aboutTorDTD;
+<!ENTITY % aboutDialogDTD SYSTEM "chrome://torbutton/locale/aboutDialog.dtd">
+%aboutDialogDTD;
diff --git a/browser/base/content/browser-menubar.inc b/browser/base/content/browser-menubar.inc
index 267ec91707ba..6f4aa9289c35 100644
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -33,6 +33,18 @@
                           command="Tools:NonFissionWindow"
                           accesskey="s" label="New Non-Fission Window"/>
 #endif
+                <menuseparator/>
+                <menuitem id="menu_newIdentity"
+                          accesskey="&torbutton.context_menu.new_identity_key;"
+                          key="torbutton-new-identity-key"
+                          label="&torbutton.context_menu.new_identity;"
+                          oncommand="torbutton_new_identity();"/>
+                <menuitem id="menu_newCircuit"
+                          accesskey="&torbutton.context_menu.new_circuit_key;"
+                          key="torbutton-new-circuit-key"
+                          label="&torbutton.context_menu.new_circuit;"
+                          oncommand="torbutton_new_circuit();"/>
+                <menuseparator/>
                 <menuitem id="menu_openLocation"
                           hidden="true"
                           command="Browser:OpenLocation"
@@ -455,17 +467,28 @@
 #endif
                    data-l10n-id="menu-help">
               <menupopup id="menu_HelpPopup" onpopupshowing="buildHelpMenu();">
-                <menuitem id="menu_openHelp"
+                <!-- dummy elements to avoid 'getElementById' errors -->
+                <box id="feedbackPage"/>
+                <box id="helpSafeMode"/>
+                <box id="menu_HelpPopup_reportPhishingtoolmenu"/>
+                <box id="menu_HelpPopup_reportPhishingErrortoolmenu"/>
+                <!-- Add Tor Browser manual link -->
+                <menuitem id="torBrowserUserManual"
+                          oncommand="gBrowser.selectedTab = gBrowser.addTab('https://tb-manual.torproject.org/' + Services.locale.requestedLocale, {triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal()});"
+                          label="&aboutTor.torbrowser_user_manual.label;"
+                          accesskey="&aboutTor.torbrowser_user_manual.accesskey;"/>
+                <!-- Bug 18905: Hide unused help menu items -->
+                <!-- <menuitem id="menu_openHelp"
                           oncommand="openHelpLink('firefox-help')"
                           onclick="checkForMiddleClick(this, event);"
                           data-l10n-id="menu-help-product"
 #ifdef XP_MACOSX
-                          key="key_openHelpMac"/>
+                          key="key_openHelpMac"/> -->
 #else
-                          />
+                          /> -->
 #endif
-                <menuitem id="menu_openTour"
-                          oncommand="openTourPage();" data-l10n-id="menu-help-show-tour"/>
+                <!-- <menuitem id="menu_openTour"
+                          oncommand="openTourPage();" data-l10n-id="menu-help-show-tour"/> -->
                 <menuitem id="help_importFromAnotherBrowser"
                           command="cmd_help_importFromAnotherBrowser" data-l10n-id="menu-help-import-from-another-browser"/>
                 <menuitem id="menu_keyboardShortcuts"
@@ -474,22 +497,22 @@
                 <menuitem id="troubleShooting"
                           oncommand="openTroubleshootingPage()"
                           onclick="checkForMiddleClick(this, event);" data-l10n-id="menu-help-troubleshooting-info"/>
-                <menuitem id="feedbackPage"
+                <!-- <menuitem id="feedbackPage"
                           oncommand="openFeedbackPage()"
-                          onclick="checkForMiddleClick(this, event);" data-l10n-id="menu-help-feedback-page"/>
-                <menuitem id="helpSafeMode"
-                          oncommand="safeModeRestart();" data-l10n-id="menu-help-safe-mode-without-addons"/>
-                <menuitem id="menu_HelpPopup_reportPhishingtoolmenu"
+                          onclick="checkForMiddleClick(this, event);" data-l10n-id="menu-help-feedback-page"/> -->
+                <!-- <menuitem id="helpSafeMode"
+                          oncommand="safeModeRestart();" data-l10n-id="menu-help-safe-mode-without-addons"/> -->
+                <!-- <menuitem id="menu_HelpPopup_reportPhishingtoolmenu"
                           disabled="true"
                           oncommand="openUILink(gSafeBrowsing.getReportURL('Phish'), event, {triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({})});"
                           onclick="checkForMiddleClick(this, event);"
-                          hidden="true" data-l10n-id="menu-help-report-deceptive-site"/>
-                <menuitem id="menu_HelpPopup_reportPhishingErrortoolmenu"
+                          hidden="true" data-l10n-id="menu-help-report-deceptive-site"/> -->
+                <!-- <menuitem id="menu_HelpPopup_reportPhishingErrortoolmenu"
                           disabled="true"
                           oncommand="ReportFalseDeceptiveSite();"
                           onclick="checkForMiddleClick(this, event);"
                           data-l10n-id="menu-help-not-deceptive"
-                          hidden="true"/>
+                          hidden="true"/> -->
                 <menuseparator id="helpPolicySeparator"
                           hidden="true"/>
                 <menuitem id="helpPolicySupport"
diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc
index aae94e8d4654..fa71bfb37a84 100644
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -374,4 +374,6 @@
          data-l10n-id="hide-other-apps-shortcut"
          modifiers="accel,alt"/>
 #endif
+    <key id="torbutton-new-identity-key" modifiers="accel shift" key="U" oncommand="torbutton_new_identity()"/>
+    <key id="torbutton-new-circuit-key" modifiers="accel shift" key="L" oncommand="torbutton_new_circuit()"/>
   </keyset>
diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js
index 4c1130a902ee..8fc0128027c0 100644
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -619,6 +619,7 @@ var gPageIcons = {
 };
 
 var gInitialPages = [
+  "about:tor",
   "about:blank",
   "about:newtab",
   "about:home",
diff --git a/browser/base/content/browser.xhtml b/browser/base/content/browser.xhtml
index 62825bfd206a..229fc2a26dd2 100644
--- a/browser/base/content/browser.xhtml
+++ b/browser/base/content/browser.xhtml
@@ -29,6 +29,8 @@
 <?xml-stylesheet href="chrome://browser/skin/searchbar.css" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/places/tree-icons.css" type="text/css"?>
 <?xml-stylesheet href="chrome://browser/skin/places/editBookmark.css" type="text/css"?>
+<?xml-stylesheet href="chrome://torbutton/skin/tor-circuit-display.css" type="text/css"?>
+<?xml-stylesheet href="chrome://torbutton/skin/torbutton.css" type="text/css"?>
 
 # All DTD information is stored in a separate file so that it can be shared by
 # hiddenWindowMac.xhtml.
@@ -105,11 +107,18 @@
   Services.scriptloader.loadSubScript("chrome://browser/content/places/places-menupopup.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/search/autocomplete-popup.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/search/searchbar.js", this);
+  Services.scriptloader.loadSubScript("chrome://torbutton/content/tor-circuit-display.js", this);
+  Services.scriptloader.loadSubScript("chrome://torbutton/content/torbutton.js", this);
 
   window.onload = gBrowserInit.onLoad.bind(gBrowserInit);
   window.onunload = gBrowserInit.onUnload.bind(gBrowserInit);
   window.onclose = WindowIsClosing;
 
+  //onLoad Handler
+  try {
+    window.addEventListener("load", torbutton_init, false);
+  } catch (e) {}
+
   window.addEventListener("MozBeforeInitialXULLayout",
     gBrowserInit.onBeforeInitialXULLayout.bind(gBrowserInit), { once: true });
 
diff --git a/browser/components/controlcenter/content/identityPanel.inc.xhtml b/browser/components/controlcenter/content/identityPanel.inc.xhtml
index 77c0b9b2413f..a8edda858e41 100644
--- a/browser/components/controlcenter/content/identityPanel.inc.xhtml
+++ b/browser/components/controlcenter/content/identityPanel.inc.xhtml
@@ -60,6 +60,23 @@
                 oncommand="gIdentityHandler.showSecuritySubView();"/>
       </hbox>
 
+      <!-- Circuit display section -->
+      <hbox id="circuit-display-container" class="identity-popup-section">
+        <vbox id="circuit-display-content" flex="1" role="group"
+              aria-labelledby="circuit-display-headline">
+          <hbox id="circuit-display-header" align="center">
+            <label id="circuit-display-headline"
+                   role="heading" aria-level="2">&torbutton.circuit_display.title;</label>
+          </hbox>
+          <html:ul id="circuit-display-nodes" dir="auto"/>
+        </vbox>
+        <vbox id="circuit-reload-content" flex="1">
+          <html:button id="circuit-reload-button"
+                       onclick="torbutton_new_circuit()">&torbutton.circuit_display.new_circuit;</html:button>
+          <hbox id="circuit-guard-note-container"/>
+        </vbox>
+      </hbox>
+
       <!-- Permissions Section -->
       <hbox class="identity-popup-section"
             when-connection="not-secure secure secure-ev secure-cert-user-overridden file extension cert-error-page">
diff --git a/browser/components/customizableui/content/panelUI.inc.xhtml b/browser/components/customizableui/content/panelUI.inc.xhtml
index 3a8b74b0a9f3..bdb8a7c227cf 100644
--- a/browser/components/customizableui/content/panelUI.inc.xhtml
+++ b/browser/components/customizableui/content/panelUI.inc.xhtml
@@ -265,7 +265,8 @@
                        class="subviewbutton subviewbutton-iconic"
                        label="&newPrivateWindow.label;"
                        key="key_privatebrowsing"
-                       command="Tools:PrivateBrowsing"/>
+                       command="Tools:PrivateBrowsing"
+                       hidden="true"/>
 #ifdef NIGHTLY_BUILD
         <toolbarbutton id="appMenu-fission-window-button"
                        class="subviewbutton subviewbutton-iconic"
@@ -281,7 +282,19 @@
         <toolbarbutton id="appMenuRestoreLastSession"
                        label="&appMenuHistory.restoreSession.label;"
                        class="subviewbutton subviewbutton-iconic"
-                       command="Browser:RestoreLastSession"/>
+                       command="Browser:RestoreLastSession"
+                       hidden="true"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appMenuNewIdentity"
+                 class="subviewbutton subviewbutton-iconic"
+                 key="torbutton-new-identity-key"
+                 label="&torbutton.context_menu.new_identity;"
+                 oncommand="torbutton_new_identity();"/>
+        <toolbarbutton id="appMenuNewCircuit"
+                 class="subviewbutton subviewbutton-iconic"
+                 key="torbutton-new-circuit-key"
+                 label="&torbutton.context_menu.new_circuit;"
+                 oncommand="torbutton_new_circuit();"/>
         <toolbarseparator/>
         <toolbaritem id="appMenu-zoom-controls" class="toolbaritem-combined-buttons" closemenu="none">
           <!-- Use a spacer, because panel sizing code gets confused when using CSS methods. -->
diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in
index 582a6e13d607..3722bf2ee22b 100644
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -253,6 +253,8 @@
 @RESPATH@/browser/chrome/torlauncher/*
 @RESPATH@/browser/@PREF_DIR@/torlauncher-prefs.js
 #endif
+ at RESPATH@/chrome/torbutton.manifest
+ at RESPATH@/chrome/torbutton/*
 @RESPATH@/chrome/toolkit at JAREXT@
 @RESPATH@/chrome/toolkit.manifest
 @RESPATH@/chrome/recording.manifest
diff --git a/docshell/base/nsAboutRedirector.cpp b/docshell/base/nsAboutRedirector.cpp
index 730fd6aea654..051f239c76ac 100644
--- a/docshell/base/nsAboutRedirector.cpp
+++ b/docshell/base/nsAboutRedirector.cpp
@@ -146,7 +146,11 @@ static const RedirEntry kRedirMap[] = {
     {"crashcontent", "about:blank",
      nsIAboutModule::HIDE_FROM_ABOUTABOUT |
          nsIAboutModule::URI_CAN_LOAD_IN_CHILD |
-         nsIAboutModule::URI_MUST_LOAD_IN_CHILD}};
+         nsIAboutModule::URI_MUST_LOAD_IN_CHILD},
+    {"tor", "chrome://torbutton/content/aboutTor/aboutTor.xhtml",
+     nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
+         nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
+         nsIAboutModule::ALLOW_SCRIPT}};
 static const int kRedirTotal = mozilla::ArrayLength(kRedirMap);
 
 NS_IMETHODIMP
diff --git a/docshell/build/components.conf b/docshell/build/components.conf
index 6d7253d01631..2d56ea33389d 100644
--- a/docshell/build/components.conf
+++ b/docshell/build/components.conf
@@ -27,6 +27,7 @@ about_pages = [
     'srcdoc',
     'support',
     'telemetry',
+    'tor',
     'url-classifier',
     'webrtc',
 ]
diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in
index 17d6471c4742..055eb4717447 100644
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -137,6 +137,10 @@
 @BINPATH@/chrome/devtools at JAREXT@
 @BINPATH@/chrome/devtools.manifest
 
+; Torbutton
+ at BINPATH@/chrome/torbutton at JAREXT@
+ at BINPATH@/chrome/torbutton.manifest
+
 ; [Default Preferences]
 ; All the pref files must be part of base to prevent migration bugs
 #ifdef MOZ_GECKOVIEW_JAR
diff --git a/toolkit/moz.build b/toolkit/moz.build
index b6f792da7124..3451334de15c 100644
--- a/toolkit/moz.build
+++ b/toolkit/moz.build
@@ -23,6 +23,7 @@ DIRS += [
     'pluginproblem',
     'profile',
     'themes',
+    'torproject/torbutton',
 ]
 
 if CONFIG['OS_ARCH'] == 'WINNT' and CONFIG['MOZ_DEFAULT_BROWSER_AGENT']:
diff --git a/toolkit/mozapps/extensions/internal/XPIProvider.jsm b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
index bcdf6f40d5ed..bf31932b59f1 100644
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1462,6 +1462,15 @@ var XPIStates = {
       for (let [id, file] of loc.readAddons()) {
         knownIds.delete(id);
 
+        // Uninstall torbutton if it is installed in the user profile
+        if (id === "torbutton at torproject.org" &&
+            loc.name === KEY_APP_PROFILE) {
+          logger.debug("Uninstalling torbutton from user profile.");
+          loc.installer.uninstallAddon(id);
+          changed = true;
+          continue;
+        }
+
         // Since it is now part of the browser, uninstall the Tor Launcher
         // extension. This will remove the Tor Launcher .xpi from user
         // profiles on macOS.
diff --git a/toolkit/torproject/torbutton b/toolkit/torproject/torbutton
new file mode 160000
index 000000000000..230b6a13008b
--- /dev/null
+++ b/toolkit/torproject/torbutton
@@ -0,0 +1 @@
+Subproject commit 230b6a13008bb7eee0111e3d8b6d68581f500757
diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
index 76e03f2d49bb..2ff107b553b2 100644
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
@@ -75,7 +75,11 @@ function getGlobalScriptIncludes(scriptPath) {
           "browser/components/search/content/"
         )
         .replace("chrome://browser/content/", "browser/base/content/")
-        .replace("chrome://global/content/", "toolkit/content/");
+        .replace("chrome://global/content/", "toolkit/content/")
+        .replace(
+          "chrome://torbutton/content/",
+          "toolkit/torproject/torbutton/chrome/content/"
+        );
 
       for (let mapping of Object.getOwnPropertyNames(MAPPINGS)) {
         if (sourceFile.includes(mapping)) {





More information about the tbb-commits mailing list