tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 8610ad3d4a568fd4e5684fc3a97cecd615e3a9a2
parent 7bcc5529d060b79154f0ed795a4fcaacfd79731a
Author: Daisuke Akatsuka <daisuke@birchill.co.jp>
Date:   Thu, 11 Dec 2025 01:12:03 +0000

Bug 1995227: Remove payloadAndSimpleHighlights r=adw

Differential Revision: https://phabricator.services.mozilla.com/D274383

Diffstat:
Mbrowser/components/urlbar/UrlbarProviderAboutPages.sys.mjs | 13+++++++++----
Mbrowser/components/urlbar/UrlbarProviderAliasEngines.sys.mjs | 4++--
Mbrowser/components/urlbar/UrlbarProviderAutofill.sys.mjs | 30+++++++++++++++++++-----------
Mbrowser/components/urlbar/UrlbarProviderBookmarkKeywords.sys.mjs | 16+++++++++++-----
Mbrowser/components/urlbar/UrlbarProviderClipboard.sys.mjs | 21+++++++++++++--------
Mbrowser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs | 55++++++++++++++++++++++++++++++++++++++-----------------
Mbrowser/components/urlbar/UrlbarProviderHistoryUrlHeuristic.sys.mjs | 13+++++++++----
Mbrowser/components/urlbar/UrlbarProviderInputHistory.sys.mjs | 45++++++++++++++++++++++++++-------------------
Mbrowser/components/urlbar/UrlbarProviderOmnibox.sys.mjs | 42++++++++++++++++++++++++------------------
Mbrowser/components/urlbar/UrlbarProviderPlaces.sys.mjs | 70+++++++++++++++++++++++++++++++++++++++-------------------------------
Mbrowser/components/urlbar/UrlbarProviderPrivateSearch.sys.mjs | 13+++++++++----
Mbrowser/components/urlbar/UrlbarProviderQuickSuggest.sys.mjs | 17++++++++---------
Mbrowser/components/urlbar/UrlbarProviderRemoteTabs.sys.mjs | 13+++++++++----
Mbrowser/components/urlbar/UrlbarProviderRestrictKeywords.sys.mjs | 13+++++++------
Mbrowser/components/urlbar/UrlbarProviderRestrictKeywordsAutofill.sys.mjs | 23+++++++++++------------
Mbrowser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs | 54+++++++++++++++++++++++++++++-------------------------
Mbrowser/components/urlbar/UrlbarProviderSemanticHistorySearch.sys.mjs | 42++++++++++++++++++++++++------------------
Mbrowser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs | 4++--
Mbrowser/components/urlbar/UrlbarProviderTokenAliasEngines.sys.mjs | 39+++++++++++++++++++++++----------------
Mbrowser/components/urlbar/UrlbarProviderTopSites.sys.mjs | 29++++++++++-------------------
Mbrowser/components/urlbar/UrlbarResult.sys.mjs | 125++++++++++++++++++++++++++++++++++---------------------------------------------
Mbrowser/components/urlbar/UrlbarUtils.sys.mjs | 4++--
Mbrowser/components/urlbar/private/AddonSuggestions.sys.mjs | 36++++++++++++++++++------------------
Mbrowser/components/urlbar/private/AmpSuggestions.sys.mjs | 19++++++++-----------
Mbrowser/components/urlbar/private/DynamicSuggestions.sys.mjs | 14+++++++++-----
Mbrowser/components/urlbar/private/MDNSuggestions.sys.mjs | 31+++++++++++++++----------------
Mbrowser/components/urlbar/private/WikipediaSuggestions.sys.mjs | 12+++++++-----
Mbrowser/components/urlbar/tests/browser/browser_bestMatch.js | 9+++++++--
Mbrowser/components/urlbar/tests/browser/browser_dynamicResults.js | 10+++++++---
Mbrowser/components/urlbar/tests/browser/browser_results_format_displayValue.js | 8+++++---
Mbrowser/components/urlbar/tests/browser/browser_urlbar_annotation.js | 4+---
Mbrowser/components/urlbar/tests/unit/head.js | 145+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
32 files changed, 548 insertions(+), 425 deletions(-)

