Bug 1791785 - When dumping symbols never emit INLINE_ORIGIN directives with an empty...
[gecko.git] / browser / actors / AboutNewTabChild.sys.mjs
blob7bb0433b050e8141bac5915e2ccbd2622d6cdd55
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
9 const { AppConstants } = ChromeUtils.import(
10   "resource://gre/modules/AppConstants.jsm"
13 const { PrivateBrowsingUtils } = ChromeUtils.import(
14   "resource://gre/modules/PrivateBrowsingUtils.jsm"
17 const lazy = {};
19 XPCOMUtils.defineLazyModuleGetters(lazy, {
20   NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
21 });
23 XPCOMUtils.defineLazyPreferenceGetter(
24   lazy,
25   "ACTIVITY_STREAM_DEBUG",
26   "browser.newtabpage.activity-stream.debug",
27   false
30 export class AboutNewTabChild extends JSWindowActorChild {
31   handleEvent(event) {
32     if (event.type == "DOMContentLoaded") {
33       // If the separate about:welcome page is enabled, we can skip all of this,
34       // since that mode doesn't load any of the Activity Stream bits.
35       if (
36         (lazy.NimbusFeatures.aboutwelcome.getVariable("enabled") ?? true) &&
37         this.contentWindow.location.pathname.includes("welcome")
38       ) {
39         return;
40       }
42       const debug = !AppConstants.RELEASE_OR_BETA && lazy.ACTIVITY_STREAM_DEBUG;
43       const debugString = debug ? "-dev" : "";
45       // This list must match any similar ones in render-activity-stream-html.js.
46       const scripts = [
47         "chrome://browser/content/contentSearchUI.js",
48         "chrome://browser/content/contentSearchHandoffUI.js",
49         "chrome://browser/content/contentTheme.js",
50         `resource://activity-stream/vendor/react${debugString}.js`,
51         `resource://activity-stream/vendor/react-dom${debugString}.js`,
52         "resource://activity-stream/vendor/prop-types.js",
53         "resource://activity-stream/vendor/react-transition-group.js",
54         "resource://activity-stream/vendor/redux.js",
55         "resource://activity-stream/vendor/react-redux.js",
56         "resource://activity-stream/data/content/activity-stream.bundle.js",
57         "resource://activity-stream/data/content/newtab-render.js",
58       ];
60       for (let script of scripts) {
61         Services.scriptloader.loadSubScript(script, this.contentWindow);
62       }
63     } else if (
64       (event.type == "pageshow" || event.type == "visibilitychange") &&
65       // The default browser notification shouldn't be shown on about:welcome
66       // since we don't want to distract from the onboarding wizard.
67       !this.contentWindow.location.pathname.includes("welcome")
68     ) {
69       // Don't show the notification in non-permanent private windows
70       // since it is expected to have very little opt-in here.
71       let contentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(
72         this.contentWindow
73       );
74       if (
75         this.document.visibilityState == "visible" &&
76         (!contentWindowPrivate ||
77           (contentWindowPrivate &&
78             PrivateBrowsingUtils.permanentPrivateBrowsing))
79       ) {
80         this.sendAsyncMessage("AboutNewTabVisible");
82         // Note: newtab feature info is currently being loaded in PrefsFeed.jsm,
83         // But we're recording exposure events here.
84         lazy.NimbusFeatures.newtab.recordExposureEvent({ once: true });
85       }
86     }
87   }