Merge mozilla-central to autoland. a=merge CLOSED TREE
[gecko.git] / browser / base / content / spotlight.js
blob7c16ffaca6a3f9b9bbcdd0712c545d23be344aed
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("chrome://browser/content/aboutwelcome/aboutwelcome.css");
50   document.body.classList.add("onboardingContainer");
51   document.body.id = "multi-stage-message-root";
52   // This value is reported as the "page" in telemetry
53   document.body.dataset.page = "spotlight";
55   // Prevent applying the default modal shadow and margins because the content
56   // handles styling, including its own modal shadowing.
57   const box = browser.closest(".dialogBox");
58   const dialog = box.closest("dialog");
59   box.classList.add("spotlightBox");
60   dialog?.classList.add("spotlight");
61   // Prevent SubDialog methods from manually setting dialog size.
62   box.setAttribute("sizeto", "available");
63   addEventListener("pagehide", () => {
64     box.classList.remove("spotlightBox");
65     dialog?.classList.remove("spotlight");
66     box.removeAttribute("sizeto");
67   });
69   // Load the bundle to render the content as configured.
70   document.head.appendChild(document.createElement("script")).src =
71     "chrome://browser/content/aboutwelcome/aboutwelcome.bundle.js";
72   ready();
75 // Indicate when we're ready to show and size (async localized) content.
76 document.mozSubdialogReady = new Promise(resolve =>
77   document.addEventListener(
78     "DOMContentLoaded",
79     () => renderMultistage(resolve),
80     {
81       once: true,
82     }
83   )