Skip to content

Commit 272fd44

Browse files
committed
With channel.redirectTo, other extensions shouldn't need an observer for our rewrites
1 parent 72cfae3 commit 272fd44

2 files changed

Lines changed: 13 additions & 39 deletions

File tree

src/chrome/content/code/HTTPS.js

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,22 @@ const HTTPS = {
5757
}
5858

5959
// Check for the new internal redirect API. If it exists, use it.
60-
if ("redirectTo" in channel) {
61-
this.log(INFO, "Using nsIHttpChannel.redirectTo: " + channel.URI.spec + " -> " + uri.spec);
62-
try {
63-
channel.redirectTo(uri);
64-
return true;
65-
} catch(e) {
66-
// This should not happen. We should only get exceptions if
67-
// the channel was already open.
68-
this.log(WARN, "Exception on nsIHttpChannel.redirectTo: "+e);
69-
70-
// Don't return: Fallback to NoScript ChannelReplacement.js
71-
}
60+
if (!"redirectTo" in channel) {
61+
this.log(WARN, "nsIHTTPChannel.redirectTo API is missing. This version of HTTPS Everywhere is useless!!!!\n!!!\n");
62+
return false;
7263
}
7364

74-
if (ChannelReplacement.supported) {
75-
HTTPSEverywhere.instance.notifyObservers(channel.URI, uri.spec);
76-
HTTPS.log(INFO,"Scheduling channel replacement for "+channel.URI.spec);
77-
ChannelReplacement.runWhenPending(channel, function() {
78-
var cr = new ChannelReplacement(channel, uri);
79-
cr.replace(true,null);
80-
cr.open();
81-
HTTPS.log(INFO,"Ran channel replacement for "+channel.URI.spec);
82-
});
65+
this.log(INFO, "Using nsIHttpChannel.redirectTo: " + channel.URI.spec + " -> " + uri.spec);
66+
try {
67+
channel.redirectTo(uri);
8368
return true;
69+
} catch(e) {
70+
// This should not happen. We should only get exceptions if
71+
// the channel was already open.
72+
this.log(WARN, "Exception on nsIHttpChannel.redirectTo: "+e);
73+
74+
// Don't return: Fallback to NoScript ChannelReplacement.js
8475
}
85-
8676
this.log(WARN,"Aborting redirection " + channel.name + ", should be HTTPS!");
8777
IOUtil.abort(channel);
8878
return false;

src/components/https-everywhere.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ const DUMMY_ARRAY = [];
109109

110110
const EARLY_VERSION_CHECK = !("nsISessionStore" in CI && typeof(/ /) === "object");
111111

112+
// This is probably obsolete since the switch to the channel.redirectTo API
112113
const OBSERVER_TOPIC_URI_REWRITE = "https-everywhere-uri-rewrite";
113114

114115
// XXX: Better plan for this?
@@ -646,23 +647,6 @@ HTTPSEverywhere.prototype = {
646647
return o_branch;
647648
},
648649

649-
/**
650-
* Notify observers of the topic OBSERVER_TOPIC_URI_REWRITE.
651-
*
652-
* @param nsIURI oldURI
653-
* @param string newSpec
654-
*/
655-
notifyObservers: function(oldURI, newSpec) {
656-
this.log(INFO, "Notifying observers of rewrite from " + oldURI.spec + " to " + newSpec);
657-
try {
658-
// The subject has to be an nsISupports and the extra data is a string,
659-
// that's why one is an nsIURI and the other is a nsIURI.spec string.
660-
this.obsService.notifyObservers(oldURI, OBSERVER_TOPIC_URI_REWRITE, newSpec);
661-
} catch (e) {
662-
this.log(WARN, "Couldn't notify observers: " + e);
663-
}
664-
},
665-
666650
chrome_opener: function(uri, args) {
667651
// we don't use window.open, because we need to work around TorButton's
668652
// state control

0 commit comments

Comments
 (0)