Bug 1864861: part 2) Remove `aIsPreload` argument from `FontLoaderUtils::BuildChannel...
[gecko.git] / browser / base / content / spotlight.js
blob48d2968bfc91637a602b1e2f4bcd63715186593a
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 const browser = window.docShell.chromeEventHandler;
6 const { document: gDoc, XPCOMUtils } = browser.ownerGlobal;
8 ChromeUtils.defineESModuleGetters(this, {
9   AboutWelcomeParent: "resource:///actors/AboutWelcomeParent.sys.mjs",
10 });
12 const CONFIG = window.arguments[0];
14 function addStylesheet(href) {
15   const link = document.head.appendChild(document.createElement("link"));
16   link.rel = "stylesheet";
17   link.href = href;
20 /**
21  * Render content based on about:welcome multistage template.
22  */
23 function renderMultistage(ready) {
24   const AWParent = new AboutWelcomeParent();
25   const receive = name => data =>
26     AWParent.onContentMessage(`AWPage:${name}`, data, browser);
28   // Expose top level functions expected by the bundle.
29   window.AWGetFeatureConfig = () => CONFIG;
30   window.AWGetSelectedTheme = receive("GET_SELECTED_THEME");
31   window.AWSelectTheme = data => receive("SELECT_THEME")(data?.toUpperCase());
32   // Do not send telemetry if message (e.g. spotlight in PBM) config sets metrics as 'block'.
33   if (CONFIG?.metrics !== "block") {
34     window.AWSendEventTelemetry = receive("TELEMETRY_EVENT");
35   }
36   window.AWSendToDeviceEmailsSupported = receive(
37     "SEND_TO_DEVICE_EMAILS_SUPPORTED"
38   );
39   window.AWAddScreenImpression = receive("ADD_SCREEN_IMPRESSION");
40   window.AWSendToParent = (name, data) => receive(name)(data);
41   window.AWFinish = () => {
42     window.close();
43   };
44   window.AWWaitForMigrationClose = receive("WAIT_FOR_MIGRATION_CLOSE");
45   window.AWEvaluateScreenTargeting = receive("EVALUATE_SCREEN_TARGETING");
47   // Update styling to be compatible with about:welcome.
48   addStylesheet(
49     "chrome://activity-stream/content/aboutwelcome/aboutwelcome.css"
50   );
52   document.body.classList.add("onboardingContainer");
53   document.body.id = "multi-stage-message-root";
54   // This value is reported as the "page" in telemetry
55   document.body.dataset.page = "spotlight";
57   // Prevent applying the default modal shadow and margins because the content
58   // handles styling, including its own modal shadowing.
59   const box = browser.closest(".dialogBox");
60   const dialog = box.closest("dialog");
61   box.classList.add("spotlightBox");
62   dialog?.classList.add("spotlight");
63   // Prevent SubDialog methods from manually setting dialog size.
64   box.setAttribute("sizeto", "available");
65   addEventListener("pagehide", () => {
66     box.classList.remove("spotlightBox");
67     dialog?.classList.remove("spotlight");
68     box.removeAttribute("sizeto");
69   });
71   // Load the bundle to render the content as configured.
72   document.head.appendChild(document.createElement("script")).src =
73     "resource://activity-stream/aboutwelcome/aboutwelcome.bundle.js";
74   ready();
77 // Indicate when we're ready to show and size (async localized) content.
78 document.mozSubdialogReady = new Promise(resolve =>
79   document.addEventListener(
80     "DOMContentLoaded",
81     () => renderMultistage(resolve),
82     {
83       once: true,
84     }
85   )