diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-09 22:56:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 22:56:04 -0500 |
commit | 166451b8f76224542b49c13cb27a258eb291f05e (patch) | |
tree | 071438b28a04b0478586272038ea343ad4cad319 /ext/bg/js | |
parent | 0f5fb804d03041b58813516721d897c4315dca8b (diff) |
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
Diffstat (limited to 'ext/bg/js')
-rw-r--r-- | ext/bg/js/backend.js | 16 | ||||
-rw-r--r-- | ext/bg/js/search-main.js | 4 | ||||
-rw-r--r-- | ext/bg/js/search.js | 10 | ||||
-rw-r--r-- | ext/bg/js/settings/popup-preview-frame-main.js | 4 | ||||
-rw-r--r-- | ext/bg/js/settings/popup-preview-frame.js | 4 |
5 files changed, 24 insertions, 14 deletions
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); diff --git a/ext/bg/js/search-main.js b/ext/bg/js/search-main.js index 38c6f4dd..f6abdfc8 100644 --- a/ext/bg/js/search-main.js +++ b/ext/bg/js/search-main.js @@ -32,12 +32,14 @@ api.forwardLogsToBackend(); await yomichan.backendReady(); + const {tabId, frameId} = await api.frameInformationGet(); + const japaneseUtil = new JapaneseUtil(wanakana); const hotkeyHandler = new HotkeyHandler(); hotkeyHandler.prepare(); - const displaySearch = new DisplaySearch(japaneseUtil, documentFocusController, hotkeyHandler); + const displaySearch = new DisplaySearch(tabId, frameId, japaneseUtil, documentFocusController, hotkeyHandler); await displaySearch.prepare(); document.documentElement.dataset.loaded = 'true'; diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index 27cba50f..dbc679b1 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -23,8 +23,8 @@ */ class DisplaySearch extends Display { - constructor(japaneseUtil, documentFocusController, hotkeyHandler) { - super('search', japaneseUtil, documentFocusController, hotkeyHandler); + constructor(tabId, frameId, japaneseUtil, documentFocusController, hotkeyHandler) { + super('search', tabId, frameId, japaneseUtil, documentFocusController, hotkeyHandler); this._searchButton = document.querySelector('#search-button'); this._queryInput = document.querySelector('#search-textbox'); this._introElement = document.querySelector('#intro'); @@ -353,7 +353,11 @@ class DisplaySearch extends Display { }, content: { definitions: null, - animate + animate, + contentOrigin: { + tabId: this.tabId, + frameId: this.frameId + } } }; if (!lookup) { details.params.lookup = 'false'; } diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js index 71454017..dcbc0d96 100644 --- a/ext/bg/js/settings/popup-preview-frame-main.js +++ b/ext/bg/js/settings/popup-preview-frame-main.js @@ -26,7 +26,7 @@ try { api.forwardLogsToBackend(); - const {frameId} = await api.frameInformationGet(); + const {tabId, frameId} = await api.frameInformationGet(); const hotkeyHandler = new HotkeyHandler(); hotkeyHandler.prepare(); @@ -34,7 +34,7 @@ const popupFactory = new PopupFactory(frameId); popupFactory.prepare(); - const preview = new PopupPreviewFrame(frameId, popupFactory, hotkeyHandler); + const preview = new PopupPreviewFrame(tabId, frameId, popupFactory, hotkeyHandler); await preview.prepare(); document.documentElement.dataset.loaded = 'true'; diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js index 73ac6caf..56100fb3 100644 --- a/ext/bg/js/settings/popup-preview-frame.js +++ b/ext/bg/js/settings/popup-preview-frame.js @@ -23,7 +23,8 @@ */ class PopupPreviewFrame { - constructor(frameId, popupFactory, hotkeyHandler) { + constructor(tabId, frameId, popupFactory, hotkeyHandler) { + this._tabId = tabId; this._frameId = frameId; this._popupFactory = popupFactory; this._hotkeyHandler = hotkeyHandler; @@ -67,6 +68,7 @@ class PopupPreviewFrame { // Overwrite frontend this._frontend = new Frontend({ + tabId: this._tabId, frameId: this._frameId, popupFactory: this._popupFactory, depth: 0, |