1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* eslint-env mozilla/browser-window */
8 * Utility object to handle WebRTC shared tab warnings.
10 var gSharedTabWarning = {
12 * Called externally by gBrowser to determine if we're
13 * in a state such that we'd want to cancel the tab switch
14 * and show the tab switch warning panel instead.
17 * The tab being switched to.
19 * True if the panel will be shown, and the tab switch should
22 willShowSharedTabWarning(tab) {
23 if (!this._sharedTabWarningEnabled) {
27 let shareState = webrtcUI.getWindowShareState(window);
28 if (shareState == webrtcUI.SHARING_NONE) {
32 if (!webrtcUI.shouldShowSharedTabWarning(tab)) {
36 this._createSharedTabWarningIfNeeded();
37 let panel = document.getElementById("sharing-tabs-warning-panel");
38 let hbox = panel.firstChild;
40 if (shareState == webrtcUI.SHARING_SCREEN) {
41 hbox.setAttribute("type", "screen");
44 "sharing-screen-warning-panel-header-span"
47 hbox.setAttribute("type", "window");
50 "sharing-window-warning-panel-header-span"
54 let allowForSessionCheckbox = document.getElementById(
55 "sharing-warning-disable-for-session"
57 allowForSessionCheckbox.checked = false;
59 panel.openPopup(tab, "bottomleft topleft", 0, 0);
65 * Called by the tab switch warning panel after it has
68 sharedTabWarningShown() {
69 let allowButton = document.getElementById("sharing-warning-proceed-to-tab");
74 * Called by the button in the tab switch warning panel
75 * to allow the switch to occur.
77 allowSharedTabSwitch() {
78 let panel = document.getElementById("sharing-tabs-warning-panel");
79 let allowForSession = document.getElementById(
80 "sharing-warning-disable-for-session"
83 let tab = panel.anchorNode;
84 webrtcUI.allowSharedTabSwitch(tab, allowForSession);
85 this._hideSharedTabWarning();
89 * Called externally by gBrowser when a tab has been added.
90 * When this occurs, if we're sharing this window, we notify
91 * the webrtcUI module to exempt the new tab from the tab switch
92 * warning, since the user opened it while they were already
96 * The tab being opened.
99 if (this._sharedTabWarningEnabled) {
100 let shareState = webrtcUI.getWindowShareState(window);
101 if (shareState != webrtcUI.SHARING_NONE) {
102 webrtcUI.tabAddedWhileSharing(tab);
107 get _sharedTabWarningEnabled() {
108 delete this._sharedTabWarningEnabled;
109 XPCOMUtils.defineLazyPreferenceGetter(
111 "_sharedTabWarningEnabled",
112 "privacy.webrtc.sharedTabWarning"
114 return this._sharedTabWarningEnabled;
118 * Internal method for hiding the tab switch warning panel.
120 _hideSharedTabWarning() {
121 let panel = document.getElementById("sharing-tabs-warning-panel");
128 * Inserts the tab switch warning panel into the DOM
129 * if it hasn't been done already yet.
131 _createSharedTabWarningIfNeeded() {
132 // Lazy load the panel the first time we need to display it.
133 if (!document.getElementById("sharing-tabs-warning-panel")) {
134 let template = document.getElementById(
135 "sharing-tabs-warning-panel-template"
137 template.replaceWith(template.content);