mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 00:38:39 +09:00
Issue #21 - Remove telemetry from PopupNotifications.jsm.
This commit is contained in:
parent
eaf9e756a0
commit
2ed3e31c4f
1 changed files with 4 additions and 110 deletions
|
|
@ -22,21 +22,6 @@ const ICON_ANCHOR_ATTRIBUTE = "popupnotificationanchor";
|
|||
|
||||
const PREF_SECURITY_DELAY = "security.notification_enable_delay";
|
||||
|
||||
// Enumerated values for the POPUP_NOTIFICATION_STATS telemetry histogram.
|
||||
const TELEMETRY_STAT_OFFERED = 0;
|
||||
const TELEMETRY_STAT_ACTION_1 = 1;
|
||||
const TELEMETRY_STAT_ACTION_2 = 2;
|
||||
const TELEMETRY_STAT_ACTION_3 = 3;
|
||||
const TELEMETRY_STAT_ACTION_LAST = 4;
|
||||
const TELEMETRY_STAT_DISMISSAL_CLICK_ELSEWHERE = 5;
|
||||
const TELEMETRY_STAT_DISMISSAL_LEAVE_PAGE = 6;
|
||||
const TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON = 7;
|
||||
const TELEMETRY_STAT_DISMISSAL_NOT_NOW = 8;
|
||||
const TELEMETRY_STAT_OPEN_SUBMENU = 10;
|
||||
const TELEMETRY_STAT_LEARN_MORE = 11;
|
||||
|
||||
const TELEMETRY_STAT_REOPENED_OFFSET = 20;
|
||||
|
||||
var popupNotificationsMap = new WeakMap();
|
||||
var gNotificationParents = new WeakMap;
|
||||
|
||||
|
|
@ -87,7 +72,6 @@ function Notification(id, message, anchorID, mainAction, secondaryActions,
|
|||
// Will become a boolean when manually toggled by the user.
|
||||
this._checkboxChecked = null;
|
||||
this.wasDismissed = false;
|
||||
this.recordedTelemetryStats = new Set();
|
||||
this.isPrivate = PrivateBrowsingUtils.isWindowPrivate(
|
||||
this.browser.ownerDocument.defaultView);
|
||||
this.timeCreated = this.owner.window.performance.now();
|
||||
|
|
@ -111,7 +95,7 @@ Notification.prototype = {
|
|||
set dismissed(value) {
|
||||
this._dismissed = value;
|
||||
if (value) {
|
||||
// Keep the dismissal into account when recording telemetry.
|
||||
// Keep the dismissal into account.
|
||||
this.wasDismissed = true;
|
||||
}
|
||||
},
|
||||
|
|
@ -147,44 +131,6 @@ Notification.prototype = {
|
|||
reshow: function() {
|
||||
this.owner._reshowNotifications(this.anchorElement, this.browser);
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a value to the specified histogram, that must be keyed by ID.
|
||||
*/
|
||||
_recordTelemetry(histogramId, value) {
|
||||
if (this.isPrivate) {
|
||||
// The reason why we don't record telemetry in private windows is because
|
||||
// the available actions can be different from regular mode. The main
|
||||
// difference is that all of the persistent permission options like
|
||||
// "Always remember" aren't there, so they really need to be handled
|
||||
// separately to avoid skewing results. For notifications with the same
|
||||
// choices, there would be no reason not to record in private windows as
|
||||
// well, but it's just simpler to use the same check for everything.
|
||||
return;
|
||||
}
|
||||
let histogram = Services.telemetry.getKeyedHistogramById(histogramId);
|
||||
histogram.add("(all)", value);
|
||||
histogram.add(this.id, value);
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds an enumerated value to the POPUP_NOTIFICATION_STATS histogram,
|
||||
* ensuring that it is recorded at most once for each distinct Notification.
|
||||
*
|
||||
* Statistics for reopened notifications are recorded in separate buckets.
|
||||
*
|
||||
* @param value
|
||||
* One of the TELEMETRY_STAT_ constants.
|
||||
*/
|
||||
_recordTelemetryStat(value) {
|
||||
if (this.wasDismissed) {
|
||||
value += TELEMETRY_STAT_REOPENED_OFFSET;
|
||||
}
|
||||
if (!this.recordedTelemetryStats.has(value)) {
|
||||
this.recordedTelemetryStats.add(value);
|
||||
this._recordTelemetry("POPUP_NOTIFICATION_STATS", value);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -531,12 +477,6 @@ PopupNotifications.prototype = {
|
|||
case "activate":
|
||||
case "TabSelect":
|
||||
let self = this;
|
||||
// This is where we could detect if the panel is dismissed if the page
|
||||
// was switched. Unfortunately, the user usually has clicked elsewhere
|
||||
// at this point so this value only gets recorded for programmatic
|
||||
// reasons, like the "Learn More" link being clicked and resulting in a
|
||||
// tab switch.
|
||||
this.nextDismissReason = TELEMETRY_STAT_DISMISSAL_LEAVE_PAGE;
|
||||
// setTimeout(..., 0) needed, otherwise openPopup from "activate" event
|
||||
// handler results in the popup being hidden again for some reason...
|
||||
this.window.setTimeout(function () {
|
||||
|
|
@ -584,11 +524,7 @@ PopupNotifications.prototype = {
|
|||
/**
|
||||
* Dismisses the notification without removing it.
|
||||
*/
|
||||
_dismiss: function PopupNotifications_dismiss(telemetryReason) {
|
||||
if (telemetryReason) {
|
||||
this.nextDismissReason = telemetryReason;
|
||||
}
|
||||
|
||||
_dismiss: function PopupNotifications_dismiss() {
|
||||
let browser = this.panel.firstChild &&
|
||||
this.panel.firstChild.notification.browser;
|
||||
this.panel.hidePopup();
|
||||
|
|
@ -669,7 +605,7 @@ PopupNotifications.prototype = {
|
|||
popupnotification.setAttribute("label", n.message);
|
||||
popupnotification.setAttribute("id", popupnotificationID);
|
||||
popupnotification.setAttribute("popupid", n.id);
|
||||
popupnotification.setAttribute("closebuttoncommand", `PopupNotifications._dismiss(${TELEMETRY_STAT_DISMISSAL_CLOSE_BUTTON});`);
|
||||
popupnotification.setAttribute("closebuttoncommand", `PopupNotifications._dismiss();`);
|
||||
if (n.mainAction) {
|
||||
popupnotification.setAttribute("buttonlabel", n.mainAction.label);
|
||||
popupnotification.setAttribute("buttonaccesskey", n.mainAction.accessKey);
|
||||
|
|
@ -677,7 +613,7 @@ PopupNotifications.prototype = {
|
|||
popupnotification.setAttribute("buttonpopupshown", "PopupNotifications._onButtonEvent(event, 'buttonpopupshown');");
|
||||
popupnotification.setAttribute("learnmoreclick", "PopupNotifications._onButtonEvent(event, 'learnmoreclick');");
|
||||
popupnotification.setAttribute("menucommand", "PopupNotifications._onMenuCommand(event);");
|
||||
popupnotification.setAttribute("closeitemcommand", `PopupNotifications._dismiss(${TELEMETRY_STAT_DISMISSAL_NOT_NOW});event.stopPropagation();`);
|
||||
popupnotification.setAttribute("closeitemcommand", `PopupNotifications._dismiss();event.stopPropagation();`);
|
||||
} else {
|
||||
popupnotification.removeAttribute("buttonlabel");
|
||||
popupnotification.removeAttribute("buttonaccesskey");
|
||||
|
|
@ -719,8 +655,6 @@ PopupNotifications.prototype = {
|
|||
popupnotification.notification = n;
|
||||
|
||||
if (n.secondaryActions) {
|
||||
let telemetryStatId = TELEMETRY_STAT_ACTION_2;
|
||||
|
||||
n.secondaryActions.forEach(function (a) {
|
||||
let item = doc.createElementNS(XUL_NS, "menuitem");
|
||||
item.setAttribute("label", a.label);
|
||||
|
|
@ -729,13 +663,6 @@ PopupNotifications.prototype = {
|
|||
item.action = a;
|
||||
|
||||
popupnotification.appendChild(item);
|
||||
|
||||
// We can only record a limited number of actions in telemetry. If
|
||||
// there are more, the latest are all recorded in the last bucket.
|
||||
item.action.telemetryStatId = telemetryStatId;
|
||||
if (telemetryStatId < TELEMETRY_STAT_ACTION_LAST) {
|
||||
telemetryStatId++;
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (n.options.hideNotNow) {
|
||||
|
|
@ -850,18 +777,10 @@ PopupNotifications.prototype = {
|
|||
// click-to-play plugins, so copy the popupid and use css.
|
||||
this.panel.setAttribute("popupid", this.panel.firstChild.getAttribute("popupid"));
|
||||
notificationsToShow.forEach(function (n) {
|
||||
// Record that the notification was actually displayed on screen.
|
||||
// Notifications that were opened a second time or that were originally
|
||||
// shown with "options.dismissed" will be recorded in a separate bucket.
|
||||
n._recordTelemetryStat(TELEMETRY_STAT_OFFERED);
|
||||
// Remember the time the notification was shown for the security delay.
|
||||
n.timeShown = this.window.performance.now();
|
||||
}, this);
|
||||
|
||||
// Unless the panel closing is triggered by a specific known code path,
|
||||
// the next reason will be that the user clicked elsewhere.
|
||||
this.nextDismissReason = TELEMETRY_STAT_DISMISSAL_CLICK_ELSEWHERE;
|
||||
|
||||
let target = this.panel;
|
||||
if (target.parentNode) {
|
||||
// NOTIFICATION_EVENT_SHOWN should be fired for the panel before
|
||||
|
|
@ -1226,16 +1145,6 @@ PopupNotifications.prototype = {
|
|||
if (notifications.indexOf(notificationObj) == -1)
|
||||
return;
|
||||
|
||||
// Record the time of the first notification dismissal if the main action
|
||||
// was not triggered in the meantime.
|
||||
let timeSinceShown = this.window.performance.now() - notificationObj.timeShown;
|
||||
if (!notificationObj.wasDismissed &&
|
||||
!notificationObj.recordedTelemetryMainAction) {
|
||||
notificationObj._recordTelemetry("POPUP_NOTIFICATION_DISMISSAL_MS",
|
||||
timeSinceShown);
|
||||
}
|
||||
notificationObj._recordTelemetryStat(this.nextDismissReason);
|
||||
|
||||
// Do not mark the notification as dismissed or fire NOTIFICATION_EVENT_DISMISSED
|
||||
// if the notification is removed.
|
||||
if (notificationObj.options.removeOnDismissal) {
|
||||
|
|
@ -1259,24 +1168,13 @@ PopupNotifications.prototype = {
|
|||
let notification = notificationEl.notification;
|
||||
|
||||
if (type == "buttonpopupshown") {
|
||||
notification._recordTelemetryStat(TELEMETRY_STAT_OPEN_SUBMENU);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == "learnmoreclick") {
|
||||
notification._recordTelemetryStat(TELEMETRY_STAT_LEARN_MORE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Record the total timing of the main action since the notification was
|
||||
// created, even if the notification was dismissed in the meantime.
|
||||
let timeSinceCreated = this.window.performance.now() - notification.timeCreated;
|
||||
if (!notification.recordedTelemetryMainAction) {
|
||||
notification.recordedTelemetryMainAction = true;
|
||||
notification._recordTelemetry("POPUP_NOTIFICATION_MAIN_ACTION_MS",
|
||||
timeSinceCreated);
|
||||
}
|
||||
|
||||
let timeSinceShown = this.window.performance.now() - notification.timeShown;
|
||||
if (timeSinceShown < this.buttonDelay) {
|
||||
Services.console.logStringMessage("PopupNotifications._onButtonEvent: " +
|
||||
|
|
@ -1285,8 +1183,6 @@ PopupNotifications.prototype = {
|
|||
return;
|
||||
}
|
||||
|
||||
notification._recordTelemetryStat(TELEMETRY_STAT_ACTION_1);
|
||||
|
||||
try {
|
||||
notification.mainAction.callback.call(undefined, {
|
||||
checkboxChecked: notificationEl.checkbox.checked
|
||||
|
|
@ -1312,8 +1208,6 @@ PopupNotifications.prototype = {
|
|||
let notificationEl = target.parentElement;
|
||||
event.stopPropagation();
|
||||
|
||||
target.notification._recordTelemetryStat(target.action.telemetryStatId);
|
||||
|
||||
try {
|
||||
target.action.callback.call(undefined, {
|
||||
checkboxChecked: notificationEl.checkbox.checked
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue