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

[or-cvs] [torbutton/master 02/31] Update Content Policy to Firefox 4.



Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Sun, 28 Nov 2010 19:03:15 -0800
Subject: Update Content Policy to Firefox 4.
Commit: afd312059cda428deccc6ae2060e9a46305a4f7d

---
 src/chrome.manifest          |    8 +++-
 src/components/cssblocker.js |  101 ++++++------------------------------------
 2 files changed, 21 insertions(+), 88 deletions(-)

diff --git a/src/chrome.manifest b/src/chrome.manifest
index cc65480..9d8682d 100644
--- a/src/chrome.manifest
+++ b/src/chrome.manifest
@@ -57,12 +57,18 @@ locale torbutton zh-CN chrome/locale/zh-CN/
 locale torbutton zh-HK chrome/locale/zh-HK/
 locale torbutton zh-TW chrome/locale/zh-TW/
 
-
 skin torbutton classic/1.0 chrome/skin/
 style chrome://global/content/customizeToolbar.xul chrome://torbutton/skin/torbutton.css
 
+# Firefox 4-style component registration
 component {e6204253-b690-4159-bfe8-d4eedab6b3be} components/cookie-jar-selector.js
 contract @torproject.org/cookie-jar-selector;1 {e6204253-b690-4159-bfe8-d4eedab6b3be}
 
+component {23f4d9ba-023a-94ab-eb75-67aed7562a18} components/cssblocker.js
+contract @torproject.org/cssblocker;1 {23f4d9ba-023a-94ab-eb75-67aed7562a18}
+
+category content-policy ContentPolicy @torproject.org/cssblocker;1
 category profile-after-change CookieJarSelector @torproject.org/cookie-jar-selector;1
 
+
+
diff --git a/src/components/cssblocker.js b/src/components/cssblocker.js
index 79e0fbf..8ee8375 100644
--- a/src/components/cssblocker.js
+++ b/src/components/cssblocker.js
@@ -440,94 +440,21 @@ ContentPolicy.prototype = {
     // API to add another addon to be protected from discovery
     addProtectedChromeHost: function(name) {
         protectedChromeHosts[name] = true;
-    }
-};
-
-/*
- * Factory object
- */
-
-var ContentPolicyInstance = null;
-
-const factory = {
-	// nsIFactory interface implementation
-	createInstance: function(outer, iid) {
-		if (outer != null) {
-           Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
-           return null;
-       }
-
-        if (!iid.equals(Components.interfaces.nsIContentPolicy) &&
-                !iid.equals(Components.interfaces.nsISupports)) {
-            Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;          
-            return null;
-        }
-
-        if(!ContentPolicyInstance)
-            ContentPolicyInstance = new ContentPolicy();
-
-		return ContentPolicyInstance;
-	},
-
-	// nsISupports interface implementation
-	QueryInterface: function(iid) {
-		if (iid.equals(Components.interfaces.nsISupports) ||
-				iid.equals(Components.interfaces.nsIModule) ||
-				iid.equals(Components.interfaces.nsIFactory))
-			return this;
-
-        /*
-		if (!iid.equals(Components.interfaces.nsIClassInfo))
-			dump("CSS Blocker: factory.QI to an unknown interface: " + iid + "\n");
-        */
-
-        Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;          
-        return null;   
-	}
-};
-
-
-/*
- * Module object
- */
-const module = {
-	registerSelf: function(compMgr, fileSpec, location, type) {
-		compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
-		compMgr.registerFactoryLocation(CSSB_CID, 
-										"Torbutton content policy",
-										CSSB_CONTRACTID,
-										fileSpec, location, type);
-
-		var catman = Components.classes["@mozilla.org/categorymanager;1"]
-					 .getService(Components.interfaces.nsICategoryManager);
-		catman.addCategoryEntry("content-policy", CSSB_CONTRACTID,
-							CSSB_CONTRACTID, true, true);
-	},
-
-	unregisterSelf: function(compMgr, fileSpec, location) {
-		compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
-
-		compMgr.unregisterFactoryLocation(CSSB_CID, fileSpec);
-		var catman = Components.classes["@mozilla.org/categorymanager;1"]
-					   .getService(Components.interfaces.nsICategoryManager);
-		catman.deleteCategoryEntry("content-policy", CSSB_CONTRACTID, true);
-	},
-
-	getClassObject: function(compMgr, cid, iid) {
-		if (cid.equals(CSSB_CID))
-            return factory;
+    },
 
-        Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
-        return null;
-	},
+    _xpcom_categories: [{category:"content-policy"}],
+    classID: CSSB_CID,
+    contractID: CSSB_CONTRACTID,
+    classDescription: "Torbutton Content Policy"
 
-	canUnload: function(compMgr) {
-		return true;
-	}
 };
 
-function NSGetModule(comMgr, fileSpec) {
-	return module;
-}
-
-
+/**
+* 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([ContentPolicy]);
+else
+    var NSGetModule = XPCOMUtils.generateNSGetModule([ContentPolicy]);
-- 
1.7.1