[cr146] Mojo typemap added for ts Urls

This is just to make the URL type more intuitive when used with strings.
This change corrects the url uses in our end.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/a2622a33efbcdc7e4bcf72510775f7f93970fce8

commit a2622a33efbcdc7e4bcf72510775f7f93970fce8
Author: Fred Shih <ffred@chromium.org>
Date:   Wed Jan 21 17:07:46 2026 -0800

    Add mojo typemap for ts Url

    Currently URLs are a object type of {url: string}. This is annoying
    because there is a stutter when using it, for example:

    myObj.url.url

    This change maps the Url object directly to a string. So one can simply
    say:

    myObj.url <-- string type!

    The URL type wasn't used because url as a string is effectively
    calcified at this point. It's (probably) too risky to change all the
    callsites to url (and probably won't give us that much...).

    Change-Id: I481085b8954cbf65bb3a4d115fd39e71b0a8fbcb
    Bug: 40615900
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7018797
    Commit-Queue: Fred Shih <ffred@chromium.org>
    Reviewed-by: Daniel Cheng <dcheng@chromium.org>
    Reviewed-by: Michael Cui <mlcui@google.com>
    Reviewed-by: Roman Arora <romanarora@chromium.org>
    Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1572659}
This commit is contained in:
Claudio DeSouza
2026-02-26 13:47:46 +00:00
parent 67ba3142fd
commit a31fb1f6bc
10 changed files with 43 additions and 46 deletions
@@ -74,7 +74,7 @@ export class BraveEducationAppElement extends CrLitElement {
BraveEducationProxyImpl.getInstance()
.handler.getServerUrl()
.then(({ url }: { url: Url }) => this.handleUrlResult_(url.url))
.then(({ url }: { url: Url }) => this.handleUrlResult_(url))
}
override disconnectedCallback() {
@@ -27,7 +27,7 @@ function MatchImage(props: { match: AutocompleteMatch }) {
)
}
if (!imageUrl) {
if (!iconUrl.url) {
if (!iconUrl) {
return (
<Icon
name='search'
@@ -38,7 +38,7 @@ function MatchImage(props: { match: AutocompleteMatch }) {
return (
<img
className='icon'
src={iconUrl.url}
src={iconUrl}
/>
)
}
@@ -87,25 +87,25 @@ export function createSearchStore() {
allowedToBeDefaultMatch: false,
contents: 'contents 1',
description: 'description 1',
iconUrl: { url: '' },
iconUrl: '',
imageUrl: '',
destinationUrl: { url: '' },
destinationUrl: '',
},
{
allowedToBeDefaultMatch: true,
contents: 'contents 2',
description: 'Ask Leo',
iconUrl: { url: '' },
iconUrl: '',
imageUrl: '',
destinationUrl: { url: '' },
destinationUrl: '',
},
{
allowedToBeDefaultMatch: true,
contents: query,
description: engine,
iconUrl: { url: '' },
iconUrl: '',
imageUrl: '',
destinationUrl: { url: '' },
destinationUrl: '',
},
],
})
@@ -154,7 +154,7 @@ export class ModelConfigUI extends ModelConfigUIBase {
// Determined at runtime based on contextSize
longConversationWarningCharacterLimit: -1,
modelSystemPrompt: this.modelSystemPrompt,
endpoint: mojomUrl,
endpoint: mojomUrl.toString(),
apiKey: this.apiKey
}
},
@@ -164,9 +164,9 @@ export class ModelConfigUI extends ModelConfigUIBase {
supportsTools: false,
isSuggestedModel: false,
isNearModel: false,
}
};
this.fire('save', { modelConfig })
this.fire('save', {modelConfig})
}
handleCloseClick_() {
@@ -243,16 +243,16 @@ export class ModelConfigUI extends ModelConfigUIBase {
private onModelItemChange_(newValue: mojom.Model | null) {
if (newValue?.options.customModelOptions) {
this.label = newValue.displayName
this.label = newValue.displayName;
this.modelRequestName =
newValue.options.customModelOptions.modelRequestName
newValue.options.customModelOptions.modelRequestName;
this.contextSize =
newValue.options.customModelOptions.contextSize
this.endpointUrl = newValue.options.customModelOptions.endpoint.url
this.apiKey = newValue.options.customModelOptions.apiKey
newValue.options.customModelOptions.contextSize;
this.endpointUrl = newValue.options.customModelOptions.endpoint;
this.apiKey = newValue.options.customModelOptions.apiKey;
this.modelSystemPrompt =
newValue.options.customModelOptions.modelSystemPrompt
this.hasVisionSupport = newValue.visionSupport
newValue.options.customModelOptions.modelSystemPrompt;
this.hasVisionSupport = newValue.visionSupport;
}
this.constructTokenEstimateString_()
}
@@ -171,7 +171,7 @@ class ModelListSection extends ModelListSectionBase {
// 2. Ollama sync preference is enabled
// 3. Ollama is actually connected
const isOllamaEndpoint =
model.options.customModelOptions?.endpoint.url === OLLAMA_ENDPOINT
model.options.customModelOptions?.endpoint === OLLAMA_ENDPOINT
return !!(isOllamaEndpoint && ollamaSyncEnabled && isOllamaConnected)
}
}
@@ -35,11 +35,11 @@ mangleAll((element) => {
if (!anchor) {
throw new Error('[chrome_urls override] Missing anchor element')
}
if (anchor.textContent !== '\${info.url.url}') {
if (anchor.textContent !== '\${info.url}') {
throw new Error('[chrome_urls override] Unexpected anchor textContent')
}
anchor.textContent = '\${info.url.url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('href="${info.url.url}"'))
anchor.textContent = '\${info.url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('href="${info.url}"'))
// Rewrite inactive chrome URLs to use brave: scheme (these also appear under
// the "List of Brave URLs" header) and rewrite internal debugging page URLs to
@@ -50,11 +50,11 @@ mangleAll((element) => {
if (!listItem) {
throw new Error('[chrome_urls override] Missing list item element')
}
if (listItem.textContent !== '\${info.url.url}') {
if (listItem.textContent !== '\${info.url}') {
throw new Error('[chrome_urls override] Unexpected list item textContent')
}
listItem.textContent = '\${info.url.url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('<li>${info.url.url}</li>'))
listItem.textContent = '\${info.url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('<li>${info.url}</li>'))
// Rewrite command URLs to use brave: scheme (these appear under the
// "Command URLs for Debug" header)
@@ -63,8 +63,8 @@ mangle((element) => {
if (!listItem) {
throw new Error('[chrome_urls override] Missing list item element')
}
if (listItem.textContent !== '\${url.url}') {
if (listItem.textContent !== '\${url}') {
throw new Error('[chrome_urls override] Unexpected list item textContent')
}
listItem.textContent = '\${url.url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('<li>${url.url}</li>'))
listItem.textContent = '\${url.replace(/chrome:/, "brave:")}'
}, x => x.text.includes('<li>${url}</li>'))
@@ -109,7 +109,7 @@ function Image({ match, isAskLeo }: { match: AutocompleteMatch, isAskLeo: boolea
// url machinery.
const isGeneric = !match.imageUrl
return isGeneric
? <SearchIcon url={match.iconUrl.url} />
? <SearchIcon url={match.iconUrl} />
: match.imageUrl.startsWith('chrome')
? <FavIcon url={match.imageUrl} />
: <MaybeImage src={match.imageUrl} />
@@ -120,7 +120,7 @@ export default function SearchResult({ match, selected, onClick }: Props) {
const description = match.swapContentsAndDescription ? match.contents : match.description
const isAskLeo = description === getLocale('searchAskLeo')
const result = <Container href={match.destinationUrl.url} aria-selected={selected} onClick={e => {
const result = <Container href={match.destinationUrl} aria-selected={selected} onClick={e => {
e.preventDefault()
onClick(e)
}}>
@@ -37,7 +37,7 @@ const Container = styled.div`
// autocomplete result.
const openMatch = (match: AutocompleteMatch, line: number, event: React.MouseEvent | KeyboardEvent, searchEngine?: SearchEngineInfo) => {
if (line === -1) {
handleOpenURLClick(match.destinationUrl.url, event)
handleOpenURLClick(match.destinationUrl, event)
return
}
@@ -64,9 +64,7 @@ const useUrlWhatYouTyped = (query: string) => React.useMemo(() => {
validateScheme(url.toString())
return {
destinationUrl: {
url: url.toString()
},
destinationUrl: url.toString(),
contents: url.toString(),
description: '',
imageUrl: `chrome://favicon/size/64@1x/${q.toString()}`,
-1
View File
@@ -1295,7 +1295,6 @@ test("brave_browser_tests") {
"//brave/components/vector_icons",
"//chrome:packed_resources",
"//chrome/browser/apps/app_service",
"//chrome/browser/apps/app_service:constants",
"//chrome/browser/themes",
"//chrome/browser/ui/webui/side_panel/bookmarks:mojo_bindings",
"//components/autofill/content/browser",
@@ -653,10 +653,10 @@ exports[`mangled files should have up to date snapshots ./chromium_src/component
- html\`<li><a href=\\"#\\">chrome://chrome-urls</a></li>\` :
+ html\`<li><a href=\\"#\\">brave://chrome-urls</a></li>\` :
html\`\${info.enabled ?
- html\`<li><a href=\\"\${info.url.url}\\">\${info.url.url}</a></li>\` :
- html\`<li>\${info.url.url}</li>\`
+ html\`<li><a href=\\"\${info.url.url}\\">\${info.url.url.replace(/chrome:/, \\"brave:\\")}</a></li>\` :
+ html\`<li>\${info.url.url.replace(/chrome:/, \\"brave:\\")}</li>\`
- html\`<li><a href=\\"\${info.url}\\">\${info.url}</a></li>\` :
- html\`<li>\${info.url}</li>\`
+ html\`<li><a href=\\"\${info.url}\\">\${info.url.replace(/chrome:/, \\"brave:\\")}</a></li>\` :
+ html\`<li>\${info.url.replace(/chrome:/, \\"brave:\\")}</li>\`
}\`
}\`)}
</ul>
@@ -666,10 +666,10 @@ exports[`mangled files should have up to date snapshots ./chromium_src/component
<ul>
\${this.internalUrlInfos_.map(info => html\`
\${this.isInternalUiEnabled_(info) ?
- html\`<li><a href=\\"\${info.url.url}\\">\${info.url.url}</a></li>\` :
- html\`<li>\${info.url.url}</li>\`
+ html\`<li><a href=\\"\${info.url.url}\\">\${info.url.url.replace(/chrome:/, \\"brave:\\")}</a></li>\` :
+ html\`<li>\${info.url.url.replace(/chrome:/, \\"brave:\\")}</li>\`
- html\`<li><a href=\\"\${info.url}\\">\${info.url}</a></li>\` :
- html\`<li>\${info.url}</li>\`
+ html\`<li><a href=\\"\${info.url}\\">\${info.url.replace(/chrome:/, \\"brave:\\")}</a></li>\` :
+ html\`<li>\${info.url.replace(/chrome:/, \\"brave:\\")}</li>\`
}\`)}
</ul>\` : ''}
\${this.commandUrls_.length ? html\`
@@ -679,8 +679,8 @@ exports[`mangled files should have up to date snapshots ./chromium_src/component
address bar if you need them.
</p>
<ul>
- \${this.commandUrls_.map(url => html\`<li>\${url.url}</li>\`)}
+ \${this.commandUrls_.map(url => html\`<li>\${url.url.replace(/chrome:/, \\"brave:\\")}</li>\`)}
- \${this.commandUrls_.map(url => html\`<li>\${url}</li>\`)}
+ \${this.commandUrls_.map(url => html\`<li>\${url.replace(/chrome:/, \\"brave:\\")}</li>\`)}
</ul>\` : ''}\`;
}
"