From df37acd17f9459c17185552f11dc4cc424e01958 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 13 Feb 2020 01:59:26 +0200 Subject: rename display initialize methods to prepare --- ext/fg/js/float.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8d61d8f6..3766d5a4 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -33,6 +33,20 @@ 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); + } + onError(error) { if (this._orphaned) { this.setContent('orphaned'); @@ -92,20 +106,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([ @@ -122,7 +122,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)] ]); -- cgit v1.2.3 From c0225f1f844376e5f61222a4d8186a2c914026eb Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 13 Feb 2020 13:18:54 +0200 Subject: notify popup about initialization --- ext/fg/js/float.js | 2 ++ ext/fg/js/popup.js | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'ext/fg') diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 3766d5a4..8871160f 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -45,6 +45,8 @@ class DisplayFloat extends Display { } this.setContentScale(scale); + + window.parent.postMessage('initialized', '*'); } onError(error) { diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index e7dae93e..6cfe49e5 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -45,6 +45,8 @@ class Popup { this._container.style.height = '0px'; this._updateVisibility(); + + window.addEventListener('message', (e) => this.onMessage(e), false); } // Public properties @@ -129,6 +131,18 @@ class Popup { } } + onMessage(e) { + const action = e.data; + const handler = Popup._windowMessageHandlers.get(action); + if (typeof handler !== 'function') { return; } + + handler(this); + } + + setInitialized() { + throw new Error('Override me'); + } + // Popup-only public functions setParent(parent) { @@ -237,7 +251,7 @@ class Popup { childrenSupported: this._childrenSupported, scale: this._contentScale }); - resolve(); + this.setInitialized = resolve; }); this._observeFullscreen(); this._onFullscreenChanged(); @@ -535,4 +549,8 @@ class Popup { } } +Popup._windowMessageHandlers = new Map([ + ['initialized', (self) => self.setInitialized()] +]); + Popup.outerStylesheet = null; -- cgit v1.2.3 From 38a6433a46a4259666864a57c5adbd58cb59db86 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Thu, 13 Feb 2020 15:04:10 +0200 Subject: remove isInjected checks from Popup --- ext/fg/js/popup.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 6cfe49e5..ad4e5181 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -27,8 +27,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; @@ -119,16 +117,12 @@ 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}); } onMessage(e) { @@ -160,7 +154,7 @@ class Popup { } isVisibleSync() { - return this._isInjected && (this._visibleOverride !== null ? this._visibleOverride : this._visible); + return (this._visibleOverride !== null ? this._visibleOverride : this._visible); } updateTheme() { @@ -239,7 +233,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: { @@ -256,7 +249,6 @@ class Popup { this._observeFullscreen(); this._onFullscreenChanged(); this.setCustomOuterCss(this._options.general.customPopupOuterCss, false); - this._isInjected = true; }); } @@ -341,10 +333,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() { -- cgit v1.2.3 From 810a7e7d92d15412974810702d954de60453dd31 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Fri, 14 Feb 2020 02:33:54 +0200 Subject: use sendMessage to notify about initialization --- ext/fg/js/float.js | 2 +- ext/fg/js/frontend.js | 3 ++- ext/fg/js/popup-proxy-host.js | 8 +++++++- ext/fg/js/popup-proxy.js | 5 +++++ ext/fg/js/popup.js | 18 ++---------------- 5 files changed, 17 insertions(+), 19 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js index 8871160f..b42ab8ee 100644 --- a/ext/fg/js/float.js +++ b/ext/fg/js/float.js @@ -46,7 +46,7 @@ class DisplayFloat extends Display { this.setContentScale(scale); - window.parent.postMessage('initialized', '*'); + apiForward('popupSetDisplayInitialized'); } onError(error) { diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 2286bf19..571bbf91 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -243,5 +243,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 427172c6..8ea70857 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -42,7 +42,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)] ])); } @@ -103,6 +104,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 63aa6bbe..f1743064 100644 --- a/ext/fg/js/popup-proxy.js +++ b/ext/fg/js/popup-proxy.js @@ -102,6 +102,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 ad4e5181..b8233cc2 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -43,8 +43,6 @@ class Popup { this._container.style.height = '0px'; this._updateVisibility(); - - window.addEventListener('message', (e) => this.onMessage(e), false); } // Public properties @@ -125,15 +123,7 @@ class Popup { this._invokeApi('setContentScale', {scale}); } - onMessage(e) { - const action = e.data; - const handler = Popup._windowMessageHandlers.get(action); - if (typeof handler !== 'function') { return; } - - handler(this); - } - - setInitialized() { + setDisplayInitialized() { throw new Error('Override me'); } @@ -244,7 +234,7 @@ class Popup { childrenSupported: this._childrenSupported, scale: this._contentScale }); - this.setInitialized = resolve; + this.setDisplayInitialized = resolve; }); this._observeFullscreen(); this._onFullscreenChanged(); @@ -540,8 +530,4 @@ class Popup { } } -Popup._windowMessageHandlers = new Map([ - ['initialized', (self) => self.setInitialized()] -]); - Popup.outerStylesheet = null; -- cgit v1.2.3