aboutsummaryrefslogtreecommitdiff
path: root/ext/js/comm
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/comm')
-rw-r--r--ext/js/comm/cross-frame-api.js12
-rw-r--r--ext/js/comm/frame-ancestry-handler.js10
-rw-r--r--ext/js/comm/frame-endpoint.js12
-rw-r--r--ext/js/comm/frame-offset-forwarder.js12
4 files changed, 29 insertions, 17 deletions
diff --git a/ext/js/comm/cross-frame-api.js b/ext/js/comm/cross-frame-api.js
index fca7c84d..eb9bed38 100644
--- a/ext/js/comm/cross-frame-api.js
+++ b/ext/js/comm/cross-frame-api.js
@@ -22,7 +22,6 @@ import {EventListenerCollection} from '../core/event-listener-collection.js';
import {ExtensionError} from '../core/extension-error.js';
import {parseJson} from '../core/json.js';
import {log} from '../core/logger.js';
-import {yomitan} from '../yomitan.js';
/**
* @augments EventDispatcher<import('cross-frame-api').CrossFrameAPIPortEvents>
@@ -290,7 +289,12 @@ export class CrossFrameAPIPort extends EventDispatcher {
}
export class CrossFrameAPI {
- constructor() {
+ /**
+ * @param {import('../comm/api.js').API} api
+ */
+ constructor(api) {
+ /** @type {import('../comm/api.js').API} */
+ this._api = api;
/** @type {number} */
this._ackTimeout = 3000; // 3 seconds
/** @type {number} */
@@ -310,7 +314,7 @@ export class CrossFrameAPI {
/** */
async prepare() {
chrome.runtime.onConnect.addListener(this._onConnect.bind(this));
- ({tabId: this._tabId = null, frameId: this._frameId = null} = await yomitan.api.frameInformationGet());
+ ({tabId: this._tabId = null, frameId: this._frameId = null} = await this._api.frameInformationGet());
}
/**
@@ -411,7 +415,7 @@ export class CrossFrameAPI {
* @returns {Promise<CrossFrameAPIPort>}
*/
async _createCommPort(otherTabId, otherFrameId) {
- await yomitan.api.openCrossFramePort(otherTabId, otherFrameId);
+ await this._api.openCrossFramePort(otherTabId, otherFrameId);
const tabPorts = this._commPorts.get(otherTabId);
if (typeof tabPorts !== 'undefined') {
diff --git a/ext/js/comm/frame-ancestry-handler.js b/ext/js/comm/frame-ancestry-handler.js
index 31739654..3e58d57b 100644
--- a/ext/js/comm/frame-ancestry-handler.js
+++ b/ext/js/comm/frame-ancestry-handler.js
@@ -17,7 +17,6 @@
*/
import {generateId} from '../core/utilities.js';
-import {yomitan} from '../yomitan.js';
/**
* This class is used to return the ancestor frame IDs for the current frame.
@@ -28,9 +27,12 @@ import {yomitan} from '../yomitan.js';
export class FrameAncestryHandler {
/**
* Creates a new instance.
+ * @param {import('../comm/cross-frame-api.js').CrossFrameAPI} crossFrameApi
* @param {number} frameId The frame ID of the current frame the instance is instantiated in.
*/
- constructor(frameId) {
+ constructor(crossFrameApi, frameId) {
+ /** @type {import('../comm/cross-frame-api.js').CrossFrameAPI} */
+ this._crossFrameApi = crossFrameApi;
/** @type {number} */
this._frameId = frameId;
/** @type {boolean} */
@@ -59,7 +61,7 @@ export class FrameAncestryHandler {
prepare() {
if (this._isPrepared) { return; }
window.addEventListener('message', this._onWindowMessage.bind(this), false);
- yomitan.crossFrame.registerHandlers([
+ this._crossFrameApi.registerHandlers([
['frameAncestryHandlerRequestFrameInfoResponse', this._onFrameAncestryHandlerRequestFrameInfoResponse.bind(this)]
]);
this._isPrepared = true;
@@ -211,7 +213,7 @@ export class FrameAncestryHandler {
const more = (window !== parent);
try {
- const response = await yomitan.crossFrame.invoke(originFrameId, 'frameAncestryHandlerRequestFrameInfoResponse', {uniqueId, frameId, nonce, more});
+ const response = await this._crossFrameApi.invoke(originFrameId, 'frameAncestryHandlerRequestFrameInfoResponse', {uniqueId, frameId, nonce, more});
if (response === null) { return; }
const nonce2 = response.nonce;
if (typeof nonce2 !== 'string') { return; }
diff --git a/ext/js/comm/frame-endpoint.js b/ext/js/comm/frame-endpoint.js
index 0008417d..d2002d2e 100644
--- a/ext/js/comm/frame-endpoint.js
+++ b/ext/js/comm/frame-endpoint.js
@@ -18,10 +18,14 @@
import {EventListenerCollection} from '../core/event-listener-collection.js';
import {generateId} from '../core/utilities.js';
-import {yomitan} from '../yomitan.js';
export class FrameEndpoint {
- constructor() {
+ /**
+ * @param {import('../comm/api.js').API} api
+ */
+ constructor(api) {
+ /** @type {import('../comm/api.js').API} */
+ this._api = api;
/** @type {string} */
this._secret = generateId(16);
/** @type {?string} */
@@ -42,7 +46,7 @@ export class FrameEndpoint {
}
/** @type {import('frame-client').FrameEndpointReadyDetails} */
const details = {secret: this._secret};
- yomitan.api.broadcastTab({action: 'frameEndpointReady', params: details});
+ this._api.broadcastTab({action: 'frameEndpointReady', params: details});
}
/**
@@ -84,6 +88,6 @@ export class FrameEndpoint {
this._eventListeners.removeAllEventListeners();
/** @type {import('frame-client').FrameEndpointConnectedDetails} */
const details = {secret, token};
- yomitan.api.sendMessageToFrame(hostFrameId, {action: 'frameEndpointConnected', params: details});
+ this._api.sendMessageToFrame(hostFrameId, {action: 'frameEndpointConnected', params: details});
}
}
diff --git a/ext/js/comm/frame-offset-forwarder.js b/ext/js/comm/frame-offset-forwarder.js
index a1f249e2..fe1ff98a 100644
--- a/ext/js/comm/frame-offset-forwarder.js
+++ b/ext/js/comm/frame-offset-forwarder.js
@@ -16,18 +16,20 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import {yomitan} from '../yomitan.js';
import {FrameAncestryHandler} from './frame-ancestry-handler.js';
export class FrameOffsetForwarder {
/**
+ * @param {import('../comm/cross-frame-api.js').CrossFrameAPI} crossFrameApi
* @param {number} frameId
*/
- constructor(frameId) {
+ constructor(crossFrameApi, frameId) {
+ /** @type {import('../comm/cross-frame-api.js').CrossFrameAPI} */
+ this._crossFrameApi = crossFrameApi;
/** @type {number} */
this._frameId = frameId;
/** @type {FrameAncestryHandler} */
- this._frameAncestryHandler = new FrameAncestryHandler(frameId);
+ this._frameAncestryHandler = new FrameAncestryHandler(crossFrameApi, frameId);
}
/**
@@ -35,7 +37,7 @@ export class FrameOffsetForwarder {
*/
prepare() {
this._frameAncestryHandler.prepare();
- yomitan.crossFrame.registerHandlers([
+ this._crossFrameApi.registerHandlers([
['frameOffsetForwarderGetChildFrameRect', this._onMessageGetChildFrameRect.bind(this)]
]);
}
@@ -55,7 +57,7 @@ export class FrameOffsetForwarder {
/** @type {Promise<?import('frame-offset-forwarder').ChildFrameRect>[]} */
const promises = [];
for (const frameId of ancestorFrameIds) {
- promises.push(yomitan.crossFrame.invoke(frameId, 'frameOffsetForwarderGetChildFrameRect', {frameId: childFrameId}));
+ promises.push(this._crossFrameApi.invoke(frameId, 'frameOffsetForwarderGetChildFrameRect', {frameId: childFrameId}));
childFrameId = frameId;
}