Bug 1944416: Restore individual tabs from closed groups in closed windows r=dao,sessi...
[gecko.git] / browser / components / urlbar / UrlbarProviderAboutPages.sys.mjs
blobbe607a80d52cc463a94f89f71286472ce1adac82
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/. */
5 /**
6  * This module exports a provider that offers about pages.
7  */
9 import {
10   UrlbarProvider,
11   UrlbarUtils,
12 } from "resource:///modules/UrlbarUtils.sys.mjs";
14 const lazy = {};
16 ChromeUtils.defineESModuleGetters(lazy, {
17   AboutPagesUtils: "resource://gre/modules/AboutPagesUtils.sys.mjs",
18   UrlbarResult: "resource:///modules/UrlbarResult.sys.mjs",
19 });
21 /**
22  * Class used to create the provider.
23  */
24 class ProviderAboutPages extends UrlbarProvider {
25   /**
26    * Unique name for the provider, used by the context to filter on providers.
27    *
28    * @returns {string}
29    */
30   get name() {
31     return "AboutPages";
32   }
34   /**
35    * The type of the provider, must be one of UrlbarUtils.PROVIDER_TYPE.
36    *
37    * @returns {UrlbarUtils.PROVIDER_TYPE}
38    */
39   get type() {
40     return UrlbarUtils.PROVIDER_TYPE.PROFILE;
41   }
43   /**
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.
47    *
48    * @param {UrlbarQueryContext} queryContext The query context object
49    * @returns {boolean} Whether this provider should be invoked for the search.
50    */
51   isActive(queryContext) {
52     return queryContext.trimmedLowerCaseSearchString.startsWith("about:");
53   }
55   /**
56    * Starts querying. Extended classes should return a Promise resolved when the
57    * provider is done searching AND returning results.
58    *
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.
62    */
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),
74           })
75         );
76         addCallback(this, result);
77       }
78     }
79   }
82 export var UrlbarProviderAboutPages = new ProviderAboutPages();