2020-04-23 00:33:12 +03:00
|
|
|
/* 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/. */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["AboutNewTabChild"];
|
|
|
|
|
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
|
|
|
const { AppConstants } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/AppConstants.jsm"
|
|
|
|
);
|
2020-09-17 20:41:51 +03:00
|
|
|
const { ExperimentAPI } = ChromeUtils.import(
|
|
|
|
"resource://messaging-system/experiments/ExperimentAPI.jsm"
|
|
|
|
);
|
2020-10-07 21:27:13 +03:00
|
|
|
const { PrivateBrowsingUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm"
|
|
|
|
);
|
2020-04-23 00:33:12 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
|
|
|
"ACTIVITY_STREAM_DEBUG",
|
|
|
|
"browser.newtabpage.activity-stream.debug",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
2020-09-17 20:41:51 +03:00
|
|
|
"isAboutWelcomePrefEnabled",
|
2020-04-23 00:33:12 +03:00
|
|
|
"browser.aboutwelcome.enabled",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
class AboutNewTabChild extends JSWindowActorChild {
|
|
|
|
handleEvent(event) {
|
|
|
|
if (event.type == "DOMContentLoaded") {
|
|
|
|
// 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 (
|
2020-09-17 20:41:51 +03:00
|
|
|
isAboutWelcomePrefEnabled &&
|
|
|
|
// about:welcome should be enabled by default if no experiment exists.
|
|
|
|
ExperimentAPI.isFeatureEnabled("aboutwelcome", true) &&
|
2020-04-23 00:33:12 +03:00
|
|
|
this.contentWindow.location.pathname.includes("welcome")
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const debug = !AppConstants.RELEASE_OR_BETA && 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);
|
|
|
|
}
|
2020-09-14 21:26:23 +03:00
|
|
|
} 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.
|
2020-10-16 00:49:03 +03:00
|
|
|
!this.contentWindow.location.pathname.includes("welcome")
|
2020-09-14 21:26:23 +03:00
|
|
|
) {
|
2020-10-16 00:49:03 +03:00
|
|
|
// 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))
|
|
|
|
) {
|
2020-09-14 21:26:23 +03:00
|
|
|
this.sendAsyncMessage("DefaultBrowserNotification");
|
|
|
|
}
|
2020-04-23 00:33:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|