[tbb-commits] [torbutton/master] Bug #15493: Update circuit display on new circuit info

gk at torproject.org gk at torproject.org
Tue Aug 25 18:06:26 UTC 2015


commit 1d4e0280b6dfca79bbd7e204d588dc4432832728
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date:   Mon Aug 24 10:04:56 2015 -0700

    Bug #15493: Update circuit display on new circuit info
---
 src/chrome/content/tor-circuit-display.js |   36 ++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/src/chrome/content/tor-circuit-display.js b/src/chrome/content/tor-circuit-display.js
index 2da7f0a..94a5346 100644
--- a/src/chrome/content/tor-circuit-display.js
+++ b/src/chrome/content/tor-circuit-display.js
@@ -123,12 +123,15 @@ let getCircuitStatusByID = function* (aController, circuitID) {
   return null;
 };
 
-// __collectIsolationData(aController)__.
+// __collectIsolationData(aController, updateUI)__.
 // Watches for STREAM SENTCONNECT events. When a SENTCONNECT event occurs, then
 // we assume isolation settings (SOCKS username+password) are now fixed for the
 // corresponding circuit. Whenever the first stream on a new circuit is seen,
 // looks up u+p and records the node data in the credentialsToNodeDataMap.
-let collectIsolationData = function (aController) {
+// We need to update the circuit display immediately after any new node data
+// is received. So the `updateUI` callback will be called at that point.
+// See https://trac.torproject.org/projects/tor/ticket/15493
+let collectIsolationData = function (aController, updateUI) {
   return aController.watchEvent(
     "STREAM",
     streamEvent => streamEvent.StreamStatus === "SENTCONNECT",
@@ -144,6 +147,7 @@ let collectIsolationData = function (aController) {
         if (credentials) {
           let nodeData = yield nodeDataForCircuit(aController, circuitStatus);
           credentialsToNodeDataMap[credentials] = nodeData;
+          updateUI();
         }
       }
     }).then(null, Cu.reportError));
@@ -274,32 +278,28 @@ let updateCircuitDisplay = function () {
 };
 
 // __syncDisplayWithSelectedTab(syncOn)__.
-// We may have multiple tabs, but there is only one instance of TorButton's popup
-// panel for displaying the Tor circuit UI. Therefore we need to update the display
-// to show the currently selected tab at its current location.
+// Whenever the user starts to open the popup menu, make sure the display
+// is the correct one for this tab. It's also possible that a new site
+// can be loaded while the popup menu is open.
+// Update the display if this happens.
 let syncDisplayWithSelectedTab = (function() {
-  let listener1 = event => { updateCircuitDisplay(); },
-      listener2 = { onLocationChange : function (aBrowser) {
+  let listener = { onLocationChange : function (aBrowser) {
                       if (aBrowser === gBrowser.selectedBrowser) {
                         updateCircuitDisplay();
                       }
                     } };
   return function (syncOn) {
+    let popupMenu = document.getElementById("torbutton-context-menu");
     if (syncOn) {
-      // Whenever a different tab is selected, change the circuit display
-      // to show the circuit for that tab's domain.
-      gBrowser.tabContainer.addEventListener("TabSelect", listener1);
+      // Update the circuit display just before the popup menu is shown.
+      popupMenu.addEventListener("popupshowing", updateCircuitDisplay);
       // If the currently selected tab has been sent to a new location,
       // update the circuit to reflect that.
-      gBrowser.addTabsProgressListener(listener2);
-      // Get started with a correct display.
-      updateCircuitDisplay();
+      gBrowser.addTabsProgressListener(listener);
     } else {
       // Stop syncing.
-      if (gBrowser.tabContainer) {
-        gBrowser.tabContainer.removeEventListener("TabSelect", listener1);
-      }
-      gBrowser.removeTabsProgressListener(listener2);
+      gBrowser.removeTabsProgressListener(listener);
+      popupMenu.removeEventListener("popupshowing", updateCircuitDisplay);
       // Hide the display.
       showCircuitDisplay(false);
     }
@@ -333,7 +333,7 @@ let setupDisplay = function (host, port, password, enablePrefName) {
             stop();
           });
           syncDisplayWithSelectedTab(true);
-          stopCollectingIsolationData = collectIsolationData(myController);
+          stopCollectingIsolationData = collectIsolationData(myController, updateCircuitDisplay);
        }
      };
   try {



More information about the tbb-commits mailing list