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

[or-cvs] r12556: Damn, this was an ugly bug. Apparently window-scoped objects (in torbutton/trunk/src: . chrome/content components)



Author: mikeperry
Date: 2007-11-23 00:47:11 -0500 (Fri, 23 Nov 2007)
New Revision: 12556

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

Damn, this was an ugly bug. Apparently window-scoped objects
are destroyed when the window is closed, even if observer
services take a reference to them.. The fix is to find a new
window to install the global observers from upon main window
close.



Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2007-11-22 17:59:42 UTC (rev 12555)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2007-11-23 05:47:11 UTC (rev 12556)
@@ -7,6 +7,7 @@
 var m_tb_prefs = false;
 var m_tb_jshooks = false;
 var m_tb_plugin_mimetypes = false;
+var m_tb_is_main_window = false;
 
 var torbutton_window_pref_observer =
 {
@@ -231,7 +232,6 @@
         torbutton_init_jshooks();
 
         torbutton_log(1, 'registering pref observer');
-        // XXX: Perf: do we really need one for each window?
         torbutton_window_pref_observer.register(); 
         m_tb_wasinited = true;
     } else {
@@ -986,24 +986,30 @@
 }
 }
 
+function torbutton_do_main_window_startup()
+{
+    torbutton_log(3, "Torbutton main window startup");
+    m_tb_is_main_window = true;
 
+    // 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_ALL|
+            //   Components.interfaces.nsIWebProgress.NOTIFY_ALL);
+        Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT|
+            Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
+
+    torbutton_unique_pref_observer.register();
+    torbutton_uninstall_observer.register();
+}
+
 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_ALL|
-//                Components.interfaces.nsIWebProgress.NOTIFY_ALL);
-                Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT|
-                Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
-
-        torbutton_unique_pref_observer.register();
-        torbutton_uninstall_observer.register();
+        torbutton_do_main_window_startup();
         m_tb_prefs.setBoolPref("extensions.torbutton.startup", false);
     }
 }
@@ -1055,6 +1061,26 @@
 
 function torbutton_close_window(event) {
     torbutton_window_pref_observer.unregister();
+
+    // XXX: This is a real ghetto hack.. When the original window
+    // closes, we need to find another window to handle observing 
+    // unique events... The right way to do this is to move the 
+    // majority of torbutton functionality into a XPCOM component.. 
+    // But that is a major overhaul..
+    if (m_tb_is_main_window) {
+        torbutton_log(3, "Original window closed. Searching for another");
+        var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+            .getService(Components.interfaces.nsIWindowMediator);
+        var enumerator = wm.getEnumerator("navigator:browser");
+        while(enumerator.hasMoreElements()) {
+            var win = enumerator.getNext();
+            if(win != window) {
+                torbutton_log(3, "Found another window");
+                win.torbutton_do_main_window_startup();
+                break;
+            }
+        }
+    }
 }
 
 window.addEventListener('load',torbutton_new_window,false);

Modified: torbutton/trunk/src/components/window-mapper.js
===================================================================
--- torbutton/trunk/src/components/window-mapper.js	2007-11-22 17:59:42 UTC (rev 12555)
+++ torbutton/trunk/src/components/window-mapper.js	2007-11-23 05:47:11 UTC (rev 12556)
@@ -99,6 +99,8 @@
       }
   },
 
+  // XXX: Handle case where browser XUL *is* the content window!
+  // (favicons and the like..)
   getBrowserForContentWindow: function(topContentWindow) {
       var cached = this.checkCache(topContentWindow);
       if(cached != null) return cached;

Modified: torbutton/trunk/src/install.rdf
===================================================================
--- torbutton/trunk/src/install.rdf	2007-11-22 17:59:42 UTC (rev 12555)
+++ torbutton/trunk/src/install.rdf	2007-11-23 05:47:11 UTC (rev 12556)
@@ -6,7 +6,7 @@
         <em:name>Torbutton</em:name>
         <em:creator>Scott Squires &amp; Mike Perry</em:creator>
         <em:id>{e0204bd5-9d31-402b-a99d-a6aa8ffebdca}</em:id>
-        <em:version>1.1.11-alpha</em:version>
+        <em:version>1.1.11-alpha-dev</em:version>
         <em:homepageURL>https://torbutton.torproject.org/dev/</em:homepageURL>
         <em:optionsURL>chrome://torbutton/content/preferences.xul</em:optionsURL>
         <em:iconURL>chrome://torbutton/skin/tor.png</em:iconURL>