simplify popup prepare

This commit is contained in:
siikamiika 2020-03-19 00:24:14 +02:00
parent 6806e7055f
commit b6c4914b79
2 changed files with 9 additions and 29 deletions

View File

@ -26,17 +26,17 @@ class PopupProxyHost {
constructor() { constructor() {
this._popups = new Map(); this._popups = new Map();
this._apiReceiver = null; this._apiReceiver = null;
this._frameIdPromise = null; this._frameId = null;
} }
// Public functions // Public functions
async prepare() { async prepare() {
this._frameIdPromise = apiFrameInformationGet(); const {frameId} = await apiFrameInformationGet();
const {frameId} = await this._frameIdPromise;
if (typeof frameId !== 'number') { return; } if (typeof frameId !== 'number') { return; }
this._frameId = frameId;
this._apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, new Map([ this._apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${this._frameId}`, new Map([
['getOrCreatePopup', this._onApiGetOrCreatePopup.bind(this)], ['getOrCreatePopup', this._onApiGetOrCreatePopup.bind(this)],
['setOptions', this._onApiSetOptions.bind(this)], ['setOptions', this._onApiSetOptions.bind(this)],
['hide', this._onApiHide.bind(this)], ['hide', this._onApiHide.bind(this)],
@ -87,7 +87,7 @@ class PopupProxyHost {
} else if (depth === null) { } else if (depth === null) {
depth = 0; depth = 0;
} }
const popup = new Popup(id, depth, this._frameIdPromise); const popup = new Popup(id, depth, this._frameId);
if (parent !== null) { if (parent !== null) {
popup.setParent(parent); popup.setParent(parent);
} }

View File

@ -23,11 +23,10 @@
*/ */
class Popup { class Popup {
constructor(id, depth, frameIdPromise) { constructor(id, depth, frameId) {
this._id = id; this._id = id;
this._depth = depth; this._depth = depth;
this._frameIdPromise = frameIdPromise; this._frameId = frameId;
this._frameId = null;
this._parent = null; this._parent = null;
this._child = null; this._child = null;
this._childrenSupported = true; this._childrenSupported = true;
@ -80,16 +79,8 @@ class Popup {
return false; return false;
} }
async broadcastRootPopupInformation() { broadcastRootPopupInformation() {
if (this._depth === 0) { if (this._depth === 0) {
try {
const {frameId} = await this._frameIdPromise;
if (typeof frameId === 'number') {
this._frameId = frameId;
}
} catch (e) {
// NOP
}
apiForward('rootPopupInformation', {popupId: this._id, frameId: this._frameId}); apiForward('rootPopupInformation', {popupId: this._id, frameId: this._frameId});
} }
} }
@ -208,18 +199,7 @@ class Popup {
} }
async _createInjectPromise() { async _createInjectPromise() {
try { this.broadcastRootPopupInformation();
const {frameId} = await this._frameIdPromise;
if (typeof frameId === 'number') {
this._frameId = frameId;
}
} catch (e) {
// NOP
}
if (this._depth === 0) {
apiForward('rootPopupInformation', {popupId: this._id, frameId: this._frameId});
}
if (this._messageToken === null) { if (this._messageToken === null) {
this._messageToken = await apiGetMessageToken(); this._messageToken = await apiGetMessageToken();