From d6b9949fb81b55379c21433f9eb53055d20b7939 Mon Sep 17 00:00:00 2001 From: TrickyPR <23250792+trickypr@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:44:17 +1000 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20browserAction=20to?= =?UTF-8?q?=20tabManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/extensions/lib/parent/ext-browserAction.js | 16 +++------------- apps/extensions/lib/types/utils.d.ts | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/extensions/lib/parent/ext-browserAction.js b/apps/extensions/lib/parent/ext-browserAction.js index e675983..7ce10e5 100644 --- a/apps/extensions/lib/parent/ext-browserAction.js +++ b/apps/extensions/lib/parent/ext-browserAction.js @@ -13,7 +13,6 @@ this.browserAction = class extends ExtensionAPIPersistent { async onManifestEntry() { const { extension } = this - /** @type {browser_action__manifest.WebExtensionManifest__extended['browser_action']} */ const options = extension.manifest.browser_action if (!options) { @@ -67,25 +66,16 @@ this.browserAction = class extends ExtensionAPIPersistent { * running extension context. */ onClicked({ fire }) { - const { extension } = this + const /** @type {Extension} */ extension = this.extension /** * @param {import("resource://app/modules/EBrowserActions.sys.mjs").IBrowserActionEvents['click']} clickInfo */ const callback = async (_name, clickInfo) => { if (fire.wakeup) await fire.wakeup() - const { tab, window } = lazy.WindowTracker.getWindowWithBrowserId( - clickInfo.tabId, - ) || { tab: null, window: null } - if (!tab || !window) { - return fire.sync(null, clickInfo.clickData) - } - - fire.sync( - tabTracker.serializeTab(extension, tab, window), - clickInfo.clickData, - ) + const tab = extension.tabManager.get(clickInfo.tabId) + fire.sync(tab.convert(), clickInfo.clickData) } this.on('click', callback) diff --git a/apps/extensions/lib/types/utils.d.ts b/apps/extensions/lib/types/utils.d.ts index 5b937bb..476b1b4 100644 --- a/apps/extensions/lib/types/utils.d.ts +++ b/apps/extensions/lib/types/utils.d.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/ban-types */ /// import { ConduitAddress } from 'resource://gre/modules/ConduitsParent.sys.mjs' -import { Extension } from 'resource://gre/modules/Extension.sys.mjs' +import { Extension as ToolkitExtension } from 'resource://gre/modules/Extension.sys.mjs' import { SchemaRoot } from 'resource://gre/modules/Schemas.sys.mjs' import { PointConduit } from './ConduitChild' @@ -15,6 +15,12 @@ declare global { type NativeTab = import('@browser/tabs').WindowTab type XULElement = Element + interface Extension extends ToolkitExtension { + tabManager: TabManagerBase + manifest: Omit & + browser_action__manifest.WebExtensionManifest__extended + } + /* eslint-disable @typescript-eslint/no-explicit-any */ function getConsole(): any function runSafeSyncWithoutClone(f: any, ...args: any[]): any @@ -1532,6 +1538,15 @@ declare global { matches(queryInfo: QueryInfo): boolean + /** + * Converts this tab object to a JSON-compatible object containing the values + * of its properties which the extension is permitted to access, in the format + * required to be returned by WebExtension APIs. + * + * @param [fallbackTabSize] + * A geometry data if the lazy geometry data for this tab hasn't been + * initialized yet. + */ convert(fallbackTabSize?: any): any queryContent(message: string, options: Options): Promise[]