diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index b9c9173ec57e..531dccd1acf8 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -734,6 +734,11 @@ nsFocusManager::WindowRaised(mozIDOMWindowProxy* aWindow) { // ATOK, so we need to do it here. BrowserParent::UnsetTopLevelWebFocusAll(); ActivateOrDeactivate(window, true); + + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) { + obs->NotifyObservers(aWindow, "window-raised", nullptr); + } } // retrieve the last focused element within the window that was raised @@ -816,6 +821,11 @@ nsFocusManager::WindowLowered(mozIDOMWindowProxy* aWindow) { // is called. if (XRE_IsParentProcess()) { ActivateOrDeactivate(window, false); + + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) { + obs->NotifyObservers(aWindow, "window-lowered", nullptr); + } } // keep track of the window being lowered, so that attempts to raise the diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 7a98e7bb72e8..b90149d6d37b 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -15386,5 +15386,18 @@ "bug_numbers": [1647876], "description": "Seconds between `user-interaction-active` and `user-interaction-inactive`. For use in evaluating baseline engagement for Project FOG.", "releaseChannelCollection": "opt-out" + }, + "FOG_EVAL_WINDOW_RAISED_S" : { + "products": ["firefox"], + "record_in_processes": ["main"], + "alert_emails": ["chutten@mozilla.com"], + "expires_in_version": "85", + "kind": "exponential", + "keyed": false, + "high": 7200, + "n_buckets": 50, + "bug_numbers": [1647876], + "description": "Seconds between a Firefox window being raised and lowered. For use in evaluating baseline engagement for Project FOG.", + "releaseChannelCollection": "opt-out" } } diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index afa0039eead4..22f3cc1b0a66 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -5002,6 +5002,22 @@ fog.eval: record_in_processes: - 'main' + window_raised: + bug_numbers: + - 1647876 + description: > + Whether a Firefox window is presently raised. + For use in evaluating baseline engagement for Project FOG. + expires: '85' + kind: 'boolean' + notification_emails: + - 'chutten@mozilla.com' + release_channel_collection: 'opt-out' + products: + - 'firefox' + record_in_processes: + - 'main' + user_active_error: bug_numbers: - 1647876 @@ -5020,6 +5036,24 @@ fog.eval: record_in_processes: - 'main' + window_raised_error: + bug_numbers: + - 1647876 + description: > + How many Telemetry stopwatch errors did we have while trying to measure window raising? + These could be attempts to start a started timer or finish an unstarted timer or so forth. + See Stopwatch::Start and Stopwatch::Finish for details. + For use in evaluating baseline engagement for Project FOG. + expires: '85' + kind: 'uint' + notification_emails: + - 'chutten@mozilla.com' + release_channel_collection: 'opt-out' + products: + - 'firefox' + record_in_processes: + - 'main' + # The following section is for probes testing the Telemetry system. They will not be # submitted in pings and are only used for testing. telemetry.test: diff --git a/toolkit/components/telemetry/pings/TelemetrySession.jsm b/toolkit/components/telemetry/pings/TelemetrySession.jsm index 56b646510a23..550b2c5dae16 100644 --- a/toolkit/components/telemetry/pings/TelemetrySession.jsm +++ b/toolkit/components/telemetry/pings/TelemetrySession.jsm @@ -856,6 +856,9 @@ var Impl = { // Attach the active-ticks related observers. this.addObserver("user-interaction-active"); this.addObserver("user-interaction-inactive"); + // For FOG Engagement Evaluation, attach window observers. + this.addObserver("window-raised"); + this.addObserver("window-lowered"); }, /** @@ -1146,6 +1149,24 @@ var Impl = { return this.send(REASON_TEST_PING); }, + /** + * Instruments window raises and lowers during a Telemetry Session. + */ + _onWindowChange(aWindow, aRaised) { + Telemetry.scalarSet("fog.eval.window_raised", aRaised); + let error = false; + if (aRaised) { + error = !TelemetryStopwatch.start("FOG_EVAL_WINDOW_RAISED_S", aWindow, { + inSeconds: true, + }); + } else { + error = !TelemetryStopwatch.finish("FOG_EVAL_WINDOW_RAISED_S", aWindow); + } + if (error) { + Telemetry.scalarAdd("fog.eval.window_raised_error", 1); + } + }, + /** * Tracks the number of "ticks" the user was active in. */ @@ -1255,6 +1276,12 @@ var Impl = { case "user-interaction-inactive": this._onActiveTick(false); break; + case "window-raised": + this._onWindowChange(aSubject, true); + break; + case "window-lowered": + this._onWindowChange(aSubject, false); + break; } return undefined; },