[or-cvs] r12563: Fix some content policy issues with caching+tagging. Potenti (in torbutton/trunk/src: chrome/content components)

mikeperry at seul.org mikeperry at seul.org
Sat Nov 24 09:38:46 UTC 2007


Author: mikeperry
Date: 2007-11-24 04:38:45 -0500 (Sat, 24 Nov 2007)
New Revision: 12563

Modified:
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/components/cssblocker.js
   torbutton/trunk/src/components/window-mapper.js
Log:

Fix some content policy issues with caching+tagging.
Potentially fixes bug 520.



Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2007-11-23 23:40:21 UTC (rev 12562)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2007-11-24 09:38:45 UTC (rev 12563)
@@ -1169,8 +1169,8 @@
         return;
         //win.alert("No window found!");
     }
-    torbutton_log(2, "Got browser "+browser.contentDocument.location+" for: " 
-            + win.location);
+    torbutton_log(2, "Got browser "+browser.contentWindow.location+" for: " 
+            + win.location + ", under: "+win.top.location);
 
     var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
     var js_enabled = m_tb_prefs.getBoolPref("javascript.enabled");

Modified: torbutton/trunk/src/components/cssblocker.js
===================================================================
--- torbutton/trunk/src/components/cssblocker.js	2007-11-23 23:40:21 UTC (rev 12562)
+++ torbutton/trunk/src/components/cssblocker.js	2007-11-24 09:38:45 UTC (rev 12563)
@@ -185,11 +185,21 @@
             return block; 
         }
 
-        // This happens on the first load of a doc and with non-browser
-        // chrome..
-        if (typeof(browser.__tb_tor_fetched) == 'undefined') {
-            this.logger.log(3, "Untagged window for "+contentLocation.spec);
-            return ok;
+        // source window of browser chrome window with a document content
+        // type means the user entered a new URL.
+        if(wind.top instanceof Components.interfaces.nsIDOMChromeWindow) {
+            // This happens on non-browser chrome: updates, dialogs, etc
+            if (!wind.top.browserDOMWindow 
+                    && typeof(browser.__tb_tor_fetched) == 'undefined') {
+                this.logger.log(3, "Untagged window for "+contentLocation.spec);
+                return ok;
+            }
+
+            if(wind.top.browserDOMWindow 
+                    && contentType == CPolicy.TYPE_DOCUMENT) {
+                this.logger.log(3, "New location for "+contentLocation.spec);
+                return ok;
+            }
         }
 
         if(browser.__tb_tor_fetched == tor_state) {

Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js	2007-11-23 23:40:21 UTC (rev 12562)
+++ torbutton/trunk/src/components/window-mapper.js	2007-11-24 09:38:45 UTC (rev 12563)
@@ -62,11 +62,10 @@
   // method of nsIClassInfo
   getHelperForLanguage: function(count) { return null; },
 
-
   checkCache: function(topContentWindow) {
-      if(typeof(this.cache[topContentWindow]) != "undefined") {
-          this.logger.log(1, "Found cached element for: "+topContentWindow.location);
-          return this.cache[topContentWindow].browser;
+      if(typeof(topContentWindow.ghetto_guid) != "undefined"
+         && typeof(this.cache[topContentWindow.ghetto_guid]) != "undefined") {
+          return this.cache[topContentWindow.ghetto_guid].browser;
       }
 
       return null;
@@ -76,8 +75,8 @@
       var insertion = new Object();
       insertion.browser = browser;
       insertion.time = Date.now();
-      this.cache[topContentWindow] = insertion; 
-      this.logger.log(2, "Cached element: "+topContentWindow.location);
+      topContentWindow.ghetto_guid = Math.random().toString()+Math.random().toString();
+      this.cache[topContentWindow.ghetto_guid] = insertion; 
   },
 
   expireOldCache: function() {
@@ -100,9 +99,12 @@
   getBrowserForContentWindow: function(topContentWindow) {
       if(topContentWindow instanceof Components.interfaces.nsIDOMChromeWindow) {
           if(topContentWindow.browserDOMWindow) {
-              this.logger.log(3, "Chrome browser found: "
+              // XXX: is this not a tabbed browser?
+              var browser = topContentWindow.getBrowser().selectedTab.linkedBrowser;
+              this.logger.log(3, "Chrome browser at "
+                      +browser.contentWindow.location+" found for: "
                       +topContentWindow.location);
-              return topContentWindow.getBrowser().selectedTab.linkedBrowser;
+              return browser;
           }
           // Allow strange chrome to go through..
           this.logger.log(3, "Odd chome window"+topContentWindow.location);
@@ -110,7 +112,9 @@
       }
 
       var cached = this.checkCache(topContentWindow);
-      if(cached != null) return cached;
+      if(cached != null) {
+          return cached;
+      }
 
       var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
           .getService(Components.interfaces.nsIWindowMediator);
@@ -121,8 +125,8 @@
           for (var i = 0; i < browser.browsers.length; ++i) {
               var b = browser.browsers[i];
               if (b && b.contentWindow == topContentWindow) {
-                  this.addCache(topContentWindow, browser);
-                  return browser;
+                  this.addCache(topContentWindow, b);
+                  return b;
               }
           }
       }



More information about the tor-commits mailing list