diff --git a/browser/resources/settings/brave_overrides/config.ts b/browser/resources/settings/brave_overrides/config.ts index 3e124f298b0c..2f79545bc787 100644 --- a/browser/resources/settings/brave_overrides/config.ts +++ b/browser/resources/settings/brave_overrides/config.ts @@ -10,11 +10,12 @@ import {RegisterPolymerComponentToIgnore} from 'chrome://resources/brave/polymer // 1. Make sure we ignore the chromium components when they are defined // 2. Override the chromium components with a subclass and define the // components with their original chromium name. -// (This is because the chomium components define themselves via customElements.define -// in their module, so we want to register to ignore the component before the module -// is imported). +// (This is because the chomium components define themselves via +// customElements.define in their module, so we want to register to ignore the +// component before the module is imported). RegisterPolymerComponentToIgnore('add-site-dialog') -RegisterPolymerComponentToIgnore('settings-site-settings-page') -RegisterPolymerComponentToIgnore('settings-clear-browsing-data-dialog') RegisterPolymerComponentToIgnore('settings-autofill-page') +RegisterPolymerComponentToIgnore('settings-clear-browsing-data-dialog') +RegisterPolymerComponentToIgnore('settings-search-page') +RegisterPolymerComponentToIgnore('settings-site-settings-page') diff --git a/browser/resources/settings/brave_overrides/search_page.ts b/browser/resources/settings/brave_overrides/search_page.ts index ad632bef7d32..189c45121e50 100644 --- a/browser/resources/settings/brave_overrides/search_page.ts +++ b/browser/resources/settings/brave_overrides/search_page.ts @@ -5,12 +5,22 @@ import '../brave_search_engines_page/brave_search_engines_page.js' -import {RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.js' +import '../brave_search_engines_page/private_search_engine_list_dialog.js' + +import { + RegisterPolymerComponentReplacement, + RegisterPolymerTemplateModifications +} from 'chrome://resources/brave/polymer_overriding.js' + +import {SettingsSearchPageElement} from '../search_page/search_page.js' +import {routes} from '../route.js' +import {type Route, RouteObserverMixin, Router} from '../router.js' import {getTrustedHTML} from 'chrome://resources/js/static_types.js' RegisterPolymerTemplateModifications({ 'settings-search-page': (templateContent) => { - const enginesSubpageTrigger = templateContent.getElementById('enginesSubpageTrigger') + const enginesSubpageTrigger = + templateContent.getElementById('enginesSubpageTrigger') if (!enginesSubpageTrigger) { console.error(`[Brave Settings Overrides] Couldn't find enginesSubpageTrigger`) } else { @@ -23,3 +33,34 @@ RegisterPolymerTemplateModifications({ } } }) + +// Subclass and replace the settings-search-page to make the default search +// dialog navigable via deep linking +RegisterPolymerComponentReplacement( + 'settings-search-page', + class BraveSettingsSearchPageElement + extends RouteObserverMixin(SettingsSearchPageElement) { + override ready() { + super.ready() + + // onOpenDialogButtonClick_ is private in the superclass, so we have to + // replace it to change its functionality + const anyThis = this as any + anyThis.onOpenDialogButtonClick_ = () => { + Router.getInstance().navigateTo(routes.DEFAULT_SEARCH) + } + + // onSearcgEngineListDialogClose_ is private in the superclass, so we have + // to replace it to change its functionality + anyThis.onSearchEngineListDialogClose_ = () => { + Router.getInstance().navigateTo(routes.SEARCH) + } + } + + override currentRouteChanged() { + const anyThis = this as any + anyThis.showSearchEngineListDialog_ = + Router.getInstance().getCurrentRoute() === routes.DEFAULT_SEARCH + } + } +) diff --git a/browser/resources/settings/brave_routes.ts b/browser/resources/settings/brave_routes.ts index bce4d58943d9..5314428409f4 100644 --- a/browser/resources/settings/brave_routes.ts +++ b/browser/resources/settings/brave_routes.ts @@ -61,7 +61,13 @@ export default function addBraveRoutes(r: Partial) { if (r.FONTS) { delete r.FONTS } - r.FONTS = r.BRAVE_CONTENT.createChild('/fonts'); + r.FONTS = r.BRAVE_CONTENT.createChild('/fonts') + } + if (r.SEARCH) { + r.DEFAULT_SEARCH = r.SEARCH.createChild('defaultSearch') + r.DEFAULT_SEARCH.isNavigableDialog = true + r.PRIVATE_SEARCH = r.SEARCH.createChild('privateSearch') + r.PRIVATE_SEARCH.isNavigableDialog = true } if (r.SITE_SETTINGS) { r.SITE_SETTINGS_AUTOPLAY = r.SITE_SETTINGS.createChild('autoplay') diff --git a/browser/resources/settings/brave_search_engines_page/brave_search_engines_page.ts b/browser/resources/settings/brave_search_engines_page/brave_search_engines_page.ts index 168ea9bc7f2f..0ca58105ce21 100644 --- a/browser/resources/settings/brave_search_engines_page/brave_search_engines_page.ts +++ b/browser/resources/settings/brave_search_engines_page/brave_search_engines_page.ts @@ -8,13 +8,17 @@ import '../settings_shared.css.js'; import '../settings_vars.css.js'; -import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; -import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js'; -import {loadTimeData} from "../i18n_setup.js" -import {BraveSearchEnginesPageBrowserProxyImpl} from './brave_search_engines_page_browser_proxy.js'; +import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js' +import {WebUiListenerMixin} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js' +import {I18nMixin} from 'chrome://resources/cr_elements/i18n_mixin.js' +import {RouteObserverMixin, Router} from '../router.js' +import {routes} from '../route.js' +import {loadTimeData} from '../i18n_setup.js' +import {BraveSearchEnginesPageBrowserProxyImpl} from './brave_search_engines_page_browser_proxy.js' import {getTemplate} from './brave_search_engines_page.html.js' -const BraveSearchEnginesPageBase = WebUiListenerMixin(PolymerElement) +const BraveSearchEnginesPageBase = + WebUiListenerMixin(I18nMixin(RouteObserverMixin(PolymerElement))) class BraveSearchEnginesPage extends BraveSearchEnginesPageBase { static get is() { @@ -48,7 +52,27 @@ class BraveSearchEnginesPage extends BraveSearchEnginesPageBase { 'private-search-engines-changed', updatePrivateSearchEngines) } - shouldShowSearchSuggestToggle_() { + override currentRouteChanged() { + this.showPrivateSearchEngineListDialog_ = + Router.getInstance().getCurrentRoute() === routes.PRIVATE_SEARCH + } + + private onOpenPrivateDialogButtonClick_() { + Router.getInstance().navigateTo(routes.PRIVATE_SEARCH) + } + + private onPrivateSearchEngineListDialogClose_() { + Router.getInstance().navigateTo(routes.SEARCH) + } + + private onPrivateSearchEngineChangedInDialog_(e: CustomEvent) { + this.confirmationToastLabel_ = this.i18n( + 'privateSearchEnginesConfirmationToastLabel', e.detail.searchEngine.name) + this.shadowRoot!.querySelector( + '#confirmationToast')!.show() + } + + private shouldShowSearchSuggestToggle_() { return !loadTimeData.getBoolean('isGuest') } diff --git a/patches/chrome-browser-resources-settings-router.ts.patch b/patches/chrome-browser-resources-settings-router.ts.patch index 351d35c33537..8eff0889dd78 100644 --- a/patches/chrome-browser-resources-settings-router.ts.patch +++ b/patches/chrome-browser-resources-settings-router.ts.patch @@ -1,12 +1,12 @@ diff --git a/chrome/browser/resources/settings/router.ts b/chrome/browser/resources/settings/router.ts -index afe6eb3c611c80833e7ceaa32368a45cf8f2dcad..9e2ae5933cb523c0cf5ab48f5bb4218abd251c42 100644 +index afe6eb3c611c80833e7ceaa32368a45cf8f2dcad..31589d11e08e64bf5778b9c21f35176e4ae0e8e2 100644 --- a/chrome/browser/resources/settings/router.ts +++ b/chrome/browser/resources/settings/router.ts @@ -121,6 +121,7 @@ export interface SettingsRoutes { IMPORT_DATA: Route; SIGN_OUT: Route; // -+ GET_STARTED: Route; SHIELDS: Route; SOCIAL_BLOCKING: Route; EXTENSIONS: Route; EXTENSIONS_V2: Route; BRAVE_SYNC: Route; BRAVE_SYNC_SETUP: Route; BRAVE_WALLET: Route; BRAVE_WEB3: Route; BRAVE_NEW_TAB: Route; THEMES: Route; ++ GET_STARTED: Route; SHIELDS: Route; SOCIAL_BLOCKING: Route; EXTENSIONS: Route; EXTENSIONS_V2: Route; BRAVE_SYNC: Route; BRAVE_SYNC_SETUP: Route; BRAVE_WALLET: Route; BRAVE_WEB3: Route; BRAVE_NEW_TAB: Route; THEMES: Route; DEFAULT_SEARCH: Route; PRIVATE_SEARCH: Route; } /** Class for navigable routes. */