move broadcastRootPopupInformation to Frontend

This commit is contained in:
siikamiika 2020-04-04 17:32:58 +03:00
parent 668be6224b
commit e4fc53480f
3 changed files with 13 additions and 13 deletions

View File

@ -18,6 +18,7 @@
/* global /* global
* TextScanner * TextScanner
* apiForward
* apiGetZoom * apiGetZoom
* apiKanjiFind * apiKanjiFind
* apiOptionsGet * apiOptionsGet
@ -53,7 +54,7 @@ class Frontend extends TextScanner {
this._runtimeMessageHandlers = new Map([ this._runtimeMessageHandlers = new Map([
['popupSetVisibleOverride', ({visible}) => { this.popup.setVisibleOverride(visible); }], ['popupSetVisibleOverride', ({visible}) => { this.popup.setVisibleOverride(visible); }],
['rootPopupRequestInformationBroadcast', () => { this.popup.broadcastRootPopupInformation(); }] ['rootPopupRequestInformationBroadcast', () => { this._broadcastRootPopupInformation(); }]
]); ]);
} }
@ -77,7 +78,7 @@ class Frontend extends TextScanner {
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
this._updateContentScale(); this._updateContentScale();
this.popup.broadcastRootPopupInformation(); this._broadcastRootPopupInformation();
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
@ -257,6 +258,12 @@ class Frontend extends TextScanner {
this._updatePopupPosition(); this._updatePopupPosition();
} }
_broadcastRootPopupInformation() {
if (!this.popup.isProxy() && this.popup.depth === 0) {
apiForward('rootPopupInformation', {popupId: this.popup.id, frameId: this.popup.frameId});
}
}
async _updatePopupPosition() { async _updatePopupPosition() {
const textSource = this.getCurrentTextSource(); const textSource = this.getCurrentTextSource();
if (textSource !== null && await this.popup.isVisible()) { if (textSource !== null && await this.popup.isVisible()) {

View File

@ -64,10 +64,6 @@ class PopupProxy {
return true; return true;
} }
broadcastRootPopupInformation() {
// NOP
}
async setOptions(options) { async setOptions(options) {
return await this._invokeHostApi('setOptions', {id: this._id, options}); return await this._invokeHostApi('setOptions', {id: this._id, options});
} }

View File

@ -17,7 +17,6 @@
*/ */
/* global /* global
* apiForward
* apiGetMessageToken * apiGetMessageToken
* apiInjectStylesheet * apiInjectStylesheet
*/ */
@ -69,6 +68,10 @@ class Popup {
return this._depth; return this._depth;
} }
get frameId() {
return this._frameId;
}
get url() { get url() {
return window.location.href; return window.location.href;
} }
@ -79,12 +82,6 @@ class Popup {
return false; return false;
} }
broadcastRootPopupInformation() {
if (this._depth === 0) {
apiForward('rootPopupInformation', {popupId: this._id, frameId: this._frameId});
}
}
async setOptions(options) { async setOptions(options) {
this._options = options; this._options = options;
this.updateTheme(); this.updateTheme();