Skip to content

Commit

Permalink
Merge pull request #27223 from brave/emerick-settings-search-engine-d…
Browse files Browse the repository at this point in the history
…eep-linking

Allow deep linking to default search engine dialogs
  • Loading branch information
emerick committed Jan 17, 2025
1 parent 5816daa commit 0dab91c
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 16 deletions.
11 changes: 6 additions & 5 deletions browser/resources/settings/brave_overrides/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
45 changes: 43 additions & 2 deletions browser/resources/settings/brave_overrides/search_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
)
8 changes: 7 additions & 1 deletion browser/resources/settings/brave_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ export default function addBraveRoutes(r: Partial<SettingsRoutes>) {
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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<CrToastElement>(
'#confirmationToast')!.show()
}

private shouldShowSearchSuggestToggle_() {
return !loadTimeData.getBoolean('isGuest')
}

Expand Down
4 changes: 2 additions & 2 deletions patches/chrome-browser-resources-settings-router.ts.patch
Original file line number Diff line number Diff line change
@@ -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;
// </if>
+ 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. */

0 comments on commit 0dab91c

Please sign in to comment.