[tbb-commits] [Git][tpo/applications/tor-browser][base-browser-115.2.0esr-13.0-1] 2 commits: Revert "Bug 42022: Prevent extension search engines from breaking the whole search system"

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Tue Sep 12 13:02:18 UTC 2023



Pier Angelo Vendrame pushed to branch base-browser-115.2.0esr-13.0-1 at The Tor Project / Applications / Tor Browser


Commits:
a4d48a95 by Pier Angelo Vendrame at 2023-09-12T15:02:03+02:00
Revert "Bug 42022: Prevent extension search engines from breaking the whole search system"

This reverts commit 9d7a9a7969394bc9503cc22ad9324666ca72cecc.

- - - - -
92026016 by Pier Angelo Vendrame at 2023-09-12T15:02:04+02:00
Bug 1849129: Prevent exceptions caused by extensions from interrupting the SearchService initialization. r=search-reviewers,Standard8

Differential Revision: https://phabricator.services.mozilla.com/D186456
- - - - -


3 changed files:

- toolkit/components/search/SearchService.sys.mjs
- + toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js
- toolkit/components/search/tests/xpcshell/xpcshell.ini


Changes:

=====================================
toolkit/components/search/SearchService.sys.mjs
=====================================
@@ -1574,11 +1574,18 @@ export class SearchService {
       "engines reported by AddonManager startup"
     );
     for (let extension of this.#startupExtensions) {
-      await this.#installExtensionEngine(
-        extension,
-        [lazy.SearchUtils.DEFAULT_TAG],
-        true
-      );
+      try {
+        await this.#installExtensionEngine(
+          extension,
+          [lazy.SearchUtils.DEFAULT_TAG],
+          true
+        );
+      } catch (ex) {
+        lazy.logConsole.error(
+          `#installExtensionEngine failed for ${extension.id}`,
+          ex
+        );
+      }
     }
     this.#startupExtensions.clear();
 
@@ -2715,7 +2722,6 @@ export class SearchService {
     };
 
     let engines = [];
-    let revert = false;
     for (let locale of locales) {
       lazy.logConsole.debug(
         "addEnginesFromExtension: installing:",
@@ -2723,28 +2729,7 @@ export class SearchService {
         ":",
         locale
       );
-      try {
-        engines.push(await installLocale(locale));
-      } catch (err) {
-        lazy.logConsole.error(
-          `Could not install the search engine of ${extension.id}`,
-          err
-        );
-        revert = true;
-        break;
-      }
-    }
-    if (revert) {
-      for (let engine of engines) {
-        try {
-          this.removeEngine(engine);
-        } catch (err) {
-          lazy.logConsole.warn(
-            "Failed to revert the addition of a search engine",
-            err
-          );
-        }
-      }
+      engines.push(await installLocale(locale));
     }
     return engines;
   }


=====================================
toolkit/components/search/tests/xpcshell/test_webextensions_startup_duplicate.js
=====================================
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const lazy = {};
+
+const { promiseShutdownManager, promiseStartupManager } = AddonTestUtils;
+
+ChromeUtils.defineESModuleGetters(lazy, {
+  ExtensionTestUtils:
+    "resource://testing-common/ExtensionXPCShellUtils.sys.mjs",
+});
+
+add_setup(async function () {
+  let server = useHttpServer();
+  server.registerContentType("sjs", "sjs");
+  await SearchTestUtils.useTestEngines("test-extensions");
+  await promiseStartupManager();
+
+  registerCleanupFunction(async () => {
+    await promiseShutdownManager();
+  });
+});
+
+add_task(async function test_install_duplicate_engine_startup() {
+  let name = "Plain";
+  let id = "plain at tests.mozilla.org";
+  consoleAllowList.push(
+    `#installExtensionEngine failed for ${id}`,
+    `An engine called ${name} already exists`
+  );
+  // Do not use SearchTestUtils.installSearchExtension, as we need to manually
+  // start the search service after installing the extension.
+  let extensionInfo = {
+    useAddonManager: "permanent",
+    files: {},
+    manifest: SearchTestUtils.createEngineManifest({
+      name,
+      search_url: "https://example.com/plain",
+    }),
+  };
+
+  let extension = lazy.ExtensionTestUtils.loadExtension(extensionInfo);
+  await extension.startup();
+
+  await Services.search.init();
+
+  await AddonTestUtils.waitForSearchProviderStartup(extension);
+  let engine = await Services.search.getEngineByName(name);
+  let submission = engine.getSubmission("foo");
+  Assert.equal(
+    submission.uri.spec,
+    "https://duckduckgo.com/?q=foo&t=ffsb",
+    "Should have not changed the app provided engine."
+  );
+
+  await extension.unload();
+});


=====================================
toolkit/components/search/tests/xpcshell/xpcshell.ini
=====================================
@@ -191,6 +191,7 @@ support-files = data/search_ignorelist.json
 [test_webextensions_migrate_to.js]
 support-files = data/search-migration.json
 [test_webextensions_normandy_upgrade.js]
+[test_webextensions_startup_duplicate.js]
 [test_webextensions_startup_remove.js]
 [test_webextensions_upgrade.js]
 [test_webextensions_valid.js]



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/44ffc800c98607bf7652b1e56f765e925b47f9dd...920260162c614477f80fce6d0bfe96830a3ebc51

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/44ffc800c98607bf7652b1e56f765e925b47f9dd...920260162c614477f80fce6d0bfe96830a3ebc51
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20230912/55523c0e/attachment-0001.htm>


More information about the tbb-commits mailing list