UrlbarProviderAboutPages.sys.mjs (2174B)
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/. */ 4 5 /** 6 * This module exports a provider that offers about pages. 7 */ 8 9 import { 10 UrlbarProvider, 11 UrlbarUtils, 12 } from "moz-src:///browser/components/urlbar/UrlbarUtils.sys.mjs"; 13 14 const lazy = {}; 15 16 ChromeUtils.defineESModuleGetters(lazy, { 17 AboutPagesUtils: "resource://gre/modules/AboutPagesUtils.sys.mjs", 18 UrlbarResult: "moz-src:///browser/components/urlbar/UrlbarResult.sys.mjs", 19 }); 20 21 /** 22 * Class used to create the provider. 23 */ 24 export class UrlbarProviderAboutPages extends UrlbarProvider { 25 /** 26 * @returns {Values<typeof UrlbarUtils.PROVIDER_TYPE>} 27 */ 28 get type() { 29 return UrlbarUtils.PROVIDER_TYPE.PROFILE; 30 } 31 32 /** 33 * Whether this provider should be invoked for the given context. 34 * If this method returns false, the providers manager won't start a query 35 * with this provider, to save on resources. 36 * 37 * @param {UrlbarQueryContext} queryContext The query context object 38 */ 39 async isActive(queryContext) { 40 return queryContext.trimmedLowerCaseSearchString.startsWith("about:"); 41 } 42 43 /** 44 * Starts querying. 45 * 46 * @param {UrlbarQueryContext} queryContext 47 * @param {(provider: UrlbarProvider, result: UrlbarResult) => void} addCallback 48 * Callback invoked by the provider to add a new result. 49 */ 50 startQuery(queryContext, addCallback) { 51 let searchString = queryContext.trimmedLowerCaseSearchString; 52 for (const aboutUrl of lazy.AboutPagesUtils.visibleAboutUrls) { 53 if (aboutUrl.startsWith(searchString)) { 54 let result = new lazy.UrlbarResult({ 55 type: UrlbarUtils.RESULT_TYPE.URL, 56 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 57 payload: { 58 title: aboutUrl, 59 url: aboutUrl, 60 icon: UrlbarUtils.getIconForUrl(aboutUrl), 61 }, 62 highlights: { 63 title: UrlbarUtils.HIGHLIGHT.TYPED, 64 url: UrlbarUtils.HIGHLIGHT.TYPED, 65 }, 66 }); 67 addCallback(this, result); 68 } 69 } 70 } 71 }