forked from mirrors/gecko-dev
Bug 1792816 - Always update the search engine placeholder name. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D165795
This commit is contained in:
parent
b93fcda801
commit
6b81196ea8
3 changed files with 63 additions and 7 deletions
|
|
@ -42,6 +42,7 @@ ChromeUtils.defineESModuleGetters(this, {
|
|||
PromptUtils: "resource://gre/modules/PromptUtils.sys.mjs",
|
||||
Sanitizer: "resource:///modules/Sanitizer.sys.mjs",
|
||||
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
|
||||
SearchUIUtils: "resource:///modules/SearchUIUtils.sys.mjs",
|
||||
SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
|
||||
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
|
||||
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
|
||||
|
|
@ -1970,6 +1971,7 @@ var gBrowserInit = {
|
|||
|
||||
BookmarkingUI.init();
|
||||
BrowserSearch.delayedStartupInit();
|
||||
SearchUIUtils.init();
|
||||
gProtectionsHandler.init();
|
||||
HomePage.delayedStartup().catch(console.error);
|
||||
|
||||
|
|
@ -3971,7 +3973,11 @@ const BrowserSearch = {
|
|||
? Services.search.getDefaultPrivate
|
||||
: Services.search.getDefault;
|
||||
let defaultEngine = await getDefault();
|
||||
|
||||
if (!this._searchInitComplete) {
|
||||
// If we haven't finished initialising, ensure the placeholder
|
||||
// preference is set for the next startup.
|
||||
SearchUIUtils.updatePlaceholderNamePreference(defaultEngine, isPrivate);
|
||||
}
|
||||
this._updateURLBarPlaceholder(defaultEngine.name, isPrivate, delayUpdate);
|
||||
},
|
||||
|
||||
|
|
@ -3994,12 +4000,7 @@ const BrowserSearch = {
|
|||
}
|
||||
|
||||
const engine = Services.search.getEngineByName(engineName);
|
||||
const prefName =
|
||||
"browser.urlbar.placeholderName" + (isPrivate ? ".private" : "");
|
||||
if (engine.isAppProvided) {
|
||||
Services.prefs.setStringPref(prefName, engineName);
|
||||
} else {
|
||||
Services.prefs.clearUserPref(prefName);
|
||||
if (!engine.isAppProvided) {
|
||||
// Set the engine name to an empty string for non-default engines, which'll
|
||||
// make sure we display the default placeholder string.
|
||||
engineName = "";
|
||||
|
|
|
|||
|
|
@ -15,6 +15,27 @@ XPCOMUtils.defineLazyGetter(lazy, "SearchUIUtilsL10n", () => {
|
|||
});
|
||||
|
||||
export var SearchUIUtils = {
|
||||
initialized: false,
|
||||
|
||||
init() {
|
||||
if (!this.initialized) {
|
||||
Services.obs.addObserver(this, "browser-search-engine-modified");
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
},
|
||||
|
||||
observe(engine, topic, data) {
|
||||
switch (data) {
|
||||
case "engine-default":
|
||||
this.updatePlaceholderNamePreference(engine, false);
|
||||
break;
|
||||
case "engine-default-private":
|
||||
this.updatePlaceholderNamePreference(engine, true);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds an open search engine and handles error UI.
|
||||
*
|
||||
|
|
@ -82,4 +103,20 @@ export var SearchUIUtils = {
|
|||
"browser.search.searchEnginesURL"
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the placeholderName preference for the default search engine.
|
||||
*
|
||||
* @param {SearchEngine} engine The new default search engine.
|
||||
* @param {boolean} isPrivate Whether this change applies to private windows.
|
||||
*/
|
||||
updatePlaceholderNamePreference(engine, isPrivate) {
|
||||
const prefName =
|
||||
"browser.urlbar.placeholderName" + (isPrivate ? ".private" : "");
|
||||
if (engine.isAppProvided) {
|
||||
Services.prefs.setStringPref(prefName, engine.name);
|
||||
} else {
|
||||
Services.prefs.clearUserPref(prefName);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -253,6 +253,24 @@ add_task(async function test_private_window_separate_engine() {
|
|||
Assert.equal(win.gURLBar.placeholder, expectedString);
|
||||
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
|
||||
// Verify that the placeholder for private windows is updated even when no
|
||||
// private window is visible (https://bugzilla.mozilla.org/1792816).
|
||||
await Services.search.setDefault(
|
||||
originalEngine,
|
||||
Ci.nsISearchService.CHANGE_REASON_UNKNOWN
|
||||
);
|
||||
await Services.search.setDefaultPrivate(
|
||||
extraPrivateEngine,
|
||||
Ci.nsISearchService.CHANGE_REASON_UNKNOWN
|
||||
);
|
||||
const win2 = await BrowserTestUtils.openNewBrowserWindow({ private: true });
|
||||
Assert.equal(win2.gURLBar.placeholder, noEngineString);
|
||||
await BrowserTestUtils.closeWindow(win2);
|
||||
|
||||
// And ensure this doesn't affect the placeholder for non private windows.
|
||||
tabs.push(await BrowserTestUtils.openNewForegroundTab(gBrowser));
|
||||
Assert.equal(win.gURLBar.placeholder, expectedString);
|
||||
});
|
||||
|
||||
add_task(async function test_search_mode_engine_web() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue