зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1041334 - Pass notificationCallbacks to Adblock element hiding shims (r=mconley)
This commit is contained in:
Родитель
7a90a4fb83
Коммит
4e6c5e845b
|
@ -129,7 +129,7 @@ let ContentPolicyChild = {
|
|||
shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra) {
|
||||
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsISyncMessageSender);
|
||||
var rval = cpmm.sendRpcMessage("Addons:ContentPolicy:Run", {}, {
|
||||
let rval = cpmm.sendRpcMessage("Addons:ContentPolicy:Run", {}, {
|
||||
contentType: contentType,
|
||||
mimeTypeGuess: mimeTypeGuess,
|
||||
contentLocation: contentLocation,
|
||||
|
@ -157,15 +157,11 @@ let ContentPolicyChild = {
|
|||
|
||||
// This is a shim channel whose only purpose is to return some string
|
||||
// data from an about: protocol handler.
|
||||
function AboutProtocolChannel(data, uri, originalURI, contentType)
|
||||
function AboutProtocolChannel(uri, contractID)
|
||||
{
|
||||
let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
|
||||
stream.setData(data, data.length);
|
||||
this._stream = stream;
|
||||
|
||||
this.URI = BrowserUtils.makeURI(uri);
|
||||
this.originalURI = BrowserUtils.makeURI(originalURI);
|
||||
this.contentType = contentType;
|
||||
this.URI = uri;
|
||||
this.originalURI = uri;
|
||||
this._contractID = contractID;
|
||||
}
|
||||
|
||||
AboutProtocolChannel.prototype = {
|
||||
|
@ -180,13 +176,35 @@ AboutProtocolChannel.prototype = {
|
|||
status: Cr.NS_OK,
|
||||
|
||||
asyncOpen: function(listener, context) {
|
||||
// Ask the parent to synchronously read all the data from the channel.
|
||||
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsISyncMessageSender);
|
||||
let rval = cpmm.sendRpcMessage("Addons:AboutProtocol:OpenChannel", {
|
||||
uri: this.URI.spec,
|
||||
contractID: this._contractID
|
||||
}, {
|
||||
notificationCallbacks: this.notificationCallbacks,
|
||||
loadGroupNotificationCallbacks: this.loadGroup.notificationCallbacks
|
||||
});
|
||||
|
||||
if (rval.length != 1) {
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
let {data, contentType} = rval[0];
|
||||
this.contentType = contentType;
|
||||
|
||||
// Return the data via an nsIStringInputStream.
|
||||
let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
|
||||
stream.setData(data, data.length);
|
||||
|
||||
let runnable = {
|
||||
run: () => {
|
||||
try {
|
||||
listener.onStartRequest(this, context);
|
||||
} catch(e) {}
|
||||
try {
|
||||
listener.onDataAvailable(this, context, this._stream, 0, this._stream.available());
|
||||
listener.onDataAvailable(this, context, stream, 0, stream.available());
|
||||
} catch(e) {}
|
||||
try {
|
||||
listener.onStopRequest(this, context, Cr.NS_OK);
|
||||
|
@ -244,7 +262,7 @@ AboutProtocolInstance.prototype = {
|
|||
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsISyncMessageSender);
|
||||
|
||||
var rval = cpmm.sendRpcMessage("Addons:AboutProtocol:GetURIFlags", {
|
||||
let rval = cpmm.sendRpcMessage("Addons:AboutProtocol:GetURIFlags", {
|
||||
uri: uri.spec,
|
||||
contractID: this._contractID
|
||||
});
|
||||
|
@ -260,25 +278,11 @@ AboutProtocolInstance.prototype = {
|
|||
// We take some shortcuts here. Ideally, we would return a CPOW that
|
||||
// wraps the add-on's nsIChannel. However, many of the methods
|
||||
// related to nsIChannel are marked [noscript], so they're not
|
||||
// available to CPOWs. Consequently, the parent simply reads all the
|
||||
// data out of the add-on's channel and returns that as a string. We
|
||||
// create a new AboutProtocolChannel whose only purpose is to return
|
||||
// the string data via an nsIStringInputStream.
|
||||
// available to CPOWs. Consequently, we return a shim channel that,
|
||||
// when opened, asks the parent to open the channel and read out all
|
||||
// the data.
|
||||
newChannel: function(uri) {
|
||||
let cpmm = Cc["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Ci.nsISyncMessageSender);
|
||||
|
||||
var rval = cpmm.sendRpcMessage("Addons:AboutProtocol:NewChannel", {
|
||||
uri: uri.spec,
|
||||
contractID: this._contractID
|
||||
});
|
||||
|
||||
if (rval.length != 1) {
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
let {data, uri, originalURI, contentType} = rval[0];
|
||||
return new AboutProtocolChannel(data, uri, originalURI, contentType);
|
||||
return new AboutProtocolChannel(uri, this._contractID);
|
||||
},
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
|
||||
|
|
|
@ -185,7 +185,7 @@ let AboutProtocolParent = {
|
|||
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageBroadcaster);
|
||||
ppmm.addMessageListener("Addons:AboutProtocol:GetURIFlags", this);
|
||||
ppmm.addMessageListener("Addons:AboutProtocol:NewChannel", this);
|
||||
ppmm.addMessageListener("Addons:AboutProtocol:OpenChannel", this);
|
||||
this._protocols = [];
|
||||
},
|
||||
|
||||
|
@ -208,8 +208,8 @@ let AboutProtocolParent = {
|
|||
switch (msg.name) {
|
||||
case "Addons:AboutProtocol:GetURIFlags":
|
||||
return this.getURIFlags(msg);
|
||||
case "Addons:AboutProtocol:NewChannel":
|
||||
return this.newChannel(msg);
|
||||
case "Addons:AboutProtocol:OpenChannel":
|
||||
return this.openChannel(msg);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
@ -225,25 +225,20 @@ let AboutProtocolParent = {
|
|||
}
|
||||
},
|
||||
|
||||
// We take some shortcuts here. Ideally, we would return a CPOW that
|
||||
// wraps the add-on's nsIChannel. However, many of the methods
|
||||
// related to nsIChannel are marked [noscript], so they're not
|
||||
// available to CPOWs. Consequently, we immediately read all the
|
||||
// data out of the channel here and pass it to the child. The child
|
||||
// then returns a shim channel that wraps an nsIStringInputStream
|
||||
// for the string we read.
|
||||
newChannel: function(msg) {
|
||||
// We immediately read all the data out of the channel here and
|
||||
// return it to the child.
|
||||
openChannel: function(msg) {
|
||||
let uri = BrowserUtils.makeURI(msg.data.uri);
|
||||
let contractID = msg.data.contractID;
|
||||
let module = Cc[contractID].getService(Ci.nsIAboutModule);
|
||||
try {
|
||||
let channel = module.newChannel(uri);
|
||||
channel.notificationCallbacks = msg.objects.notificationCallbacks;
|
||||
channel.loadGroup = {notificationCallbacks: msg.objects.loadGroupNotificationCallbacks};
|
||||
let stream = channel.open();
|
||||
let data = NetUtil.readInputStreamToString(stream, stream.available(), {});
|
||||
return {
|
||||
data: data,
|
||||
uri: channel.URI.spec,
|
||||
originalURI: channel.originalURI.spec,
|
||||
contentType: channel.contentType
|
||||
};
|
||||
} catch (e) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче