AboutPrivateBrowsingChild.sys.mjs (1946B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 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 6 import { RemotePageChild } from "resource://gre/actors/RemotePageChild.sys.mjs"; 7 8 const lazy = {}; 9 10 ChromeUtils.defineESModuleGetters(lazy, { 11 EnrollmentType: "resource://nimbus/ExperimentAPI.sys.mjs", 12 NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", 13 }); 14 15 export class AboutPrivateBrowsingChild extends RemotePageChild { 16 actorCreated() { 17 super.actorCreated(); 18 let window = this.contentWindow; 19 20 Cu.exportFunction(this.PrivateBrowsingRecordClick.bind(this), window, { 21 defineAs: "PrivateBrowsingRecordClick", 22 }); 23 Cu.exportFunction( 24 this.PrivateBrowsingShouldHideDefault.bind(this), 25 window, 26 { 27 defineAs: "PrivateBrowsingShouldHideDefault", 28 } 29 ); 30 Cu.exportFunction( 31 this.PrivateBrowsingPromoExposureTelemetry.bind(this), 32 window, 33 { defineAs: "PrivateBrowsingPromoExposureTelemetry" } 34 ); 35 Cu.exportFunction(this.FeltPrivacyExposureTelemetry.bind(this), window, { 36 defineAs: "FeltPrivacyExposureTelemetry", 37 }); 38 } 39 40 PrivateBrowsingRecordClick(source) { 41 const metadata = lazy.NimbusFeatures.pbNewtab.getEnrollmentMetadata( 42 lazy.EnrollmentType.EXPERIMENT 43 ); 44 if (metadata) { 45 Glean.aboutprivatebrowsing["click" + source].record(); 46 } 47 return !!metadata; 48 } 49 50 PrivateBrowsingShouldHideDefault() { 51 const config = lazy.NimbusFeatures.pbNewtab.getAllVariables() || {}; 52 return config?.content?.hideDefault; 53 } 54 55 PrivateBrowsingPromoExposureTelemetry() { 56 lazy.NimbusFeatures.pbNewtab.recordExposureEvent({ once: false }); 57 } 58 59 FeltPrivacyExposureTelemetry() { 60 lazy.NimbusFeatures.feltPrivacy.recordExposureEvent({ once: true }); 61 } 62 }