From 166451b8f76224542b49c13cb27a258eb291f05e Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Tue, 9 Feb 2021 22:56:04 -0500 Subject: Improve popup window ownership (#1364) * Update frameInformationGet to also return the tab ID * Add tabId to Frontend * Pass tabId/frameId to Display * Pass ownership information using setContent * Remove ownerFrameId for Popup classes * Use frameId instead of ownerFrameId for screenshotting * Use contentOrigin instead of owner * Update _invokeContentOrigin implementation --- ext/bg/js/backend.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'ext/bg/js/backend.js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index f1983cb3..fd90a220 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -525,8 +525,10 @@ class Backend { } _onApiFrameInformationGet(params, sender) { + const tab = sender.tab; + const tabId = tab ? tab.id : void 0; const frameId = sender.frameId; - return Promise.resolve({frameId}); + return Promise.resolve({tabId, frameId}); } _onApiInjectStylesheet({type, value}, sender) { @@ -1505,17 +1507,17 @@ class Backend { return isValidTab ? tab : null; } - async _getScreenshot(windowId, tabId, ownerFrameId, format, quality) { + async _getScreenshot(windowId, tabId, frameId, format, quality) { if (typeof windowId !== 'number') { throw new Error('Invalid window ID'); } let token = null; try { - if (typeof tabId === 'number' && typeof ownerFrameId === 'number') { + if (typeof tabId === 'number' && typeof frameId === 'number') { const action = 'setAllVisibleOverride'; const params = {value: false, priority: 0, awaitFrame: true}; - token = await this._sendMessageTabPromise(tabId, {action, params}, {frameId: ownerFrameId}); + token = await this._sendMessageTabPromise(tabId, {action, params}, {frameId}); } return await new Promise((resolve, reject) => { @@ -1533,7 +1535,7 @@ class Backend { const action = 'clearAllVisibleOverride'; const params = {token}; try { - await this._sendMessageTabPromise(tabId, {action, params}, {frameId: ownerFrameId}); + await this._sendMessageTabPromise(tabId, {action, params}, {frameId}); } catch (e) { // NOP } @@ -1634,8 +1636,8 @@ class Backend { } async _injectAnkNoteScreenshot(ankiConnect, timestamp, definitionDetails, details) { - const {windowId, tabId, ownerFrameId, format, quality} = details; - const dataUrl = await this._getScreenshot(windowId, tabId, ownerFrameId, format, quality); + const {windowId, tabId, frameId, format, quality} = details; + const dataUrl = await this._getScreenshot(windowId, tabId, frameId, format, quality); const {mediaType, data} = this._getDataUrlInfo(dataUrl); const extension = this._mediaUtility.getFileExtensionFromImageMediaType(mediaType); -- cgit v1.2.3