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

[or-cvs] r11710: Another possibility for bug #460. Apparently webprogress eve (in torbutton/trunk/src: chrome/content components defaults/preferences)



Author: mikeperry
Date: 2007-09-29 17:33:15 -0400 (Sat, 29 Sep 2007)
New Revision: 11710

Modified:
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/components/crash-observer.js
   torbutton/trunk/src/components/cssblocker.js
   torbutton/trunk/src/defaults/preferences/preferences.js
Log:

Another possibility for bug #460. Apparently webprogress
events are not delivered to tabs loading in the background.
You need to subscribe to some other notification service
instead. However, you only want one of these notifications
running, which means you have to recieve a startup event.
The chrome cannot recieve startup events, so you have to
roll your own. XUL is fun.




Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2007-09-29 11:09:08 UTC (rev 11709)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2007-09-29 21:33:15 UTC (rev 11710)
@@ -191,9 +191,7 @@
         torbutton_init_jshooks();
 
         torbutton_log(1, 'registering pref observer');
-        // FIXME: Hrmm... Do we really need observers for each window?
         torbutton_pref_observer.register(); 
-        torbutton_uninstall_observer.register();
         m_tb_wasinited = true;
     } else {
         torbutton_log(1, 'skipping pref observer init');
@@ -794,6 +792,7 @@
 
     // Only tag new windows
     if (typeof(browser.__tb_js_state) == 'undefined') {
+        torbutton_log(3, "Tagging new window: "+tor_tag);
         browser.__tb_js_state = tor_tag;
     }
 }
@@ -919,6 +918,24 @@
 }
 
 
+function torbutton_do_onetime_startup()
+{
+    if(m_tb_prefs.getBoolPref("extensions.torbutton.startup")) {
+        torbutton_log(3, "Torbutton onetime startup");
+        // http://www.xulplanet.com/references/xpcomref/ifaces/nsIWebProgress.html
+        var progress =
+            Components.classes["@mozilla.org/docloaderservice;1"].
+            getService(Components.interfaces.nsIWebProgress);
+
+        progress.addProgressListener(torbutton_weblistener,
+                Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT|
+                Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
+
+        torbutton_uninstall_observer.register();
+        m_tb_prefs.setBoolPref("extensions.torbutton.startup", false);
+    }
+}
+
 function torbutton_new_tab(event)
 { 
     // listening for new tabs
@@ -942,20 +959,17 @@
         torbutton_init();
     }
     
+    torbutton_do_onetime_startup();
     torbutton_crash_recover();
 
-    torbutton_tag_new_browser(browser, 
+    torbutton_tag_new_browser(browser.browsers[0], 
             !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled"),
             m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins"));
 
-    browser.addProgressListener(torbutton_weblistener,
-      Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT|
-      Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
 }
 
 function torbutton_close_window(event) {
     torbutton_pref_observer.unregister();
-    torbutton_uninstall_observer.unregister();
 }
 
 window.addEventListener('load',torbutton_new_window,false);
@@ -1120,7 +1134,7 @@
             win.alert("Sandbox evaluation failed. Date hooks not applied!");
         }
     } catch (e) {
-        win.alert("Sandbox evaluation failed. Date hooks not applied!");
+        win.alert("Exception in sandbox evaluation. Date hooks not applied!");
     }
 
     torbutton_log(2, "Finished hook: " + doc.location);
@@ -1128,23 +1142,7 @@
     return;
 }
 
