Skip to content

Commit

Permalink
Simplify wrapper for nsIChannel + make channel private only once
Browse files Browse the repository at this point in the history
(preparation for #150)
  • Loading branch information
Infocatcher committed May 27, 2014
1 parent 0d8e9e6 commit d6b985d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ var privateProtocol = {
// Also we can't use nsIPrivateBrowsingChannel.setPrivate(true) for chrome:// URI
var redirect = "chrome://privatetab/content/protocolRedirect.html#" + newSpec;
var channel = Services.io.newChannel(redirect, null, null);
var ensurePrivate = function() {
this.makeChannelPrivate(channel);
ensurePrivate = function() {}; // Don't call again in case of success
}.bind(this);
var channelWrapper = {
__proto__: channel,
_makePrivate: this.makeChannelPrivate.bind(this, channel),
asyncOpen: function(aListener, aContext) {
_log("[protocol] nsIChannel.asyncOpen()");
this._makePrivate();
_log("[protocol] nsIChannel.asyncOpen() => ensurePrivate()");
ensurePrivate();
return channel.asyncOpen.apply(this, arguments);
},
open: function() {
_log("[protocol] nsIChannel.open()");
this._makePrivate();
_log("[protocol] nsIChannel.open() => ensurePrivate()");
ensurePrivate();
return channel.open.apply(this, arguments);
}
};
Expand Down

0 comments on commit d6b985d

Please sign in to comment.