browser-webrtc.js (3892B)
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/. */ 4 5 /** 6 * Utility object to handle WebRTC shared tab warnings. 7 */ 8 var gSharedTabWarning = { 9 /** 10 * Called externally by gBrowser to determine if we're 11 * in a state such that we'd want to cancel the tab switch 12 * and show the tab switch warning panel instead. 13 * 14 * @param tab (<tab>) 15 * The tab being switched to. 16 * @returns boolean 17 * True if the panel will be shown, and the tab switch should 18 * be cancelled. 19 */ 20 willShowSharedTabWarning(tab) { 21 if (!this._sharedTabWarningEnabled) { 22 return false; 23 } 24 25 let shareState = webrtcUI.getWindowShareState(window); 26 if (shareState == webrtcUI.SHARING_NONE) { 27 return false; 28 } 29 30 if (!webrtcUI.shouldShowSharedTabWarning(tab)) { 31 return false; 32 } 33 34 this._createSharedTabWarningIfNeeded(); 35 let panel = document.getElementById("sharing-tabs-warning-panel"); 36 let hbox = panel.firstChild; 37 38 if (shareState == webrtcUI.SHARING_SCREEN) { 39 hbox.setAttribute("type", "screen"); 40 panel.setAttribute( 41 "aria-labelledby", 42 "sharing-screen-warning-panel-header-span" 43 ); 44 } else { 45 hbox.setAttribute("type", "window"); 46 panel.setAttribute( 47 "aria-labelledby", 48 "sharing-window-warning-panel-header-span" 49 ); 50 } 51 52 let allowForSessionCheckbox = document.getElementById( 53 "sharing-warning-disable-for-session" 54 ); 55 allowForSessionCheckbox.checked = false; 56 57 panel.openPopup(tab, "bottomleft topleft", 0, 0); 58 59 return true; 60 }, 61 62 /** 63 * Called by the tab switch warning panel after it has 64 * shown. 65 */ 66 sharedTabWarningShown() { 67 let allowButton = document.getElementById("sharing-warning-proceed-to-tab"); 68 allowButton.focus(); 69 }, 70 71 /** 72 * Called by the button in the tab switch warning panel 73 * to allow the switch to occur. 74 */ 75 allowSharedTabSwitch() { 76 let panel = document.getElementById("sharing-tabs-warning-panel"); 77 let allowForSession = document.getElementById( 78 "sharing-warning-disable-for-session" 79 ).checked; 80 81 let tab = panel.anchorNode; 82 webrtcUI.allowSharedTabSwitch(tab, allowForSession); 83 this._hideSharedTabWarning(); 84 }, 85 86 /** 87 * Called externally by gBrowser when a tab has been added. 88 * When this occurs, if we're sharing this window, we notify 89 * the webrtcUI module to exempt the new tab from the tab switch 90 * warning, since the user opened it while they were already 91 * sharing. 92 * 93 * @param tab (<tab>) 94 * The tab being opened. 95 */ 96 tabAdded(tab) { 97 if (this._sharedTabWarningEnabled) { 98 let shareState = webrtcUI.getWindowShareState(window); 99 if (shareState != webrtcUI.SHARING_NONE) { 100 webrtcUI.tabAddedWhileSharing(tab); 101 } 102 } 103 }, 104 105 get _sharedTabWarningEnabled() { 106 delete this._sharedTabWarningEnabled; 107 XPCOMUtils.defineLazyPreferenceGetter( 108 this, 109 "_sharedTabWarningEnabled", 110 "privacy.webrtc.sharedTabWarning" 111 ); 112 return this._sharedTabWarningEnabled; 113 }, 114 115 /** 116 * Internal method for hiding the tab switch warning panel. 117 */ 118 _hideSharedTabWarning() { 119 let panel = document.getElementById("sharing-tabs-warning-panel"); 120 if (panel) { 121 panel.hidePopup(); 122 } 123 }, 124 125 /** 126 * Inserts the tab switch warning panel into the DOM 127 * if it hasn't been done already yet. 128 */ 129 _createSharedTabWarningIfNeeded() { 130 // Lazy load the panel the first time we need to display it. 131 if (!document.getElementById("sharing-tabs-warning-panel")) { 132 let template = document.getElementById( 133 "sharing-tabs-warning-panel-template" 134 ); 135 template.replaceWith(template.content); 136 } 137 }, 138 };