Bug 1685680 [wpt PR 27099] - Add missing jsapi tests for wasm reference-types proposa...
[gecko.git] / browser / actors / AboutNewTabChild.jsm
blob949dc78909e0e6a3a3dc82a11a5a97906d49e2bc
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 var EXPORTED_SYMBOLS = ["AboutNewTabChild"];
9 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
10 const { XPCOMUtils } = ChromeUtils.import(
11   "resource://gre/modules/XPCOMUtils.jsm"
13 const { AppConstants } = ChromeUtils.import(
14   "resource://gre/modules/AppConstants.jsm"
16 const { ExperimentAPI } = ChromeUtils.import(
17   "resource://messaging-system/experiments/ExperimentAPI.jsm"
19 const { PrivateBrowsingUtils } = ChromeUtils.import(
20   "resource://gre/modules/PrivateBrowsingUtils.jsm"
23 XPCOMUtils.defineLazyPreferenceGetter(
24   this,
25   "ACTIVITY_STREAM_DEBUG",
26   "browser.newtabpage.activity-stream.debug",
27   false
30 XPCOMUtils.defineLazyPreferenceGetter(
31   this,
32   "isAboutWelcomePrefEnabled",
33   "browser.aboutwelcome.enabled",
34   false
37 class AboutNewTabChild extends JSWindowActorChild {
38   handleEvent(event) {
39     if (event.type == "DOMContentLoaded") {
40       // If the separate about:welcome page is enabled, we can skip all of this,
41       // since that mode doesn't load any of the Activity Stream bits.
42       if (
43         isAboutWelcomePrefEnabled &&
44         // about:welcome should be enabled by default if no experiment exists.
45         ExperimentAPI.isFeatureEnabled("aboutwelcome", true) &&
46         this.contentWindow.location.pathname.includes("welcome")
47       ) {
48         return;
49       }
51       const debug = !AppConstants.RELEASE_OR_BETA && ACTIVITY_STREAM_DEBUG;
52       const debugString = debug ? "-dev" : "";
54       // This list must match any similar ones in render-activity-stream-html.js.
55       const scripts = [
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",
67       ];
69       for (let script of scripts) {
70         Services.scriptloader.loadSubScript(script, this.contentWindow);
71       }
72     } else if (
73       (event.type == "pageshow" || event.type == "visibilitychange") &&
74       // The default browser notification shouldn't be shown on about:welcome
75       // since we don't want to distract from the onboarding wizard.
76       !this.contentWindow.location.pathname.includes("welcome")
77     ) {
78       // Don't show the notification in non-permanent private windows
79       // since it is expected to have very little opt-in here.
80       let contentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate(
81         this.contentWindow
82       );
83       if (
84         this.document.visibilityState == "visible" &&
85         (!contentWindowPrivate ||
86           (contentWindowPrivate &&
87             PrivateBrowsingUtils.permanentPrivateBrowsing))
88       ) {
89         this.sendAsyncMessage("DefaultBrowserNotification");
90       }
91     }
92   }