Commit 7fcfba11 authored by Mike Conley's avatar Mike Conley
Browse files

Bug 1639283 - Add Telemetry to some of our WebRTC UI. r=pbz, data-review=mmccorquodale a=RyanVM

Differential Revision: https://phabricator.services.mozilla.com/D76213
parent bbfb6f36
......@@ -49,6 +49,8 @@ var webrtcUI = {
"privacy.webrtc.legacyGlobalIndicator",
true
);
Services.telemetry.setEventRecordingEnabled("webrtc.ui", true);
}
},
......@@ -72,12 +74,24 @@ var webrtcUI = {
SHARING_SCREEN: 2,
// Set of browser windows that are being shared over WebRTC.
sharedWindows: new WeakSet(),
sharedBrowserWindows: new WeakSet(),
// True if one or more screens is being shared.
sharingScreen: false,
allowedSharedBrowsers: new WeakSet(),
allowTabSwitchesForSession: false,
tabSwitchCountForSession: 0,
// True if a window or screen is being shared.
sharingDisplay: false,
// The session ID is used to try to differentiate between instances
// where the user is sharing their display somehow. If the user
// transitions from a state of not sharing their display, to sharing a
// display, we bump the ID.
sharingDisplaySessionId: 0,
// Map of browser elements to indicator data.
perTabIndicators: new Map(),
activePerms: new Map(),
......@@ -301,25 +315,35 @@ var webrtcUI = {
};
}
let wasSharingDisplay = this.sharingDisplay;
// Reset our internal notion of whether or not we're sharing
// a screen or browser window. Now we'll go through the shared
// devices and re-determine what's being shared.
let sharingBrowserWindow = false;
let sharedWindowRawDeviceIds = new Set();
this.sharingDisplay = false;
this.sharingScreen = false;
let suppressNotifications = false;
// First, go through the streams and collect the counts on things
// like the total number of shared windows, and whether or not we're
// sharing screens.
for (let stream of this._streams) {
let { state } = stream;
suppressNotifications |= state.suppressNotifications;
for (let device of state.devices) {
let mediaSource = device.mediaSource;
if (mediaSource == "window" || mediaSource == "screen") {
this.sharingDisplay = true;
}
if (!device.scary) {
continue;
}
let mediaSource = device.mediaSource;
if (mediaSource == "window") {
sharedWindowRawDeviceIds.add(device.rawId);
} else if (mediaSource == "screen") {
......@@ -337,7 +361,9 @@ var webrtcUI = {
}
}
this.sharedWindows = new WeakSet();
// Next, go through the list of shared windows, and map them
// to our browser windows so that we know which ones are shared.
this.sharedBrowserWindows = new WeakSet();
for (let win of BrowserWindowTracker.orderedWindows) {
let rawDeviceId;
......@@ -350,7 +376,7 @@ var webrtcUI = {
continue;
}
if (sharedWindowRawDeviceIds.has(rawDeviceId)) {
this.sharedWindows.add(win);
this.sharedBrowserWindows.add(win);
// If we've shared a window, then the initially selected tab
// in that window should be exempt from tab switch warnings,
......@@ -362,6 +388,42 @@ var webrtcUI = {
}
}
// If we weren't sharing a window or screen, and now are, bump
// the sharingDisplaySessionId. We use this ID for Event
// telemetry, and consider a transition from no shared displays
// to some shared displays as a new session.
if (!wasSharingDisplay && this.sharingDisplay) {
this.sharingDisplaySessionId++;
}
// If we were adding a new display stream, record some Telemetry for
// it with the most recent sharedDisplaySessionId. We do this separately
// from the loops above because those take into account the pre-existing
// streams that might already have been shared.
if (aData.devices) {
// The mixture of camelCase with under_score notation here is due to
// an unfortunate collision of conventions between this file and
// Event Telemetry.
let silence_notifs = suppressNotifications ? "true" : "false";
for (let device of aData.devices) {
if (device.mediaSource == "screen") {
this.recordEvent("share_display", "screen", {
silence_notifs,
});
} else if (device.mediaSource == "window") {
if (device.scary) {
this.recordEvent("share_display", "browser_window", {
silence_notifs,
});
} else {
this.recordEvent("share_display", "window", {
silence_notifs,
});
}
}
}
}
// Since we're not sharing a screen or browser window,
// we can clear these state variables, which are used
// to warn users on tab switching when sharing. These
......@@ -587,7 +649,7 @@ var webrtcUI = {
getWindowShareState(window) {
if (this.sharingScreen) {
return this.SHARING_SCREEN;
} else if (this.sharedWindows.has(window)) {
} else if (this.sharedBrowserWindows.has(window)) {
return this.SHARING_WINDOW;
}
return this.SHARING_NONE;
......@@ -613,10 +675,15 @@ var webrtcUI = {
}
this.tabSwitchCountForSession++;
return (
let shouldShow =
!this.allowTabSwitchesForSession &&
!this.allowedSharedBrowsers.has(browser.permanentKey)
);
!this.allowedSharedBrowsers.has(browser.permanentKey);
if (shouldShow) {
this.recordEvent("tab_switch_warning", "tab_switch_warning");
}
return shouldShow;
},
allowSharedTabSwitch(tab, allowForSession) {
......@@ -625,6 +692,20 @@ var webrtcUI = {
this.allowedSharedBrowsers.add(browser.permanentKey);
gBrowser.selectedTab = tab;
this.allowTabSwitchesForSession = allowForSession;
if (allowForSession) {
this.recordEvent("allow_all_tabs", "allow_all_tabs");
}
},
recordEvent(type, object, args = {}) {
Services.telemetry.recordEvent(
"webrtc.ui",
type,
object,
this.sharingDisplaySessionId.toString(),
args
);
},
};
......
......@@ -2104,3 +2104,65 @@ security.ui.certerror:
is_frame: If the error page is loaded in an iframe.
has_sts: If the error page is for a site with HSTS headers or with a pinned key.
panel_open: If the advanced panel was open at the time of the interaction.
webrtc.ui:
share_display:
objects:
- screen
- window
- browser_window
description: >
Recorded when a display is shared. The value for this event is a unique
ID that differentiates different sharing sessions. A new sharing session
is created when the user transitions from not sharing a display to
sharing at least one display.
extra_keys:
silence_notifs: True if the user opted in to silencing DOM notifications.
notification_emails:
- mconley@mozilla.com
- vchin@mozilla.com
products:
- "firefox"
record_in_processes:
- main
bug_numbers:
- 1639283
expiry_version: "82"
release_channel_collection: opt-out
tab_switch_warning:
objects: ["tab_switch_warning"]
description: >
Recorded when the tab switch warning is displayed. The value for this
event is a unique ID that differentiates different sharing sessions. A
new sharing session is created when the user transitions from not
sharing a display to sharing at least one display.
notification_emails:
- mconley@mozilla.com
- vchin@mozilla.com
products:
- "firefox"
record_in_processes:
- main
bug_numbers:
- 1639283
expiry_version: "82"
release_channel_collection: opt-out
allow_all_tabs:
objects: ["allow_all_tabs"]
description: >
Recorded when the user chooses to allow all tab switches and suppress the
warning for a sharing session. The value for this event is a unique ID
that differentiates different sharing sessions. A new sharing session is
created when the user transitions from not sharing a display to sharing
at least one display.
notification_emails:
- mconley@mozilla.com
- vchin@mozilla.com
products:
- "firefox"
record_in_processes:
- main
bug_numbers:
- 1639283
expiry_version: "82"
release_channel_collection: opt-out
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment