aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/display.js43
-rw-r--r--ext/js/display/popup-main.js4
-rw-r--r--ext/js/display/search-display-controller.js14
-rw-r--r--ext/js/display/search-main.js6
4 files changed, 21 insertions, 46 deletions
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index d30ed8a0..f1cd4caf 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -46,20 +46,14 @@ import {QueryParser} from './query-parser.js';
export class Display extends EventDispatcher {
/**
* @param {import('../application.js').Application} application
- * @param {number|undefined} tabId
- * @param {number|undefined} frameId
* @param {import('display').DisplayPageType} pageType
* @param {import('../dom/document-focus-controller.js').DocumentFocusController} documentFocusController
* @param {import('../input/hotkey-handler.js').HotkeyHandler} hotkeyHandler
*/
- constructor(application, tabId, frameId, pageType, documentFocusController, hotkeyHandler) {
+ constructor(application, pageType, documentFocusController, hotkeyHandler) {
super();
/** @type {import('../application.js').Application} */
this._application = application;
- /** @type {number|undefined} */
- this._tabId = tabId;
- /** @type {number|undefined} */
- this._frameId = frameId;
/** @type {import('display').DisplayPageType} */
this._pageType = pageType;
/** @type {import('../dom/document-focus-controller.js').DocumentFocusController} */
@@ -159,10 +153,10 @@ export class Display extends EventDispatcher {
this._parentPopupId = null;
/** @type {?number} */
this._parentFrameId = null;
- /** @type {number|undefined} */
- this._contentOriginTabId = tabId;
- /** @type {number|undefined} */
- this._contentOriginFrameId = frameId;
+ /** @type {?number} */
+ this._contentOriginTabId = application.tabId;
+ /** @type {?number} */
+ this._contentOriginFrameId = application.frameId;
/** @type {boolean} */
this._childrenSupported = true;
/** @type {?FrameEndpoint} */
@@ -588,10 +582,10 @@ export class Display extends EventDispatcher {
* @returns {Promise<import('cross-frame-api').ApiReturn<TName>>}
*/
async invokeContentOrigin(action, params) {
- if (this._contentOriginTabId === this._tabId && this._contentOriginFrameId === this._frameId) {
+ if (this._contentOriginTabId === this._application.tabId && this._contentOriginFrameId === this._application.frameId) {
throw new Error('Content origin is same page');
}
- if (typeof this._contentOriginTabId !== 'number' || typeof this._contentOriginFrameId !== 'number') {
+ if (this._contentOriginTabId === null || this._contentOriginFrameId === null) {
throw new Error('No content origin is assigned');
}
return await this._application.crossFrame.invokeTab(this._contentOriginTabId, this._contentOriginFrameId, action, params);
@@ -604,7 +598,8 @@ export class Display extends EventDispatcher {
* @returns {Promise<import('cross-frame-api').ApiReturn<TName>>}
*/
async invokeParentFrame(action, params) {
- if (this._parentFrameId === null || this._parentFrameId === this._frameId) {
+ const {frameId} = this._application;
+ if (frameId === null || this._parentFrameId === null || this._parentFrameId === frameId) {
throw new Error('Invalid parent frame');
}
return await this._application.crossFrame.invoke(this._parentFrameId, action, params);
@@ -832,6 +827,7 @@ export class Display extends EventDispatcher {
_onExtensionUnloaded() {
const type = 'unloaded';
if (this._contentType === type) { return; }
+ const {tabId, frameId} = this._application;
/** @type {import('display').ContentDetails} */
const details = {
focus: false,
@@ -839,10 +835,7 @@ export class Display extends EventDispatcher {
params: {type},
state: {},
content: {
- contentOrigin: {
- tabId: this._tabId,
- frameId: this._frameId
- }
+ contentOrigin: {tabId, frameId}
}
};
this.setContent(details);
@@ -1222,7 +1215,7 @@ export class Display extends EventDispatcher {
const {contentOrigin} = content;
if (typeof contentOrigin === 'object' && contentOrigin !== null) {
const {tabId, frameId} = contentOrigin;
- if (typeof tabId === 'number' && typeof frameId === 'number') {
+ if (tabId !== null && frameId !== null) {
this._contentOriginTabId = tabId;
this._contentOriginFrameId = frameId;
contentOriginValid = true;
@@ -1673,12 +1666,12 @@ export class Display extends EventDispatcher {
* @param {import('settings').ProfileOptions} options
*/
async _updateNestedFrontend(options) {
- if (typeof this._frameId !== 'number') { return; }
+ const {tabId, frameId} = this._application;
+ if (tabId === null || frameId === null) { return; }
const isSearchPage = (this._pageType === 'search');
const isEnabled = (
this._childrenSupported &&
- typeof this._tabId === 'number' &&
(
(isSearchPage) ?
(options.scanning.enableOnSearchPage) :
@@ -1707,10 +1700,6 @@ export class Display extends EventDispatcher {
/** */
async _setupNestedFrontend() {
- if (typeof this._frameId !== 'number') {
- throw new Error('No frameId assigned');
- }
-
const useProxyPopup = this._parentFrameId !== null;
const parentPopupId = this._parentPopupId;
const parentFrameId = this._parentFrameId;
@@ -1720,7 +1709,7 @@ export class Display extends EventDispatcher {
import('../app/frontend.js')
]);
- const popupFactory = new PopupFactory(this._application, this._frameId);
+ const popupFactory = new PopupFactory(this._application);
popupFactory.prepare();
/** @type {import('frontend').ConstructorDetails} */
@@ -1730,8 +1719,6 @@ export class Display extends EventDispatcher {
parentPopupId,
parentFrameId,
depth: this._depth + 1,
- tabId: this._tabId,
- frameId: this._frameId,
popupFactory,
pageType: this._pageType,
allowRootFramePopupProxy: true,
diff --git a/ext/js/display/popup-main.js b/ext/js/display/popup-main.js
index a244c2e0..8f92aaa8 100644
--- a/ext/js/display/popup-main.js
+++ b/ext/js/display/popup-main.js
@@ -29,12 +29,10 @@ await Application.main(async (application) => {
const documentFocusController = new DocumentFocusController();
documentFocusController.prepare();
- const {tabId, frameId} = await application.api.frameInformationGet();
-
const hotkeyHandler = new HotkeyHandler();
hotkeyHandler.prepare(application.crossFrame);
- const display = new Display(application, tabId, frameId, 'popup', documentFocusController, hotkeyHandler);
+ const display = new Display(application, 'popup', documentFocusController, hotkeyHandler);
await display.prepare();
const displayAudio = new DisplayAudio(display);
diff --git a/ext/js/display/search-display-controller.js b/ext/js/display/search-display-controller.js
index 6767dce7..4b8141e1 100644
--- a/ext/js/display/search-display-controller.js
+++ b/ext/js/display/search-display-controller.js
@@ -24,17 +24,11 @@ import {querySelectorNotNull} from '../dom/query-selector.js';
export class SearchDisplayController {
/**
- * @param {number|undefined} tabId
- * @param {number|undefined} frameId
* @param {import('./display.js').Display} display
* @param {import('./display-audio.js').DisplayAudio} displayAudio
* @param {import('./search-persistent-state-controller.js').SearchPersistentStateController} searchPersistentStateController
*/
- constructor(tabId, frameId, display, displayAudio, searchPersistentStateController) {
- /** @type {number|undefined} */
- this._tabId = tabId;
- /** @type {number|undefined} */
- this._frameId = frameId;
+ constructor(display, displayAudio, searchPersistentStateController) {
/** @type {import('./display.js').Display} */
this._display = display;
/** @type {import('./display-audio.js').DisplayAudio} */
@@ -519,6 +513,7 @@ export class SearchDisplayController {
if (flags !== null) {
optionsContext.flags = flags;
}
+ const {tabId, frameId} = this._display.application;
/** @type {import('display').ContentDetails} */
const details = {
focus: false,
@@ -536,10 +531,7 @@ export class SearchDisplayController {
content: {
dictionaryEntries: void 0,
animate,
- contentOrigin: {
- tabId: this._tabId,
- frameId: this._frameId
- }
+ contentOrigin: {tabId, frameId}
}
};
if (!lookup) { details.params.lookup = 'false'; }
diff --git a/ext/js/display/search-main.js b/ext/js/display/search-main.js
index 5c6a31ca..fd90ee0e 100644
--- a/ext/js/display/search-main.js
+++ b/ext/js/display/search-main.js
@@ -36,12 +36,10 @@ await Application.main(async (application) => {
const searchActionPopupController = new SearchActionPopupController(searchPersistentStateController);
searchActionPopupController.prepare();
- const {tabId, frameId} = await application.api.frameInformationGet();
-
const hotkeyHandler = new HotkeyHandler();
hotkeyHandler.prepare(application.crossFrame);
- const display = new Display(application, tabId, frameId, 'search', documentFocusController, hotkeyHandler);
+ const display = new Display(application, 'search', documentFocusController, hotkeyHandler);
await display.prepare();
const displayAudio = new DisplayAudio(display);
@@ -50,7 +48,7 @@ await Application.main(async (application) => {
const displayAnki = new DisplayAnki(display, displayAudio);
displayAnki.prepare();
- const searchDisplayController = new SearchDisplayController(tabId, frameId, display, displayAudio, searchPersistentStateController);
+ const searchDisplayController = new SearchDisplayController(display, displayAudio, searchPersistentStateController);
await searchDisplayController.prepare();
display.initializeState();