summaryrefslogtreecommitdiffstats
path: root/browser/components/extensions/parent/ext-search.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/extensions/parent/ext-search.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--browser/components/extensions/parent/ext-search.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/browser/components/extensions/parent/ext-search.js b/browser/components/extensions/parent/ext-search.js
new file mode 100644
index 0000000000..fe600ca900
--- /dev/null
+++ b/browser/components/extensions/parent/ext-search.js
@@ -0,0 +1,76 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+
+"use strict";
+
+var { ExtensionError } = ExtensionUtils;
+
+this.search = class extends ExtensionAPI {
+ getAPI(context) {
+ return {
+ search: {
+ async get() {
+ await searchInitialized;
+ let visibleEngines = await Services.search.getVisibleEngines();
+ let defaultEngine = await Services.search.getDefault();
+ return Promise.all(
+ visibleEngines.map(async engine => {
+ let favIconUrl;
+ if (engine.iconURI) {
+ // Convert moz-extension:-URLs to data:-URLs to make sure that
+ // extensions can see icons from other extensions, even if they
+ // are not web-accessible.
+ // Also prevents leakage of extension UUIDs to other extensions..
+ if (
+ engine.iconURI.schemeIs("moz-extension") &&
+ engine.iconURI.host !== context.extension.uuid
+ ) {
+ favIconUrl = await ExtensionUtils.makeDataURI(
+ engine.iconURI.spec
+ );
+ } else {
+ favIconUrl = engine.iconURI.spec;
+ }
+ }
+
+ return {
+ name: engine.name,
+ isDefault: engine.name === defaultEngine.name,
+ alias: engine.alias || undefined,
+ favIconUrl,
+ };
+ })
+ );
+ },
+
+ async search(searchProperties) {
+ await searchInitialized;
+ let engine;
+ if (searchProperties.engine) {
+ engine = Services.search.getEngineByName(searchProperties.engine);
+ if (!engine) {
+ throw new ExtensionError(
+ `${searchProperties.engine} was not found`
+ );
+ }
+ }
+
+ const tab = searchProperties.tabId
+ ? tabTracker.getTab(searchProperties.tabId)
+ : null;
+
+ await windowTracker.topWindow.BrowserSearch.loadSearchFromExtension(
+ searchProperties.query,
+ engine,
+ tab,
+ context.principal
+ );
+ },
+ },
+ };
+ }
+};