DevToolsSocketStatus.sys.mjs (1807B)
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 * Singleton that should be updated whenever a socket is opened or closed for 7 * incoming connections. 8 * 9 * Notifies observers via "devtools-socket" when the status might have have 10 * changed. 11 * 12 * Currently observed by browser/base/content/browser.js in order to display 13 * the "remote control" visual cue also used for Marionette and Remote Agent. 14 */ 15 export const DevToolsSocketStatus = { 16 _browserToolboxSockets: 0, 17 _otherSockets: 0, 18 19 /** 20 * Check if there are opened DevTools sockets. 21 * 22 * @param {object=} options 23 * @param {boolean=} options.excludeBrowserToolboxSockets 24 * Exclude sockets opened by local Browser Toolbox sessions. Defaults to 25 * false. 26 * 27 * @return {boolean} 28 * Returns true if there are DevTools sockets opened and matching the 29 * provided options if any. 30 */ 31 hasSocketOpened(options = {}) { 32 const { excludeBrowserToolboxSockets = false } = options; 33 if (excludeBrowserToolboxSockets) { 34 return this._otherSockets > 0; 35 } 36 return this._browserToolboxSockets + this._otherSockets > 0; 37 }, 38 39 notifySocketOpened(options) { 40 const { fromBrowserToolbox } = options; 41 if (fromBrowserToolbox) { 42 this._browserToolboxSockets++; 43 } else { 44 this._otherSockets++; 45 } 46 47 Services.obs.notifyObservers(this, "devtools-socket"); 48 }, 49 50 notifySocketClosed(options) { 51 const { fromBrowserToolbox } = options; 52 if (fromBrowserToolbox) { 53 this._browserToolboxSockets--; 54 } else { 55 this._otherSockets--; 56 } 57 58 Services.obs.notifyObservers(this, "devtools-socket"); 59 }, 60 };