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

[or-cvs] [torbutton/maint-1.2 18/37] Strip identifying info off Google searchbox queries.



Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Wed, 31 Mar 2010 02:21:35 -0700
Subject: Strip identifying info off Google searchbox queries.
Commit: 3ec7406268481472dbeb35eb2cb26a82e1703762

---
 src/chrome/content/torbutton.js         |   43 +++++++++++++++++++++++++++++++
 src/defaults/preferences/preferences.js |    1 +
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index c0d97bb..f279e72 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -3041,6 +3041,46 @@ var torbutton_proxyservice = {
   }
 }
 
+function torbutton_wrap_search_service()
+{
+  var ss = Cc["@mozilla.org/browser/search-service;1"]
+                 .getService(Ci.nsIBrowserSearchService);
+  var junk = {"value":0};
+  var engines = ss.getEngines(junk);
+
+  for(var i = 0; i < engines.length; ++i) {
+    var origEngineObj = engines[i].wrappedJSObject;
+    torbutton_log(2, "Got engine: "+origEngineObj._name);
+    // hrmm.. could use
+    // searchForm.match(/^www\.google\.(co\.\S\S|com|\S\S|com\.\S\S)$/);
+    if(origEngineObj._name.indexOf("Google") != -1) {
+      torbutton_log(3, "Found google search plugin to wrap.");
+      origEngineObj.oldGetSubmission=origEngineObj.getSubmission;
+      origEngineObj.getSubmission = function lmbd(aData, respType) {
+        var sub = this.oldGetSubmission(aData, respType);
+        if(!m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled")
+            || !m_tb_prefs.getBoolPref("extensions.torbutton.fix_google_srch")) {
+          return sub;
+        }
+
+        var querymatch = sub.uri.path.match("[\?\&](q=[^&]+)[\&]")[1];
+        var querypath = sub.uri.path.split("?")[0];
+        torbutton_log(3, "Got submission call to Google search.");
+
+        var newURI = Cc["@mozilla.org/network/standard-url;1"]
+                          .createInstance(Ci.nsIStandardURL);
+        newURI.init(Ci.nsIStandardURL.URLTYPE_STANDARD, 80,
+                sub.uri.scheme+"://"+sub.uri.host+querypath+"?"+querymatch,
+                sub.uri.originCharset, null);
+        newURI = newURI.QueryInterface(Components.interfaces.nsIURI);
+        sub._uri = newURI;
+        torbutton_log(3, "Returning new search url.");
+        return sub;
+      };
+    }
+  }
+}
+
 function torbutton_do_main_window_startup()
 {
     torbutton_log(3, "Torbutton main window startup");
@@ -3178,6 +3218,9 @@ function torbutton_do_startup()
           torbutton_new_google_cookie();
         }
 
+        // Wrap Google search service.
+        torbutton_wrap_search_service();
+
         m_tb_prefs.setBoolPref("extensions.torbutton.startup", false);
     }
 }
diff --git a/src/defaults/preferences/preferences.js b/src/defaults/preferences/preferences.js
index b39c4d2..708e121 100644
--- a/src/defaults/preferences/preferences.js
+++ b/src/defaults/preferences/preferences.js
@@ -178,6 +178,7 @@ pref("extensions.torbutton.asked_google_captcha", false);
 pref("extensions.torbutton.redir_url.1", "https://www.ixquick.com/do/metasearch.pl?query=";);
 pref("extensions.torbutton.redir_url.2", "http://www.bing.com/search?q=";);
 pref("extensions.torbutton.redir_url.3", "https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=";);
+pref("extensions.torbutton.fix_google_srch", true);
 
 // User agent prefs:
 pref("extensions.torbutton.appname_override","Netscape");
-- 
1.6.5