summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/float.js32
-rw-r--r--ext/fg/js/frontend.js3
-rw-r--r--ext/fg/js/popup-proxy-host.js8
-rw-r--r--ext/fg/js/popup-proxy.js5
-rw-r--r--ext/fg/js/popup.js25
5 files changed, 41 insertions, 32 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index d31b8336..418c69b6 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -34,6 +34,22 @@ class DisplayFloat extends Display {
window.addEventListener('message', (e) => this.onMessage(e), false);
}
+ async prepare(options, popupInfo, url, childrenSupported, scale) {
+ await super.prepare(options);
+
+ const {id, depth, parentFrameId} = popupInfo;
+ this.optionsContext.depth = depth;
+ this.optionsContext.url = url;
+
+ if (childrenSupported) {
+ popupNestedInitialize(id, depth, parentFrameId, url);
+ }
+
+ this.setContentScale(scale);
+
+ apiForward('popupSetDisplayInitialized');
+ }
+
onError(error) {
if (this._orphaned) {
this.setContent('orphaned');
@@ -93,20 +109,6 @@ class DisplayFloat extends Display {
setContentScale(scale) {
document.body.style.fontSize = `${scale}em`;
}
-
- async initialize(options, popupInfo, url, childrenSupported, scale) {
- await super.initialize(options);
-
- const {id, depth, parentFrameId} = popupInfo;
- this.optionsContext.depth = depth;
- this.optionsContext.url = url;
-
- if (childrenSupported) {
- popupNestedInitialize(id, depth, parentFrameId, url);
- }
-
- this.setContentScale(scale);
- }
}
DisplayFloat._onKeyDownHandlers = new Map([
@@ -123,7 +125,7 @@ DisplayFloat._messageHandlers = new Map([
['setContent', (self, {type, details}) => self.setContent(type, details)],
['clearAutoPlayTimer', (self) => self.clearAutoPlayTimer()],
['setCustomCss', (self, {css}) => self.setCustomCss(css)],
- ['initialize', (self, {options, popupInfo, url, childrenSupported, scale}) => self.initialize(options, popupInfo, url, childrenSupported, scale)],
+ ['initialize', (self, {options, popupInfo, url, childrenSupported, scale}) => self.prepare(options, popupInfo, url, childrenSupported, scale)],
['setContentScale', (self, {scale}) => self.setContentScale(scale)]
]);
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 3611d44e..a620fb03 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -244,5 +244,6 @@ Frontend._windowMessageHandlers = new Map([
]);
Frontend._runtimeMessageHandlers = new Map([
- ['popupSetVisibleOverride', (self, {visible}) => { self.popup.setVisibleOverride(visible); }]
+ ['popupSetVisibleOverride', (self, {visible}) => { self.popup.setVisibleOverride(visible); }],
+ ['popupSetDisplayInitialized', (self) => { self.popup.setDisplayInitialized(); }]
]);
diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js
index 98729796..f6a3d451 100644
--- a/ext/fg/js/popup-proxy-host.js
+++ b/ext/fg/js/popup-proxy-host.js
@@ -43,7 +43,8 @@ class PopupProxyHost {
['showContent', ({id, elementRect, writingMode, type, details}) => this._onApiShowContent(id, elementRect, writingMode, type, details)],
['setCustomCss', ({id, css}) => this._onApiSetCustomCss(id, css)],
['clearAutoPlayTimer', ({id}) => this._onApiClearAutoPlayTimer(id)],
- ['setContentScale', ({id, scale}) => this._onApiSetContentScale(id, scale)]
+ ['setContentScale', ({id, scale}) => this._onApiSetContentScale(id, scale)],
+ ['setDisplayInitialized', ({id}) => this._onApiSetDisplayInitialized(id)]
]));
}
@@ -104,6 +105,11 @@ class PopupProxyHost {
return popup.setContentScale(scale);
}
+ async _onApiSetDisplayInitialized(id) {
+ const popup = this._getPopup(id);
+ return popup.setDisplayInitialized();
+ }
+
// Private functions
_createPopupInternal(parentId, depth) {
diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js
index db6dffb1..6f3c0f1c 100644
--- a/ext/fg/js/popup-proxy.js
+++ b/ext/fg/js/popup-proxy.js
@@ -103,6 +103,11 @@ class PopupProxy {
this._invokeHostApi('setContentScale', {id, scale});
}
+ async setDisplayInitialized() {
+ const id = await this._getPopupId();
+ this._invokeHostApi('setDisplayInitialized', {id});
+ }
+
// Private
_getPopupId() {
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 0b142dda..d077b1f8 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -28,8 +28,6 @@ class Popup {
this._child = null;
this._childrenSupported = true;
this._injectPromise = null;
- this._isInjected = false;
- this._isInjectedAndLoaded = false;
this._visible = false;
this._visibleOverride = null;
this._options = null;
@@ -118,16 +116,16 @@ class Popup {
}
clearAutoPlayTimer() {
- if (this._isInjectedAndLoaded) {
- this._invokeApi('clearAutoPlayTimer');
- }
+ this._invokeApi('clearAutoPlayTimer');
}
setContentScale(scale) {
this._contentScale = scale;
- if (this._isInjectedAndLoaded) {
- this._invokeApi('setContentScale', {scale});
- }
+ this._invokeApi('setContentScale', {scale});
+ }
+
+ setDisplayInitialized() {
+ throw new Error('Override me');
}
// Popup-only public functions
@@ -147,7 +145,7 @@ class Popup {
}
isVisibleSync() {
- return this._isInjected && (this._visibleOverride !== null ? this._visibleOverride : this._visible);
+ return (this._visibleOverride !== null ? this._visibleOverride : this._visible);
}
updateTheme() {
@@ -226,7 +224,6 @@ class Popup {
return new Promise((resolve) => {
const parentFrameId = (typeof this._frameId === 'number' ? this._frameId : null);
this._container.addEventListener('load', () => {
- this._isInjectedAndLoaded = true;
this._invokeApi('initialize', {
options: this._options,
popupInfo: {
@@ -238,12 +235,11 @@ class Popup {
childrenSupported: this._childrenSupported,
scale: this._contentScale
});
- resolve();
+ this.setDisplayInitialized = resolve;
});
this._observeFullscreen();
this._onFullscreenChanged();
this.setCustomOuterCss(this._options.general.customPopupOuterCss, false);
- this._isInjected = true;
});
}
@@ -328,10 +324,9 @@ class Popup {
}
_invokeApi(action, params={}) {
- if (!this._isInjectedAndLoaded) {
- throw new Error('Frame not loaded');
+ if (this._container.contentWindow) {
+ this._container.contentWindow.postMessage({action, params}, '*');
}
- this._container.contentWindow.postMessage({action, params}, '*');
}
_observeFullscreen() {