1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 * This module exports a provider that offers about pages.
12 } from "resource:///modules/UrlbarUtils.sys.mjs";
16 ChromeUtils.defineESModuleGetters(lazy, {
17 AboutPagesUtils: "resource://gre/modules/AboutPagesUtils.sys.mjs",
18 UrlbarResult: "resource:///modules/UrlbarResult.sys.mjs",
22 * Class used to create the provider.
24 class ProviderAboutPages extends UrlbarProvider {
26 * Unique name for the provider, used by the context to filter on providers.
35 * The type of the provider, must be one of UrlbarUtils.PROVIDER_TYPE.
37 * @returns {UrlbarUtils.PROVIDER_TYPE}
40 return UrlbarUtils.PROVIDER_TYPE.PROFILE;
44 * Whether this provider should be invoked for the given context.
45 * If this method returns false, the providers manager won't start a query
46 * with this provider, to save on resources.
48 * @param {UrlbarQueryContext} queryContext The query context object
49 * @returns {boolean} Whether this provider should be invoked for the search.
51 isActive(queryContext) {
52 return queryContext.trimmedLowerCaseSearchString.startsWith("about:");
56 * Starts querying. Extended classes should return a Promise resolved when the
57 * provider is done searching AND returning results.
59 * @param {UrlbarQueryContext} queryContext The query context object
60 * @param {Function} addCallback Callback invoked by the provider to add a new
61 * result. A UrlbarResult should be passed to it.
63 startQuery(queryContext, addCallback) {
64 let searchString = queryContext.trimmedLowerCaseSearchString;
65 for (const aboutUrl of lazy.AboutPagesUtils.visibleAboutUrls) {
66 if (aboutUrl.startsWith(searchString)) {
67 let result = new lazy.UrlbarResult(
68 UrlbarUtils.RESULT_TYPE.URL,
69 UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
70 ...lazy.UrlbarResult.payloadAndSimpleHighlights(queryContext.tokens, {
71 title: [aboutUrl, UrlbarUtils.HIGHLIGHT.TYPED],
72 url: [aboutUrl, UrlbarUtils.HIGHLIGHT.TYPED],
73 icon: UrlbarUtils.getIconForUrl(aboutUrl),
76 addCallback(this, result);
82 export var UrlbarProviderAboutPages = new ProviderAboutPages();