[NTP] Don't show the chat input if users have disabled search (#35226)
Users who had hidden the search input before the chat input feature was added would unexpectedly see the chat input on upgrade. Default the chat input pref to hidden if they've explicitly hidden the search input.
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include "brave/components/ai_chat/core/common/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_news/common/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_rewards/core/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_search_conversion/pref_names.h"
|
||||
#include "brave/components/brave_talk/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
|
||||
#include "brave/components/constants/pref_names.h"
|
||||
@@ -130,6 +131,35 @@ void NewTabPageInitializer::Initialize() {
|
||||
std::make_unique<ThemeSource>(GetProfile()));
|
||||
}
|
||||
|
||||
// static
|
||||
void NewTabPageInitializer::MigrateProfilePrefs(PrefService* prefs) {
|
||||
// Added 2026-03: Migrate "hide all widgets" into individual widget prefs.
|
||||
if (prefs->GetBoolean(kNewTabPageHideAllWidgets)) {
|
||||
prefs->SetBoolean(kNewTabPageHideAllWidgets, false);
|
||||
prefs->SetBoolean(kNewTabPageShowRewards, false);
|
||||
#if BUILDFLAG(ENABLE_BRAVE_TALK)
|
||||
prefs->SetBoolean(brave_talk::prefs::kNewTabPageShowBraveTalk, false);
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_BRAVE_VPN)
|
||||
prefs->SetBoolean(kNewTabPageShowBraveVPN, false);
|
||||
#endif
|
||||
}
|
||||
prefs->ClearPref(kNewTabPageHideAllWidgets);
|
||||
|
||||
// Added 2026-04: Set chat input visibility to hidden if the user has
|
||||
// explicitly hidden the search input.
|
||||
using brave_search_conversion::prefs::kMigratedNTPChatInputFromSearch;
|
||||
using brave_search_conversion::prefs::kShowNTPChatInput;
|
||||
using brave_search_conversion::prefs::kShowNTPSearchBox;
|
||||
if (!prefs->GetBoolean(kMigratedNTPChatInputFromSearch)) {
|
||||
prefs->SetBoolean(kMigratedNTPChatInputFromSearch, true);
|
||||
if (auto* user_value = prefs->GetUserPrefValue(kShowNTPSearchBox);
|
||||
user_value && !user_value->GetBool()) {
|
||||
prefs->SetBoolean(kShowNTPChatInput, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Profile* NewTabPageInitializer::GetProfile() {
|
||||
return Profile::FromWebUI(&web_ui_.get());
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace regional_capabilities {
|
||||
class RegionalCapabilitiesService;
|
||||
}
|
||||
|
||||
class PrefService;
|
||||
class Profile;
|
||||
|
||||
namespace brave_new_tab_page_refresh {
|
||||
@@ -41,6 +42,9 @@ class NewTabPageInitializer {
|
||||
|
||||
void Initialize();
|
||||
|
||||
// Migrates profile prefs associated with the NTP.
|
||||
static void MigrateProfilePrefs(PrefService* prefs);
|
||||
|
||||
private:
|
||||
Profile* GetProfile();
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "brave/components/brave_shields/content/browser/ad_block_service.h"
|
||||
#include "brave/components/brave_shields/core/browser/brave_shields_p3a.h"
|
||||
#include "brave/components/brave_sync/brave_sync_prefs.h"
|
||||
#include "brave/components/brave_talk/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_vpn/common/buildflags/buildflags.h"
|
||||
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
|
||||
#include "brave/components/constants/pref_names.h"
|
||||
@@ -59,12 +58,9 @@
|
||||
#include "brave/browser/brave_rewards/rewards_prefs_util.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_BRAVE_TALK)
|
||||
#include "brave/components/brave_talk/pref_names.h"
|
||||
#endif
|
||||
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
#include "brave/browser/ui/tabs/brave_tab_prefs.h"
|
||||
#include "brave/browser/ui/webui/brave_new_tab_page_refresh/new_tab_page_initializer.h"
|
||||
#include "brave/browser/ui/webui/welcome_page/brave_welcome_ui_prefs.h"
|
||||
#endif
|
||||
|
||||
@@ -258,18 +254,10 @@ void MigrateObsoleteProfilePrefs(PrefService* profile_prefs,
|
||||
#endif
|
||||
|
||||
// Added 2026-03
|
||||
if (profile_prefs->GetBoolean(kNewTabPageHideAllWidgets)) {
|
||||
profile_prefs->SetBoolean(kNewTabPageHideAllWidgets, false);
|
||||
profile_prefs->SetBoolean(kNewTabPageShowRewards, false);
|
||||
#if BUILDFLAG(ENABLE_BRAVE_TALK)
|
||||
profile_prefs->SetBoolean(brave_talk::prefs::kNewTabPageShowBraveTalk,
|
||||
false);
|
||||
#if !BUILDFLAG(IS_ANDROID)
|
||||
brave_new_tab_page_refresh::NewTabPageInitializer::MigrateProfilePrefs(
|
||||
profile_prefs);
|
||||
#endif
|
||||
#if BUILDFLAG(ENABLE_BRAVE_VPN)
|
||||
profile_prefs->SetBoolean(kNewTabPageShowBraveVPN, false);
|
||||
#endif
|
||||
}
|
||||
profile_prefs->ClearPref(kNewTabPageHideAllWidgets);
|
||||
|
||||
// END_MIGRATE_OBSOLETE_PROFILE_PREFS
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ inline constexpr char kShowNTPSearchBox[] =
|
||||
|
||||
inline constexpr char kShowNTPChatInput[] = "brave.brave_search.show-ntp-chat";
|
||||
|
||||
inline constexpr char kMigratedNTPChatInputFromSearch[] =
|
||||
"brave.brave_search.migrated-ntp-chat-from-search";
|
||||
|
||||
inline constexpr char kLastUsedNTPSearchEngine[] =
|
||||
"brave.brave_search.last-used-ntp-search-engine";
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
|
||||
registry->RegisterBooleanPref(prefs::kDismissed, false);
|
||||
registry->RegisterBooleanPref(prefs::kShowNTPSearchBox, true);
|
||||
registry->RegisterBooleanPref(prefs::kShowNTPChatInput, true);
|
||||
registry->RegisterBooleanPref(prefs::kMigratedNTPChatInputFromSearch, false);
|
||||
registry->RegisterStringPref(prefs::kLastUsedNTPSearchEngine,
|
||||
"search.brave.com");
|
||||
registry->RegisterBooleanPref(prefs::kPromptEnableSuggestions, true);
|
||||
|
||||
Reference in New Issue
Block a user