Bug 1790673 - Add pref to disable open in Private Search urlbar result. r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D157238
This commit is contained in:
Dale Harvey 2022-09-14 10:25:46 +00:00
Родитель 2ee22045da
Коммит adea50e5d0
5 изменённых файлов: 35 добавлений и 4 удалений

Просмотреть файл

@ -1083,10 +1083,11 @@ class MuxerUnifiedComplete extends UrlbarMuxer {
// are other results and all of them are searches. It should not be shown
// if the user typed an alias because that's an explicit engine choice.
if (
state.canShowPrivateSearch &&
(result.type != UrlbarUtils.RESULT_TYPE.SEARCH ||
result.payload.providesSearchMode ||
(result.heuristic && result.payload.keyword))
!Services.search.separatePrivateDefaultUrlbarResultEnabled ||
(state.canShowPrivateSearch &&
(result.type != UrlbarUtils.RESULT_TYPE.SEARCH ||
result.payload.providesSearchMode ||
(result.heuristic && result.payload.keyword)))
) {
state.canShowPrivateSearch = false;
}

Просмотреть файл

@ -17,6 +17,7 @@ add_setup(async function() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.search.separatePrivateDefault.ui.enabled", true],
["browser.search.separatePrivateDefault.urlbarResult.enabled", true],
["browser.search.separatePrivateDefault", true],
["browser.urlbar.suggest.searches", true],
],
@ -117,6 +118,21 @@ add_task(async function test_search() {
await AssertPrivateResult(window, await Services.search.getDefault(), false);
});
add_task(async function test_search_urlbar_result_disabled() {
info("Test that 'Search in a Private Window' does not appear when disabled");
await SpecialPowers.pushPrefEnv({
set: [
["browser.search.separatePrivateDefault.urlbarResult.enabled", false],
],
});
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: "unique198273982173",
});
await AssertNoPrivateResult(window);
await SpecialPowers.popPrefEnv();
});
add_task(async function test_search_disabled_suggestions() {
info(
"Test that 'Search in a Private Window' appears if suggestions are disabled"

Просмотреть файл

@ -18,6 +18,7 @@ add_setup(async function() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.search.separatePrivateDefault.ui.enabled", true],
["browser.search.separatePrivateDefault.urlbarResult.enabled", true],
["browser.search.separatePrivateDefault", true],
["browser.urlbar.suggest.searches", true],
],

Просмотреть файл

@ -1243,6 +1243,14 @@ export class SearchService {
this.#onSeparateDefaultPrefChanged.bind(this)
);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"separatePrivateDefaultUrlbarResultEnabled",
lazy.SearchUtils.BROWSER_SEARCH_PREF +
"separatePrivateDefault.urlbarResult.enabled",
false
);
// We need to catch the region being updated
// during initialisation so we start listening
// straight away.

Просмотреть файл

@ -473,6 +473,11 @@ interface nsISearchService : nsISupports
Promise getDefaultPrivate();
Promise setDefaultPrivate(in nsISearchEngine engine);
/**
* Whether to display the "Search in Private Window" result in the urlbar.
*/
readonly attribute boolean separatePrivateDefaultUrlbarResultEnabled;
/**
* Allows the add-on manager to discover if a WebExtension based search engine
* may change the default to an application provided search engine.