summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:21:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 05:21:19 +0000
commit520a92573ce79e3628762e4ce06e284d50c2e548 (patch)
treedd7bece82fdce266f06a6a2a6043264255631ee7 /toolkit/components/extensions
parentAdding debian version 115.10.0esr-1~deb12u1. (diff)
downloadfirefox-esr-520a92573ce79e3628762e4ce06e284d50c2e548.tar.xz
firefox-esr-520a92573ce79e3628762e4ce06e284d50c2e548.zip
Merging upstream version 115.11.0esr.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions')
-rw-r--r--toolkit/components/extensions/Extension.sys.mjs3
-rw-r--r--toolkit/components/extensions/parent/ext-backgroundPage.js4
-rw-r--r--toolkit/components/extensions/parent/ext-runtime.js7
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js81
-rw-r--r--toolkit/components/extensions/test/xpcshell/xpcshell-common.ini1
5 files changed, 92 insertions, 4 deletions
diff --git a/toolkit/components/extensions/Extension.sys.mjs b/toolkit/components/extensions/Extension.sys.mjs
index caff299eb6..e773745c65 100644
--- a/toolkit/components/extensions/Extension.sys.mjs
+++ b/toolkit/components/extensions/Extension.sys.mjs
@@ -1224,7 +1224,8 @@ export class ExtensionData {
let { manifest } = this;
if (
!manifest.background ||
- manifest.background.service_worker ||
+ (manifest.background.service_worker &&
+ WebExtensionPolicy.backgroundServiceWorkerEnabled) ||
this.manifestVersion > 2
) {
return false;
diff --git a/toolkit/components/extensions/parent/ext-backgroundPage.js b/toolkit/components/extensions/parent/ext-backgroundPage.js
index 725be65122..568d049b9d 100644
--- a/toolkit/components/extensions/parent/ext-backgroundPage.js
+++ b/toolkit/components/extensions/parent/ext-backgroundPage.js
@@ -264,7 +264,9 @@ this.backgroundPage = class extends ExtensionAPI {
let { manifest } = extension;
extension.backgroundState = BACKGROUND_STATE.STARTING;
- this.isWorker = Boolean(manifest.background.service_worker);
+ this.isWorker =
+ !!manifest.background.service_worker &&
+ WebExtensionPolicy.backgroundServiceWorkerEnabled;
let BackgroundClass = this.isWorker ? BackgroundWorker : BackgroundPage;
diff --git a/toolkit/components/extensions/parent/ext-runtime.js b/toolkit/components/extensions/parent/ext-runtime.js
index cd18e0f0aa..2122e8faed 100644
--- a/toolkit/components/extensions/parent/ext-runtime.js
+++ b/toolkit/components/extensions/parent/ext-runtime.js
@@ -237,9 +237,12 @@ this.runtime = class extends ExtensionAPIPersistent {
},
async internalWakeupBackground() {
+ const { background } = extension.manifest;
if (
- extension.manifest.background &&
- !extension.manifest.background.service_worker &&
+ background &&
+ (background.page || background.scripts) &&
+ // Note: if background.service_worker is specified, it takes
+ // precedence over page/scripts, and persistentBackground is false.
!extension.persistentBackground
) {
await extension.wakeupBackground();
diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js b/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js
new file mode 100644
index 0000000000..fc59b1810d
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_background_script_and_service_worker.js
@@ -0,0 +1,81 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+async function testExtensionWithBackground({
+ with_scripts = false,
+ with_service_worker = false,
+ with_page = false,
+ expected_background_type,
+ expected_manifest_warnings = [],
+}) {
+ let background = {};
+ if (with_scripts) {
+ background.scripts = ["scripts.js"];
+ }
+ if (with_service_worker) {
+ background.service_worker = "sw.js";
+ }
+ if (with_page) {
+ background.page = "page.html";
+ }
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: { background },
+ files: {
+ "scripts.js": () => {
+ browser.test.sendMessage("from_bg", "scripts");
+ },
+ "sw.js": () => {
+ browser.test.sendMessage("from_bg", "service_worker");
+ },
+ "page.html": `<!DOCTYPE html><script src="page.js"></script>`,
+ "page.js": () => {
+ browser.test.sendMessage("from_bg", "page");
+ },
+ },
+ });
+ ExtensionTestUtils.failOnSchemaWarnings(false);
+ await extension.startup();
+ ExtensionTestUtils.failOnSchemaWarnings(true);
+ Assert.deepEqual(
+ extension.extension.warnings,
+ expected_manifest_warnings,
+ "Expected manifest warnings"
+ );
+ info("Waiting for background to start");
+ Assert.equal(
+ await extension.awaitMessage("from_bg"),
+ expected_background_type,
+ "Expected background type"
+ );
+ await extension.unload();
+}
+
+add_task(async function test_page_and_scripts() {
+ await testExtensionWithBackground({
+ with_page: true,
+ with_scripts: true,
+ // Should be expected_background_type: "scripts", not "page".
+ // https://github.com/w3c/webextensions/issues/282#issuecomment-1443332913
+ // ... but changing that may potentially affect backcompat of existing
+ // Firefox add-ons.
+ expected_background_type: "page",
+ expected_manifest_warnings: [
+ "Reading manifest: Warning processing background.scripts: An unexpected property was found in the WebExtension manifest.",
+ ],
+ });
+});
+
+add_task(
+ { skip_if: () => WebExtensionPolicy.backgroundServiceWorkerEnabled },
+ async function test_scripts_and_service_worker_when_sw_disabled() {
+ await testExtensionWithBackground({
+ with_scripts: true,
+ with_service_worker: true,
+ expected_background_type: "scripts",
+ expected_manifest_warnings: [
+ "Reading manifest: Warning processing background.service_worker: An unexpected property was found in the WebExtension manifest.",
+ ],
+ });
+ }
+);
diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
index f76456124d..81beee5810 100644
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -25,6 +25,7 @@ skip-if = os == "android" # Bug 1700482
skip-if = os == "android" # Android does not use Places for history.
[test_ext_background_private_browsing.js]
[test_ext_background_runtime_connect_params.js]
+[test_ext_background_script_and_service_worker.js]
[test_ext_background_sub_windows.js]
[test_ext_background_teardown.js]
[test_ext_background_telemetry.js]