Ticket #1678: salty-horse-patch.txt

File salty-horse-patch.txt, 7.1 KB (added by nickm, 9 years ago)

patch from salty-horse on IRC

Line 
1diff --git a/src/chrome.manifest b/src/chrome.manifest
2index 0a1a0c7..6f2e5b8 100644
3--- a/src/chrome.manifest
4+++ b/src/chrome.manifest
5@@ -3,3 +3,11 @@ content https-everywhere chrome/content/
6 locale https-everywhere en chrome/locale/en/
7 
8 skin https-everywhere classic/1.0 chrome/skin/
9+
10+component {32c165b4-fe5e-4964-9250-603c410631b4} components/https-everywhere.js
11+contract @eff.org/https-everywhere;1 {32c165b4-fe5e-4964-9250-603c410631b4}
12+
13+category profile-before-change HTTPSEverywhere @eff.org/https-everywhere;1
14+category profile-after-change HTTPSEverywhere @eff.org/https-everywhere;1
15+category net-channel-event-sinks HTTPSEverywhere @eff.org/https-everywhere;1
16+category content-policy HTTPSEverywhere @eff.org/https-everywhere;1
17diff --git a/src/components/https-everywhere.js b/src/components/https-everywhere.js
18index da1ea39..2652b75 100644
19--- a/src/components/https-everywhere.js
20+++ b/src/components/https-everywhere.js
21@@ -20,6 +20,7 @@ const CP_SHOULDPROCESS = 4;
22 
23 const SERVICE_CTRID = "@eff.org/https-everywhere;1";
24 const SERVICE_ID=Components.ID("{32c165b4-fe5e-4964-9250-603c410631b4}");
25+const SERVICE_NAME = "Encrypts your communications with a number of major websites";
26 
27 const IOS = CC["@mozilla.org/network/io-service;1"].getService(CI.nsIIOService);
28 const OS = CC['@mozilla.org/observer-service;1'].getService(CI.nsIObserverService);
29@@ -120,6 +121,8 @@ function https_everywhereLog(level, str) {
30   }
31 }
32 
33+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
34+
35 function HTTPSEverywhere() {
36   // Hacks to set up logging in each component
37   HTTPS.log = https_everywhereLog;
38@@ -150,20 +153,39 @@ function HTTPSEverywhere() {
39 // HTTP redirects) correctly.
40 
41 HTTPSEverywhere.prototype = {
42-  QueryInterface: function(iid) {
43-    if (!iid.equals(CI.nsIObserver)
44-        && !iid.equals(CI.nsISupports)
45-        && !iid.equals(CI.nsIContentPolicy)
46-        && !iid.equals(CI.nsISupportsWeakReference)
47-        && !iid.equals(CI.nsIWebProgressListener)
48-        && !iid.equals(CI.nsIChannelEventSink)) {
49-      Components.returnCode = CR.NS_ERROR_NO_INTERFACE;
50-      this.log(INFO,"Bad QI: "+iid);
51-      return null;
52-    }
53-    this.log(VERB,"Good QI: "+iid);
54-    return this;
55+  // properties required for XPCOM registration:
56+  classDescription: SERVICE_NAME,
57+  classID:          SERVICE_ID,
58+  contractID:       SERVICE_CTRID,
59+
60+  _xpcom_factory: factory,
61+
62+  // [optional] an array of categories to register this component in.
63+  _xpcom_categories: [{
64+    // Each object in the array specifies the parameters to pass to
65+    // nsICategoryManager.addCategoryEntry(). 'true' is passed for
66+    // both aPersist and aReplace params.
67+    category: "app-startup",
68   },
69+  {
70+    category: "content-policy",
71+    // optional, defaults to false. When set to true, and only if 'value'
72+    // is not specified, the concatenation of the string "service," and the
73+    // object's contractID is passed as aValue parameter of addCategoryEntry.
74+    service: true,
75+  },
76+  ],
77+
78+  // QueryInterface implementation, e.g. using the generateQI helper
79+  QueryInterface: XPCOMUtils.generateQI(
80+    [Components.interfaces.nsIObserver,
81+     Components.interfaces.nsIMyInterface,
82+     Components.interfaces.nsISupports,
83+     Components.interfaces.nsIContentPolicy,
84+     Components.interfaces.nsISupportsWeakReference,
85+     Components.interfaces.nsIWebProgressListener,
86+     Components.interfaces.nsIChannelEventSink ]),
87+
88   wrappedJSObject: null,  // Initialized by constructor
89 
90   getWeakReference: function () {
91@@ -197,11 +219,6 @@ HTTPSEverywhere.prototype = {
92       HTTPS.forceChannel(channel);
93     } else if (topic == "app-startup") {
94       this.log(DBUG,"Got app-startup");
95-      OS.addObserver(this, "http-on-modify-request", false);
96-      var dls = CC['@mozilla.org/docloaderservice;1']
97-        .getService(CI.nsIWebProgress);
98-      dls.addProgressListener(this, CI.nsIWebProgress.NOTIFY_STATE_REQUEST);
99-      this.log(INFO,"ChannelReplacement.supported = "+ChannelReplacement.supported);
100     } else if (topic == "profile-before-change") {
101       this.log(INFO, "Got profile-before-change");
102       var catman = Components.classes["@mozilla.org/categorymanager;1"]
103@@ -209,9 +226,12 @@ HTTPSEverywhere.prototype = {
104       catman.deleteCategoryEntry("net-channel-event-sinks", SERVICE_CTRID, true);
105       Thread.hostRunning = false;
106     } else if (topic == "profile-after-change") {
107-      // This is currently separate from app-startup for hackish historical
108-      // reasons; not sure if that's necessary.
109       this.log(DBUG, "Got profile-after-change");
110+      OS.addObserver(this, "http-on-modify-request", false);
111+      var dls = CC['@mozilla.org/docloaderservice;1']
112+        .getService(CI.nsIWebProgress);
113+      dls.addProgressListener(this, CI.nsIWebProgress.NOTIFY_STATE_REQUEST);
114+      this.log(INFO,"ChannelReplacement.supported = "+ChannelReplacement.supported);
115       HTTPSRules.init();
116       Thread.hostRunning = true;
117       var catman = Components.classes["@mozilla.org/categorymanager;1"]
118@@ -333,53 +353,11 @@ const factory = {
119   }
120 };
121 
122-
123-/*
124- * Module object
125- */
126-const module = {
127-  registerSelf: function(compMgr, fileSpec, location, type) {
128-    compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
129-    compMgr.registerFactoryLocation(SERVICE_ID,
130-                    "HTTPS-Everywhere",
131-                    SERVICE_CTRID,
132-                    fileSpec, location, type);
133-
134-    var catman = Components.classes["@mozilla.org/categorymanager;1"]
135-           .getService(Components.interfaces.nsICategoryManager);
136-    catman.addCategoryEntry("app-startup", SERVICE_CTRID,
137-              SERVICE_CTRID, true, true);
138-    catman.addCategoryEntry("content-policy", SERVICE_CTRID,
139-              SERVICE_CTRID, true, true);
140-
141-  },
142-
143-  unregisterSelf: function(compMgr, fileSpec, location) {
144-    compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
145-
146-    compMgr.unregisterFactoryLocation(SERVICE_ID, fileSpec);
147-
148-    var catman = Components.classes["@mozilla.org/categorymanager;1"]
149-             .getService(Components.interfaces.nsICategoryManager);
150-    catman.deleteCategoryEntry("app-startup", SERVICE_CTRID, true);
151-    catman.deleteCategoryEntry("content-policy", SERVICE_CTRID, true);
152-  },
153-
154-  getClassObject: function(compMgr, cid, iid) {
155-    if (cid.equals(SERVICE_ID))
156-      return factory;
157-
158-    Components.returnCode = CR.NS_ERROR_NOT_REGISTERED;
159-    return null;
160-  },
161-
162-  canUnload: function(compMgr) {
163-    return true;
164-  }
165-};
166-
167-function NSGetModule(comMgr, fileSpec) {
168-  return module;
169-}
170-
171-
172+/**
173+* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4).
174+* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 (Firefox 3.6).
175+*/
176+if (XPCOMUtils.generateNSGetFactory)
177+    var NSGetFactory = XPCOMUtils.generateNSGetFactory([HTTPSEverywhere]);
178+else
179+    var NSGetModule = XPCOMUtils.generateNSGetModule([HTTPSEverywhere]);