diff --git a/browser/components/extensions/ext-bookmarks.js b/browser/components/extensions/ext-bookmarks.js index b8b7650fdb7..874def39721 100644 --- a/browser/components/extensions/ext-bookmarks.js +++ b/browser/components/extensions/ext-bookmarks.js @@ -6,7 +6,6 @@ var Bookmarks = PlacesUtils.bookmarks; Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/browser/components/extensions/ext-browserAction.js b/browser/components/extensions/ext-browserAction.js index 782bf6a2352..1a26eb81528 100644 --- a/browser/components/extensions/ext-browserAction.js +++ b/browser/components/extensions/ext-browserAction.js @@ -11,7 +11,6 @@ Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, DefaultWeakMap, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/browser/components/extensions/ext-pageAction.js b/browser/components/extensions/ext-pageAction.js index 23a84ed811a..4a48f327d21 100644 --- a/browser/components/extensions/ext-pageAction.js +++ b/browser/components/extensions/ext-pageAction.js @@ -6,7 +6,6 @@ Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, DefaultWeakMap, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/browser/components/extensions/ext-tabs.js b/browser/components/extensions/ext-tabs.js index 1d778e38834..fbdd60f0beb 100644 --- a/browser/components/extensions/ext-tabs.js +++ b/browser/components/extensions/ext-tabs.js @@ -230,7 +230,7 @@ extensions.registerAPI((extension, context) => { }; }).api(), - onReplaced: ignoreEvent(), + onReplaced: ignoreEvent(context, "tabs.onReplaced"), onRemoved: new EventManager(context, "tabs.onRemoved", fire => { let tabListener = event => { diff --git a/browser/components/extensions/ext-windows.js b/browser/components/extensions/ext-windows.js index 5333a096f0b..ac09074c49d 100644 --- a/browser/components/extensions/ext-windows.js +++ b/browser/components/extensions/ext-windows.js @@ -5,7 +5,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "aboutNewTabService", Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/toolkit/components/extensions/ExtensionContent.jsm b/toolkit/components/extensions/ExtensionContent.jsm index a5e50fc0fee..c4c80de1b48 100644 --- a/toolkit/components/extensions/ExtensionContent.jsm +++ b/toolkit/components/extensions/ExtensionContent.jsm @@ -33,7 +33,6 @@ var { runSafeSyncWithoutClone, MessageBroker, Messenger, - ignoreEvent, injectAPI, flushJarCache, } = ExtensionUtils; diff --git a/toolkit/components/extensions/ExtensionUtils.jsm b/toolkit/components/extensions/ExtensionUtils.jsm index c7b7b90bcc2..f4393302ff1 100644 --- a/toolkit/components/extensions/ExtensionUtils.jsm +++ b/toolkit/components/extensions/ExtensionUtils.jsm @@ -245,12 +245,27 @@ SingletonEventManager.prototype = { }; // Simple API for event listeners where events never fire. -function ignoreEvent() +function ignoreEvent(context, name) { return { - addListener: function(context, callback) {}, - removeListener: function(context, callback) {}, - hasListener: function(context, callback) {}, + addListener: function(callback) { + let id = context.extension.id; + let frame = Components.stack.caller; + let msg = `In add-on ${id}, attempting to use listener "${name}", which is unimplemented.`; + let winID = context.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID; + let scriptError = Cc["@mozilla.org/scripterror;1"] + .createInstance(Ci.nsIScriptError); + scriptError.initWithWindowID(msg, frame.filename, null, + frame.lineNumber, frame.columnNumber, + Ci.nsIScriptError.warningFlag, + "content javascript", winID); + let consoleService = Cc['@mozilla.org/consoleservice;1'] + .getService(Ci.nsIConsoleService); + consoleService.logMessage(scriptError); + }, + removeListener: function(callback) {}, + hasListener: function(callback) {}, }; } diff --git a/toolkit/components/extensions/ext-alarms.js b/toolkit/components/extensions/ext-alarms.js index 9d83c9807da..e294ff09256 100644 --- a/toolkit/components/extensions/ext-alarms.js +++ b/toolkit/components/extensions/ext-alarms.js @@ -3,7 +3,6 @@ var { classes: Cc, interfaces: Ci, utils: Cu } = Components; Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/toolkit/components/extensions/ext-cookies.js b/toolkit/components/extensions/ext-cookies.js index de55dd95aca..d79796a5820 100644 --- a/toolkit/components/extensions/ext-cookies.js +++ b/toolkit/components/extensions/ext-cookies.js @@ -2,7 +2,6 @@ const { interfaces: Ci, utils: Cu } = Components; Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/toolkit/components/extensions/ext-notifications.js b/toolkit/components/extensions/ext-notifications.js index 463ece20bd9..bb8c4be9739 100644 --- a/toolkit/components/extensions/ext-notifications.js +++ b/toolkit/components/extensions/ext-notifications.js @@ -138,8 +138,8 @@ extensions.registerPrivilegedAPI("notifications", (extension, context) => { }).api(), // FIXME - onButtonClicked: ignoreEvent(), - onClicked: ignoreEvent(), + onButtonClicked: ignoreEvent(context, "notifications.onButtonClicked"), + onClicked: ignoreEvent(context, "notifications.onClicked"), }, }; }); diff --git a/toolkit/components/extensions/ext-runtime.js b/toolkit/components/extensions/ext-runtime.js index d77c25cf8ee..c19460e3d81 100644 --- a/toolkit/components/extensions/ext-runtime.js +++ b/toolkit/components/extensions/ext-runtime.js @@ -37,7 +37,7 @@ extensions.registerAPI((extension, context) => { }; }).api(), - onInstalled: ignoreEvent(), + onInstalled: ignoreEvent(context, "runtime.onInstalled"), onMessage: context.messenger.onMessage("runtime.onMessage"), diff --git a/toolkit/components/extensions/ext-storage.js b/toolkit/components/extensions/ext-storage.js index ed91dbd88ff..697876c4f93 100644 --- a/toolkit/components/extensions/ext-storage.js +++ b/toolkit/components/extensions/ext-storage.js @@ -6,7 +6,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "ExtensionStorage", Cu.import("resource://gre/modules/ExtensionUtils.jsm"); var { EventManager, - ignoreEvent, runSafe, } = ExtensionUtils; diff --git a/toolkit/components/extensions/ext-webNavigation.js b/toolkit/components/extensions/ext-webNavigation.js index 4f3ce5787ec..a370c6081af 100644 --- a/toolkit/components/extensions/ext-webNavigation.js +++ b/toolkit/components/extensions/ext-webNavigation.js @@ -68,7 +68,7 @@ extensions.registerPrivilegedAPI("webNavigation", (extension, context) => { onCompleted: new WebNavigationEventManager(context, "onCompleted").api(), onErrorOccurred: new WebNavigationEventManager(context, "onErrorOccurred").api(), onReferenceFragmentUpdated: new WebNavigationEventManager(context, "onReferenceFragmentUpdated").api(), - onCreatedNavigationTarget: ignoreEvent(), + onCreatedNavigationTarget: ignoreEvent(context, "webNavigation.onCreatedNavigationTarget"), }, }; }); diff --git a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html index 50e5d4ad85f..24c6eb77bd9 100644 --- a/toolkit/components/extensions/test/mochitest/test_ext_notifications.html +++ b/toolkit/components/extensions/test/mochitest/test_ext_notifications.html @@ -17,6 +17,9 @@ add_task(function* test_notifications() { var opts = {title: "Testing Notification", message: "Carry on"}; + // Test an unimplemented listener. + browser.notifications.onClicked.addListener(function() {}); + browser.notifications.create("5", opts, function(id) { browser.test.sendMessage("running", id); browser.test.notifyPass("background test passed");