Skip to content

Commit

Permalink
Allow deep linking to default search engine dialogs (uplift to 1.75.x) (
Browse files Browse the repository at this point in the history
#27273)

Merge pull request #27223 from brave/emerick-settings-search-engine-deep-linking

Allow deep linking to default search engine dialogs
  • Loading branch information
emerick authored Jan 21, 2025
1 parent befbba8 commit d08987c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 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: 42 additions & 3 deletions browser/resources/settings/brave_overrides/search_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@

import '../brave_search_engines_page/brave_search_engines_page.js'

import '../brave_search_engines_page/private_search_engine_list_dialog.js';
import '../brave_search_engines_page/private_search_engine_list_dialog.js'

import {RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.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'
import {loadTimeData} from '../i18n_setup.js'

RegisterPolymerTemplateModifications({
'settings-search-page': (templateContent) => {
const enginesSubpageTrigger = templateContent.getElementById('enginesSubpageTrigger')
const enginesSubpageTrigger =
templateContent.getElementById('enginesSubpageTrigger')
if (!enginesSubpageTrigger) {
console.error(`[Settings] Couldn't find enginesSubpageTrigger`)
} else {
Expand All @@ -34,3 +42,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 @@ -59,7 +59,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 @@ -9,13 +9,16 @@ 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 {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'
import type {CrToastElement} from 'chrome://resources/cr_elements/cr_toast/cr_toast.js'
import type {SearchEngine} from '../search_engines_page/search_engines_browser_proxy.js'

const BraveSearchEnginesPageBase = WebUiListenerMixin(I18nMixin(PolymerElement))
const BraveSearchEnginesPageBase =
WebUiListenerMixin(I18nMixin(RouteObserverMixin(PolymerElement)))

class BraveSearchEnginesPage extends BraveSearchEnginesPageBase {
static get is() {
Expand Down Expand Up @@ -68,12 +71,17 @@ class BraveSearchEnginesPage extends BraveSearchEnginesPageBase {
'private-search-engines-changed', updatePrivateSearchEngines)
}

override currentRouteChanged() {
this.showPrivateSearchEngineListDialog_ =
Router.getInstance().getCurrentRoute() === routes.PRIVATE_SEARCH
}

private onOpenPrivateDialogButtonClick_() {
this.showPrivateSearchEngineListDialog_ = true
Router.getInstance().navigateTo(routes.PRIVATE_SEARCH)
}

private onPrivateSearchEngineListDialogClose_() {
this.showPrivateSearchEngineListDialog_ = false
Router.getInstance().navigateTo(routes.SEARCH)
}

private onPrivateSearchEngineChangedInDialog_(e: CustomEvent) {
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..f714d77dd58abb5aafa3495c7e48ff9f71431a98 100644
index afe6eb3c611c80833e7ceaa32368a45cf8f2dcad..7cdd33a762c5be031e45e2d97bbdd867663cb293 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; SITE_SETTINGS_AUTOPLAY: Route; SITE_SETTINGS_GOOGLE_SIGN_IN: Route; SITE_SETTINGS_LOCALHOST_ACCESS: Route; SITE_SETTINGS_BRAVE_OPEN_AI_CHAT: Route; SITE_SETTINGS_ETHEREUM: Route; SITE_SETTINGS_SOLANA: Route; SITE_SETTINGS_SHIELDS_STATUS: Route; SHIELDS_ADBLOCK: Route; SHORTCUTS: Route; BRAVE_WALLET_NETWORKS: Route; BRAVE_LEO_ASSISTANT: Route; BRAVE_CONTENT: 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; SITE_SETTINGS_AUTOPLAY: Route; SITE_SETTINGS_GOOGLE_SIGN_IN: Route; SITE_SETTINGS_LOCALHOST_ACCESS: Route; SITE_SETTINGS_BRAVE_OPEN_AI_CHAT: Route; SITE_SETTINGS_ETHEREUM: Route; SITE_SETTINGS_SOLANA: Route; SITE_SETTINGS_SHIELDS_STATUS: Route; SHIELDS_ADBLOCK: Route; SHORTCUTS: Route; BRAVE_WALLET_NETWORKS: Route; BRAVE_LEO_ASSISTANT: Route; BRAVE_CONTENT: Route; DEFAULT_SEARCH: Route; PRIVATE_SEARCH: Route;
}

/** Class for navigable routes. */

0 comments on commit d08987c

Please sign in to comment.