From e1715d6268266220630b564abad73bdc1923be81 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Fri, 5 Nov 2021 20:27:03 +0000 Subject: [PATCH] Bug 1728326 - Rename internal WebExtensions events related to the background script (from background-page into background-script). r=zombie Differential Revision: https://phabricator.services.mozilla.com/D124783 --- .../components/extensions/ExtensionCommon.jsm | 2 +- .../extensions/parent/ext-backgroundPage.js | 28 +++++++++---------- .../extensions/parent/ext-runtime.js | 8 +++--- .../test_ext_background_early_shutdown.js | 20 ++++++++----- .../test_ext_background_service_worker.js | 2 +- .../xpcshell/test_ext_messaging_startup.js | 24 ++++++++-------- .../xpcshell/test_ext_persistent_events.js | 2 +- .../test/xpcshell/test_ext_proxy_startup.js | 20 ++++++------- .../xpcshell/test_ext_webRequest_startup.js | 14 +++++----- 9 files changed, 62 insertions(+), 58 deletions(-) diff --git a/toolkit/components/extensions/ExtensionCommon.jsm b/toolkit/components/extensions/ExtensionCommon.jsm index 5a19ae9904f3..3c701ff4c6e0 100644 --- a/toolkit/components/extensions/ExtensionCommon.jsm +++ b/toolkit/components/extensions/ExtensionCommon.jsm @@ -2293,7 +2293,7 @@ class EventManager { return; } primed.pendingEvents.push({ args, resolve, reject }); - extension.emit("background-page-event"); + extension.emit("background-script-event"); }); let fire = { diff --git a/toolkit/components/extensions/parent/ext-backgroundPage.js b/toolkit/components/extensions/parent/ext-backgroundPage.js index cf8f4dc876be..8045257ab5a9 100644 --- a/toolkit/components/extensions/parent/ext-backgroundPage.js +++ b/toolkit/components/extensions/parent/ext-backgroundPage.js @@ -83,7 +83,7 @@ class BackgroundPage extends HiddenExtensionPage { if (extension.persistentListeners) { EventManager.clearPrimedListeners(this.extension, false); } - extension.emit("background-page-aborted"); + extension.emit("background-script-aborted"); return; } @@ -103,7 +103,7 @@ class BackgroundPage extends HiddenExtensionPage { EventManager.clearPrimedListeners(extension, !!this.extension); } - extension.emit("background-page-started"); + extension.emit("background-script-started"); } shutdown() { @@ -175,8 +175,7 @@ class BackgroundWorker { EventManager.clearPrimedListeners(this.extension, false); } - // TODO(bug 17228326): rename this to "background-script-aborted". - extension.emit("background-page-aborted"); + extension.emit("background-script-aborted"); return; } @@ -194,8 +193,7 @@ class BackgroundWorker { EventManager.clearPrimedListeners(extension, !!this.extension); } - // TODO(bug 17228326): rename this to "background-script-started". - extension.emit("background-page-started"); + extension.emit("background-script-started"); } shutdown(isAppShutdown) { @@ -286,18 +284,18 @@ this.backgroundPage = class extends ExtensionAPI { // Used by runtime messaging to wait for background page listeners. let bgStartupPromise = new Promise(resolve => { let done = () => { - extension.off("background-page-started", done); - extension.off("background-page-aborted", done); + extension.off("background-script-started", done); + extension.off("background-script-aborted", done); extension.off("shutdown", done); resolve(); }; - extension.on("background-page-started", done); - extension.on("background-page-aborted", done); + extension.on("background-script-started", done); + extension.on("background-script-aborted", done); extension.on("shutdown", done); }); extension.wakeupBackground = () => { - extension.emit("background-page-event"); + extension.emit("background-script-event"); extension.wakeupBackground = () => bgStartupPromise; return bgStartupPromise; }; @@ -308,7 +306,7 @@ this.backgroundPage = class extends ExtensionAPI { EventManager.primeListeners(extension); - extension.once("start-background-page", async () => { + extension.once("start-background-script", async () => { if (!this.extension) { // Extension was shut down. Don't build the background page. // Primed listeners have been cleared in onShutdown. @@ -324,13 +322,13 @@ this.backgroundPage = class extends ExtensionAPI { // or else we can miss it if the event occurs after the first // window is painted but before #2 // 2. After all windows have been restored. - extension.once("background-page-event", async () => { + extension.once("background-script-event", async () => { await ExtensionParent.browserPaintedPromise; - extension.emit("start-background-page"); + extension.emit("start-background-script"); }); ExtensionParent.browserStartupPromise.then(() => { - extension.emit("start-background-page"); + extension.emit("start-background-script"); }); } diff --git a/toolkit/components/extensions/parent/ext-runtime.js b/toolkit/components/extensions/parent/ext-runtime.js index 725abbd4715f..e148f4095d5e 100644 --- a/toolkit/components/extensions/parent/ext-runtime.js +++ b/toolkit/components/extensions/parent/ext-runtime.js @@ -38,9 +38,9 @@ this.runtime = class extends ExtensionAPI { return () => {}; } let listener = () => fire.sync(); - extension.on("background-page-started", listener); + extension.on("background-script-started", listener); return () => { - extension.off("background-page-started", listener); + extension.off("background-script-started", listener); }; }, }).api(), @@ -70,9 +70,9 @@ this.runtime = class extends ExtensionAPI { break; } }; - extension.on("background-page-started", listener); + extension.on("background-script-started", listener); return () => { - extension.off("background-page-started", listener); + extension.off("background-script-started", listener); }; }, }).api(), diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js b/toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js index 5077c5dc2859..67019e907dc9 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js @@ -125,19 +125,25 @@ add_task(async function test_unload_extension_during_background_page_startup() { let bgStartupPromise = new Promise(resolve => { function onBackgroundPageDone(eventName) { - extension.extension.off("background-page-started", onBackgroundPageDone); - extension.extension.off("background-page-aborted", onBackgroundPageDone); + extension.extension.off( + "background-script-started", + onBackgroundPageDone + ); + extension.extension.off( + "background-script-aborted", + onBackgroundPageDone + ); - if (eventName === "background-page-aborted") { - info("Background page startup was interrupted"); + if (eventName === "background-script-aborted") { + info("Background script startup was interrupted"); resolve("bg_aborted"); } else { - info("Background page startup finished normally"); + info("Background script startup finished normally"); resolve("bg_fully_loaded"); } } - extension.extension.on("background-page-started", onBackgroundPageDone); - extension.extension.on("background-page-aborted", onBackgroundPageDone); + extension.extension.on("background-script-started", onBackgroundPageDone); + extension.extension.on("background-script-aborted", onBackgroundPageDone); }); let bgStartingPromise = new Promise(resolve => { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_background_service_worker.js b/toolkit/components/extensions/test/xpcshell/test_ext_background_service_worker.js index d7163ea07d8f..0e8bf8b4f8a6 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_background_service_worker.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_service_worker.js @@ -418,7 +418,7 @@ add_task(async function test_serviceworker_lifecycle_events() { info( "trigger delayed call to nsIServiceWorkerManager.registerForAddonPrincipal" ); - extension.extension.emit("start-background-page"); + extension.extension.emit("start-background-script"); info("Force activate the extension worker"); const newSwReg = swm.getRegistrationByPrincipal( diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_messaging_startup.js b/toolkit/components/extensions/test/xpcshell/test_ext_messaging_startup.js index c629c51509da..5d5a4adb7043 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_messaging_startup.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_messaging_startup.js @@ -27,7 +27,7 @@ const PAGE_HTML = `