diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/shared/security/DevToolsSocketStatus.sys.mjs | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/shared/security/DevToolsSocketStatus.sys.mjs')
-rw-r--r-- | devtools/shared/security/DevToolsSocketStatus.sys.mjs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/devtools/shared/security/DevToolsSocketStatus.sys.mjs b/devtools/shared/security/DevToolsSocketStatus.sys.mjs new file mode 100644 index 0000000000..8acfbdd8c4 --- /dev/null +++ b/devtools/shared/security/DevToolsSocketStatus.sys.mjs @@ -0,0 +1,60 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Singleton that should be updated whenever a socket is opened or closed for + * incoming connections. + * + * Notifies observers via "devtools-socket" when the status might have have + * changed. + * + * Currently observed by browser/base/content/browser.js in order to display + * the "remote control" visual cue also used for Marionette and Remote Agent. + */ +export const DevToolsSocketStatus = { + _browserToolboxSockets: 0, + _otherSockets: 0, + + /** + * Check if there are opened DevTools sockets. + * + * @param {Object=} options + * @param {boolean=} options.excludeBrowserToolboxSockets + * Exclude sockets opened by local Browser Toolbox sessions. Defaults to + * false. + * + * @return {boolean} + * Returns true if there are DevTools sockets opened and matching the + * provided options if any. + */ + hasSocketOpened(options = {}) { + const { excludeBrowserToolboxSockets = false } = options; + if (excludeBrowserToolboxSockets) { + return this._otherSockets > 0; + } + return this._browserToolboxSockets + this._otherSockets > 0; + }, + + notifySocketOpened(options) { + const { fromBrowserToolbox } = options; + if (fromBrowserToolbox) { + this._browserToolboxSockets++; + } else { + this._otherSockets++; + } + + Services.obs.notifyObservers(this, "devtools-socket"); + }, + + notifySocketClosed(options) { + const { fromBrowserToolbox } = options; + if (fromBrowserToolbox) { + this._browserToolboxSockets--; + } else { + this._otherSockets--; + } + + Services.obs.notifyObservers(this, "devtools-socket"); + }, +}; |