diff --git a/browser/components/extensions/ext-bookmarks.js b/browser/components/extensions/ext-bookmarks.js index b8b39cc63144..b85d2190a452 100644 --- a/browser/components/extensions/ext-bookmarks.js +++ b/browser/components/extensions/ext-bookmarks.js @@ -317,7 +317,7 @@ this.bookmarks = class extends ExtensionAPI { } }, - onCreated: new EventManager(context, "bookmarks.onCreated", fire => { + onCreated: new SingletonEventManager(context, "bookmarks.onCreated", fire => { let listener = (event, bookmark) => { fire.sync(bookmark.id, bookmark); }; @@ -330,7 +330,7 @@ this.bookmarks = class extends ExtensionAPI { }; }).api(), - onRemoved: new EventManager(context, "bookmarks.onRemoved", fire => { + onRemoved: new SingletonEventManager(context, "bookmarks.onRemoved", fire => { let listener = (event, data) => { fire.sync(data.guid, data.info); }; @@ -343,7 +343,7 @@ this.bookmarks = class extends ExtensionAPI { }; }).api(), - onChanged: new EventManager(context, "bookmarks.onChanged", fire => { + onChanged: new SingletonEventManager(context, "bookmarks.onChanged", fire => { let listener = (event, data) => { fire.sync(data.guid, data.info); }; @@ -356,7 +356,7 @@ this.bookmarks = class extends ExtensionAPI { }; }).api(), - onMoved: new EventManager(context, "bookmarks.onMoved", fire => { + onMoved: new SingletonEventManager(context, "bookmarks.onMoved", fire => { let listener = (event, data) => { fire.sync(data.guid, data.info); }; diff --git a/browser/components/extensions/ext-browserAction.js b/browser/components/extensions/ext-browserAction.js index e6708ed0a83e..454daa764078 100644 --- a/browser/components/extensions/ext-browserAction.js +++ b/browser/components/extensions/ext-browserAction.js @@ -566,7 +566,7 @@ this.browserAction = class extends ExtensionAPI { return { browserAction: { - onClicked: new EventManager(context, "browserAction.onClicked", fire => { + onClicked: new SingletonEventManager(context, "browserAction.onClicked", fire => { let listener = () => { fire.async(tabManager.convert(tabTracker.activeTab)); }; diff --git a/browser/components/extensions/ext-c-devtools-panels.js b/browser/components/extensions/ext-c-devtools-panels.js index ca52034a73d9..eab046f60118 100644 --- a/browser/components/extensions/ext-c-devtools-panels.js +++ b/browser/components/extensions/ext-c-devtools-panels.js @@ -102,7 +102,7 @@ class ChildDevToolsPanel extends EventEmitter { api() { return { - onShown: new EventManager( + onShown: new SingletonEventManager( this.context, "devtoolsPanel.onShown", fire => { const listener = (eventName, panelContentWindow) => { fire.asyncWithoutClone(panelContentWindow); @@ -113,7 +113,7 @@ class ChildDevToolsPanel extends EventEmitter { }; }).api(), - onHidden: new EventManager( + onHidden: new SingletonEventManager( this.context, "devtoolsPanel.onHidden", fire => { const listener = () => { fire.async(); @@ -160,7 +160,7 @@ this.devtools_panels = class extends ExtensionAPI { get themeName() { return themeChangeObserver.themeName; }, - onThemeChanged: new EventManager( + onThemeChanged: new SingletonEventManager( context, "devtools.panels.onThemeChanged", fire => { const listener = (eventName, themeName) => { fire.async(themeName); diff --git a/browser/components/extensions/ext-c-menus.js b/browser/components/extensions/ext-c-menus.js index 73a462d48a31..e8aef091bac2 100644 --- a/browser/components/extensions/ext-c-menus.js +++ b/browser/components/extensions/ext-c-menus.js @@ -158,7 +158,7 @@ this.menusInternal = class extends ExtensionAPI { return context.childManager.callParentAsyncFunction("menusInternal.removeAll", []); }, - onClicked: new EventManager(context, "menus.onClicked", fire => { + onClicked: new SingletonEventManager(context, "menus.onClicked", fire => { let listener = (info, tab) => { fire.async(info, tab); }; diff --git a/browser/components/extensions/ext-c-omnibox.js b/browser/components/extensions/ext-c-omnibox.js index 11e9d5bb0f3e..fe82cc612c0c 100644 --- a/browser/components/extensions/ext-c-omnibox.js +++ b/browser/components/extensions/ext-c-omnibox.js @@ -9,7 +9,7 @@ this.omnibox = class extends ExtensionAPI { getAPI(context) { return { omnibox: { - onInputChanged: new EventManager(context, "omnibox.onInputChanged", fire => { + onInputChanged: new SingletonEventManager(context, "omnibox.onInputChanged", fire => { let listener = (text, id) => { fire.asyncWithoutClone(text, suggestions => { context.childManager.callParentFunctionNoReturn("omnibox_internal.addSuggestions", [ diff --git a/browser/components/extensions/ext-commands.js b/browser/components/extensions/ext-commands.js index ca677a465e0d..c903c4d77dd4 100644 --- a/browser/components/extensions/ext-commands.js +++ b/browser/components/extensions/ext-commands.js @@ -241,7 +241,7 @@ this.commands = class extends ExtensionAPI { }); })); }, - onCommand: new EventManager(context, "commands.onCommand", fire => { + onCommand: new SingletonEventManager(context, "commands.onCommand", fire => { let listener = (eventName, commandName) => { fire.async(commandName); }; diff --git a/browser/components/extensions/ext-devtools-network.js b/browser/components/extensions/ext-devtools-network.js index 1029a7e787af..e9596dd29d2a 100644 --- a/browser/components/extensions/ext-devtools-network.js +++ b/browser/components/extensions/ext-devtools-network.js @@ -10,7 +10,7 @@ this.devtools_network = class extends ExtensionAPI { return { devtools: { network: { - onNavigated: new EventManager(context, "devtools.onNavigated", fire => { + onNavigated: new SingletonEventManager(context, "devtools.onNavigated", fire => { let listener = (event, data) => { fire.async(data.url); }; diff --git a/browser/components/extensions/ext-geckoProfiler.js b/browser/components/extensions/ext-geckoProfiler.js index 7fe44b45cfd9..88e4787a7fbc 100644 --- a/browser/components/extensions/ext-geckoProfiler.js +++ b/browser/components/extensions/ext-geckoProfiler.js @@ -374,7 +374,7 @@ this.geckoProfiler = class extends ExtensionAPI { throw new Error(`Ran out of options to get symbols from library ${debugName} ${breakpadId}.`); }, - onRunning: new EventManager(context, "geckoProfiler.onRunning", fire => { + onRunning: new SingletonEventManager(context, "geckoProfiler.onRunning", fire => { isRunningObserver.addObserver(fire.async); return () => { isRunningObserver.removeObserver(fire.async); diff --git a/browser/components/extensions/ext-history.js b/browser/components/extensions/ext-history.js index 8ca22f4309b4..6b1112545823 100644 --- a/browser/components/extensions/ext-history.js +++ b/browser/components/extensions/ext-history.js @@ -219,7 +219,7 @@ this.history = class extends ExtensionAPI { return Promise.resolve(results); }, - onVisited: new EventManager(context, "history.onVisited", fire => { + onVisited: new SingletonEventManager(context, "history.onVisited", fire => { let listener = (event, data) => { fire.sync(data); }; @@ -230,7 +230,7 @@ this.history = class extends ExtensionAPI { }; }).api(), - onVisitRemoved: new EventManager(context, "history.onVisitRemoved", fire => { + onVisitRemoved: new SingletonEventManager(context, "history.onVisitRemoved", fire => { let listener = (event, data) => { fire.sync(data); }; @@ -241,7 +241,7 @@ this.history = class extends ExtensionAPI { }; }).api(), - onTitleChanged: new EventManager(context, "history.onTitleChanged", fire => { + onTitleChanged: new SingletonEventManager(context, "history.onTitleChanged", fire => { let listener = (event, data) => { fire.sync(data); }; diff --git a/browser/components/extensions/ext-menus.js b/browser/components/extensions/ext-menus.js index 82f46281592e..f381055f865c 100644 --- a/browser/components/extensions/ext-menus.js +++ b/browser/components/extensions/ext-menus.js @@ -673,7 +673,7 @@ this.menusInternal = class extends ExtensionAPI { } }, - onClicked: new EventManager(context, "menusInternal.onClicked", fire => { + onClicked: new SingletonEventManager(context, "menusInternal.onClicked", fire => { let listener = (event, info, tab) => { fire.async(info, tab); }; diff --git a/browser/components/extensions/ext-omnibox.js b/browser/components/extensions/ext-omnibox.js index b85b112ad8f5..488e51a63fa3 100644 --- a/browser/components/extensions/ext-omnibox.js +++ b/browser/components/extensions/ext-omnibox.js @@ -40,7 +40,7 @@ this.omnibox = class extends ExtensionAPI { } }, - onInputStarted: new EventManager(context, "omnibox.onInputStarted", fire => { + onInputStarted: new SingletonEventManager(context, "omnibox.onInputStarted", fire => { let listener = (eventName) => { fire.sync(); }; @@ -50,7 +50,7 @@ this.omnibox = class extends ExtensionAPI { }; }).api(), - onInputCancelled: new EventManager(context, "omnibox.onInputCancelled", fire => { + onInputCancelled: new SingletonEventManager(context, "omnibox.onInputCancelled", fire => { let listener = (eventName) => { fire.sync(); }; @@ -60,7 +60,7 @@ this.omnibox = class extends ExtensionAPI { }; }).api(), - onInputEntered: new EventManager(context, "omnibox.onInputEntered", fire => { + onInputEntered: new SingletonEventManager(context, "omnibox.onInputEntered", fire => { let listener = (eventName, text, disposition) => { fire.sync(text, disposition); }; @@ -81,7 +81,7 @@ this.omnibox = class extends ExtensionAPI { } }, - onInputChanged: new EventManager(context, "omnibox_internal.onInputChanged", fire => { + onInputChanged: new SingletonEventManager(context, "omnibox_internal.onInputChanged", fire => { let listener = (eventName, text, id) => { fire.sync(text, id); }; diff --git a/browser/components/extensions/ext-pageAction.js b/browser/components/extensions/ext-pageAction.js index d3f37fb39984..13e6172cee00 100644 --- a/browser/components/extensions/ext-pageAction.js +++ b/browser/components/extensions/ext-pageAction.js @@ -269,7 +269,7 @@ this.pageAction = class extends ExtensionAPI { return { pageAction: { - onClicked: new EventManager(context, "pageAction.onClicked", fire => { + onClicked: new SingletonEventManager(context, "pageAction.onClicked", fire => { let listener = (evt, tab) => { fire.async(tabManager.convert(tab)); }; diff --git a/browser/components/extensions/ext-sessions.js b/browser/components/extensions/ext-sessions.js index fe1f0b347891..e52ba95c0749 100644 --- a/browser/components/extensions/ext-sessions.js +++ b/browser/components/extensions/ext-sessions.js @@ -127,7 +127,7 @@ this.sessions = class extends ExtensionAPI { return createSession(session, extension, closedId); }, - onChanged: new EventManager(context, "sessions.onChanged", fire => { + onChanged: new SingletonEventManager(context, "sessions.onChanged", fire => { let observer = () => { fire.async(); }; diff --git a/browser/components/extensions/ext-tabs.js b/browser/components/extensions/ext-tabs.js index a5b4bf11ffa5..a86551a46cae 100644 --- a/browser/components/extensions/ext-tabs.js +++ b/browser/components/extensions/ext-tabs.js @@ -100,7 +100,7 @@ this.tabs = class extends ExtensionAPI { let self = { tabs: { - onActivated: new EventManager(context, "tabs.onActivated", fire => { + onActivated: new SingletonEventManager(context, "tabs.onActivated", fire => { let listener = (eventName, event) => { fire.async(event); }; @@ -111,7 +111,7 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onCreated: new EventManager(context, "tabs.onCreated", fire => { + onCreated: new SingletonEventManager(context, "tabs.onCreated", fire => { let listener = (eventName, event) => { fire.async(tabManager.convert(event.nativeTab, event.currentTab)); }; @@ -128,7 +128,7 @@ this.tabs = class extends ExtensionAPI { * the tabId in an array to match the API. * @see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/onHighlighted */ - onHighlighted: new EventManager(context, "tabs.onHighlighted", fire => { + onHighlighted: new SingletonEventManager(context, "tabs.onHighlighted", fire => { let listener = (eventName, event) => { fire.async({tabIds: [event.tabId], windowId: event.windowId}); }; @@ -139,7 +139,7 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onAttached: new EventManager(context, "tabs.onAttached", fire => { + onAttached: new SingletonEventManager(context, "tabs.onAttached", fire => { let listener = (eventName, event) => { fire.async(event.tabId, {newWindowId: event.newWindowId, newPosition: event.newPosition}); }; @@ -150,7 +150,7 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onDetached: new EventManager(context, "tabs.onDetached", fire => { + onDetached: new SingletonEventManager(context, "tabs.onDetached", fire => { let listener = (eventName, event) => { fire.async(event.tabId, {oldWindowId: event.oldWindowId, oldPosition: event.oldPosition}); }; @@ -161,7 +161,7 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onRemoved: new EventManager(context, "tabs.onRemoved", fire => { + onRemoved: new SingletonEventManager(context, "tabs.onRemoved", fire => { let listener = (eventName, event) => { fire.async(event.tabId, {windowId: event.windowId, isWindowClosing: event.isWindowClosing}); }; @@ -172,11 +172,11 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onReplaced: new EventManager(context, "tabs.onReplaced", fire => { + onReplaced: new SingletonEventManager(context, "tabs.onReplaced", fire => { return () => {}; }).api(), - onMoved: new EventManager(context, "tabs.onMoved", fire => { + onMoved: new SingletonEventManager(context, "tabs.onMoved", fire => { // There are certain circumstances where we need to ignore a move event. // // Namely, the first time the tab is moved after it's created, we need @@ -219,7 +219,7 @@ this.tabs = class extends ExtensionAPI { }; }).api(), - onUpdated: new EventManager(context, "tabs.onUpdated", fire => { + onUpdated: new SingletonEventManager(context, "tabs.onUpdated", fire => { const restricted = ["url", "favIconUrl", "title"]; function sanitize(extension, changeInfo) { @@ -679,7 +679,7 @@ this.tabs = class extends ExtensionAPI { return Promise.resolve(); }, - onZoomChange: new EventManager(context, "tabs.onZoomChange", fire => { + onZoomChange: new SingletonEventManager(context, "tabs.onZoomChange", fire => { let getZoomLevel = browser => { let {ZoomManager} = browser.ownerGlobal; diff --git a/browser/components/extensions/ext-utils.js b/browser/components/extensions/ext-utils.js index 7926ce3a516b..a30e66fb8dc3 100644 --- a/browser/components/extensions/ext-utils.js +++ b/browser/components/extensions/ext-utils.js @@ -122,7 +122,7 @@ class WindowTracker extends WindowTrackerBase { * @param {function} listener * The listener function to call when a DOM event is received. */ -global.WindowEventManager = class extends EventManager { +global.WindowEventManager = class extends SingletonEventManager { constructor(context, name, event, listener) { super(context, name, fire => { let listener2 = listener.bind(null, fire); diff --git a/browser/components/extensions/ext-windows.js b/browser/components/extensions/ext-windows.js index e511572fe73a..78da834f0376 100644 --- a/browser/components/extensions/ext-windows.js +++ b/browser/components/extensions/ext-windows.js @@ -39,7 +39,7 @@ this.windows = class extends ExtensionAPI { fire.async(windowTracker.getId(window)); }).api(), - onFocusChanged: new EventManager(context, "windows.onFocusChanged", fire => { + onFocusChanged: new SingletonEventManager(context, "windows.onFocusChanged", fire => { // Keep track of the last windowId used to fire an onFocusChanged event let lastOnFocusChangedWindowId; diff --git a/toolkit/components/extensions/ExtensionChild.jsm b/toolkit/components/extensions/ExtensionChild.jsm index fa6aa5165a1b..772dac579879 100644 --- a/toolkit/components/extensions/ExtensionChild.jsm +++ b/toolkit/components/extensions/ExtensionChild.jsm @@ -46,11 +46,11 @@ const { } = ExtensionUtils; const { - EventManager, LocalAPIImplementation, LocaleData, NoCloneSpreadArgs, SchemaAPIInterface, + SingletonEventManager, } = ExtensionCommon; const isContentProcess = Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT; @@ -133,7 +133,7 @@ class Port { this.postMessage(json); }, - onDisconnect: new EventManager(this.context, "Port.onDisconnect", fire => { + onDisconnect: new SingletonEventManager(this.context, "Port.onDisconnect", fire => { return this.registerOnDisconnect(holder => { let error = holder.deserialize(this.context.cloneScope); portError = error && this.context.normalizeError(error); @@ -141,7 +141,7 @@ class Port { }); }).api(), - onMessage: new EventManager(this.context, "Port.onMessage", fire => { + onMessage: new SingletonEventManager(this.context, "Port.onMessage", fire => { return this.registerOnMessage(holder => { let msg = holder.deserialize(this.context.cloneScope); fire.asyncWithoutClone(msg, portObj); @@ -349,7 +349,7 @@ class Messenger { } _onMessage(name, filter) { - return new EventManager(this.context, name, fire => { + return new SingletonEventManager(this.context, name, fire => { let listener = { messageFilterPermissive: this.optionalFilter, messageFilterStrict: this.filter, @@ -440,7 +440,7 @@ class Messenger { } _onConnect(name, filter) { - return new EventManager(this.context, name, fire => { + return new SingletonEventManager(this.context, name, fire => { let listener = { messageFilterPermissive: this.optionalFilter, messageFilterStrict: this.filter, diff --git a/toolkit/components/extensions/ExtensionCommon.jsm b/toolkit/components/extensions/ExtensionCommon.jsm index bb5fdb4c37ae..bcf81ebb7ccb 100644 --- a/toolkit/components/extensions/ExtensionCommon.jsm +++ b/toolkit/components/extensions/ExtensionCommon.jsm @@ -1359,7 +1359,7 @@ defineLazyGetter(LocaleData.prototype, "availableLocales", function() { // This is a generic class for managing event listeners. Example usage: // -// new EventManager(context, "api.subAPI", fire => { +// new SingletonEventManager(context, "api.subAPI", fire => { // let listener = (...) => { // // Fire any listeners registered with addListener. // fire.async(arg1, arg2); @@ -1378,14 +1378,14 @@ defineLazyGetter(LocaleData.prototype, "availableLocales", function() { // content process). |name| is for debugging. |register| is a function // to register the listener. |register| should return an // unregister function that will unregister the listener. -function EventManager(context, name, register) { +function SingletonEventManager(context, name, register) { this.context = context; this.name = name; this.register = register; this.unregister = new Map(); } -EventManager.prototype = { +SingletonEventManager.prototype = { addListener(callback, ...args) { if (this.unregister.has(callback)) { return; @@ -1508,12 +1508,12 @@ const stylesheetMap = new DefaultMap(url => { ExtensionCommon = { BaseContext, CanOfAPIs, - EventManager, LocalAPIImplementation, LocaleData, NoCloneSpreadArgs, SchemaAPIInterface, SchemaAPIManager, + SingletonEventManager, SpreadArgs, ignoreEvent, stylesheetMap, diff --git a/toolkit/components/extensions/ext-alarms.js b/toolkit/components/extensions/ext-alarms.js index 7b387404194f..e466ee95d2d3 100644 --- a/toolkit/components/extensions/ext-alarms.js +++ b/toolkit/components/extensions/ext-alarms.js @@ -136,7 +136,7 @@ this.alarms = class extends ExtensionAPI { return Promise.resolve(cleared); }, - onAlarm: new EventManager(context, "alarms.onAlarm", fire => { + onAlarm: new SingletonEventManager(context, "alarms.onAlarm", fire => { let callback = alarm => { fire.sync(alarm.data); }; diff --git a/toolkit/components/extensions/ext-c-test.js b/toolkit/components/extensions/ext-c-test.js index 33601621338b..f63761d3d965 100644 --- a/toolkit/components/extensions/ext-c-test.js +++ b/toolkit/components/extensions/ext-c-test.js @@ -168,7 +168,7 @@ this.test = class extends ExtensionAPI { } }, - onMessage: new EventManager(context, "test.onMessage", fire => { + onMessage: new SingletonEventManager(context, "test.onMessage", fire => { let handler = (event, ...args) => { fire.async(...args); }; diff --git a/toolkit/components/extensions/ext-c-toolkit.js b/toolkit/components/extensions/ext-c-toolkit.js index c9cb5d5f4644..386a4410683f 100644 --- a/toolkit/components/extensions/ext-c-toolkit.js +++ b/toolkit/components/extensions/ext-c-toolkit.js @@ -4,10 +4,10 @@ Cu.import("resource://gre/modules/ExtensionCommon.jsm"); // These are defined on "global" which is used for the same scopes as the other // ext-c-*.js files. -/* exported EventManager */ -/* global EventManager: false */ +/* exported SingletonEventManager */ +/* global SingletonEventManager: false */ -global.EventManager = ExtensionCommon.EventManager; +global.SingletonEventManager = ExtensionCommon.SingletonEventManager; global.initializeBackgroundPage = (contentWindow) => { // Override the `alert()` method inside background windows; diff --git a/toolkit/components/extensions/ext-cookies.js b/toolkit/components/extensions/ext-cookies.js index 85f65ac47523..236485452f50 100644 --- a/toolkit/components/extensions/ext-cookies.js +++ b/toolkit/components/extensions/ext-cookies.js @@ -378,7 +378,7 @@ this.cookies = class extends ExtensionAPI { return Promise.resolve(result); }, - onChanged: new EventManager(context, "cookies.onChanged", fire => { + onChanged: new SingletonEventManager(context, "cookies.onChanged", fire => { let observer = (subject, topic, data) => { let notify = (removed, cookie, cause) => { cookie.QueryInterface(Ci.nsICookie2); diff --git a/toolkit/components/extensions/ext-downloads.js b/toolkit/components/extensions/ext-downloads.js index 0dac53668753..de2ad2d02302 100644 --- a/toolkit/components/extensions/ext-downloads.js +++ b/toolkit/components/extensions/ext-downloads.js @@ -738,7 +738,7 @@ this.downloads = class extends ExtensionAPI { // ... // } - onChanged: new EventManager(context, "downloads.onChanged", fire => { + onChanged: new SingletonEventManager(context, "downloads.onChanged", fire => { const handler = (what, item) => { let changes = {}; const noundef = val => (val === undefined) ? null : val; @@ -766,7 +766,7 @@ this.downloads = class extends ExtensionAPI { }; }).api(), - onCreated: new EventManager(context, "downloads.onCreated", fire => { + onCreated: new SingletonEventManager(context, "downloads.onCreated", fire => { const handler = (what, item) => { fire.async(item.serialize()); }; @@ -780,7 +780,7 @@ this.downloads = class extends ExtensionAPI { }; }).api(), - onErased: new EventManager(context, "downloads.onErased", fire => { + onErased: new SingletonEventManager(context, "downloads.onErased", fire => { const handler = (what, item) => { fire.async(item.id); }; diff --git a/toolkit/components/extensions/ext-idle.js b/toolkit/components/extensions/ext-idle.js index 32f4cd1309fb..c5ddeb7dd21c 100644 --- a/toolkit/components/extensions/ext-idle.js +++ b/toolkit/components/extensions/ext-idle.js @@ -76,7 +76,7 @@ this.idle = class extends ExtensionAPI { setDetectionInterval: function(detectionIntervalInSeconds) { setDetectionInterval(extension, context, detectionIntervalInSeconds); }, - onStateChanged: new EventManager(context, "idle.onStateChanged", fire => { + onStateChanged: new SingletonEventManager(context, "idle.onStateChanged", fire => { let listener = (event, data) => { fire.sync(data); }; diff --git a/toolkit/components/extensions/ext-management.js b/toolkit/components/extensions/ext-management.js index 0e46732b201d..6b79c4ba685f 100644 --- a/toolkit/components/extensions/ext-management.js +++ b/toolkit/components/extensions/ext-management.js @@ -224,7 +224,7 @@ this.management = class extends ExtensionAPI { addon.userDisabled = !enabled; }, - onDisabled: new EventManager(context, "management.onDisabled", fire => { + onDisabled: new SingletonEventManager(context, "management.onDisabled", fire => { let listener = (event, data) => { fire.async(data); }; @@ -235,7 +235,7 @@ this.management = class extends ExtensionAPI { }; }).api(), - onEnabled: new EventManager(context, "management.onEnabled", fire => { + onEnabled: new SingletonEventManager(context, "management.onEnabled", fire => { let listener = (event, data) => { fire.async(data); }; @@ -246,7 +246,7 @@ this.management = class extends ExtensionAPI { }; }).api(), - onInstalled: new EventManager(context, "management.onInstalled", fire => { + onInstalled: new SingletonEventManager(context, "management.onInstalled", fire => { let listener = (event, data) => { fire.async(data); }; @@ -257,7 +257,7 @@ this.management = class extends ExtensionAPI { }; }).api(), - onUninstalled: new EventManager(context, "management.onUninstalled", fire => { + onUninstalled: new SingletonEventManager(context, "management.onUninstalled", fire => { let listener = (event, data) => { fire.async(data); }; diff --git a/toolkit/components/extensions/ext-notifications.js b/toolkit/components/extensions/ext-notifications.js index 13d4309c04ad..b4032f531351 100644 --- a/toolkit/components/extensions/ext-notifications.js +++ b/toolkit/components/extensions/ext-notifications.js @@ -133,7 +133,7 @@ this.notifications = class extends ExtensionAPI { return Promise.resolve(result); }, - onClosed: new EventManager(context, "notifications.onClosed", fire => { + onClosed: new SingletonEventManager(context, "notifications.onClosed", fire => { let listener = (event, notificationId) => { // FIXME: Support the byUser argument. fire.async(notificationId, true); @@ -145,7 +145,7 @@ this.notifications = class extends ExtensionAPI { }; }).api(), - onClicked: new EventManager(context, "notifications.onClicked", fire => { + onClicked: new SingletonEventManager(context, "notifications.onClicked", fire => { let listener = (event, notificationId) => { fire.async(notificationId, true); }; diff --git a/toolkit/components/extensions/ext-proxy.js b/toolkit/components/extensions/ext-proxy.js index b698aef91ae2..45ed5003a2b3 100644 --- a/toolkit/components/extensions/ext-proxy.js +++ b/toolkit/components/extensions/ext-proxy.js @@ -52,7 +52,7 @@ this.proxy = class extends ExtensionAPI { this.register(url); }, - onProxyError: new EventManager(context, "proxy.onProxyError", fire => { + onProxyError: new SingletonEventManager(context, "proxy.onProxyError", fire => { let listener = (name, error) => { fire.async(error); }; diff --git a/toolkit/components/extensions/ext-runtime.js b/toolkit/components/extensions/ext-runtime.js index 71754febb2c3..3e9bf3b4205e 100644 --- a/toolkit/components/extensions/ext-runtime.js +++ b/toolkit/components/extensions/ext-runtime.js @@ -19,7 +19,7 @@ this.runtime = class extends ExtensionAPI { let {extension} = context; return { runtime: { - onStartup: new EventManager(context, "runtime.onStartup", fire => { + onStartup: new SingletonEventManager(context, "runtime.onStartup", fire => { if (context.incognito) { // This event should not fire if we are operating in a private profile. return () => {}; @@ -35,7 +35,7 @@ this.runtime = class extends ExtensionAPI { }; }).api(), - onInstalled: new EventManager(context, "runtime.onInstalled", fire => { + onInstalled: new SingletonEventManager(context, "runtime.onInstalled", fire => { let temporary = !!extension.addonData.temporarilyInstalled; let listener = () => { @@ -63,7 +63,7 @@ this.runtime = class extends ExtensionAPI { }; }).api(), - onUpdateAvailable: new EventManager(context, "runtime.onUpdateAvailable", fire => { + onUpdateAvailable: new SingletonEventManager(context, "runtime.onUpdateAvailable", fire => { let instanceID = extension.addonData.instanceID; AddonManager.addUpgradeListener(instanceID, upgrade => { extension.upgrade = upgrade; diff --git a/toolkit/components/extensions/ext-storage.js b/toolkit/components/extensions/ext-storage.js index 8092b3bbb37d..8dbed03b7012 100644 --- a/toolkit/components/extensions/ext-storage.js +++ b/toolkit/components/extensions/ext-storage.js @@ -63,7 +63,7 @@ this.storage = class extends ExtensionAPI { }, }, - onChanged: new EventManager(context, "storage.onChanged", fire => { + onChanged: new SingletonEventManager(context, "storage.onChanged", fire => { let listenerLocal = changes => { fire.async(changes, "local"); }; diff --git a/toolkit/components/extensions/ext-toolkit.js b/toolkit/components/extensions/ext-toolkit.js index e190ff40a729..6532885fe088 100644 --- a/toolkit/components/extensions/ext-toolkit.js +++ b/toolkit/components/extensions/ext-toolkit.js @@ -5,19 +5,19 @@ /* exported getCookieStoreIdForTab, getCookieStoreIdForContainer, getContainerForCookieStoreId, isValidCookieStoreId, isContainerCookieStoreId, - EventManager */ + SingletonEventManager */ /* global getCookieStoreIdForTab:false, getCookieStoreIdForContainer:false, getContainerForCookieStoreId: false, isValidCookieStoreId:false, isContainerCookieStoreId:false, isDefaultCookieStoreId: false, isPrivateCookieStoreId:false, - EventManager: false */ + SingletonEventManager: false */ XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService", "resource://gre/modules/ContextualIdentityService.jsm"); Cu.import("resource://gre/modules/ExtensionCommon.jsm"); -global.EventManager = ExtensionCommon.EventManager; +global.SingletonEventManager = ExtensionCommon.SingletonEventManager; /* globals DEFAULT_STORE, PRIVATE_STORE, CONTAINER_STORE */ diff --git a/toolkit/components/extensions/ext-webNavigation.js b/toolkit/components/extensions/ext-webNavigation.js index 11ba6dead942..d57f14df8426 100644 --- a/toolkit/components/extensions/ext-webNavigation.js +++ b/toolkit/components/extensions/ext-webNavigation.js @@ -144,10 +144,10 @@ function WebNavigationEventManager(context, eventName) { }; }; - return EventManager.call(this, context, name, register); + return SingletonEventManager.call(this, context, name, register); } -WebNavigationEventManager.prototype = Object.create(EventManager.prototype); +WebNavigationEventManager.prototype = Object.create(SingletonEventManager.prototype); const convertGetFrameResult = (tabId, data) => { return { @@ -165,7 +165,7 @@ this.webNavigation = class extends ExtensionAPI { return { webNavigation: { - onTabReplaced: new EventManager(context, "webNavigation.onTabReplaced", fire => { + onTabReplaced: new SingletonEventManager(context, "webNavigation.onTabReplaced", fire => { return () => {}; }).api(), onBeforeNavigate: new WebNavigationEventManager(context, "onBeforeNavigate").api(), diff --git a/toolkit/components/extensions/ext-webRequest.js b/toolkit/components/extensions/ext-webRequest.js index 25725737ff40..e8709f996abd 100644 --- a/toolkit/components/extensions/ext-webRequest.js +++ b/toolkit/components/extensions/ext-webRequest.js @@ -11,7 +11,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "WebRequest", "resource://gre/modules/WebRequest.jsm"); // EventManager-like class specifically for WebRequest. Inherits from -// EventManager. Takes care of converting |details| parameter +// SingletonEventManager. Takes care of converting |details| parameter // when invoking listeners. function WebRequestEventManager(context, eventName) { let name = `webRequest.${eventName}`; @@ -118,10 +118,10 @@ function WebRequestEventManager(context, eventName) { }; }; - return EventManager.call(this, context, name, register); + return SingletonEventManager.call(this, context, name, register); } -WebRequestEventManager.prototype = Object.create(EventManager.prototype); +WebRequestEventManager.prototype = Object.create(SingletonEventManager.prototype); this.webRequest = class extends ExtensionAPI { getAPI(context) { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contexts.js b/toolkit/components/extensions/test/xpcshell/test_ext_contexts.js index 86e2f31b506e..9e6870f2932f 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_contexts.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contexts.js @@ -8,7 +8,7 @@ Cu.import("resource://gre/modules/ExtensionCommon.jsm"); var { BaseContext, - EventManager, + SingletonEventManager, } = ExtensionCommon; class StubContext extends BaseContext { @@ -60,10 +60,10 @@ add_task(async function test_post_unload_promises() { add_task(async function test_post_unload_listeners() { let context = new StubContext(); - let fire; - let manager = new EventManager(context, "EventManager", _fire => { - fire = () => { - _fire.async(); + let fireSingleton; + let onSingleton = new SingletonEventManager(context, "onSingleton", fire => { + fireSingleton = () => { + fire.async(); }; return () => {}; }); @@ -73,17 +73,17 @@ add_task(async function test_post_unload_listeners() { }; // Check that event listeners isn't called after it has been removed. - manager.addListener(fail); + onSingleton.addListener(fail); - let promise = new Promise(resolve => manager.addListener(resolve)); + let promise = new Promise(resolve => onSingleton.addListener(resolve)); - fire(); + fireSingleton("onSingleton"); // The `fireSingleton` call ia dispatched asynchronously, so it won't // have fired by this point. The `fail` listener that we remove now // should not be called, even though the event has already been // enqueued. - manager.removeListener(fail); + onSingleton.removeListener(fail); // Wait for the remaining listener to be called, which should always // happen after the `fail` listener would normally be called. @@ -91,15 +91,15 @@ add_task(async function test_post_unload_listeners() { // Check that the event listener isn't called after the context has // unloaded. - manager.addListener(fail); + onSingleton.addListener(fail); // The `fire` callback always dispatches events // asynchronously, so we need to test that any pending event callbacks // aren't fired after the context unloads. We also need to test that // any `fire` calls that happen *after* the context is unloaded also // do not trigger callbacks. - fire(); - Promise.resolve().then(fire); + fireSingleton("onSingleton"); + Promise.resolve("onSingleton").then(fireSingleton); context.unload();