aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/float.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-08 19:50:13 -0400
committerGitHub <noreply@github.com>2020-07-08 19:50:13 -0400
commit295ffa6e54d04cedef35a4798cabdae71f824ee1 (patch)
tree8dc2e9dff44f63d1c0f4011094b6a104d35e4185 /ext/fg/js/float.js
parent128588bb92142950b53ed3f51774c13b35a82fae (diff)
Refactor DisplayFloat=>Frontend message passing (#652)
* Change getOrCreatePopup arguments to be an object * Add ownerFrameId to popup and DisplayFloat * Refactor DisplayFloat host action invocation * Use CrossFrameAPI instead of window.postMessage * Update popup closing functionality on the search page
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r--ext/fg/js/float.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 83355c5c..2837f748 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -30,6 +30,7 @@ class DisplayFloat extends Display {
this._secret = yomichan.generateId(16);
this._token = null;
this._nestedPopupsPrepared = false;
+ this._ownerFrameId = null;
this._windowMessageHandlers = new Map([
['initialize', {handler: this._onMessageInitialize.bind(this), authenticate: false}],
['configure', {handler: this._onMessageConfigure.bind(this)}],
@@ -60,7 +61,7 @@ class DisplayFloat extends Display {
}
onEscape() {
- window.parent.postMessage('popupClose', '*');
+ this._invoke('closePopup');
}
async setOptionsContext(optionsContext) {
@@ -134,7 +135,8 @@ class DisplayFloat extends Display {
this._initialize(params);
}
- async _onMessageConfigure({messageId, frameId, popupId, optionsContext, childrenSupported, scale}) {
+ async _onMessageConfigure({messageId, frameId, ownerFrameId, popupId, optionsContext, childrenSupported, scale}) {
+ this._ownerFrameId = ownerFrameId;
this.setOptionsContext(optionsContext);
await this.updateOptions();
@@ -173,7 +175,7 @@ class DisplayFloat extends Display {
// Private
_copySelection() {
- window.parent.postMessage('selectionCopy', '*');
+ this._invoke('copySelection');
}
_clearAutoPlayTimer() {
@@ -266,4 +268,8 @@ class DisplayFloat extends Display {
);
await frontend.prepare();
}
+
+ _invoke(action, params={}) {
+ return api.crossFrame.invoke(this._ownerFrameId, action, params);
+ }
}