Author: Seth Schoen <[email protected]> Date: Mon, 1 Nov 2010 19:09:17 -0700 Subject: apply observer patch from Justin Samuel for RequestPolicy compatibility (#1574) Commit: 2a373b5824fb8642dc05deb3e1c06b5f39496ef9
see https://trac.torproject.org/projects/tor/ticket/1574 --- src/chrome/content/code/HTTPSRules.js | 2 ++ src/components/https-everywhere.js | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/chrome/content/code/HTTPSRules.js b/src/chrome/content/code/HTTPSRules.js index be7ee7b..7f3bcd7 100644 --- a/src/chrome/content/code/HTTPSRules.js +++ b/src/chrome/content/code/HTTPSRules.js @@ -97,6 +97,8 @@ RuleSet.prototype = { var newuri = this.rewrittenURI(uri); if (!newuri) return false; this.log(NOTE,"Rewriting " + uri.spec + " -> " + newuri.spec + "\n"); + HTTPSEverywhere.instance.notifyObservers(uri, newuri.spec); + uri.scheme = newuri.scheme; uri.userPass = newuri.userPass; uri.username = newuri.username; diff --git a/src/components/https-everywhere.js b/src/components/https-everywhere.js index 9ba17de..03a04b7 100644 --- a/src/components/https-everywhere.js +++ b/src/components/https-everywhere.js @@ -96,6 +96,8 @@ const DUMMYOBJ = {}; const EARLY_VERSION_CHECK = !("nsISessionStore" in CI && typeof(/ /) === "object"); +const OBSERVER_TOPIC_URI_REWRITE = "https-everywhere-uri-rewrite"; + function xpcom_generateQI(iids) { var checks = []; for each (var iid in iids) { @@ -131,10 +133,12 @@ function HTTPSEverywhere() { // https://developer.mozilla.org/en/Observer_Notifications // https://developer.mozilla.org/en/nsIObserverService. // https://developer.mozilla.org/en/nsIObserver - var obsService = CC["@mozilla.org/observer-service;1"] + // We also use the observer service to let other extensions know about URIs + // we rewrite. + this.obsService = CC["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); - obsService.addObserver(this, "profile-before-change", false); - obsService.addObserver(this, "profile-after-change", false); + this.obsService.addObserver(this, "profile-before-change", false); + this.obsService.addObserver(this, "profile-after-change", false); return; } @@ -336,6 +340,23 @@ HTTPSEverywhere.prototype = { return o_branch; }, + /** + * Notify observers of the topic OBSERVER_TOPIC_URI_REWRITE. + * + * @param nsIURI oldURI + * @param string newSpec + */ + notifyObservers: function(oldURI, newSpec) { + this.log(INFO, "Notifying observers of rewrite from " + oldURI.spec + " to " + newSpec); + try { + // The subject has to be an nsISupports and the extra data is a string, + // that's why one is an nsIURI and the other is a nsIURI.spec string. + this.obsService.notifyObservers(oldURI, OBSERVER_TOPIC_URI_REWRITE, newSpec); + } catch (e) { + this.log(WARN, "Couldn't notify observers: " + e); + } + } + }; var prefs = 0; -- 1.7.1
