commit 46633f5e2c5cf65cc610bd0c7b433adf0de8beb7
parent 30cf57717aec3d6a6a90001432910d2361a8fc01
Author: Moritz Beier <mbeier@mozilla.com>
Date: Thu, 4 Dec 2025 09:25:45 +0000
Bug 2003799 - Ignore keyword.enabled in new searchbar. r=dao,urlbar-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D274928
Diffstat:
6 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/browser/components/urlbar/SearchModeSwitcher.sys.mjs b/browser/components/urlbar/SearchModeSwitcher.sys.mjs
@@ -292,7 +292,11 @@ export class SearchModeSwitcher {
const inSearchMode = this.#input.searchMode;
if (!lazy.UrlbarPrefs.get("unifiedSearchButton.always")) {
const keywordEnabled = lazy.UrlbarPrefs.get("keyword.enabled");
- if (!keywordEnabled && !inSearchMode) {
+ if (
+ this.#input.sapName != "searchbar" &&
+ !keywordEnabled &&
+ !inSearchMode
+ ) {
icon = SearchModeSwitcher.DEFAULT_ICON_KEYWORD_DISABLED;
}
} else if (!inSearchMode) {
diff --git a/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs b/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs
@@ -106,6 +106,7 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider {
}
if (
+ queryContext.sapName == "searchbar" ||
lazy.UrlbarPrefs.get("keyword.enabled") ||
queryContext.restrictSource == UrlbarUtils.RESULT_SOURCE.SEARCH ||
queryContext.searchMode
diff --git a/browser/components/urlbar/UrlbarUtils.sys.mjs b/browser/components/urlbar/UrlbarUtils.sys.mjs
@@ -2634,7 +2634,12 @@ export class UrlbarQueryContext {
// Disallow remote results for strings containing tokens that look like URIs
// to avoid disclosing information about networks and passwords.
- if (this.fixupInfo?.href && !this.fixupInfo?.isSearch) {
+ // (Unless the search is happening in the searchbar.)
+ if (
+ this.sapName != "searchbar" &&
+ this.fixupInfo?.href &&
+ !this.fixupInfo?.isSearch
+ ) {
return false;
}
diff --git a/browser/components/urlbar/tests/unit/test_UrlbarProviderSearchSuggestions.js b/browser/components/urlbar/tests/unit/test_UrlbarProviderSearchSuggestions.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+https://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const { UrlbarProviderSearchSuggestions } = ChromeUtils.importESModule(
+ "moz-src:///browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs"
+);
+
+const KEYWORD_ENABLED = "keyword.enabled";
+
+add_setup(async function () {
+ await Services.search.init();
+});
+
+add_task(async function test_allowRemoteSuggestions() {
+ let suggestionsProvider = new UrlbarProviderSearchSuggestions();
+
+ let context = createContext("bacon", {
+ isPrivate: false,
+ sapName: "urlbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ suggestionsProvider._allowRemoteSuggestions(context),
+ "Remote suggestions should be enabled with keyword enabled"
+ );
+
+ info("Setting " + KEYWORD_ENABLED + "=false");
+ Services.prefs.setBoolPref(KEYWORD_ENABLED, false);
+
+ context = createContext("bacon", {
+ isPrivate: false,
+ sapName: "urlbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ !suggestionsProvider._allowRemoteSuggestions(context),
+ "Remote suggestions should be disabled with keyword disabled"
+ );
+
+ context = createContext("bacon", {
+ isPrivate: false,
+ sapName: "searchbar",
+ sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
+ });
+ Assert.ok(
+ suggestionsProvider._allowRemoteSuggestions(context),
+ "Remote suggestions should still be enabled on searchbar"
+ );
+
+ Services.prefs.clearUserPref(KEYWORD_ENABLED);
+});
diff --git a/browser/components/urlbar/tests/unit/test_providerHeuristicFallback.js b/browser/components/urlbar/tests/unit/test_providerHeuristicFallback.js
@@ -390,6 +390,23 @@ add_task(async function () {
],
});
+ info("Forced search through searchbar, keyword.enabled = false");
+ query = "bacon";
+ context = createContext(query, {
+ isPrivate: false,
+ sapName: "searchbar",
+ });
+ await check_results({
+ context,
+ matches: [
+ makeSearchResult(context, {
+ engineName: SUGGESTIONS_ENGINE_NAME,
+ heuristic: true,
+ query: "bacon",
+ }),
+ ],
+ });
+
info("Non-search restriction token and invalid URL, keyword.enabled = false");
query = "bacon *";
context = createContext(query, { isPrivate: false });
diff --git a/browser/components/urlbar/tests/unit/xpcshell.toml b/browser/components/urlbar/tests/unit/xpcshell.toml
@@ -16,6 +16,8 @@ support-files = ["data/engine.xml"]
["test_UrlbarPrefs.js"]
+["test_UrlbarProviderSearchSuggestions.js"]
+
["test_UrlbarProviderSemanticHistorySearch.js"]
["test_UrlbarQueryContext.js"]