diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-06-21 16:14:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-21 16:14:05 -0400 |
commit | f2991fb9ee8e83738b726eb558af992f4bb5d9dc (patch) | |
tree | 6323a3ec9549131a6ef19e16595fd08fb5c31b9f /ext/bg/js/settings/popup-preview-frame.js | |
parent | 244ab31bb2edb53ff7aecb51d2dd60b50a24c194 (diff) |
Frontend initialization refactor (#610)
* Create member functions for ignoreElements and ignorePoint
* Create addFullscreenChangeEventListener utility
* Move popup creation management into Frontend
* Move getUrl implementation
* Remove old setup
* Remove try/catch block
* Error wrap
* Add prepare call to TextScanner
* Update depth when popup changes
* Refactor how Frontend gets PopupFactory and frameId
* Update popup preview to work
* Update popup preview frame to use the frontend's popup
* Update how nested popups are set up
* Error wrap
* Update how popups are set up on the search page
* Error wrap
* Error unwrap
* Add missing prepare
* Remove use of frontendInitializationData
* Catch and log errors
Diffstat (limited to 'ext/bg/js/settings/popup-preview-frame.js')
-rw-r--r-- | ext/bg/js/settings/popup-preview-frame.js | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js index 21fee7ee..98630503 100644 --- a/ext/bg/js/settings/popup-preview-frame.js +++ b/ext/bg/js/settings/popup-preview-frame.js @@ -18,17 +18,17 @@ /* global * Frontend * Popup - * PopupFactory * TextSourceRange * api */ class PopupPreviewFrame { - constructor() { + constructor(frameId, popupFactory) { + this._frameId = frameId; + this._popupFactory = popupFactory; this._frontend = null; this._frontendGetOptionsContextOld = null; this._apiOptionsGetOld = null; - this._popup = null; this._popupSetCustomOuterCssOld = null; this._popupShown = false; this._themeChangeTimeout = null; @@ -55,24 +55,25 @@ class PopupPreviewFrame { api.optionsGet = this._apiOptionsGet.bind(this); // Overwrite frontend - const {frameId} = await api.frameInformationGet(); - - const popupFactory = new PopupFactory(frameId); - await popupFactory.prepare(); - - this._popup = popupFactory.getOrCreatePopup(); - this._popup.setChildrenSupported(false); - - this._popupSetCustomOuterCssOld = this._popup.setCustomOuterCss.bind(this._popup); - this._popup.setCustomOuterCss = this._popupSetCustomOuterCss.bind(this); - - this._frontend = new Frontend(this._popup); + this._frontend = new Frontend( + this._frameId, + this._popupFactory, + { + allowRootFramePopupProxy: false + } + ); this._frontendGetOptionsContextOld = this._frontend.getOptionsContext.bind(this._frontend); this._frontend.getOptionsContext = this._getOptionsContext.bind(this); await this._frontend.prepare(); this._frontend.setDisabledOverride(true); this._frontend.canClearSelection = false; + const popup = this._frontend.popup; + popup.setChildrenSupported(false); + + this._popupSetCustomOuterCssOld = popup.setCustomOuterCss.bind(popup); + popup.setCustomOuterCss = this._popupSetCustomOuterCss.bind(this); + // Update search this._updateSearch(); } @@ -132,7 +133,9 @@ class PopupPreviewFrame { } this._themeChangeTimeout = setTimeout(() => { this._themeChangeTimeout = null; - this._popup.updateTheme(); + const popup = this._frontend.popup; + if (popup === null) { return; } + popup.updateTheme(); }, 300); } @@ -154,12 +157,16 @@ class PopupPreviewFrame { _setCustomCss({css}) { if (this._frontend === null) { return; } - this._popup.setCustomCss(css); + const popup = this._frontend.popup; + if (popup === null) { return; } + popup.setCustomCss(css); } _setCustomOuterCss({css}) { if (this._frontend === null) { return; } - this._popup.setCustomOuterCss(css, false); + const popup = this._frontend.popup; + if (popup === null) { return; } + popup.setCustomOuterCss(css, false); } async _updateOptionsContext({optionsContext}) { @@ -188,7 +195,8 @@ class PopupPreviewFrame { this._textSource = source; await this._frontend.showContentCompleted(); - if (this._popup.isVisibleSync()) { + const popup = this._frontend.popup; + if (popup !== null && popup.isVisibleSync()) { this._popupShown = true; } |