* Whether this provider should be invoked for the given context. * If this method returns false, the providers manager won't start a query * with this provider, to save on resources. * * @param {UrlbarQueryContext} queryContext The query context object */ async isActive(queryContext) { return ( (!queryContext.restrictSource || queryContext.restrictSource == UrlbarUtils.RESULT_SOURCE.BOOKMARKS) && !queryContext.searchMode && !!queryContext.tokens.length ); } /** * Starts querying. * * @param {UrlbarQueryContext} queryContext * @param {(provider: UrlbarProvider, result: UrlbarResult) => void} addCallback * Callback invoked by the provider to add a new result. */ async startQuery(queryContext, addCallback) { let keyword = queryContext.tokens[0]?.value; let searchString = UrlbarUtils.substringAfter( queryContext.searchString, keyword ).trim(); let { entry, url, postData } = await lazy.KeywordUtils.getBindableKeyword( keyword, searchString ); if (!entry || !url) { return; } let title; if (entry.url.host && searchString) { // If we have a search string, the result has the title // "host: searchString". title = UrlbarUtils.strings.formatStringFromName( "bookmarkKeywordSearch", [ entry.url.host, queryContext.tokens .slice(1) .map(t => t.value) .join(" "), ] ); } else { title = UrlbarUtils.prepareUrlForDisplay(url); } let result = new lazy.UrlbarResult({ type: UrlbarUtils.RESULT_TYPE.KEYWORD, source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS, heuristic: true, 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); } } PK