Bug 1211665 - Filter add-ons console messages based on ConsoleID or originAttributes.addonId. r=baku

MozReview-Commit-ID: 2yEWhX6shkx

--HG--
extra : transplant_source : %93Xn%FD-%BF%AE%E6%CF%A0%F5%C7SG%93%D0%04%EAw%28
This commit is contained in:
Luca Greco 2016-03-29 17:40:39 +02:00
Родитель 2a28dabb62
Коммит 3983a24109
3 изменённых файлов: 34 добавлений и 9 удалений

Просмотреть файл

@ -316,7 +316,7 @@ update(AddonConsoleActor.prototype, {
case "ConsoleAPI":
if (!this.consoleAPIListener) {
this.consoleAPIListener =
new ConsoleAPIListener(null, this, "addon/" + this.addon.id);
new ConsoleAPIListener(null, this, { addonId: this.addon.id });
this.consoleAPIListener.init();
}
startedListeners.push(listener);

Просмотреть файл

@ -67,7 +67,7 @@ function run_test() {
listener.destroy();
listener = new ConsoleAPIListener(null, callback, "foo");
listener = new ConsoleAPIListener(null, callback, {consoleID: "foo"});
listener.init();
messages = listener.getCachedMessages();

Просмотреть файл

@ -794,12 +794,14 @@ ConsoleServiceListener.prototype =
* - onConsoleAPICall(). This method is invoked with one argument, the
* Console API message that comes from the observer service, whenever
* a relevant console API call is received.
* @param string consoleID
* Options - The consoleID that this listener should listen to
* @param object filteringOptions
* Options - The filteringOptions that this listener should listen to
(e.g. { addonId: "..." } or { consoleID: "..." }).
*/
function ConsoleAPIListener(window, owner, consoleID) {
function ConsoleAPIListener(window, owner, {addonId, consoleID} = {}) {
this.window = window;
this.owner = owner;
this.addonId = addonId;
this.consoleID = consoleID;
}
exports.ConsoleAPIListener = ConsoleAPIListener;
@ -825,10 +827,10 @@ ConsoleAPIListener.prototype =
owner: null,
/**
* The consoleID that we listen for. If not null then only messages from this
* The addonId that we listen for. If not null then only messages from this
* console will be returned.
*/
consoleID: null,
addonId: null,
/**
* Initialize the window.console API observer.
@ -896,8 +898,31 @@ ConsoleAPIListener.prototype =
}
}
if (this.consoleID && message.consoleID !== this.consoleID) {
return false;
if (this.consoleID) {
// Filtering based on the old-style consoleID property used by
// the legacy Console JSM module.
if (message.consoleID !== this.consoleID) {
return false;
}
}
if (this.addonId) {
if (!message.consoleID && !message.originAttributes) {
return false;
}
// Filtering based on the old-style consoleID property used by
// the legacy Console JSM module.
if (message.consoleID && message.consoleID !== `addon/${this.addonId}`) {
return false;
}
// Filtering based on the originAttributes used by
// the Console API object.
if (message.originAttributes &&
message.originAttributes.addonId !== this.addonId) {
return false;
}
}
return true;