Skip to content

Commit ac9c851

Browse files
committed
Bug 2055614 - SearchEngines.PreventInstalls should suppress OpenSearch add-engine offers instead of blocking discovery. r=Standard8,urlbar-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D313575
1 parent 5c8739d commit ac9c851

5 files changed

Lines changed: 31 additions & 7 deletions

File tree

‎browser/actors/LinkHandlerChild.sys.mjs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ export class LinkHandlerChild extends JSWindowActorChild {
129129
}
130130
break;
131131
case "search":
132-
if (!Services.policies.isAllowed("installSearchEngine")) {
133-
break;
134-
}
135-
136132
if (!searchAdded && event.type == "DOMLinkAdded") {
137133
let type = link.type && link.type.toLowerCase();
138134
type = type.replace(/^\s+|\s*(?:;.*)?$/g, "");

‎browser/components/enterprisepolicies/tests/browser/browser_policy_search_engine.js‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
ChromeUtils.defineESModuleGetters(this, {
66
CustomizableUITestUtils:
77
"resource://testing-common/CustomizableUITestUtils.sys.mjs",
8+
OpenSearchManager:
9+
"moz-src:///browser/components/search/OpenSearchManager.sys.mjs",
810
SearchbarTestUtils: "resource://testing-common/UrlbarTestUtils.sys.mjs",
911
});
1012

@@ -40,6 +42,14 @@ async function test_opensearch(shouldWork) {
4042
null,
4143
"There should be no search engines available to add"
4244
);
45+
// The engine is still discovered so it remains usable for a one-off
46+
// contextual search; only installing it is prevented.
47+
ok(
48+
OpenSearchManager.getEngines(tab.linkedBrowser).some(
49+
e => e.title == "newEngine"
50+
),
51+
"The engine is still discovered for contextual search"
52+
);
4353
}
4454
popup.hide();
4555
await BrowserTestUtils.removeTab(tab);

‎browser/components/search/OpenSearchManager.sys.mjs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class _OpenSearchManager {
134134
* The window whose UI should be updated.
135135
*/
136136
updateOpenSearchBadge(win) {
137-
let engines = this.#offeredEngines.get(win.gBrowser.selectedBrowser);
137+
let engines = this.getInstallableEngines(win.gBrowser.selectedBrowser);
138138
for (let urlbar of /** @type {NodeListOf<UrlbarInput>} */ (
139139
win.document.querySelectorAll("moz-urlbar")
140140
)) {
@@ -224,6 +224,24 @@ class _OpenSearchManager {
224224
return this.#offeredEngines.get(browser) || [];
225225
}
226226

227+
/**
228+
* Get the open search engines offered by a browser that the user is allowed
229+
* to install. Returns an empty list when the installSearchEngine policy
230+
* disallows installing engines, even though the engines remain available for
231+
* one-off searches (e.g. contextual search).
232+
*
233+
* @param {MozBrowser} browser
234+
* The browser for which to get the engines.
235+
* @returns {OpenSearchData[]}
236+
* The installable open search engines.
237+
*/
238+
getInstallableEngines(browser) {
239+
if (!Services.policies.isAllowed("installSearchEngine")) {
240+
return [];
241+
}
242+
return this.getEngines(browser);
243+
}
244+
227245
clearEngines(browser) {
228246
this.#offeredEngines.delete(browser);
229247
this.#hiddenEngines.delete(browser);

‎browser/components/search/SearchOneOffs.sys.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ export class SearchOneOffs {
440440
return;
441441
}
442442

443-
const addEngines = lazy.OpenSearchManager.getEngines(
443+
const addEngines = lazy.OpenSearchManager.getInstallableEngines(
444444
this.window.gBrowser.selectedBrowser
445445
);
446446

‎browser/components/urlbar/content/SearchModeSwitcher.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ export class SearchModeSwitcher {
619619
this.#buildSettingsButton();
620620

621621
// Add engines that can be installed.
622-
let openSearchEngines = lazy.OpenSearchManager.getEngines(
622+
let openSearchEngines = lazy.OpenSearchManager.getInstallableEngines(
623623
browser.selectedBrowser
624624
);
625625
openSearchEngines = openSearchEngines.slice(

0 commit comments

Comments
 (0)