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"; 6 7var EXPORTED_SYMBOLS = ["AboutNewTabChild"]; 8 9const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); 10const { XPCOMUtils } = ChromeUtils.import( 11 "resource://gre/modules/XPCOMUtils.jsm" 12); 13const { AppConstants } = ChromeUtils.import( 14 "resource://gre/modules/AppConstants.jsm" 15); 16 17const { PrivateBrowsingUtils } = ChromeUtils.import( 18 "resource://gre/modules/PrivateBrowsingUtils.jsm" 19); 20 21XPCOMUtils.defineLazyModuleGetters(this, { 22 NimbusFeatures: "resource://nimbus/ExperimentAPI.jsm", 23}); 24 25XPCOMUtils.defineLazyPreferenceGetter( 26 this, 27 "ACTIVITY_STREAM_DEBUG", 28 "browser.newtabpage.activity-stream.debug", 29 false 30); 31 32class AboutNewTabChild extends JSWindowActorChild { 33 handleEvent(event) { 34 if (event.type == "DOMContentLoaded") { 35 // If the separate about:welcome page is enabled, we can skip all of this, 36 // since that mode doesn't load any of the Activity Stream bits. 37 if ( 38 NimbusFeatures.aboutwelcome.isEnabled({ defaultValue: true }) && 39 this.contentWindow.location.pathname.includes("welcome") 40 ) { 41 return; 42 } 43 44 const debug = !AppConstants.RELEASE_OR_BETA && ACTIVITY_STREAM_DEBUG; 45 const debugString = debug ? "-dev" : ""; 46 47 // This list must match any similar ones in render-activity-stream-html.js. 48 const scripts = [ 49 "chrome://browser/content/contentSearchUI.js", 50 "chrome://browser/content/contentSearchHandoffUI.js", 51 "chrome://browser/content/contentTheme.js", 52 `resource://activity-stream/vendor/react${debugString}.js`, 53 `resource://activity-stream/vendor/react-dom${debugString}.js`, 54 "resource://activity-stream/vendor/prop-types.js", 55 "resource://activity-stream/vendor/react-transition-group.js", 56 "resource://activity-stream/vendor/redux.js", 57 "resource://activity-stream/vendor/react-redux.js", 58 "resource://activity-stream/data/content/activity-stream.bundle.js", 59 "resource://activity-stream/data/content/newtab-render.js", 60 ]; 61 62 for (let script of scripts) { 63 Services.scriptloader.loadSubScript(script, this.contentWindow); 64 } 65 } else if ( 66 (event.type == "pageshow" || event.type == "visibilitychange") && 67 // The default browser notification shouldn't be shown on about:welcome 68 // since we don't want to distract from the onboarding wizard. 69 !this.contentWindow.location.pathname.includes("welcome") 70 ) { 71 // Don't show the notification in non-permanent private windows 72 // since it is expected to have very little opt-in here. 73 let contentWindowPrivate = PrivateBrowsingUtils.isContentWindowPrivate( 74 this.contentWindow 75 ); 76 if ( 77 this.document.visibilityState == "visible" && 78 (!contentWindowPrivate || 79 (contentWindowPrivate && 80 PrivateBrowsingUtils.permanentPrivateBrowsing)) 81 ) { 82 this.sendAsyncMessage("AboutNewTabVisible"); 83 84 // Note: newtab feature info is currently being loaded in PrefsFeed.jsm, 85 // But we're recording exposure events here. 86 NimbusFeatures.newtab.recordExposureEvent({ once: true }); 87 } 88 } 89 } 90} 91