Skip to content
Browse files

Style update and compatibility update

  • Loading branch information...
1 parent 82ca571 commit d2cfc6dc58e519be9547a4a7629ec48cb9c5b964 @meh committed
Showing with 118 additions and 126 deletions.
  1. +114 −122 components/do.js
  2. +4 −4 install.rdf
View
236 components/do.js
@@ -10,129 +10,121 @@
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*********************************************************************/
-
function SmartRefererSpoofer () { }
SmartRefererSpoofer.prototype = (function () {
- var Observer = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
- var NetworkIO = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
- var ScriptSecurityManager = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);
- var EffectiveTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].getService(Components.interfaces.nsIEffectiveTLDService);
-
- var Interfaces = {
- Channel: Components.interfaces.nsIChannel,
- HTTPChannel: Components.interfaces.nsIHttpChannel,
- Supports: Components.interfaces.nsISupports,
- Observer: Components.interfaces.nsIObserver,
- SupportsWeakReference: Components.interfaces.nsISupportsWeakReference
- };
-
- function log (what) {
- what = what.toString();
-
- dump(what);
- dump("\n");
- }
-
- function modify (http) {
- try {
- http.QueryInterface(Interfaces.Channel);
-
- var referer = NetworkIO.newURI(http.getRequestHeader("Referer"), null, null);
- }
- catch (e) {
- return false;
- }
-
- try {
- var [fromURI, toURI] = [http.URI.clone(), referer.clone()];
-
- try {
- var isIP = false;
-
- EffectiveTLDService.getPublicSuffix(fromURI);
- EffectiveTLDService.getPublicSuffix(toURI);
- }
- catch (e) {
- if (e == NS_ERROR_HOST_IS_IP_ADDRESS) {
- isIP = true;
- }
- }
-
- if (!isIP) {
- let [from, to] = [fromURI, toURI].map(function (x) x.host.split('.').reverse());
- let index = 0;
-
- while (from[index] || to[index]) {
- if (from[index] == to[index]) {
- index++;
- }
- else {
- from.splice(index);
- to.splice(index);
- }
- }
-
- if (from.length == 0) {
- throw Components.results.NS_ERROR_DOM_BAD_URI;
- }
-
- fromURI.host = from.reverse().join('.');
- toURI.host = to.reverse().join('.');
-
- try {
- if (EffectiveTLDService.getPublicSuffix(fromURI) == fromURI.host) {
- throw Components.results.NS_ERROR_DOM_BAD_URI;
- }
- }
- catch (e) {
- if (e == Components.results.NS_ERROR_DOM_BAD_URI) {
- throw e;
- }
- }
- }
-
- ScriptSecurityManager.checkSameOriginURI(fromURI, toURI, false);
-
- return false;
- }
- catch (e) {
- http.referrer = null;
- http.setRequestHeader("Referer", null, false);
-
- return true;
- }
- }
-
- function observe (subject, topic, data) {
- switch (topic) {
- case "http-on-modify-request":
- modify(subject.QueryInterface(Interfaces.HTTPChannel));
- break;
-
- case "profile-after-change":
- Observer.addObserver(this, "http-on-modify-request", false);
- break;
- }
- }
-
- return {
- observe: observe,
-
- QueryInterface: function (id) {
- if (!id.equals(Interfaces.Supports) && !id.equals(Interfaces.Observer) && !id.equals(Interfaces.SupportsWeakReference)) {
- throw Components.results.NS_ERROR_NO_INTERFACE;
- }
-
- return this;
- },
-
- classID: Components.ID("55fbf7cd-18ab-4f94-a9ff-4cf21192bcd8"),
- contractID: "smart-referer@meh.paranoid.pk/do;1",
- classDescription: "Smart Referer Spoofer",
-
- _xpcom_categories: [{ category: "profile-after-change" }]
- };
+ var Observer = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
+ var NetworkIO = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
+ var ScriptSecurityManager = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService(Components.interfaces.nsIScriptSecurityManager);
+ var EffectiveTLDService = Components.classes["@mozilla.org/network/effective-tld-service;1"].getService(Components.interfaces.nsIEffectiveTLDService);
+
+ var Interfaces = {
+ Channel: Components.interfaces.nsIChannel,
+ HTTPChannel: Components.interfaces.nsIHttpChannel,
+ Supports: Components.interfaces.nsISupports,
+ Observer: Components.interfaces.nsIObserver,
+ SupportsWeakReference: Components.interfaces.nsISupportsWeakReference
+ };
+
+ function modify (http) {
+ try {
+ http.QueryInterface(Interfaces.Channel);
+
+ var referer = NetworkIO.newURI(http.getRequestHeader("Referer"), null, null);
+ }
+ catch (e) {
+ return false;
+ }
+
+ try {
+ var [fromURI, toURI] = [http.URI.clone(), referer.clone()];
+
+ try {
+ var isIP = false;
+
+ EffectiveTLDService.getPublicSuffix(fromURI);
+ EffectiveTLDService.getPublicSuffix(toURI);
+ }
+ catch (e) {
+ if (e == NS_ERROR_HOST_IS_IP_ADDRESS) {
+ isIP = true;
+ }
+ }
+
+ if (!isIP) {
+ let [from, to] = [fromURI, toURI].map(function (x) x.host.split('.').reverse());
+ let index = 0;
+
+ while (from[index] || to[index]) {
+ if (from[index] == to[index]) {
+ index++;
+ }
+ else {
+ from.splice(index);
+ to.splice(index);
+ }
+ }
+
+ if (from.length == 0) {
+ throw Components.results.NS_ERROR_DOM_BAD_URI;
+ }
+
+ fromURI.host = from.reverse().join('.');
+ toURI.host = to.reverse().join('.');
+
+ try {
+ if (EffectiveTLDService.getPublicSuffix(fromURI) == fromURI.host) {
+ throw Components.results.NS_ERROR_DOM_BAD_URI;
+ }
+ }
+ catch (e) {
+ if (e == Components.results.NS_ERROR_DOM_BAD_URI) {
+ throw e;
+ }
+ }
+ }
+
+ ScriptSecurityManager.checkSameOriginURI(fromURI, toURI, false);
+
+ return false;
+ }
+ catch (e) {
+ http.referrer = null;
+ http.setRequestHeader("Referer", null, false);
+
+ return true;
+ }
+ }
+
+ function observe (subject, topic, data) {
+ switch (topic) {
+ case "http-on-modify-request":
+ modify(subject.QueryInterface(Interfaces.HTTPChannel));
+ break;
+
+ case "profile-after-change":
+ Observer.addObserver(this, "http-on-modify-request", false);
+ break;
+ }
+ }
+
+ return {
+ observe: observe,
+
+ QueryInterface: function (id) {
+ if (!id.equals(Interfaces.Supports) && !id.equals(Interfaces.Observer) && !id.equals(Interfaces.SupportsWeakReference)) {
+ throw Components.results.NS_ERROR_NO_INTERFACE;
+ }
+
+ return this;
+ },
+
+ classID: Components.ID("55fbf7cd-18ab-4f94-a9ff-4cf21192bcd8"),
+ contractID: "smart-referer@meh.paranoid.pk/do;1",
+ classDescription: "Smart Referer Spoofer",
+
+ _xpcom_categories: [{ category: "profile-after-change" }]
+ };
})();
/**
@@ -142,8 +134,8 @@ SmartRefererSpoofer.prototype = (function () {
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
if (XPCOMUtils.generateNSGetFactory) {
- var NSGetFactory = XPCOMUtils.generateNSGetFactory([SmartRefererSpoofer]);
+ var NSGetFactory = XPCOMUtils.generateNSGetFactory([SmartRefererSpoofer]);
}
else {
- var NSGetModule = XPCOMUtils.generateNSGetModule([SmartRefererSpoofer]);
+ var NSGetModule = XPCOMUtils.generateNSGetModule([SmartRefererSpoofer]);
}
View
8 install.rdf
@@ -7,21 +7,21 @@
<em:id>smart-referer@meh.paranoid.pk</em:id>
<em:version>0.0.3.1</em:version>
<em:type>2</em:type>
-
+
<!-- Target Application this extension can install into,
with minimum and maximum supported versions. -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0</em:minVersion>
- <em:maxVersion>8.0</em:maxVersion>
+ <em:maxVersion>10.0</em:maxVersion>
</Description>
</em:targetApplication>
-
+
<!-- Front End MetaData -->
<em:name>Smart Referer</em:name>
<em:description>Enable smart referers everywhere (send referer only on same domain)</em:description>
<em:creator>meh.</em:creator>
<em:homepageURL>http://github.com/meh/smart-referer</em:homepageURL>
- </Description>
+ </Description>
</RDF>

0 comments on commit d2cfc6d

Please sign in to comment.
Something went wrong with that request. Please try again.