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/. */
6 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
8 import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
9 import { RemotePageChild } from "resource://gre/actors/RemotePageChild.sys.mjs";
13 ChromeUtils.defineESModuleGetters(lazy, {
14 NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
17 XPCOMUtils.defineLazyPreferenceGetter(
19 "ACTIVITY_STREAM_DEBUG",
20 "browser.newtabpage.activity-stream.debug",
26 export class AboutNewTabChild extends RemotePageChild {
28 if (event.type == "DOMDocElementInserted") {
29 let portID = Services.appinfo.processID + ":" + ++gNextPortID;
31 this.sendAsyncMessage("Init", {
33 url: this.contentWindow.document.documentURI.replace(/[\#|\?].*$/, ""),
35 } else if (event.type == "load") {
36 this.sendAsyncMessage("Load");
37 } else if (event.type == "DOMContentLoaded") {
38 if (!this.contentWindow.document.body.firstElementChild) {
39 return; // about:newtab is a blank page
42 // If the separate about:welcome page is enabled, we can skip all of this,
43 // since that mode doesn't load any of the Activity Stream bits.
45 (lazy.NimbusFeatures.aboutwelcome.getVariable("enabled") ?? true) &&
46 this.contentWindow.location.pathname.includes("welcome")
51 const debug = !AppConstants.RELEASE_OR_BETA && lazy.ACTIVITY_STREAM_DEBUG;
52 const debugString = debug ? "-dev" : "";
54 // This list must match any similar ones in render-activity-stream-html.js.
56 "chrome://browser/content/contentSearchUI.js",
57 "chrome://browser/content/contentSearchHandoffUI.js",
58 "chrome://browser/content/contentTheme.js",
59 `resource://activity-stream/vendor/react${debugString}.js`,
60 `resource://activity-stream/vendor/react-dom${debugString}.js`,
61 "resource://activity-stream/vendor/prop-types.js",
62 "resource://activity-stream/vendor/react-transition-group.js",
63 "resource://activity-stream/vendor/redux.js",
64 "resource://activity-stream/vendor/react-redux.js",
65 "resource://activity-stream/data/content/activity-stream.bundle.js",
66 "resource://activity-stream/data/content/newtab-render.js",
69 for (let script of scripts) {
70 Services.scriptloader.loadSubScript(script, this.contentWindow);
72 } else if (event.type == "unload") {
74 this.sendAsyncMessage("Unload");
76 // If the tab has been closed the frame message manager has already been
80 (event.type == "pageshow" || event.type == "visibilitychange") &&
81 // The default browser notification shouldn't be shown on about:welcome
82 // since we don't want to distract from the onboarding wizard.
83 !this.contentWindow.location.pathname.includes("welcome")
85 // Don't show the notification in non-permanent private windows
86 // since it is expected to have very little opt-in here.
87 let contentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(
91 this.document.visibilityState == "visible" &&
92 (!contentWindowPrivate ||
93 (contentWindowPrivate &&
94 PrivateBrowsingUtils.permanentPrivateBrowsing))
96 this.sendAsyncMessage("AboutNewTabVisible");
98 // Note: newtab feature info is currently being loaded in PrefsFeed.sys.mjs,
99 // But we're recording exposure events here.
100 lazy.NimbusFeatures.newtab.recordExposureEvent({ once: true });