[or-cvs] [torbutton/master 05/31] Update 1.3.x components to Firefox 4.
mikeperry at torproject.org
mikeperry at torproject.org
Tue Jan 4 07:02:18 UTC 2011
Author: Mike Perry <mikeperry-git at fscked.org>
Date: Tue, 30 Nov 2010 22:12:29 -0800
Subject: Update 1.3.x components to Firefox 4.
Commit: 42add9f6ebd558f2f7763c0f5d95597c7c67f289
---
src/chrome.manifest | 10 ++++
src/components/cookie-jar-selector.js | 1 +
src/components/tor-protocol.js | 66 ++++-------------------
src/components/torRefSpoofer.js | 94 +++++++++------------------------
src/components/tors-protocol.js | 66 ++++-------------------
5 files changed, 61 insertions(+), 176 deletions(-)
diff --git a/src/chrome.manifest b/src/chrome.manifest
index cbcf30a..a849c90 100644
--- a/src/chrome.manifest
+++ b/src/chrome.manifest
@@ -73,8 +73,18 @@ contract @torproject.org/torbutton-logger;1 {f36d72c9-9718-4134-b550-e109638331d
component {b985e49c-12cb-4f29-9d14-b62603332ec4} components/window-mapper.js
contract @torproject.org/content-window-mapper;1 {b985e49c-12cb-4f29-9d14-b62603332ec4}
+component {65be2be0-ceb4-44c2-91a5-9c75c53430bf} components/torRefSpoofer.js
+contract @torproject.org/torRefSpoofer;1 {65be2be0-ceb4-44c2-91a5-9c75c53430bf}
+
+component {52183e20-4d4b-11de-8a39-0800200c9a66} components/tor-protocol.js
+contract @mozilla.org/network/protocol;1?name=tor {52183e20-4d4b-11de-8a39-0800200c9a66}
+
+component {a5a4bc50-5e8d-11de-8a39-0800200c9a66} components/tors-protocol.js
+contract @mozilla.org/network/protocol;1?name=tors {a5a4bc50-5e8d-11de-8a39-0800200c9a66}
+
category content-policy ContentPolicy @torproject.org/cssblocker;1
category profile-after-change CookieJarSelector @torproject.org/cookie-jar-selector;1
+category profile-after-change RefSpoofer @torproject.org/torRefSpoofer;1
diff --git a/src/components/cookie-jar-selector.js b/src/components/cookie-jar-selector.js
index 2956f23..4122862 100644
--- a/src/components/cookie-jar-selector.js
+++ b/src/components/cookie-jar-selector.js
@@ -563,6 +563,7 @@ CookieJarSelector.prototype =
// after profil loading, initialize a timer to call timerCallback
// at a specified interval
this.timer.initWithCallback(this.timerCallback, 60 * 1000, nsITimer.TYPE_REPEATING_SLACK); // 1 minute
+ this.logger.log(3, "Cookie jar selector got profile-after-change");
break;
}
},
diff --git a/src/components/tor-protocol.js b/src/components/tor-protocol.js
index 111112c..e8bb68e 100644
--- a/src/components/tor-protocol.js
+++ b/src/components/tor-protocol.js
@@ -79,61 +79,19 @@ Protocol.prototype =
return ios.newChannelFromURI(aURI);
}
},
-}
-
-var ProtocolFactory = new Object();
-
-ProtocolFactory.createInstance = function (outer, iid)
-{
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
-
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return new Protocol();
+ // method of nsIClassInfo
+ classDescription: "Tor protocol handler",
+ classID: kPROTOCOL_CID,
+ contractID: kPROTOCOL_CONTRACTID,
}
-
/**
- * JS XPCOM component registration goop:
- *
- * We set ourselves up to observe the xpcom-startup category. This provides
- * us with a starting point.
- */
-
-var TestModule = new Object();
-
-TestModule.registerSelf = function (compMgr, fileSpec, location, type)
-{
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(kPROTOCOL_CID,
- kPROTOCOL_NAME,
- kPROTOCOL_CONTRACTID,
- fileSpec,
- location,
- type);
-}
-
-TestModule.getClassObject = function (compMgr, cid, iid)
-{
- if (!cid.equals(kPROTOCOL_CID))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- return ProtocolFactory;
-}
-
-TestModule.canUnload = function (compMgr)
-{
- return true;
-}
-
-function NSGetModule(compMgr, fileSpec)
-{
- return TestModule;
-}
-
+* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
+* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
+*/
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+if (XPCOMUtils.generateNSGetFactory)
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]);
+else
+ var NSGetModule = XPCOMUtils.generateNSGetModule([Protocol]);
diff --git a/src/components/torRefSpoofer.js b/src/components/torRefSpoofer.js
index ad198a5..3533256 100644
--- a/src/components/torRefSpoofer.js
+++ b/src/components/torRefSpoofer.js
@@ -1,20 +1,16 @@
-function LOG(text)
-{
- var logger = Components.classes["@torproject.org/torbutton-logger;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
- logger.log("RefSpoof: " + text);
-/* var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- prompt.alert(null, "debug", text);
- */
-}
+const kMODULE_CID = Components.ID("65be2be0-ceb4-44c2-91a5-9c75c53430bf");
+const kMODULE_CONTRACTID = "@torproject.org/torRefSpoofer;1";
+function RefSpoofer() {
+ this.logger = Components.classes["@torproject.org/torbutton-logger;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
+ this.logger.log(3, "RefSpoof component created");
+}
-var refObserver = {
+RefSpoofer.prototype = {
observe: function(subject, topic, data)
{
if (topic == "http-on-modify-request") {
- //LOG("----------------------------> (" + subject + ") mod request");
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var tor_enabled = prefs.getBoolPref("extensions.torbutton.tor_enabled");
@@ -26,8 +22,8 @@ var refObserver = {
this.onModifyRequest(subject);
return;
}
- if (topic == "app-startup") {
- //LOG("----------------------------> app-startup");
+ if (topic == "profile-after-change") {
+ this.logger.log(3, "RefSpoof got profile-after-change");
var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "http-on-modify-request", false);
return;
@@ -70,10 +66,11 @@ var refObserver = {
return;
//if they do not have the same host
this.adjustRef(oHttpChannel, requestURI.scheme + "://" + requestURI.host);
- LOG("Adjusting Referer from " + refererHost + " to " + requestURI.host);
+ this.loger.safe_log(3, "Adjusting Referer, ",
+ "from " + refererHost + " to " + requestURI.host);
}
catch (ex) {
- LOG("onModifyRequest: " + ex);
+ this.loger.log(5, "RefSpoof onModifyRequest: " +ex);
}
else if (spoofmode == 2)
this.adjustRef(oHttpChannel, "");
@@ -89,7 +86,7 @@ var refObserver = {
return true;
}
catch (ex) {
- LOG("adjustRef: " + ex);
+ this.loger.log(5, "RefSpoof adjustRef: " +ex);
}
return false;
},
@@ -100,58 +97,19 @@ var refObserver = {
!iid.equals(Components.interfaces.nsISupportsWeakReference))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
- }
-};
-
-var myModule = {
-
- myCID: Components.ID("65be2be0-ceb4-44c2-91a5-9c75c53430bf"),
- myProgID: "@torproject.org/torRefSpoofer;1",
- myName: "RefSpoofComp",
- registerSelf: function (compMgr, fileSpec, location, type) {
- var compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(this.myCID,this.myName,this.myProgID,fileSpec,location,type);
- //LOG("----------------------------> registerSelf");
- var catMgr = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMgr.addCategoryEntry("app-startup", this.myName, this.myProgID, true, true);
- },
-
- getClassObject: function (compMgr, cid, iid) {
- //LOG("----------------------------> getClassObject");
- return this.myFactory;
},
-
- canUnload: function(compMgr) {
- return true;
- },
-
- unregisterSelf: function(compMgr, fileSpec, location) {
- // Remove the auto-startup
- compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.unregisterFactoryLocation(this.myCID, fileSpec);
- var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMan.deleteCategoryEntry("app-startup", this.myProgID, true);
- },
-
- getClassObject: function(compMgr, cid, iid) {
- if (!cid.equals(this.myCID))
- throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this.myFactory;
- },
-
- myFactory: {
- // Implement nsIFactory
- createInstance: function(outer, iid)
- {
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return refObserver.QueryInterface(iid);
- }
- }
+ _xpcom_categories: [{category:"profile-after-change"}],
+ classID: kMODULE_CID,
+ contractID: kMODULE_CONTRACTID,
+ classDescription: "Tor Ref Spoofer"
};
-function NSGetModule(compMgr, fileSpec) {
- return myModule;
-}
+/**
+* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
+* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
+*/
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+if (XPCOMUtils.generateNSGetFactory)
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([RefSpoofer]);
+else
+ var NSGetModule = XPCOMUtils.generateNSGetModule([RefSpoofer]);
diff --git a/src/components/tors-protocol.js b/src/components/tors-protocol.js
index 1470301..ca82b47 100644
--- a/src/components/tors-protocol.js
+++ b/src/components/tors-protocol.js
@@ -79,61 +79,19 @@ Protocol.prototype =
return ios.newChannelFromURI(aURI);
}
},
-}
-
-var ProtocolFactory = new Object();
-
-ProtocolFactory.createInstance = function (outer, iid)
-{
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
-
- if (!iid.equals(nsIProtocolHandler) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return new Protocol();
+ // method of nsIClassInfo
+ classDescription: "Tor protocol handler",
+ classID: kPROTOCOL_CID,
+ contractID: kPROTOCOL_CONTRACTID
}
-
/**
- * JS XPCOM component registration goop:
- *
- * We set ourselves up to observe the xpcom-startup category. This provides
- * us with a starting point.
- */
-
-var TestModule = new Object();
-
-TestModule.registerSelf = function (compMgr, fileSpec, location, type)
-{
- compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(kPROTOCOL_CID,
- kPROTOCOL_NAME,
- kPROTOCOL_CONTRACTID,
- fileSpec,
- location,
- type);
-}
-
-TestModule.getClassObject = function (compMgr, cid, iid)
-{
- if (!cid.equals(kPROTOCOL_CID))
- throw Components.results.NS_ERROR_NO_INTERFACE;
-
- if (!iid.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- return ProtocolFactory;
-}
-
-TestModule.canUnload = function (compMgr)
-{
- return true;
-}
-
-function NSGetModule(compMgr, fileSpec)
-{
- return TestModule;
-}
-
+* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
+* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
+*/
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+if (XPCOMUtils.generateNSGetFactory)
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]);
+else
+ var NSGetModule = XPCOMUtils.generateNSGetModule([Protocol]);
--
1.7.1
More information about the tor-commits
mailing list