summaryrefslogtreecommitdiffstats
path: root/browser/actors/AboutNewTabChild.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/actors/AboutNewTabChild.sys.mjs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/actors/AboutNewTabChild.sys.mjs')
-rw-r--r--browser/actors/AboutNewTabChild.sys.mjs86
1 files changed, 86 insertions, 0 deletions
diff --git a/browser/actors/AboutNewTabChild.sys.mjs b/browser/actors/AboutNewTabChild.sys.mjs
new file mode 100644
index 0000000000..f228831668
--- /dev/null
+++ b/browser/actors/AboutNewTabChild.sys.mjs
@@ -0,0 +1,86 @@
+/* vim: set ts=2 sw=2 sts=2 et tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
+
+import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
+import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
+
+const lazy = {};
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm",
+});
+
+XPCOMUtils.defineLazyPreferenceGetter(
+ lazy,
+ "ACTIVITY_STREAM_DEBUG",
+ "browser.newtabpage.activity-stream.debug",
+ false
+);
+
+export class AboutNewTabChild extends JSWindowActorChild {
+ handleEvent(event) {
+ if (event.type == "DOMContentLoaded") {
+ if (!this.contentWindow.document.body.firstElementChild) {
+ return; // about:newtab is a blank page
+ }
+
+ // If the separate about:welcome page is enabled, we can skip all of this,
+ // since that mode doesn't load any of the Activity Stream bits.
+ if (
+ (lazy.NimbusFeatures.aboutwelcome.getVariable("enabled") ?? true) &&
+ this.contentWindow.location.pathname.includes("welcome")
+ ) {
+ return;
+ }
+
+ const debug = !AppConstants.RELEASE_OR_BETA && lazy.ACTIVITY_STREAM_DEBUG;
+ const debugString = debug ? "-dev" : "";
+
+ // This list must match any similar ones in render-activity-stream-html.js.
+ const scripts = [
+ "chrome://browser/content/contentSearchUI.js",
+ "chrome://browser/content/contentSearchHandoffUI.js",
+ "chrome://browser/content/contentTheme.js",
+ `resource://activity-stream/vendor/react${debugString}.js`,
+ `resource://activity-stream/vendor/react-dom${debugString}.js`,
+ "resource://activity-stream/vendor/prop-types.js",
+ "resource://activity-stream/vendor/react-transition-group.js",
+ "resource://activity-stream/vendor/redux.js",
+ "resource://activity-stream/vendor/react-redux.js",
+ "resource://activity-stream/data/content/activity-stream.bundle.js",
+ "resource://activity-stream/data/content/newtab-render.js",
+ ];
+
+ for (let script of scripts) {
+ Services.scriptloader.loadSubScript(script, this.contentWindow);
+ }
+ } else if (
+ (event.type == "pageshow" || event.type == "visibilitychange") &&
+ // The default browser notification shouldn't be shown on about:welcome
+ // since we don't want to distract from the onboarding wizard.
+ !this.contentWindow.location.pathname.includes("welcome")
+ ) {
+ // Don't show the notification in non-permanent private windows
+ // since it is expected to have very little opt-in here.
+ let contentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(
+ this.contentWindow
+ );
+ if (
+ this.document.visibilityState == "visible" &&
+ (!contentWindowPrivate ||
+ (contentWindowPrivate &&
+ PrivateBrowsingUtils.permanentPrivateBrowsing))
+ ) {
+ this.sendAsyncMessage("AboutNewTabVisible");
+
+ // Note: newtab feature info is currently being loaded in PrefsFeed.jsm,
+ // But we're recording exposure events here.
+ lazy.NimbusFeatures.newtab.recordExposureEvent({ once: true });
+ }
+ }
+ }
+}