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/. */
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"
19 XPCOMUtils.defineLazyModuleGetters(lazy, {
20 NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
23 XPCOMUtils.defineLazyPreferenceGetter(
25 "ACTIVITY_STREAM_DEBUG",
26 "browser.newtabpage.activity-stream.debug",
30 export class AboutNewTabChild extends JSWindowActorChild {
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.
36 (lazy.NimbusFeatures.aboutwelcome.getVariable("enabled") ?? true) &&
37 this.contentWindow.location.pathname.includes("welcome")
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.
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",
60 for (let script of scripts) {
61 Services.scriptloader.loadSubScript(script, this.contentWindow);
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")
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(
75 this.document.visibilityState == "visible" &&
76 (!contentWindowPrivate ||
77 (contentWindowPrivate &&
78 PrivateBrowsingUtils.permanentPrivateBrowsing))
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 });