diff --git a/browser/components/urlbar/UrlbarProviderAboutPages.sys.mjs b/browser/components/urlbar/UrlbarProviderAboutPages.sys.mjs @@ -52,13 +52,18 @@ export class UrlbarProviderAboutPages extends UrlbarProvider { for (const aboutUrl of lazy.AboutPagesUtils.visibleAboutUrls) { if (aboutUrl.startsWith(searchString)) { let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [aboutUrl, UrlbarUtils.HIGHLIGHT.TYPED], - url: [aboutUrl, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + title: aboutUrl, + url: aboutUrl, icon: UrlbarUtils.getIconForUrl(aboutUrl), - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + url: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderAliasEngines.sys.mjs b/browser/components/urlbar/UrlbarProviderAliasEngines.sys.mjs @@ -70,12 +70,12 @@ export class UrlbarProviderAliasEngines extends UrlbarProvider { type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { engine: engine.name, keyword: alias, query: query.trimStart(), icon, - }), + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderAutofill.sys.mjs b/browser/components/urlbar/UrlbarProviderAutofill.sys.mjs @@ -862,12 +862,12 @@ export class UrlbarProviderAutofill extends UrlbarProvider { } let payload = { - url: [finalCompleteValue, UrlbarUtils.HIGHLIGHT.TYPED], + url: finalCompleteValue, icon: UrlbarUtils.getIconForUrl(finalCompleteValue), }; if (title) { - payload.title = [title, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.title = title; } else { let trimHttps = lazy.UrlbarPrefs.getScotchBonnetPref("trimHttps"); let displaySpec = UrlbarUtils.prepareUrlForDisplay(finalCompleteValue, { @@ -879,10 +879,11 @@ export class UrlbarProviderAutofill extends UrlbarProvider { trimEmptyQuery: true, trimSlash: !this._searchString.includes("/"), }); - payload.fallbackTitle = [fallbackTitle, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.fallbackTitle = fallbackTitle; } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.HISTORY, heuristic: true, @@ -893,10 +894,12 @@ export class UrlbarProviderAutofill extends UrlbarProvider { selectionEnd: autofilledValue.length, type: autofilledType, }, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + fallbackTitle: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -934,6 +937,7 @@ export class UrlbarProviderAutofill extends UrlbarProvider { queryContext.searchString + aboutUrl.substring(queryContext.searchString.length); return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.HISTORY, heuristic: true, @@ -943,11 +947,15 @@ export class UrlbarProviderAutofill extends UrlbarProvider { selectionStart: queryContext.searchString.length, selectionEnd: autofilledValue.length, }, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [trimmedUrl, UrlbarUtils.HIGHLIGHT.TYPED], - url: [aboutUrl, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + title: trimmedUrl, + url: aboutUrl, icon: UrlbarUtils.getIconForUrl(aboutUrl), - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + url: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } } diff --git a/browser/components/urlbar/UrlbarProviderBookmarkKeywords.sys.mjs b/browser/components/urlbar/UrlbarProviderBookmarkKeywords.sys.mjs @@ -86,17 +86,23 @@ export class UrlbarProviderBookmarkKeywords extends UrlbarProvider { } let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.KEYWORD, source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [title, UrlbarUtils.HIGHLIGHT.TYPED], - url: [url, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [keyword, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + title, + url, + keyword, input: queryContext.searchString, postData, icon: UrlbarUtils.getIconForUrl(entry.url), - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + url: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderClipboard.sys.mjs b/browser/components/urlbar/UrlbarProviderClipboard.sys.mjs @@ -116,19 +116,24 @@ export class UrlbarProviderClipboard extends UrlbarProvider { async startQuery(queryContext, addCallback) { // If the query was started, isActive should have cached a url already. let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - fallbackTitle: [ - UrlbarUtils.prepareUrlForDisplay(this.#previousClipboard.value, { + payload: { + fallbackTitle: UrlbarUtils.prepareUrlForDisplay( + this.#previousClipboard.value, + { trimURL: false, - }), - UrlbarUtils.HIGHLIGHT.NONE, - ], - url: [this.#previousClipboard.value, UrlbarUtils.HIGHLIGHT.NONE], + } + ), + url: this.#previousClipboard.value, icon: "chrome://global/skin/icons/clipboard.svg", isBlockable: true, - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.NONE, + url: UrlbarUtils.HIGHLIGHT.NONE, + }, }); addCallback(this, result); diff --git a/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs b/browser/components/urlbar/UrlbarProviderHeuristicFallback.sys.mjs @@ -159,13 +159,18 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider { !lazy.UrlbarPrefs.get("keyword.enabled") ) { return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - fallbackTitle: [searchUrl, UrlbarUtils.HIGHLIGHT.NONE], - url: [searchUrl, UrlbarUtils.HIGHLIGHT.NONE], - }), + payload: { + fallbackTitle: searchUrl, + url: searchUrl, + }, + highlights: { + fallbackTitle: UrlbarUtils.HIGHLIGHT.NONE, + url: UrlbarUtils.HIGHLIGHT.NONE, + }, }); } @@ -221,14 +226,19 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider { } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - fallbackTitle: [displayURL, UrlbarUtils.HIGHLIGHT.NONE], - url: [escapedURL, UrlbarUtils.HIGHLIGHT.NONE], + payload: { + fallbackTitle: displayURL, + url: escapedURL, icon: iconUri, - }), + }, + highlights: { + fallbackTitle: UrlbarUtils.HIGHLIGHT.NONE, + url: UrlbarUtils.HIGHLIGHT.NONE, + }, }); } @@ -277,13 +287,18 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider { } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - query: [query.trimStart(), UrlbarUtils.HIGHLIGHT.NONE], - keyword: [firstToken, UrlbarUtils.HIGHLIGHT.NONE], - }), + payload: { + query: query.trimStart(), + keyword: firstToken, + }, + highlights: { + query: UrlbarUtils.HIGHLIGHT.NONE, + keyword: UrlbarUtils.HIGHLIGHT.NONE, + }, }); } @@ -321,15 +336,21 @@ export class UrlbarProviderHeuristicFallback extends UrlbarProvider { } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, heuristic, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + engine: engine.name, icon: UrlbarUtils.ICON.SEARCH_GLASS, - query: [query, UrlbarUtils.HIGHLIGHT.NONE], - keyword: keyword ? [keyword, UrlbarUtils.HIGHLIGHT.NONE] : undefined, - }), + query, + keyword, + }, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + query: UrlbarUtils.HIGHLIGHT.NONE, + keyword: UrlbarUtils.HIGHLIGHT.NONE, + }, }); } } diff --git a/browser/components/urlbar/UrlbarProviderHistoryUrlHeuristic.sys.mjs b/browser/components/urlbar/UrlbarProviderHistoryUrlHeuristic.sys.mjs @@ -109,14 +109,19 @@ export class UrlbarProviderHistoryUrlHeuristic extends UrlbarProvider { } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.HISTORY, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [inputedURL, UrlbarUtils.HIGHLIGHT.TYPED], - title: [title, UrlbarUtils.HIGHLIGHT.NONE], + payload: { + url: inputedURL, + title, icon: UrlbarUtils.getIconForUrl(resultSet[0].getResultByName("url")), - }), + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.NONE, + }, }); } } diff --git a/browser/components/urlbar/UrlbarProviderInputHistory.sys.mjs b/browser/components/urlbar/UrlbarProviderInputHistory.sys.mjs @@ -136,23 +136,24 @@ export class UrlbarProviderInputHistory extends UrlbarProvider { continue; } let userContextId = row.getResultByName("userContextId") || 0; - let { payload, payloadHighlights } = - lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [url, UrlbarUtils.HIGHLIGHT.TYPED], - title: [resultTitle, UrlbarUtils.HIGHLIGHT.TYPED], - icon: UrlbarUtils.getIconForUrl(url), - userContextId, - lastVisit, - }); - if (lazy.UrlbarPrefs.get("secondaryActions.switchToTab")) { - payload.action = - UrlbarUtils.createTabSwitchSecondaryAction(userContextId); - } let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, source: UrlbarUtils.RESULT_SOURCE.TABS, - payload, - payloadHighlights, + payload: { + url, + title: resultTitle, + icon: UrlbarUtils.getIconForUrl(url), + userContextId, + lastVisit, + action: lazy.UrlbarPrefs.get("secondaryActions.switchToTab") + ? UrlbarUtils.createTabSwitchSecondaryAction(userContextId) + : undefined, + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); continue; @@ -178,12 +179,13 @@ export class UrlbarProviderInputHistory extends UrlbarProvider { let isBlockable = resultSource == UrlbarUtils.RESULT_SOURCE.HISTORY; let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: resultSource, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [url, UrlbarUtils.HIGHLIGHT.TYPED], - title: [resultTitle, UrlbarUtils.HIGHLIGHT.TYPED], - tags: [resultTags, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + url, + title: resultTitle, + tags: resultTags, icon: UrlbarUtils.getIconForUrl(url), isBlockable, blockL10n: isBlockable @@ -194,7 +196,12 @@ export class UrlbarProviderInputHistory extends UrlbarProvider { "awesome-bar-result-menu" : undefined, lastVisit, - }), + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + tags: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); diff --git a/browser/components/urlbar/UrlbarProviderOmnibox.sys.mjs b/browser/components/urlbar/UrlbarProviderOmnibox.sys.mjs @@ -99,15 +99,21 @@ export class UrlbarProviderOmnibox extends UrlbarProvider { let keyword = queryContext.tokens[0].value; let description = lazy.ExtensionSearchHandler.getDescription(keyword); let heuristicResult = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.OMNIBOX, source: UrlbarUtils.RESULT_SOURCE.ADDON, heuristic: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [description, UrlbarUtils.HIGHLIGHT.TYPED], - content: [queryContext.searchString, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [queryContext.tokens[0].value, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + title: description, + content: queryContext.searchString, + keyword: queryContext.tokens[0].value, icon: UrlbarUtils.ICON.EXTENSION, - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + content: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, heuristicResult); @@ -129,21 +135,21 @@ export class UrlbarProviderOmnibox extends UrlbarProvider { continue; } let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.OMNIBOX, source: UrlbarUtils.RESULT_SOURCE.ADDON, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - { - title: [suggestion.description, UrlbarUtils.HIGHLIGHT.TYPED], - content: [content, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [ - queryContext.tokens[0].value, - UrlbarUtils.HIGHLIGHT.TYPED, - ], - isBlockable: suggestion.deletable, - icon: UrlbarUtils.ICON.EXTENSION, - } - ), + payload: { + title: suggestion.description, + content, + keyword: queryContext.tokens[0].value, + isBlockable: suggestion.deletable, + icon: UrlbarUtils.ICON.EXTENSION, + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + content: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs b/browser/components/urlbar/UrlbarProviderPlaces.sys.mjs @@ -274,7 +274,7 @@ function convertLegacyMatches(context, matches, urls) { continue; } urls.add(makeMapKeyForResult(url, match)); - let result = makeUrlbarResult(context.tokens, { + let result = makeUrlbarResult(context, { url, // `match.icon` is an empty string if there is no icon. Use undefined // instead so that tests can be simplified by not including `icon: ""` in @@ -300,8 +300,7 @@ function convertLegacyMatches(context, matches, urls) { /** * Creates a new UrlbarResult from the provided data. * - * @param {UrlbarSearchStringTokenData[]} tokens - * The search tokens. + * @param {UrlbarQueryContext} queryContext * @param {object} info * @param {string} info.url * @param {string} info.title @@ -312,51 +311,52 @@ function convertLegacyMatches(context, matches, urls) { * @param {number} info.frecency * @param {string} info.style */ -function makeUrlbarResult(tokens, info) { +function makeUrlbarResult(queryContext, info) { let action = lazy.PlacesUtils.parseActionUrl(info.url); if (action) { switch (action.type) { case "searchengine": // Return a form history result. return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.HISTORY, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(tokens, { + payload: { engine: action.params.engineName, isBlockable: true, blockL10n: { id: "urlbar-result-menu-remove-from-history" }, helpUrl: Services.urlFormatter.formatURLPref("app.support.baseURL") + "awesome-bar-result-menu", - suggestion: [ - action.params.searchSuggestion, - UrlbarUtils.HIGHLIGHT.SUGGESTED, - ], + suggestion: action.params.searchSuggestion, lowerCaseSuggestion: action.params.searchSuggestion.toLocaleLowerCase(), - }), + }, + highlights: { + suggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + }, }); case "switchtab": { - let payloadAndHighlights = lazy.UrlbarResult.payloadAndSimpleHighlights( - tokens, - { - url: [action.params.url, UrlbarUtils.HIGHLIGHT.TYPED], - title: [info.title, UrlbarUtils.HIGHLIGHT.TYPED], + return new lazy.UrlbarResult({ + queryContext, + type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + source: UrlbarUtils.RESULT_SOURCE.TABS, + payload: { + url: action.params.url, + title: info.title, icon: info.icon, userContextId: info.userContextId, lastVisit: info.lastVisit, tabGroup: info.tabGroup, frecency: info.frecency, - } - ); - if (lazy.UrlbarPrefs.get("secondaryActions.switchToTab")) { - payloadAndHighlights.payload.action = - UrlbarUtils.createTabSwitchSecondaryAction(info.userContextId); - } - return new lazy.UrlbarResult({ - type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, - source: UrlbarUtils.RESULT_SOURCE.TABS, - ...payloadAndHighlights, + action: lazy.UrlbarPrefs.get("secondaryActions.switchToTab") + ? UrlbarUtils.createTabSwitchSecondaryAction(info.userContextId) + : undefined, + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } default: @@ -404,24 +404,32 @@ function makeUrlbarResult(tokens, info) { // We should also just include tags that match the searchString. tags = titleTags.split(",").filter(tag => { let lowerCaseTag = tag.toLocaleLowerCase(); - return tokens.some(token => lowerCaseTag.includes(token.lowerCaseValue)); + return queryContext.tokens.some(token => + lowerCaseTag.includes(token.lowerCaseValue) + ); }); } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(tokens, { - url: [info.url, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + url: info.url, icon: info.icon, - title: [title, UrlbarUtils.HIGHLIGHT.TYPED], - tags: [tags, UrlbarUtils.HIGHLIGHT.TYPED], + title, + tags, isBlockable, blockL10n, helpUrl, lastVisit: info.lastVisit, frecency: info.frecency, - }), + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + tags: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } diff --git a/browser/components/urlbar/UrlbarProviderPrivateSearch.sys.mjs b/browser/components/urlbar/UrlbarProviderPrivateSearch.sys.mjs @@ -103,16 +103,21 @@ export class UrlbarProviderPrivateSearch extends UrlbarProvider { } let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, suggestedIndex: 1, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], - query: [searchString, UrlbarUtils.HIGHLIGHT.NONE], + payload: { + engine: engine.name, + query: searchString, icon, inPrivateWindow: true, isPrivateEngine, - }), + }, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + query: UrlbarUtils.HIGHLIGHT.NONE, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderQuickSuggest.sys.mjs b/browser/components/urlbar/UrlbarProviderQuickSuggest.sys.mjs @@ -472,23 +472,22 @@ export class UrlbarProviderQuickSuggest extends UrlbarProvider { if (suggestion.full_keyword) { payload.title = suggestion.title; - payload.qsSuggestion = [ - suggestion.full_keyword, - UrlbarUtils.HIGHLIGHT.SUGGESTED, - ]; + payload.qsSuggestion = suggestion.full_keyword; } else { - payload.title = [suggestion.title, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.title = suggestion.title; payload.shouldShowUrl = true; } return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.SEARCH, isBestMatch: !!suggestion.is_top_pick, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload, + highlights: { + qsSuggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } diff --git a/browser/components/urlbar/UrlbarProviderRemoteTabs.sys.mjs b/browser/components/urlbar/UrlbarProviderRemoteTabs.sys.mjs @@ -206,15 +206,20 @@ export class UrlbarProviderRemoteTabs extends UrlbarProvider { } let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.REMOTE_TAB, source: UrlbarUtils.RESULT_SOURCE.TABS, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [tab.url, UrlbarUtils.HIGHLIGHT.TYPED], - title: [tab.title, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + url: tab.url, + title: tab.title, device: client.name, icon: lazy.showRemoteIconsPref ? tab.icon : "", lastUsed: (tab.lastUsed || 0) * 1000, - }), + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); // We want to return the most relevant remote tabs and thus the most diff --git a/browser/components/urlbar/UrlbarProviderRestrictKeywords.sys.mjs b/browser/components/urlbar/UrlbarProviderRestrictKeywords.sys.mjs @@ -70,18 +70,19 @@ export class UrlbarProviderRestrictKeywords extends UrlbarProvider { )?.icon; let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.RESTRICT, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, hideRowLabel: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { icon, keyword: token, - l10nRestrictKeywords: [ - l10nRestrictKeywords, - UrlbarUtils.HIGHLIGHT.TYPED, - ], + l10nRestrictKeywords, providesSearchMode: true, - }), + }, + highlights: { + l10nRestrictKeywords: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/UrlbarProviderRestrictKeywordsAutofill.sys.mjs b/browser/components/urlbar/UrlbarProviderRestrictKeywordsAutofill.sys.mjs @@ -149,10 +149,10 @@ export class UrlbarProviderRestrictKeywordsAutofill extends UrlbarProvider { source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, heuristic: true, hideRowLabel: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { keyword: restrictSymbol, providesSearchMode: false, - }), + }, }); addCallback(this, result); } @@ -189,6 +189,7 @@ export class UrlbarProviderRestrictKeywordsAutofill extends UrlbarProvider { )?.icon; return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.RESTRICT, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, hideRowLabel: true, @@ -197,19 +198,17 @@ export class UrlbarProviderRestrictKeywordsAutofill extends UrlbarProvider { selectionStart: queryContext.searchString.length, selectionEnd: value.length, }, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { icon, keyword: token, - l10nRestrictKeywords: [ - l10nRestrictKeywords, - UrlbarUtils.HIGHLIGHT.TYPED, - ], - autofillKeyword: [ - keywordPreservingUserCase, - UrlbarUtils.HIGHLIGHT.TYPED, - ], + l10nRestrictKeywords, + autofillKeyword: keywordPreservingUserCase, providesSearchMode: true, - }), + }, + highlights: { + l10nRestrictKeywords: UrlbarUtils.HIGHLIGHT.TYPED, + autofillKeyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } } diff --git a/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs b/browser/components/urlbar/UrlbarProviderSearchSuggestions.sys.mjs @@ -492,33 +492,33 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { } try { - let payload = { - engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], - suggestion: [entry.value, UrlbarUtils.HIGHLIGHT.SUGGESTED], - lowerCaseSuggestion: entry.value.toLocaleLowerCase(), - tailPrefix, - tail: [tail, UrlbarUtils.HIGHLIGHT.SUGGESTED], - tailOffsetIndex: tail ? entry.tailOffsetIndex : undefined, - keyword: [alias ? alias : undefined, UrlbarUtils.HIGHLIGHT.TYPED], - trending: entry.trending, - description: entry.description || undefined, - query: [searchString.trim(), UrlbarUtils.HIGHLIGHT.NONE], - icon: !entry.value ? await engine.getIconURL() : entry.icon, - }; - - if (entry.trending) { - payload.helpUrl = TRENDING_HELP_URL; - } - results.push( new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, isRichSuggestion: !!entry.icon, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload: { + engine: engine.name, + suggestion: entry.value, + lowerCaseSuggestion: entry.value.toLocaleLowerCase(), + tailPrefix, + tail, + tailOffsetIndex: tail ? entry.tailOffsetIndex : undefined, + keyword: alias || undefined, + trending: entry.trending, + description: entry.description || undefined, + query: searchString.trim(), + icon: !entry.value ? await engine.getIconURL() : entry.icon, + helpUrl: entry.trending ? TRENDING_HELP_URL : undefined, + }, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + suggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + tail: UrlbarUtils.HIGHLIGHT.SUGGESTED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + query: UrlbarUtils.HIGHLIGHT.NONE, + }, }) ); } catch (err) { @@ -639,17 +639,21 @@ export class UrlbarProviderSearchSuggestions extends UrlbarProvider { function makeFormHistoryResult(queryContext, engine, entry) { return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.HISTORY, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { engine: engine.name, - suggestion: [entry.value, UrlbarUtils.HIGHLIGHT.SUGGESTED], + suggestion: entry.value, lowerCaseSuggestion: entry.value.toLocaleLowerCase(), isBlockable: true, blockL10n: { id: "urlbar-result-menu-remove-from-history" }, helpUrl: Services.urlFormatter.formatURLPref("app.support.baseURL") + "awesome-bar-result-menu", - }), + }, + highlights: { + suggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + }, }); } diff --git a/browser/components/urlbar/UrlbarProviderSemanticHistorySearch.sys.mjs b/browser/components/urlbar/UrlbarProviderSemanticHistorySearch.sys.mjs @@ -139,11 +139,12 @@ export class UrlbarProviderSemanticHistorySearch extends UrlbarProvider { ) ) { const result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.HISTORY, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [res.title, UrlbarUtils.HIGHLIGHT.NONE], - url: [res.url, UrlbarUtils.HIGHLIGHT.NONE], + payload: { + title: res.title, + url: res.url, icon: UrlbarUtils.getIconForUrl(res.url), isBlockable: true, blockL10n: { id: "urlbar-result-menu-remove-from-history" }, @@ -151,7 +152,11 @@ export class UrlbarProviderSemanticHistorySearch extends UrlbarProvider { Services.urlFormatter.formatURLPref("app.support.baseURL") + "awesome-bar-result-menu", frecency: res.frecency, - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.NONE, + url: UrlbarUtils.HIGHLIGHT.NONE, + }, }); addCallback(this, result); } @@ -200,24 +205,25 @@ export class UrlbarProviderSemanticHistorySearch extends UrlbarProvider { ) { continue; } - let { payload, payloadHighlights } = - lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [res.url, UrlbarUtils.HIGHLIGHT.NONE], - title: [res.title, UrlbarUtils.HIGHLIGHT.NONE], + let result = new lazy.UrlbarResult({ + queryContext, + type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + source: UrlbarUtils.RESULT_SOURCE.TABS, + payload: { + url: res.url, + title: res.title, icon: UrlbarUtils.getIconForUrl(res.url), userContextId: tabUserContextId, tabGroup: tabGroupId, lastVisit: res.lastVisit, - }); - if (lazy.UrlbarPrefs.get("secondaryActions.switchToTab")) { - payload.action = - UrlbarUtils.createTabSwitchSecondaryAction(tabUserContextId); - } - let result = new lazy.UrlbarResult({ - type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, - source: UrlbarUtils.RESULT_SOURCE.TABS, - payload, - payloadHighlights, + action: lazy.UrlbarPrefs.get("secondaryActions.switchToTab") + ? UrlbarUtils.createTabSwitchSecondaryAction(tabUserContextId) + : undefined, + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.NONE, + title: UrlbarUtils.HIGHLIGHT.NONE, + }, }); addCallback(this, result); added = true; diff --git a/browser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs b/browser/components/urlbar/UrlbarProviderTabToSearch.sys.mjs @@ -379,7 +379,7 @@ function makeResult(context, engine, satisfiesAutofillThreshold = false) { type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, suggestedIndex: 1, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(context.tokens, { + payload: { engine: engine.name, isGeneralPurposeEngine: engine.isGeneralPurposeEngine, searchUrlDomainWithoutSuffix: searchUrlDomainWithoutSuffix(engine), @@ -387,7 +387,7 @@ function makeResult(context, engine, satisfiesAutofillThreshold = false) { icon: UrlbarUtils.ICON.SEARCH_GLASS, query: "", satisfiesAutofillThreshold, - }), + }, }); } diff --git a/browser/components/urlbar/UrlbarProviderTokenAliasEngines.sys.mjs b/browser/components/urlbar/UrlbarProviderTokenAliasEngines.sys.mjs @@ -123,17 +123,22 @@ export class UrlbarProviderTokenAliasEngines extends UrlbarProvider { engine.name != this._autofillData?.result.payload.engine ) { let result = new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, hideRowLabel: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [tokenAliases[0], UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + engine: engine.name, + keyword: tokenAliases[0], keywords: tokenAliases.join(", "), - query: ["", UrlbarUtils.HIGHLIGHT.TYPED], + query: "", icon: await engine.getIconURL(), providesSearchMode: true, - }), + }, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); if (instance != this.queryInstance) { break; @@ -190,6 +195,7 @@ export class UrlbarProviderTokenAliasEngines extends UrlbarProvider { alias.substr(queryContext.searchString.length); let value = aliasPreservingUserCase + " "; return new lazy.UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, // We set suggestedIndex = 0 instead of the heuristic because we @@ -203,17 +209,18 @@ export class UrlbarProviderTokenAliasEngines extends UrlbarProvider { selectionEnd: value.length, }, hideRowLabel: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - { - engine: [engine.name, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [aliasPreservingUserCase, UrlbarUtils.HIGHLIGHT.TYPED], - keywords: tokenAliases.join(", "), - query: ["", UrlbarUtils.HIGHLIGHT.TYPED], - icon: await engine.getIconURL(), - providesSearchMode: true, - } - ), + payload: { + engine: engine.name, + keyword: aliasPreservingUserCase, + keywords: tokenAliases.join(", "), + query: "", + icon: await engine.getIconURL(), + providesSearchMode: true, + }, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } } diff --git a/browser/components/urlbar/UrlbarProviderTopSites.sys.mjs b/browser/components/urlbar/UrlbarProviderTopSites.sys.mjs @@ -248,10 +248,7 @@ export class UrlbarProviderTopSites extends UrlbarProvider { let result = new lazy.UrlbarResult({ type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, source: UrlbarUtils.RESULT_SOURCE.TABS, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload, }); addCallback(this, result); switchToTabResultAdded = true; @@ -287,10 +284,7 @@ export class UrlbarProviderTopSites extends UrlbarProvider { let result = new lazy.UrlbarResult({ type: UrlbarUtils.RESULT_TYPE.URL, source: resultSource, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload, }); addCallback(this, result); break; @@ -320,17 +314,14 @@ export class UrlbarProviderTopSites extends UrlbarProvider { let result = new lazy.UrlbarResult({ type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.SEARCH, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - { - keyword: site.title, - providesSearchMode: true, - engine: engine.name, - query: "", - icon: site.favicon, - isPinned: site.isPinned, - } - ), + payload: { + keyword: site.title, + providesSearchMode: true, + engine: engine.name, + query: "", + icon: site.favicon, + isPinned: site.isPinned, + }, }); addCallback(this, result); break; diff --git a/browser/components/urlbar/UrlbarResult.sys.mjs b/browser/components/urlbar/UrlbarResult.sys.mjs @@ -37,13 +37,13 @@ ChromeUtils.defineESModuleGetters(lazy, { */ export class UrlbarResult { /** - * @typedef {object} Payload - * @property {string} [qsSuggestion] - * The suggestion text from quick suggest. + * @typedef {{ [name: string]: any }} Payload + * @typedef {Record<string, typeof lazy.UrlbarUtils.HIGHLIGHT>} Highlights */ /** * @param {object} params + * @param {object} [params.queryContext] Used for highlighting. * @param {Values<typeof lazy.UrlbarUtils.RESULT_TYPE>} params.type * @param {Values<typeof lazy.UrlbarUtils.RESULT_SOURCE>} params.source * @param {UrlbarAutofillData} [params.autofill] @@ -63,9 +63,11 @@ export class UrlbarResult { * @param {number} [params.suggestedIndex] * @param {Payload} [params.payload] * @param {object} [params.payloadHighlights] + * @param {Highlights} [params.highlights] * @param {boolean} [params.testForceNewContent] Used for test only. */ constructor({ + queryContext, type, source, autofill, @@ -85,6 +87,7 @@ export class UrlbarResult { suggestedIndex, payload, payloadHighlights = {}, + highlights = null, testForceNewContent, }) { // Type describes the payload and visualization that should be used for @@ -106,11 +109,28 @@ export class UrlbarResult { if (!payload || typeof payload != "object") { throw new Error("Invalid result payload"); } - this.#payload = this.#validatePayload(payload); if (!payloadHighlights || typeof payloadHighlights != "object") { throw new Error("Invalid result payload highlights"); } + + payload = Object.fromEntries( + Object.entries(payload).filter(([_, v]) => v != undefined) + ); + + if (highlights) { + if (!queryContext) { + throw new Error("queryContext is needed to highlight"); + } + this.#initPayloadAndHighlights({ + payload, + payloadHighlights, + tokens: queryContext.tokens, + highlightTargets: highlights, + }); + } + + this.#payload = this.#validatePayload(payload); this.#payloadHighlights = Object.freeze(payloadHighlights); this.#autofill = autofill; @@ -375,54 +395,12 @@ export class UrlbarResult { return payload; } - /** - * A convenience function that takes a payload annotated with - * UrlbarUtils.HIGHLIGHT enums and returns the payload and the payload's - * highlights. Use this function when the highlighting required by your - * payload is based on simple substring matching, as done by - * UrlbarUtils.getTokenMatches(). Pass the return values as the `payload` and - * `payloadHighlights` params of the UrlbarResult constructor. - * `payloadHighlights` is optional. If omitted, payload will not be - * highlighted. - * - * If the payload doesn't have a title or has an empty title, and it also has - * a URL, then this function also sets the title to the URL's domain. - * - * @param {Array} tokens The tokens that should be highlighted in each of the - * payload properties. - * @param {object} payloadInfo An object that looks like this: - * { payloadPropertyName: payloadPropertyInfo } - * - * Each payloadPropertyInfo may be either a string or an array. If - * it's a string, then the property value will be that string, and no - * highlighting will be applied to it. If it's an array, then it - * should look like this: [payloadPropertyValue, highlightType]. - * payloadPropertyValue may be a string or an array of strings. If - * it's a string, then the payloadHighlights in the return value will - * be an array of match highlights as described in - * UrlbarUtils.getTokenMatches(). If it's an array, then - * payloadHighlights will be an array of arrays of match highlights, - * one element per element in payloadPropertyValue. - * @returns {{ payload: object, payloadHighlights: object }} - */ - static payloadAndSimpleHighlights(tokens, payloadInfo) { - let payload = {}; - let highlightTypes = {}; - - for (let [name, valueOrValues] of Object.entries(payloadInfo)) { - if (Array.isArray(valueOrValues)) { - if (valueOrValues.length) { - payload[name] = valueOrValues[0]; - let highlightType = valueOrValues[1]; - if (highlightType) { - highlightTypes[name] = highlightType; - } - } - } else if (valueOrValues != undefined) { - payload[name] = valueOrValues; - } - } - + #initPayloadAndHighlights({ + payload, + payloadHighlights, + tokens, + highlightTargets, + }) { if ( !payload.title && !payload.fallbackTitle && @@ -431,16 +409,16 @@ export class UrlbarResult { ) { // If there's no title, show the domain as the title. Not all valid URLs // have a domain. - highlightTypes.title = lazy.UrlbarUtils.HIGHLIGHT.TYPED; try { payload.title = new URL(payload.url).URI.displayHostPort; + highlightTargets.title = lazy.UrlbarUtils.HIGHLIGHT.TYPED; } catch (e) {} } if (payload.url) { // For display purposes we need to unescape the url. payload.displayUrl = lazy.UrlbarUtils.prepareUrlForDisplay(payload.url); - highlightTypes.displayUrl = highlightTypes.url; + highlightTargets.displayUrl = highlightTargets.url; } // For performance reasons limit excessive string lengths, to reduce the @@ -453,26 +431,29 @@ export class UrlbarResult { } } - let payloadHighlights = {}; - if (tokens) { - for (let [name, highlightType] of Object.entries(highlightTypes)) { - let value = payload[name]; - let highlights = Array.isArray(value) - ? value.map(subval => - lazy.UrlbarUtils.getTokenMatches(tokens, subval, highlightType) - ) - : lazy.UrlbarUtils.getTokenMatches( - tokens, - value || "", - highlightType - ); - if (highlights.length) { - payloadHighlights[name] = highlights; - } - } + if (!tokens?.length) { + return; } - return { payload, payloadHighlights }; + for (let [name, highlightType] of Object.entries(highlightTargets)) { + if (!highlightType) { + continue; + } + + let value = payload[name]; + if (!value) { + continue; + } + + let highlights = Array.isArray(value) + ? value.map(subval => + lazy.UrlbarUtils.getTokenMatches(tokens, subval, highlightType) + ) + : lazy.UrlbarUtils.getTokenMatches(tokens, value || "", highlightType); + if (highlights.length) { + payloadHighlights[name] = highlights; + } + } } static _dynamicResultTypesByName = new Map(); diff --git a/browser/components/urlbar/UrlbarUtils.sys.mjs b/browser/components/urlbar/UrlbarUtils.sys.mjs @@ -1732,7 +1732,7 @@ export var UrlbarUtils = { * The text content to give the node. * @param {Array} highlights * Array of highlights as returned by `UrlbarUtils.getTokenMatches()` or - * `UrlbarResult.payloadAndSimpleHighlights()`. + * `UrlbarResult.payloadHighlights`. */ addTextContentWithHighlights(parentNode, textContent, highlights) { parentNode.textContent = ""; @@ -3394,7 +3394,7 @@ export class L10nCache { * If this is set, apply substring highlighting to the corresponding l10n * arguments in `args`. Each value in this object should be an array of * highlights as returned by `UrlbarUtils.getTokenMatches()` or - * `UrlbarResult.payloadAndSimpleHighlights()`. + * `UrlbarResult.payloadHighlights`. * @param {string} [options.attribute] * If the string applies to an attribute on the element, pass the name of * the attribute. The string in the Fluent file should define a value for diff --git a/browser/components/urlbar/private/AddonSuggestions.sys.mjs b/browser/components/urlbar/private/AddonSuggestions.sys.mjs @@ -87,21 +87,8 @@ export class AddonSuggestions extends SuggestProvider { } } - const payload = { - url: url.href, - originalUrl: suggestion.url, - shouldShowUrl: true, - // Rust uses `iconUrl` but Merino uses `icon`. - icon: suggestion.iconUrl ?? suggestion.icon, - title: suggestion.title, - description: suggestion.description, - bottomTextL10n: { - id: "firefox-suggest-addons-recommended", - }, - helpUrl: lazy.QuickSuggest.HELP_URL, - }; - return new lazy.UrlbarResult({ + queryContext, type: lazy.UrlbarUtils.RESULT_TYPE.URL, source: lazy.UrlbarUtils.RESULT_SOURCE.SEARCH, isBestMatch: true, @@ -109,10 +96,23 @@ export class AddonSuggestions extends SuggestProvider { isRichSuggestion: true, richSuggestionIconSize: 24, showFeedbackMenu: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload: { + url: url.href, + originalUrl: suggestion.url, + shouldShowUrl: true, + // Rust uses `iconUrl` but Merino uses `icon`. + icon: suggestion.iconUrl ?? suggestion.icon, + title: suggestion.title, + description: suggestion.description, + bottomTextL10n: { + id: "firefox-suggest-addons-recommended", + }, + helpUrl: lazy.QuickSuggest.HELP_URL, + }, + // TODO: We have to set highlights to calculate displayUrl now. But, since + // it is not related to the higilights, think about it with another + // way. + highlights: {}, }); } diff --git a/browser/components/urlbar/private/AmpSuggestions.sys.mjs b/browser/components/urlbar/private/AmpSuggestions.sys.mjs @@ -114,6 +114,7 @@ export class AmpSuggestions extends SuggestProvider { url: normalized.url, originalUrl: normalized.rawUrl, title: normalized.title, + qsSuggestion: normalized.fullKeyword, requestId: normalized.requestId, urlTimestampIndex: normalized.urlTimestampIndex, sponsoredImpressionUrl: normalized.impressionUrl, @@ -130,13 +131,6 @@ export class AmpSuggestions extends SuggestProvider { lazy.UrlbarPrefs.get("quickSuggestAmpTopPickCharThreshold") <= queryContext.trimmedLowerCaseSearchString.length; - payload.qsSuggestion = [ - normalized.fullKeyword, - isTopPick - ? lazy.UrlbarUtils.HIGHLIGHT.TYPED - : lazy.UrlbarUtils.HIGHLIGHT.SUGGESTED, - ]; - let resultParams = {}; if (isTopPick) { resultParams.isBestMatch = true; @@ -154,14 +148,17 @@ export class AmpSuggestions extends SuggestProvider { } return new lazy.UrlbarResult({ + queryContext, type: lazy.UrlbarUtils.RESULT_TYPE.URL, source: lazy.UrlbarUtils.RESULT_SOURCE.SEARCH, isRichSuggestion: true, ...resultParams, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload, + highlights: { + qsSuggestion: isTopPick + ? lazy.UrlbarUtils.HIGHLIGHT.TYPED + : lazy.UrlbarUtils.HIGHLIGHT.SUGGESTED, + }, }); } diff --git a/browser/components/urlbar/private/DynamicSuggestions.sys.mjs b/browser/components/urlbar/private/DynamicSuggestions.sys.mjs @@ -103,17 +103,21 @@ export class DynamicSuggestions extends SuggestProvider { return null; } + payload.isManageable = true; + payload.helpUrl = lazy.QuickSuggest.HELP_URL; + let resultProperties = { ...result }; delete resultProperties.payload; return new lazy.UrlbarResult({ + queryContext, type: lazy.UrlbarUtils.RESULT_TYPE.URL, source: lazy.UrlbarUtils.RESULT_SOURCE.SEARCH, ...resultProperties, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - ...payload, - isManageable: true, - helpUrl: lazy.QuickSuggest.HELP_URL, - }), + payload, + // TODO: We have to set highlights to calculate displayUrl now. But, since + // it is not related to the higilights, think about it with another + // way. + highlights: {}, }); } diff --git a/browser/components/urlbar/private/MDNSuggestions.sys.mjs b/browser/components/urlbar/private/MDNSuggestions.sys.mjs @@ -55,27 +55,26 @@ export class MDNSuggestions extends SuggestProvider { ); url.searchParams.set("utm_content", "treatment"); - const payload = { - icon: "chrome://global/skin/icons/mdn.svg", - url: url.href, - originalUrl: suggestion.url, - title: [suggestion.title, lazy.UrlbarUtils.HIGHLIGHT.TYPED], - description: suggestion.description, - shouldShowUrl: true, - bottomTextL10n: { - id: "firefox-suggest-mdn-bottom-text", - }, - }; - return new lazy.UrlbarResult({ + queryContext, type: lazy.UrlbarUtils.RESULT_TYPE.URL, source: lazy.UrlbarUtils.RESULT_SOURCE.OTHER_NETWORK, isBestMatch: true, showFeedbackMenu: true, - ...lazy.UrlbarResult.payloadAndSimpleHighlights( - queryContext.tokens, - payload - ), + payload: { + icon: "chrome://global/skin/icons/mdn.svg", + url: url.href, + originalUrl: suggestion.url, + title: suggestion.title, + description: suggestion.description, + shouldShowUrl: true, + bottomTextL10n: { + id: "firefox-suggest-mdn-bottom-text", + }, + }, + highlights: { + title: lazy.UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } diff --git a/browser/components/urlbar/private/WikipediaSuggestions.sys.mjs b/browser/components/urlbar/private/WikipediaSuggestions.sys.mjs @@ -49,19 +49,21 @@ export class WikipediaSuggestions extends SuggestProvider { makeResult(queryContext, suggestion) { return new lazy.UrlbarResult({ + queryContext, type: lazy.UrlbarUtils.RESULT_TYPE.URL, source: lazy.UrlbarUtils.RESULT_SOURCE.SEARCH, - ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { url: suggestion.url, title: suggestion.title, - qsSuggestion: [ + qsSuggestion: // Merino uses snake_case, so this will be `full_keyword` for it. suggestion.fullKeyword ?? suggestion.full_keyword, - lazy.UrlbarUtils.HIGHLIGHT.SUGGESTED, - ], isBlockable: true, isManageable: true, - }), + }, + highlights: { + qsSuggestion: lazy.UrlbarUtils.HIGHLIGHT.SUGGESTED, + }, }); } diff --git a/browser/components/urlbar/tests/browser/browser_bestMatch.js b/browser/components/urlbar/tests/browser/browser_bestMatch.js @@ -178,13 +178,18 @@ async function withProvider(result, callback) { function makeBestMatchResult(payloadExtra = {}) { return new UrlbarResult({ + queryContext: { tokens: [] }, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.SEARCH, isBestMatch: true, - ...UrlbarResult.payloadAndSimpleHighlights([], { + payload: { title: "Test best match", url: "https://example.com/best-match", ...payloadExtra, - }), + }, + // TODO: We have to set highlights to calculate displayUrl now. But, since + // it is not related to the higilights, think about it with another + // way. + highlights: {}, }); } diff --git a/browser/components/urlbar/tests/browser/browser_dynamicResults.js b/browser/components/urlbar/tests/browser/browser_dynamicResults.js @@ -574,13 +574,17 @@ add_task(async function highlighting() { class TestHighlightProvider extends TestProvider { startQuery(context, addCallback) { let result = new UrlbarResult({ + queryContext: context, type: UrlbarUtils.RESULT_TYPE.DYNAMIC, source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, suggestedIndex: 1, - ...UrlbarResult.payloadAndSimpleHighlights(context.tokens, { + payload: { dynamicType: DYNAMIC_TYPE_NAME, - text: ["Test title", UrlbarUtils.HIGHLIGHT.TYPED], - }), + text: "Test title", + }, + highlights: { + text: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js b/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js @@ -10,12 +10,14 @@ add_task(async function test_receive_punycode_result() { class ResultWithHighlightsProvider extends UrlbarTestUtils.TestProvider { startQuery(context, addCallback) { let result = new UrlbarResult({ + queryContext: context, type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.HISTORY, suggestedIndex: 0, - ...UrlbarResult.payloadAndSimpleHighlights(context.tokens, { - url: [url, UrlbarUtils.HIGHLIGHT.TYPED], - }), + payload: { url }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); addCallback(this, result); } diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_annotation.js b/browser/components/urlbar/tests/browser/browser_urlbar_annotation.js @@ -71,9 +71,7 @@ function registerProvider(payload) { new UrlbarResult({ type: UrlbarUtils.RESULT_TYPE.URL, source: UrlbarUtils.RESULT_SOURCE.SEARCH, - ...UrlbarResult.payloadAndSimpleHighlights([], { - ...payload, - }), + payload, }), ], priority: Infinity, diff --git a/browser/components/urlbar/tests/unit/head.js b/browser/components/urlbar/tests/unit/head.js @@ -456,15 +456,16 @@ function makeBookmarkResult( } ) { return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source, heuristic, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [uri, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + url: uri, + title, + tags, // Check against undefined so consumers can pass in the empty string. - icon: [typeof iconUri != "undefined" ? iconUri : `page-icon:${uri}`], - title: [title, UrlbarUtils.HIGHLIGHT.TYPED], - tags: [tags, UrlbarUtils.HIGHLIGHT.TYPED], + icon: typeof iconUri != "undefined" ? iconUri : `page-icon:${uri}`, isBlockable: source == UrlbarUtils.RESULT_SOURCE.HISTORY ? true : undefined, blockL10n: @@ -476,7 +477,12 @@ function makeBookmarkResult( ? Services.urlFormatter.formatURLPref("app.support.baseURL") + "awesome-bar-result-menu" : undefined, - }), + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + tags: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -495,18 +501,22 @@ function makeBookmarkResult( */ function makeFormHistoryResult(queryContext, { suggestion, engineName }) { return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.SEARCH, source: UrlbarUtils.RESULT_SOURCE.HISTORY, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { + payload: { engine: engineName, - suggestion: [suggestion, UrlbarUtils.HIGHLIGHT.SUGGESTED], + suggestion, lowerCaseSuggestion: suggestion.toLocaleLowerCase(), isBlockable: true, blockL10n: { id: "urlbar-result-menu-remove-from-history" }, helpUrl: Services.urlFormatter.formatURLPref("app.support.baseURL") + "awesome-bar-result-menu", - }), + }, + highlights: { + suggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + }, }); } @@ -533,17 +543,22 @@ function makeOmniboxResult( queryContext, { content, description, keyword, heuristic = false } ) { - let payload = { - title: [description, UrlbarUtils.HIGHLIGHT.TYPED], - content: [content, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [keyword, UrlbarUtils.HIGHLIGHT.TYPED], - icon: [UrlbarUtils.ICON.EXTENSION], - }; return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.OMNIBOX, source: UrlbarUtils.RESULT_SOURCE.ADDON, heuristic, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, payload), + payload: { + title: description, + content, + keyword, + icon: UrlbarUtils.ICON.EXTENSION, + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + content: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -571,16 +586,21 @@ function makeTabSwitchResult( { uri, title, iconUri, userContextId, tabGroup } ) { return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH, source: UrlbarUtils.RESULT_SOURCE.TABS, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - url: [uri, UrlbarUtils.HIGHLIGHT.TYPED], - title: [title, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + url: uri, + title, // Check against undefined so consumers can pass in the empty string. icon: typeof iconUri != "undefined" ? iconUri : `page-icon:${uri}`, - userContextId: [userContextId || 0], - tabGroup: [tabGroup || null], - }), + userContextId: userContextId || 0, + tabGroup, + }, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -610,17 +630,24 @@ function makeKeywordSearchResult( { uri, keyword, title, iconUri, postData, heuristic = false } ) { return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.KEYWORD, source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS, heuristic, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, { - title: [title ? title : uri, UrlbarUtils.HIGHLIGHT.TYPED], - url: [uri, UrlbarUtils.HIGHLIGHT.TYPED], - keyword: [keyword, UrlbarUtils.HIGHLIGHT.TYPED], - input: [queryContext.searchString, UrlbarUtils.HIGHLIGHT.TYPED], + payload: { + title: title || uri, + url: uri, + keyword, + input: queryContext.searchString, postData: postData || null, icon: typeof iconUri != "undefined" ? iconUri : `page-icon:${uri}`, - }), + }, + highlights: { + title: UrlbarUtils.HIGHLIGHT.TYPED, + url: UrlbarUtils.HIGHLIGHT.TYPED, + keyword: UrlbarUtils.HIGHLIGHT.TYPED, + input: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -649,8 +676,8 @@ function makeRemoteTabResult( { uri, device, title, iconUri, lastUsed = 0 } ) { let payload = { - url: [uri, UrlbarUtils.HIGHLIGHT.TYPED], - device: [device, UrlbarUtils.HIGHLIGHT.TYPED], + url: uri, + device, // Check against undefined so consumers can pass in the empty string. icon: typeof iconUri != "undefined" ? iconUri : `page-icon:${uri}`, lastUsed: lastUsed * 1000, @@ -658,15 +685,21 @@ function makeRemoteTabResult( // Check against undefined so consumers can pass in the empty string. if (typeof title != "undefined") { - payload.title = [title, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.title = title; } else { - payload.title = [uri, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.title = uri; } return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.REMOTE_TAB, source: UrlbarUtils.RESULT_SOURCE.TABS, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, payload), + payload, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + device: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -762,22 +795,15 @@ function makeSearchResult( } let payload = { - engine: [engineName, UrlbarUtils.HIGHLIGHT.TYPED], - suggestion: [suggestion, UrlbarUtils.HIGHLIGHT.SUGGESTED], + engine: engineName, + suggestion, tailPrefix, - tail: [tail, UrlbarUtils.HIGHLIGHT.SUGGESTED], + tail, tailOffsetIndex, - keyword: [ - alias, - providesSearchMode - ? UrlbarUtils.HIGHLIGHT.TYPED - : UrlbarUtils.HIGHLIGHT.NONE, - ], + keyword: alias, // Check against undefined so consumers can pass in the empty string. - query: [ + query: typeof query != "undefined" ? query : queryContext.trimmedSearchString, - UrlbarUtils.HIGHLIGHT.TYPED, - ], icon: engineIconUri, providesSearchMode, inPrivateWindow, @@ -814,12 +840,22 @@ function makeSearchResult( } return new UrlbarResult({ + queryContext, type, source, heuristic, isRichSuggestion, providerName, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, payload), + payload, + highlights: { + engine: UrlbarUtils.HIGHLIGHT.TYPED, + suggestion: UrlbarUtils.HIGHLIGHT.SUGGESTED, + tail: UrlbarUtils.HIGHLIGHT.SUGGESTED, + keyword: providesSearchMode + ? UrlbarUtils.HIGHLIGHT.TYPED + : UrlbarUtils.HIGHLIGHT.NONE, + query: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); } @@ -863,15 +899,15 @@ function makeVisitResult( } ) { let payload = { - url: [uri, UrlbarUtils.HIGHLIGHT.TYPED], + url: uri, }; if (title) { - payload.title = [title, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.title = title; } if (fallbackTitle) { - payload.fallbackTitle = [fallbackTitle, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.fallbackTitle = fallbackTitle; } if ( @@ -896,15 +932,22 @@ function makeVisitResult( } if (!heuristic && tags) { - payload.tags = [tags, UrlbarUtils.HIGHLIGHT.TYPED]; + payload.tags = tags; } return new UrlbarResult({ + queryContext, type: UrlbarUtils.RESULT_TYPE.URL, source, heuristic, providerName, - ...UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, payload), + payload, + highlights: { + url: UrlbarUtils.HIGHLIGHT.TYPED, + title: UrlbarUtils.HIGHLIGHT.TYPED, + fallbackTitle: UrlbarUtils.HIGHLIGHT.TYPED, + tags: UrlbarUtils.HIGHLIGHT.TYPED, + }, }); }