diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/shared/security/DevToolsSocketStatus.sys.mjs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
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"); + }, +}; |