-var torbutton_weblistener =
-{
-  QueryInterface: function(aIID)
-  {
-   if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
-       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
-       aIID.equals(Components.interfaces.nsISupports))
-     return this;
-   throw Components.results.NS_NOINTERFACE;
-  },
-
-  onStateChange: function(aProgress, aRequest, aFlag, aStatus)
-  { /*torbutton_log(1, 'State change()'); */return 0; },
-
-  onLocationChange: function(aProgress, aRequest, aURI)
-  {
-    torbutton_log(1, 'onLocationChange');
+function torbutton_check_progress(aProgress) {
     // This fires when the location bar changes i.e load event is confirmed
     // or when the user switches tabs
     if(aProgress) {
@@ -1161,13 +1159,42 @@
         torbutton_log(3, "No aProgress for location!");
     }
     return 0;
+}
+
+var torbutton_weblistener =
+{
+  QueryInterface: function(aIID)
+  {
+   if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
+       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
+       aIID.equals(Components.interfaces.nsISupports))
+     return this;
+   throw Components.results.NS_NOINTERFACE;
   },
 
-  onProgressChange: function(webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) 
-  { /* torbutton_log(1, 'called progressChange'); */ return 0; },
+  onStateChange: function(aProgress, aRequest, aFlag, aStatus)
+  { 
+      torbutton_log(1, 'State change()');
+      return torbutton_check_progress(aProgress);
+  },
+
+  onLocationChange: function(aProgress, aRequest, aURI)
+  {
+      torbutton_log(1, 'onLocationChange');
+      return torbutton_check_progress(aProgress);
+  },
+
+  onProgressChange: function(aProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) 
+  { 
+      torbutton_log(1, 'called progressChange'); 
+      return torbutton_check_progress(aProgress);
+  },
   
-  onStatusChange: function() 
-  { /*torbutton_log(1, 'called statusChange'); */ return 0; },
+  onStatusChange: function(aProgress, request, stat, message) 
+  { 
+      torbutton_log(1, 'called progressChange'); 
+      return torbutton_check_progress(aProgress);
+  },
   
   onSecurityChange: function() {return 0;},
   

Modified: torbutton/trunk/src/components/crash-observer.js
===================================================================
--- torbutton/trunk/src/components/crash-observer.js	2007-09-29 11:09:08 UTC (rev 11709)
+++ torbutton/trunk/src/components/crash-observer.js	2007-09-29 21:33:15 UTC (rev 11710)
@@ -22,6 +22,16 @@
 const kStoreInterfaces = ["nsISessionStartup", "nsIObserver", 
                           "nsISupportsWeakReference"];
 
+var StartupObserver = {
+    observe: function(aSubject, aTopic, aData) {
+      if(aTopic == "final-ui-startup") {
+          Components.classes["@mozilla.org/preferences-service;1"]
+              .getService(Components.interfaces.nsIPrefBranch)
+              .setBoolPref("extensions.torbutton.startup", true);
+      } 
+    },
+};
+
 function StoreWrapper() {
   this._prefs = Components.classes["@mozilla.org/preferences-service;1"]
       .getService(Components.interfaces.nsIPrefBranch);
@@ -77,6 +87,10 @@
   observe: function sss_observe(aSubject, aTopic, aData) {
     if(aTopic == "app-startup") {
       this._startup = true;
+      var observerService = Cc["@mozilla.org/observer-service;1"].
+          getService(Ci.nsIObserverService);
+
+      observerService.addObserver(StartupObserver, "final-ui-startup", false);
     } 
     this._store().observe(aSubject, aTopic, aData);
   },

Modified: torbutton/trunk/src/components/cssblocker.js
===================================================================
--- torbutton/trunk/src/components/cssblocker.js	2007-09-29 11:09:08 UTC (rev 11709)
+++ torbutton/trunk/src/components/cssblocker.js	2007-09-29 21:33:15 UTC (rev 11710)
@@ -174,7 +174,7 @@
         for (var i = 0; i < browser.browsers.length; ++i) {
             var b = browser.browsers[i];
             if (b && b.contentDocument == doc) {
-                if (typeof(browser.__tb_js_state) == 'undefined') {
+                if (typeof(b.__tb_js_state) == 'undefined') {
                     this.log("UNTAGGED WINDOW2!!!!!!!!!");
                     return block;
                 }
@@ -182,7 +182,7 @@
                 if(b.__tb_js_state == torTag) {
                     return ok;
                 } else {
-                    this.log("block2\n");
+                    this.log("block2: "+b.__tb_js_state+"\n");
                     return block;
                 }
             }

Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js	2007-09-29 11:09:08 UTC (rev 11709)
+++ torbutton/trunk/src/defaults/preferences/preferences.js	2007-09-29 21:33:15 UTC (rev 11710)
@@ -68,6 +68,7 @@
 pref("extensions.torbutton.shutdown_method",1); // 0=none, 1=tor, 2=all
 pref("extensions.torbutton.block_tforms",true);
 pref("extensions.torbutton.block_ntforms",false);
+pref("extensions.torbutton.startup",false);
 pref("extensions.torbutton.crashed",false);
 
 // Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4