Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow deep linking to default search engine dialogs (uplift to 1.75.x) #27273

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. */
Loading