Bug 1864861: part 2) Remove `aIsPreload` argument from `FontLoaderUtils::BuildChannel...
[gecko.git] / browser / base / content / browser-webrtc.js
blob889769f292679cabea6de1ebac4c11e1f64bf674
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 */
7 /**
8  * Utility object to handle WebRTC shared tab warnings.
9  */
10 var gSharedTabWarning = {
11   /**
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.
15    *
16    * @param tab (<tab>)
17    *   The tab being switched to.
18    * @returns boolean
19    *   True if the panel will be shown, and the tab switch should
20    *   be cancelled.
21    */
22   willShowSharedTabWarning(tab) {
23     if (!this._sharedTabWarningEnabled) {
24       return false;
25     }
27     let shareState = webrtcUI.getWindowShareState(window);
28     if (shareState == webrtcUI.SHARING_NONE) {
29       return false;
30     }
32     if (!webrtcUI.shouldShowSharedTabWarning(tab)) {
33       return false;
34     }
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");
42       panel.setAttribute(
43         "aria-labelledby",
44         "sharing-screen-warning-panel-header-span"
45       );
46     } else {
47       hbox.setAttribute("type", "window");
48       panel.setAttribute(
49         "aria-labelledby",
50         "sharing-window-warning-panel-header-span"
51       );
52     }
54     let allowForSessionCheckbox = document.getElementById(
55       "sharing-warning-disable-for-session"
56     );
57     allowForSessionCheckbox.checked = false;
59     panel.openPopup(tab, "bottomleft topleft", 0, 0);
61     return true;
62   },
64   /**
65    * Called by the tab switch warning panel after it has
66    * shown.
67    */
68   sharedTabWarningShown() {
69     let allowButton = document.getElementById("sharing-warning-proceed-to-tab");
70     allowButton.focus();
71   },
73   /**
74    * Called by the button in the tab switch warning panel
75    * to allow the switch to occur.
76    */
77   allowSharedTabSwitch() {
78     let panel = document.getElementById("sharing-tabs-warning-panel");
79     let allowForSession = document.getElementById(
80       "sharing-warning-disable-for-session"
81     ).checked;
83     let tab = panel.anchorNode;
84     webrtcUI.allowSharedTabSwitch(tab, allowForSession);
85     this._hideSharedTabWarning();
86   },
88   /**
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
93    * sharing.
94    *
95    * @param tab (<tab>)
96    *   The tab being opened.
97    */
98   tabAdded(tab) {
99     if (this._sharedTabWarningEnabled) {
100       let shareState = webrtcUI.getWindowShareState(window);
101       if (shareState != webrtcUI.SHARING_NONE) {
102         webrtcUI.tabAddedWhileSharing(tab);
103       }
104     }
105   },
107   get _sharedTabWarningEnabled() {
108     delete this._sharedTabWarningEnabled;
109     XPCOMUtils.defineLazyPreferenceGetter(
110       this,
111       "_sharedTabWarningEnabled",
112       "privacy.webrtc.sharedTabWarning"
113     );
114     return this._sharedTabWarningEnabled;
115   },
117   /**
118    * Internal method for hiding the tab switch warning panel.
119    */
120   _hideSharedTabWarning() {
121     let panel = document.getElementById("sharing-tabs-warning-panel");
122     if (panel) {
123       panel.hidePopup();
124     }
125   },
127   /**
128    * Inserts the tab switch warning panel into the DOM
129    * if it hasn't been done already yet.
130    */
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"
136       );
137       template.replaceWith(template.content);
138     }
139   },