ission = lazy.lastSubmission; if (lastSubmission === 0) { // If this is the first time maybeSubmitPing is called, set the lastSubmission time to now // so that we don't submit a ping with just one event. lazy.console.debug("Setting lastSubmission to now."); Services.prefs.setIntPref( LAST_SUBMISSION_PREF, CaptchaDetectionPingUtils.i32SafeDate() ); return; } if ( lastSubmission > CaptchaDetectionPingUtils.i32SafeDate() - lazy.submissionInterval ) { lazy.console.debug("Not enough time has passed since last submission."); return; } CaptchaDetectionPingUtils.flushPing(); } static prefsOfInterest = { networkCookieCookiebehavior: { type: "Int", name: "network.cookie.cookieBehavior", }, privacyTrackingprotectionEnabled: { type: "Bool", name: "privacy.trackingprotection.enabled", }, privacyTrackingprotectionCryptominingEnabled: { type: "Bool", name: "privacy.trackingprotection.cryptomining.enabled", }, privacyTrackingprotectionFingerprintingEnabled: { type: "Bool", name: "privacy.trackingprotection.fingerprinting.enabled", }, privacyFingerprintingprotection: { type: "Bool", name: "privacy.fingerprintingProtection", }, networkCookieCookiebehaviorOptinpartitioning: { type: "Bool", name: "network.cookie.cookieBehavior.optInPartitioning", }, privacyResistfingerprinting: { type: "Bool", name: "privacy.resistFingerprinting", }, privacyTrackingprotectionPbmEnabled: { type: "Bool", name: "privacy.trackingprotection.pbmode.enabled", }, privacyFingerprintingprotectionPbm: { type: "Bool", name: "privacy.fingerprintingProtection.pbmode", }, networkCookieCookiebehaviorOptinpartitioningPbm: { type: "Bool", name: "network.cookie.cookieBehavior.optInPartitioning.pbmode", }, privacyResistfingerprintingPbmode: { type: "Bool", name: "privacy.resistFingerprinting.pbmode", }, }; static initialized = false; static profileIsOpen = true; static init() { if (CaptchaDetectionPingUtils.initialized) { return; } Object.values(CaptchaDetectionPingUtils.prefsOfInterest).forEach(pref => { Services.prefs.addObserver( pref.name, CaptchaDetectionPingUtils.flushPing ); }); // maybeSubmitPing changes lastSubmission, and causes tests to fail. if (!Cu.isInAutomation) { ChromeUtils.idleDispatch(() => CaptchaDetectionPingUtils.maybeSubmitPing(false) ); } this.initialized = true; try { lazy.AsyncShutdown.profileBeforeChange.addBlocker( "CaptchaDetectionPingUtils: Don't submit pings after shutdown", async () => { this.profileIsOpen = false; } ); } catch (e) { // This is not a critical error, so we just log it. // According to https://searchfox.org/mozilla-central/rev/d5baa11e35e0186c3c867f4948010f0742198467/toolkit/components/asyncshutdown/nsIAsyncShutdown.idl#82-103 // this error can happen if it is too late to add a blocker. lazy.console.error( "Failed to add blocker for profileBeforeChange: " + e.message ); this.profileIsOpen = false; } } } /** * @typedef lazy * @type {object} * @property {ConsoleInstance} console - console instance. * @property {AsyncShutdown} AsyncShutdown - AsyncShutdown module. */ PK