Skip to content

Instantly share code, notes, and snippets.

@nmaier
Created December 23, 2010 07:06
Show Gist options
  • Save nmaier/752681 to your computer and use it in GitHub Desktop.
Save nmaier/752681 to your computer and use it in GitHub Desktop.
Minimal patch to support Firefox 4
--- components/refcontrolComp.js Mon Jan 19 23:26:36 1970
+++ components/refcontrolComp.js Mon Jan 19 23:26:36 1970
@@ -1,7 +1,7 @@
-
-var refcontrolObserver = {
+function refcontrolObserver() {}
+refcontrolObserver.prototype = {
bEnabled: true,
aRefActions: {},
dump: function(aMessage)
@@ -96,15 +96,17 @@
adjustRef: function(oChannel, sSite)
{
try {
var sRef;
var refAction = this.aRefActions[sSite];
- if (refAction == undefined)
+ if (!refAction) {
return false;
+ }
- if (refAction.if3rdParty && !this.is3rdPartyRequest(oChannel))
+ if (refAction.if3rdParty && !this.is3rdPartyRequest(oChannel)) {
return false;
+ }
if (refAction.str.charAt(0) == '@')
{
// special actions
switch (refAction.str)
@@ -121,11 +123,11 @@
}
}
else
sRef = this.performVariableInterpolation(oChannel, refAction.str);
-//this.dump("adjustRef: setting Referer for " + oChannel.URI.spec + " to " + sRef);
+// this.dump("adjustRef: setting Referer for " + oChannel.URI.spec + " to " + sRef);
oChannel.setRequestHeader("Referer", sRef, false);
if (oChannel.referrer)
oChannel.referrer.spec = sRef;
return true;
@@ -221,25 +223,27 @@
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
this.prefBranch = prefService.getBranch("refcontrol.");
this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
this.prefBranch.addObserver("enabled", this, true);
this.prefBranch.addObserver("actions", this, true);
+ this.onChangeEnabled(this.prefBranch);
+ this.onChangeActions(this.prefBranch);
} catch (ex) {
this.dump("onAppStartup: " + ex);
}
},
// Implement nsIObserver
observe: function(aSubject, aTopic, aData)
{
-//this.dump("observe: " + aTopic);
try {
switch (aTopic)
{
case 'http-on-modify-request':
- aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
- this.onModifyRequest(aSubject);
+ if (aSubject instanceof Components.interfaces.nsIHttpChannel) {
+ this.onModifyRequest(aSubject);
+ }
break;
case 'nsPref:changed':
aSubject.QueryInterface(Components.interfaces.nsIPrefBranch);
switch (aData)
@@ -255,10 +259,11 @@
break;
}
break;
case 'app-startup':
+ case 'profile-after-change':
this.onAppStartup();
break;
default:
this.dump("observe: unknown topic: " + aTopic);
@@ -276,70 +281,98 @@
!iid.equals(Components.interfaces.nsIObserver) &&
!iid.equals(Components.interfaces.nsISupportsWeakReference))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
- }
+ },
+
+ classDescription: "RefControl observer",
+ contractID: "@mozilla.org/refcontrol;1",
+ classID: Components.ID("{07C3DD15-0F44-4723-94DE-720B3B2FF9AF}"),
+ _xpcom_categories: [{category: 'profile-after-change'}]
};
-var refcontrolModule = {
- myCID: Components.ID("{07C3DD15-0F44-4723-94DE-720B3B2FF9AF}"),
- myContractID: "@mozilla.org/refcontrol;1",
-
- firstTime: true,
+try {
+ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+ if (XPCOMUtils.generateNSGetFactory) {
+ // moz-2.0+
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([refcontrolObserver]);
+ }
+ else {
+ // moz-1.9
+ if (!XPCOMUtils.defineLazyGetter) {
+ // moz < 1.9.2; no profile-after-change category, needs service:true
+ refControlObserver.prototype._xpcom_categories = [{category: 'app-startup', service: true}];
+ }
+ function NSGetModule() XPCOMUtils.generateModule([refcontrolObserver]);
+ }
+}
+catch (ex) {
+ // legacy code < moz-1.9
+ var refcontrolModule = {
+ firstTime: true,
- // Implement nsIModule
- registerSelf: function(compMgr, fileSpec, location, type)
- {
- if (this.firstTime)
+ // Implement nsIModule
+ registerSelf: function(compMgr, fileSpec, location, type)
{
- this.firstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- }
-
- compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- compMgr.registerFactoryLocation(this.myCID, "RefControl Component", this.myContractID,
- fileSpec, location, type);
-
- var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
- catMan.addCategoryEntry("app-startup", "RefControl", this.myContractID, true, 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.myContractID, 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;
- },
+ var rcp = refcontrolObserver.prototype;
+ if (this.firstTime)
+ {
+ this.firstTime = false;
+ throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
+ }
- canUnload: function(compMgr) { return true; },
- // end Implement nsIModule
+ compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.registerFactoryLocation(rcp.classID, rcp.classDescription, rcp.contractID,
+ fileSpec, location, type);
+
+ var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
+ catMan.addCategoryEntry("app-startup", "RefControl", rcp.contractID, true, true);
+ },
- myFactory: {
- // Implement nsIFactory
- createInstance: function(outer, iid)
+ unregisterSelf: function(compMgr, fileSpec, location)
{
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
+ var rcp = refcontrolObserver.prototype;
- return refcontrolObserver.QueryInterface(iid);
- }
- }
-};
+ // Remove the auto-startup
+ compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+ compMgr.unregisterFactoryLocation(rcp.classID, fileSpec);
+
+ var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(Components.interfaces.nsICategoryManager);
+ catMan.deleteCategoryEntry("app-startup", rcp.contractID, true);
+ },
-/* module initialisation */
-function NSGetModule(comMgr, fileSpec) { return refcontrolModule; }
+ getClassObject: function(compMgr, cid, iid)
+ {
+ var rcp = refcontrolObserver.prototype;
+ if (!cid.equals(rcp.classID))
+ throw Components.results.NS_ERROR_FACTORY_NOT_REGISTERED;
+
+ if (!iid.equals(Components.interfaces.nsIFactory))
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+
+ return this.myFactory;
+ },
+
+ canUnload: function(compMgr) { return true; },
+ // end Implement nsIModule
+
+ myFactory: {
+ // Implement nsIFactory
+ obj: null,
+ createInstance: function(outer, iid)
+ {
+ if (outer != null)
+ throw Components.results.NS_ERROR_NO_AGGREGATION;
+
+ if (!this.obj) {
+ this.obj = new refcontrolObserver();
+ }
+ return this.obj.QueryInterface(iid);
+ }
+ }
+ };
+ /* module initialisation */
+ function NSGetModule(comMgr, fileSpec) { return refcontrolModule; }
+}
\ No newline at end of file
--- chrome.manifest Mon Jan 19 23:26:36 1970
+++ chrome.manifest Mon Jan 19 23:26:36 1970
@@ -23,5 +23,9 @@
locale refcontrol ru-RU jar:chrome/RefControl.jar!/locale/ru-RU/
locale refcontrol tr-TR jar:chrome/RefControl.jar!/locale/tr-TR/
locale refcontrol uk-UA jar:chrome/RefControl.jar!/locale/uk-UA/
locale refcontrol zh-CN jar:chrome/RefControl.jar!/locale/zh-CN/
locale refcontrol zh-TW jar:chrome/RefControl.jar!/locale/zh-TW/
+
+component {07C3DD15-0F44-4723-94DE-720B3B2FF9AF} components/refcontrolComp.js
+contract @mozilla.org/refcontrol;1 {07C3DD15-0F44-4723-94DE-720B3B2FF9AF}
+category profile-after-change @mozilla.org/refcontrol;1 @mozilla.org/refcontrol;1
\ No newline at end of file
--- install.rdf Mon Jan 19 23:26:36 1970
+++ install.rdf Mon Jan 19 23:26:36 1970
@@ -4,11 +4,11 @@
<Description about="urn:mozilla:install-manifest">
<em:id>{455D905A-D37C-4643-A9E2-F6FEFAA0424A}</em:id>
<em:name>RefControl</em:name>
- <em:version>0.8.13</em:version>
+ <em:version>0.8.13.0nm</em:version>
<em:type>2</em:type>
<em:description>Control what gets sent as the HTTP Referer on a per-site basis.</em:description>
<em:creator>James Abbatiello</em:creator>
<em:contributor>ca-AD Locale - el_libre</em:contributor>
<em:contributor>cs-CZ Locale - MartinZubek</em:contributor>
@@ -66,11 +66,11 @@
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.0</em:minVersion>
- <em:maxVersion>3.6.*</em:maxVersion>
+ <em:maxVersion>4.0.*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment