aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-10 22:13:59 -0400
committerGitHub <noreply@github.com>2020-07-10 22:13:59 -0400
commit8389cd8ba27f328123fb73e72b24e69a4a6de2c1 (patch)
tree3d697dd1599415678dd708746cb2bdbcc43fd9cd /ext/fg/js/popup.js
parent964f011409e824da52510c7de16a1c64ebae1787 (diff)
Popup crossFrame communication (#658)
* Add support for dynamic message handlers * Pass messages using crossFrame.invoke instead of contentWindow.postMessage * Set up async handlers * Simplify configure call and response
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js23
1 files changed, 3 insertions, 20 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 78561de3..4f2de4f2 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -257,22 +257,7 @@ class Popup {
await frameClient.connect(this._frame, this._targetOrigin, this._frameId, setupFrame);
// Configure
- const messageId = yomichan.generateId(16);
- const popupPreparedPromise = yomichan.getTemporaryListenerResult(
- chrome.runtime.onMessage,
- (message, {resolve}) => {
- if (
- isObject(message) &&
- message.action === 'popupConfigured' &&
- isObject(message.params) &&
- message.params.messageId === messageId
- ) {
- resolve();
- }
- }
- );
- this._invokeApi('configure', {
- messageId,
+ await this._invokeApi('configure', {
frameId: this._frameId,
ownerFrameId: this._ownerFrameId,
popupId: this._id,
@@ -280,8 +265,6 @@ class Popup {
childrenSupported: this._childrenSupported,
scale: this._contentScale
});
-
- return popupPreparedPromise;
}
_onFrameLoad() {
@@ -456,12 +439,12 @@ class Popup {
return dark ? 'dark' : 'light';
}
- _invokeApi(action, params={}) {
+ async _invokeApi(action, params={}) {
const contentWindow = this._frame.contentWindow;
if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; }
const message = this._frameClient.createMessage({action, params});
- contentWindow.postMessage(message, this._targetOrigin);
+ return await api.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message);
}
_getFrameParentElement() {