summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/extensions/parent/ext-sessions.js
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/components/extensions/parent/ext-sessions.js')
-rw-r--r--comm/mail/components/extensions/parent/ext-sessions.js62
1 files changed, 62 insertions, 0 deletions
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}`];
+ }
+ }
+ }
+ }
+};