From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../components/extensions/parent/ext-sessions.js | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 comm/mail/components/extensions/parent/ext-sessions.js (limited to 'comm/mail/components/extensions/parent/ext-sessions.js') diff --git a/comm/mail/components/extensions/parent/ext-sessions.js b/comm/mail/components/extensions/parent/ext-sessions.js new file mode 100644 index 0000000000..3abe652fe3 --- /dev/null +++ b/comm/mail/components/extensions/parent/ext-sessions.js @@ -0,0 +1,62 @@ +/* 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/. */ + +"use strict"; + +var { ExtensionSupport } = ChromeUtils.import( + "resource:///modules/ExtensionSupport.jsm" +); +var { ExtensionCommon } = ChromeUtils.importESModule( + "resource://gre/modules/ExtensionCommon.sys.mjs" +); +var { makeWidgetId } = ExtensionCommon; + +function getSessionData(tabId, extension) { + let nativeTab = tabTracker.getTab(tabId); + let widgetId = makeWidgetId(extension.id); + + if (!nativeTab._ext.extensionSession) { + nativeTab._ext.extensionSession = {}; + } + if (!nativeTab._ext.extensionSession[`${widgetId}`]) { + nativeTab._ext.extensionSession[`${widgetId}`] = {}; + } + return nativeTab._ext.extensionSession[`${widgetId}`]; +} + +this.sessions = class extends ExtensionAPI { + getAPI(context) { + return { + sessions: { + setTabValue(tabId, key, value) { + let sessionData = getSessionData(tabId, context.extension); + sessionData[key] = value; + }, + getTabValue(tabId, key) { + let sessionData = getSessionData(tabId, context.extension); + return sessionData[key]; + }, + removeTabValue(tabId, key) { + let sessionData = getSessionData(tabId, context.extension); + delete sessionData[key]; + }, + }, + }; + } + + static onUninstall(extensionId) { + // Remove session data. + let widgetId = makeWidgetId(extensionId); + for (let window of Services.wm.getEnumerator("mail:3pane")) { + for (let tabInfo of window.gTabmail.tabInfo) { + if ( + tabInfo._ext.extensionSession && + tabInfo._ext.extensionSession[`${widgetId}`] + ) { + delete tabInfo._ext.extensionSession[`${widgetId}`]; + } + } + } + } +}; -- cgit v1.2.3