summaryrefslogtreecommitdiff
path: root/ext/js/app
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/app')
-rw-r--r--ext/js/app/content-script-main.js9
-rw-r--r--ext/js/app/frontend.js23
-rw-r--r--ext/js/app/popup-factory.js21
3 files changed, 21 insertions, 32 deletions
diff --git a/ext/js/app/content-script-main.js b/ext/js/app/content-script-main.js
index 23d36b48..34160fd1 100644
--- a/ext/js/app/content-script-main.js
+++ b/ext/js/app/content-script-main.js
@@ -22,21 +22,14 @@ import {Frontend} from './frontend.js';
import {PopupFactory} from './popup-factory.js';
await Application.main(async (application) => {
- const {tabId, frameId} = await application.api.frameInformationGet();
- if (typeof frameId !== 'number') {
- throw new Error('Failed to get frameId');
- }
-
const hotkeyHandler = new HotkeyHandler();
hotkeyHandler.prepare(application.crossFrame);
- const popupFactory = new PopupFactory(application, frameId);
+ const popupFactory = new PopupFactory(application);
popupFactory.prepare();
const frontend = new Frontend({
application,
- tabId,
- frameId,
popupFactory,
depth: 0,
parentPopupId: null,
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js
index 84a8f1e6..1a3fbbe1 100644
--- a/ext/js/app/frontend.js
+++ b/ext/js/app/frontend.js
@@ -39,8 +39,6 @@ export class Frontend {
pageType,
popupFactory,
depth,
- tabId,
- frameId,
parentPopupId,
parentFrameId,
useProxyPopup,
@@ -57,10 +55,6 @@ export class Frontend {
this._popupFactory = popupFactory;
/** @type {number} */
this._depth = depth;
- /** @type {number|undefined} */
- this._tabId = tabId;
- /** @type {number} */
- this._frameId = frameId;
/** @type {?string} */
this._parentPopupId = parentPopupId;
/** @type {?number} */
@@ -588,8 +582,13 @@ export class Frontend {
return null;
}
+ const {frameId} = this._application;
+ if (frameId === null) {
+ return null;
+ }
+
return await this._popupFactory.getOrCreatePopup({
- frameId: this._frameId,
+ frameId,
depth: this._depth,
childrenSupported: this._childrenSupported
});
@@ -703,12 +702,10 @@ export class Frontend {
};
if (sentence !== null) { detailsState.sentence = sentence; }
if (documentTitle !== null) { detailsState.documentTitle = documentTitle; }
+ const {tabId, frameId} = this._application;
/** @type {import('display').HistoryContent} */
const detailsContent = {
- contentOrigin: {
- tabId: this._tabId,
- frameId: this._frameId
- }
+ contentOrigin: {tabId, frameId}
};
if (dictionaryEntries !== null) {
detailsContent.dictionaryEntries = dictionaryEntries;
@@ -819,7 +816,7 @@ export class Frontend {
*/
_signalFrontendReady(targetFrameId) {
/** @type {import('application').ApiMessageNoFrameId<'frontendReady'>} */
- const message = {action: 'frontendReady', params: {frameId: this._frameId}};
+ const message = {action: 'frontendReady', params: {frameId: this._application.frameId}};
if (targetFrameId === null) {
this._application.api.broadcastTab(message);
} else {
@@ -867,7 +864,7 @@ export class Frontend {
}
chrome.runtime.onMessage.addListener(onMessage);
- this._application.api.broadcastTab({action: 'frontendRequestReadyBroadcast', params: {frameId: this._frameId}});
+ this._application.api.broadcastTab({action: 'frontendRequestReadyBroadcast', params: {frameId: this._application.frameId}});
});
}
diff --git a/ext/js/app/popup-factory.js b/ext/js/app/popup-factory.js
index c5187291..4338bb3a 100644
--- a/ext/js/app/popup-factory.js
+++ b/ext/js/app/popup-factory.js
@@ -29,15 +29,12 @@ export class PopupFactory {
/**
* Creates a new instance.
* @param {import('../application.js').Application} application
- * @param {number} frameId The frame ID of the host frame.
*/
- constructor(application, frameId) {
+ constructor(application) {
/** @type {import('../application.js').Application} */
this._application = application;
- /** @type {number} */
- this._frameId = frameId;
/** @type {FrameOffsetForwarder} */
- this._frameOffsetForwarder = new FrameOffsetForwarder(application.crossFrame, frameId);
+ this._frameOffsetForwarder = new FrameOffsetForwarder(application.crossFrame);
/** @type {Map<string, import('popup').PopupAny>} */
this._popups = new Map();
/** @type {Map<string, {popup: import('popup').PopupAny, token: string}[]>} */
@@ -115,6 +112,9 @@ export class PopupFactory {
depth = 0;
}
+ const currentFrameId = this._application.frameId;
+ if (currentFrameId === null) { throw new Error('Cannot create popup: no frameId'); }
+
if (popupWindow) {
// New unique id
if (id === null) {
@@ -124,11 +124,11 @@ export class PopupFactory {
application: this._application,
id,
depth,
- frameId: this._frameId
+ frameId: currentFrameId
});
this._popups.set(id, popup);
return popup;
- } else if (frameId === this._frameId) {
+ } else if (frameId === currentFrameId) {
// New unique id
if (id === null) {
id = generateId(16);
@@ -137,7 +137,7 @@ export class PopupFactory {
application: this._application,
id,
depth,
- frameId: this._frameId,
+ frameId: currentFrameId,
childrenSupported
});
if (parent !== null) {
@@ -155,13 +155,12 @@ export class PopupFactory {
throw new Error('Invalid frameId');
}
const useFrameOffsetForwarder = (parentPopupId === null);
- /** @type {{id: string, depth: number, frameId: number}} */
- const info = await this._application.crossFrame.invoke(frameId, 'popupFactoryGetOrCreatePopup', /** @type {import('popup-factory').GetOrCreatePopupDetails} */ ({
+ const info = await this._application.crossFrame.invoke(frameId, 'popupFactoryGetOrCreatePopup', {
id,
parentPopupId,
frameId,
childrenSupported
- }));
+ });
id = info.id;
const popup = new PopupProxy({
application: this._application,