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