use sendMessage to notify about initialization

This commit is contained in:
siikamiika 2020-02-14 02:33:54 +02:00
parent d7e1ef01d8
commit 810a7e7d92
5 changed files with 17 additions and 19 deletions

View File

@ -46,7 +46,7 @@ class DisplayFloat extends Display {
this.setContentScale(scale); this.setContentScale(scale);
window.parent.postMessage('initialized', '*'); apiForward('popupSetDisplayInitialized');
} }
onError(error) { onError(error) {

View File

@ -243,5 +243,6 @@ Frontend._windowMessageHandlers = new Map([
]); ]);
Frontend._runtimeMessageHandlers = 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(); }]
]); ]);

View File

@ -42,7 +42,8 @@ class PopupProxyHost {
['showContent', ({id, elementRect, writingMode, type, details}) => this._onApiShowContent(id, elementRect, writingMode, type, details)], ['showContent', ({id, elementRect, writingMode, type, details}) => this._onApiShowContent(id, elementRect, writingMode, type, details)],
['setCustomCss', ({id, css}) => this._onApiSetCustomCss(id, css)], ['setCustomCss', ({id, css}) => this._onApiSetCustomCss(id, css)],
['clearAutoPlayTimer', ({id}) => this._onApiClearAutoPlayTimer(id)], ['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); return popup.setContentScale(scale);
} }
async _onApiSetDisplayInitialized(id) {
const popup = this._getPopup(id);
return popup.setDisplayInitialized();
}
// Private functions // Private functions
_createPopupInternal(parentId, depth) { _createPopupInternal(parentId, depth) {

View File

@ -102,6 +102,11 @@ class PopupProxy {
this._invokeHostApi('setContentScale', {id, scale}); this._invokeHostApi('setContentScale', {id, scale});
} }
async setDisplayInitialized() {
const id = await this._getPopupId();
this._invokeHostApi('setDisplayInitialized', {id});
}
// Private // Private
_getPopupId() { _getPopupId() {

View File

@ -43,8 +43,6 @@ class Popup {
this._container.style.height = '0px'; this._container.style.height = '0px';
this._updateVisibility(); this._updateVisibility();
window.addEventListener('message', (e) => this.onMessage(e), false);
} }
// Public properties // Public properties
@ -125,15 +123,7 @@ class Popup {
this._invokeApi('setContentScale', {scale}); this._invokeApi('setContentScale', {scale});
} }
onMessage(e) { setDisplayInitialized() {
const action = e.data;
const handler = Popup._windowMessageHandlers.get(action);
if (typeof handler !== 'function') { return; }
handler(this);
}
setInitialized() {
throw new Error('Override me'); throw new Error('Override me');
} }
@ -244,7 +234,7 @@ class Popup {
childrenSupported: this._childrenSupported, childrenSupported: this._childrenSupported,
scale: this._contentScale scale: this._contentScale
}); });
this.setInitialized = resolve; this.setDisplayInitialized = resolve;
}); });
this._observeFullscreen(); this._observeFullscreen();
this._onFullscreenChanged(); this._onFullscreenChanged();
@ -540,8 +530,4 @@ class Popup {
} }
} }
Popup._windowMessageHandlers = new Map([
['initialized', (self) => self.setInitialized()]
]);
Popup.outerStylesheet = null; Popup.outerStylesheet = null;