refactor
This commit is contained in:
parent
d20ece9f07
commit
9fe1e38afb
@ -22,15 +22,23 @@
|
||||
|
||||
class FrameOffsetForwarder {
|
||||
constructor() {
|
||||
this._forwardFrameOffset = window !== window.parent ?
|
||||
this._started = false;
|
||||
|
||||
this._forwardFrameOffset = (
|
||||
window !== window.parent ?
|
||||
this._forwardFrameOffsetParent.bind(this) :
|
||||
this._forwardFrameOffsetOrigin.bind(this);
|
||||
this._forwardFrameOffsetOrigin.bind(this)
|
||||
);
|
||||
|
||||
this._windowMessageHandlers = new Map([
|
||||
['getFrameOffset', ({offset, uniqueId}, e) => { return this._onGetFrameOffset(offset, uniqueId, e); }]
|
||||
['getFrameOffset', ({offset, uniqueId}, e) => this._onGetFrameOffset(offset, uniqueId, e)]
|
||||
]);
|
||||
}
|
||||
|
||||
start() {
|
||||
if (this._started) { return; }
|
||||
window.addEventListener('message', this.onMessage.bind(this), false);
|
||||
this._started = true;
|
||||
}
|
||||
|
||||
async applyOffset(x, y) {
|
||||
@ -44,7 +52,6 @@ class FrameOffsetForwarder {
|
||||
chrome.runtime.onMessage.removeListener(runtimeMessageCallback);
|
||||
callback();
|
||||
frameOffsetResolve(params);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
chrome.runtime.onMessage.addListener(runtimeMessageCallback);
|
||||
|
@ -40,23 +40,26 @@ async function main() {
|
||||
chrome.runtime.onMessage.removeListener(runtimeMessageCallback);
|
||||
callback();
|
||||
rootPopupInformationResolve(params);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
chrome.runtime.onMessage.addListener(runtimeMessageCallback);
|
||||
apiForward('rootPopupInformationGet');
|
||||
apiForward('rootPopupRequestInformationBroadcast');
|
||||
|
||||
const {popupId, frameId} = await rootPopupInformationPromise;
|
||||
|
||||
window._frameOffsetForwarder = new FrameOffsetForwarder();
|
||||
const applyFrameOffset = window._frameOffsetForwarder.applyOffset.bind(window._frameOffsetForwarder);
|
||||
const frameOffsetForwarder = new FrameOffsetForwarder();
|
||||
frameOffsetForwarder.start();
|
||||
const applyFrameOffset = frameOffsetForwarder.applyOffset.bind(frameOffsetForwarder);
|
||||
|
||||
popup = new PopupProxy(popupId, 0, null, frameId, url, applyFrameOffset);
|
||||
await popup.prepare();
|
||||
} else if (proxy) {
|
||||
popup = new PopupProxy(null, depth + 1, id, parentFrameId, url);
|
||||
await popup.prepare();
|
||||
} else {
|
||||
window._frameOffsetForwarder = new FrameOffsetForwarder();
|
||||
const frameOffsetForwarder = new FrameOffsetForwarder();
|
||||
frameOffsetForwarder.start();
|
||||
|
||||
const popupHost = new PopupProxyHost();
|
||||
await popupHost.prepare();
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Frontend extends TextScanner {
|
||||
|
||||
this._runtimeMessageHandlers = new Map([
|
||||
['popupSetVisibleOverride', ({visible}) => { this.popup.setVisibleOverride(visible); }],
|
||||
['rootPopupInformationGet', () => { this.popup.broadcastRootPopupInformation(); }]
|
||||
['rootPopupRequestInformationBroadcast', () => { this.popup.broadcastRootPopupInformation(); }]
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
class PopupProxy {
|
||||
constructor(id, depth, parentId, parentFrameId, url, applyFrameOffset=async (x, y) => [x, y]) {
|
||||
constructor(id, depth, parentId, parentFrameId, url, applyFrameOffset=null) {
|
||||
this._parentId = parentId;
|
||||
this._parentFrameId = parentFrameId;
|
||||
this._id = id;
|
||||
@ -81,7 +81,7 @@ class PopupProxy {
|
||||
}
|
||||
|
||||
async containsPoint(x, y) {
|
||||
if (this._depth === 0) {
|
||||
if (this._applyFrameOffset !== null) {
|
||||
[x, y] = await this._applyFrameOffset(x, y);
|
||||
}
|
||||
return await this._invokeHostApi('containsPoint', {id: this._id, x, y});
|
||||
@ -89,7 +89,7 @@ class PopupProxy {
|
||||
|
||||
async showContent(elementRect, writingMode, type=null, details=null) {
|
||||
let {x, y, width, height} = elementRect;
|
||||
if (this._depth === 0) {
|
||||
if (this._applyFrameOffset !== null) {
|
||||
[x, y] = await this._applyFrameOffset(x, y);
|
||||
}
|
||||
elementRect = {x, y, width, height};
|
||||
|
@ -368,7 +368,6 @@ class Popup {
|
||||
chrome.runtime.onMessage.removeListener(runtimeMessageCallback);
|
||||
callback();
|
||||
resolve();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
chrome.runtime.onMessage.addListener(runtimeMessageCallback);
|
||||
|
Loading…
Reference in New Issue
Block a user