[or-cvs] r10660: Improve user agent hooking for navigator.* js stuff. Make js (in torbutton/trunk/src: . chrome/content defaults/preferences)

mikeperry at seul.org mikeperry at seul.org
Fri Jun 22 17:43:56 UTC 2007


Author: mikeperry
Date: 2007-06-22 13:43:56 -0400 (Fri, 22 Jun 2007)
New Revision: 10660

Modified:
   torbutton/trunk/src/chrome/content/jshooks.js
   torbutton/trunk/src/chrome/content/torbutton.js
   torbutton/trunk/src/defaults/preferences/preferences.js
   torbutton/trunk/src/install.rdf
Log:

Improve user agent hooking for navigator.* js stuff. Make
jshooking more invisible. Add glue to disable tor and restore
browser state on uninstal/disable of the extension. Also fix
sessionstoring bug found by phobos.



Modified: torbutton/trunk/src/chrome/content/jshooks.js
===================================================================
--- torbutton/trunk/src/chrome/content/jshooks.js	2007-06-22 16:01:24 UTC (rev 10659)
+++ torbutton/trunk/src/chrome/content/jshooks.js	2007-06-22 17:43:56 UTC (rev 10660)
@@ -1,4 +1,4 @@
-var __HookObjects = function() {
+window.__HookObjects = function() {
   /* XXX: Removeme once verified not to run twice */
   if (typeof(window.__tb_hooks_ran) != 'undefined') {
       alert("Error, double jshook!");
@@ -13,9 +13,11 @@
   /* Hrmm.. Is it possible this breaks plugin install or other weird shit
      for non-windows OS's? */
   if(__tb_set_uagent) {
-      var tmp_oscpu = __tb_oscpu;
-      var tmp_platform = __tb_platform;
+      var tmp_oscpu = window.__tb_oscpu;
+      var tmp_platform = window.__tb_platform;
+      var tmp_productSub = window.__tb_productSub;
       navigator.__defineGetter__("oscpu", function() { return tmp_oscpu;});
+      navigator.__defineGetter__("productSub", function() { return tmp_productSub;});
       /*navigator.__defineGetter__("platform", function() { return tmp_platform;});*/
   }
 
@@ -155,12 +157,15 @@
   Date.UTC=function(){return tmp.apply(tmp, arguments); }
 }
 
-if (__HookObjects) {
-    __HookObjects();
-    __HookObjects = undefined;
-    __tb_set_uagent = undefined;
-    __tb_oscpu = undefined;
-    __tb_platform = undefined;
+if (window.__HookObjects) {
+    window.__HookObjects();
+
+    delete window['__HookObjects'];
+    delete window['__tb_set_uagent'];
+    delete window['__tb_oscpu'];
+    delete window['__tb_platform'];
+    delete window['__tb_productSub'];
+
     /* XXX: Removeme */
     window.__tb_hooks_ran = true;
 }

Modified: torbutton/trunk/src/chrome/content/torbutton.js
===================================================================
--- torbutton/trunk/src/chrome/content/torbutton.js	2007-06-22 16:01:24 UTC (rev 10659)
+++ torbutton/trunk/src/chrome/content/torbutton.js	2007-06-22 17:43:56 UTC (rev 10660)
@@ -179,8 +179,9 @@
         torbutton_init_jshooks();
 
         torbutton_log(5, 'registering pref observer');
-        // FIXME: Hrmm... Do we really need a pref observer for each window?
+        // 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(5, 'skipping pref observer init');
@@ -521,24 +522,24 @@
     // http://kb.mozillazine.org/About:config_entries
     if(mode) {
         if(torprefs.getBoolPref('block_thwrite')) {
-            m_tb_prefs.setIntPref("browser.sessionstore.privacy_level", 2);
+            m_tb_prefs.setIntPref("browser.sessionstore.enabled", false);
             m_tb_prefs.setIntPref("browser.download.manager.retention", 0);
             m_tb_prefs.setBoolPref("browser.formfill.enable", false);
             m_tb_prefs.setBoolPref("signon.rememberSignons", false);
         } else {
-            m_tb_prefs.setIntPref("browser.sessionstore.privacy_level", 1);
+            m_tb_prefs.setIntPref("browser.sessionstore.enabled", true);
             m_tb_prefs.setIntPref("browser.download.manager.retention", 2);
             m_tb_prefs.setBoolPref("browser.formfill.enable", true);
             m_tb_prefs.setBoolPref("signon.rememberSignons", true);
         }
     } else {
         if(torprefs.getBoolPref('block_nthwrite')) {
-            m_tb_prefs.setIntPref("browser.sessionstore.privacy_level", 2);
+            m_tb_prefs.setIntPref("browser.sessionstore.enabled", false);
             m_tb_prefs.setIntPref("browser.download.manager.retention", 0);
             m_tb_prefs.setBoolPref("browser.formfill.enable", false);
             m_tb_prefs.setBoolPref("signon.rememberSignons", false);
         } else {
-            m_tb_prefs.setIntPref("browser.sessionstore.privacy_level", 1);
+            m_tb_prefs.setIntPref("browser.sessionstore.enabled", true);
             m_tb_prefs.setIntPref("browser.download.manager.retention", 2);
             m_tb_prefs.setBoolPref("browser.formfill.enable", true);
             m_tb_prefs.setBoolPref("signon.rememberSignons", true);
@@ -788,6 +789,52 @@
       Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
 }
 
+// Technique courtesy of:
+// http://xulsolutions.blogspot.com/2006/07/creating-uninstall-script-for.html
+const TORBUTTON_EXTENSION_UUID = "{E0204BD5-9D31-402B-A99D-A6AA8FFEBDCA}";
+var torbutton_uninstall_observer = {
+_uninstall : false,
+observe : function(subject, topic, data) {
+  if (topic == "em-action-requested") {
+    subject.QueryInterface(Components.interfaces.nsIUpdateItem);
+    torbutton_log(1, "Uninstall: "+data+" "+subject.id.toUpperCase());
+
+    if (subject.id.toUpperCase() == TORBUTTON_EXTENSION_UUID) {
+      torbutton_log(1, "Uninstall: "+data);
+      // XXX: What about disabled??
+      if (data == "item-uninstalled" || data == "item-disabled") {
+        this._uninstall = true;
+      } else if (data == "item-cancel-action") {
+        this._uninstall = false;
+      }
+    }
+  } else if (topic == "quit-application-granted") {
+    if (this._uninstall) {
+        torbutton_disable_tor();
+        // Still called by pref observer:
+        // torbutton_update_status(false, false);
+    }
+    this.unregister();
+  }
+},
+register : function() {
+ var observerService =
+   Components.classes["@mozilla.org/observer-service;1"].
+     getService(Components.interfaces.nsIObserverService);
+
+ observerService.addObserver(this, "em-action-requested", false);
+ observerService.addObserver(this, "quit-application-granted", false);
+},
+unregister : function() {
+  var observerService =
+    Components.classes["@mozilla.org/observer-service;1"].
+      getService(Components.interfaces.nsIObserverService);
+
+  observerService.removeObserver(this,"em-action-requested");
+  observerService.removeObserver(this,"quit-application-granted");
+}
+}
+
 window.addEventListener('load',torbutton_new_window,false);
 getBrowser().addEventListener("TabOpen", torbutton_new_tab, false);
 
@@ -866,9 +913,10 @@
      */
 
     var str = "<"+"script>\r\n";
-    str += "var __tb_set_uagent="+m_tb_prefs.getBoolPref('extensions.torbutton.set_uagent')+";\r\n";
-    str += "var __tb_oscpu=\""+m_tb_prefs.getCharPref('extensions.torbutton.oscpu_override')+"\";\r\n";
-    str += "var __tb_platform=\""+m_tb_prefs.getCharPref('extensions.torbutton.platform_override')+"\";\r\n";
+    str += "window.__tb_set_uagent="+m_tb_prefs.getBoolPref('extensions.torbutton.set_uagent')+";\r\n";
+    str += "window.__tb_oscpu=\""+m_tb_prefs.getCharPref('extensions.torbutton.oscpu_override')+"\";\r\n";
+    str += "window.__tb_platform=\""+m_tb_prefs.getCharPref('extensions.torbutton.platform_override')+"\";\r\n";
+    str += "window.__tb_productSub=\""+m_tb_prefs.getCharPref('extensions.torbutton.productsub_override')+"\";\r\n";
     str += m_tb_jshooks; 
     str += "</"+"script>";
     var d = doc.createElement("div");

Modified: torbutton/trunk/src/defaults/preferences/preferences.js
===================================================================
--- torbutton/trunk/src/defaults/preferences/preferences.js	2007-06-22 16:01:24 UTC (rev 10659)
+++ torbutton/trunk/src/defaults/preferences/preferences.js	2007-06-22 17:43:56 UTC (rev 10660)
@@ -62,6 +62,7 @@
 pref("extensions.torbutton.appversion_override","5.0 (Windows; en-US)");
 pref("extensions.torbutton.platform_override","Win32");
 pref("extensions.torbutton.oscpu_override", "Windows NT 5.1");
-pref("extensions.torbutton.useragent_override","Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4");
+pref("extensions.torbutton.useragent_override", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4");
+pref("extensions.torbutton.productsub_override","20070515");
 pref("extensions.torbutton.useragent_vendor", "");
 pref("extensions.torbutton.useragent_vendorSub","");

Modified: torbutton/trunk/src/install.rdf
===================================================================
--- torbutton/trunk/src/install.rdf	2007-06-22 16:01:24 UTC (rev 10659)
+++ torbutton/trunk/src/install.rdf	2007-06-22 17:43:56 UTC (rev 10660)
@@ -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.1-alpha</em:version>
+        <em:version>1.1.2-alpha</em:version>
         <em:homepageURL>http://freehaven.net/~squires/torbutton/</em:homepageURL>
         <em:updateURL>http://freehaven.net/~squires/torbutton/update.rdf</em:updateURL>
         <em:optionsURL>chrome://torbutton/content/preferences.xul</em:optionsURL>



More information about the tor-commits mailing list