diff options
author | Alex Yatskov <alex@foosoft.net> | 2020-02-24 21:31:14 -0800 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2020-02-24 21:31:14 -0800 |
commit | d32f4def0eeed1599857bc04c973337a2a13dd8b (patch) | |
tree | 61149656f361dd2d9998d67d68249dc184b73fbb /ext/bg/js/settings/popup-preview-frame.js | |
parent | 0c5b9b1fa1599cbf769d96cdebc226310f9dd8bc (diff) | |
parent | 706c3edcffb0078d71fd5b58775f16cf5fc1205b (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/settings/popup-preview-frame.js')
-rw-r--r-- | ext/bg/js/settings/popup-preview-frame.js | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/ext/bg/js/settings/popup-preview-frame.js b/ext/bg/js/settings/popup-preview-frame.js index 37a4b416..aa2b6100 100644 --- a/ext/bg/js/settings/popup-preview-frame.js +++ b/ext/bg/js/settings/popup-preview-frame.js @@ -16,15 +16,18 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +/*global apiOptionsGet, Popup, PopupProxyHost, Frontend, TextSourceRange*/ class SettingsPopupPreview { constructor() { this.frontend = null; this.apiOptionsGetOld = apiOptionsGet; - this.popupInjectOuterStylesheetOld = Popup.injectOuterStylesheet; + this.popup = null; + this.popupSetCustomOuterCssOld = null; this.popupShown = false; this.themeChangeTimeout = null; this.textSource = null; + this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, ''); } static create() { @@ -49,18 +52,18 @@ class SettingsPopupPreview { const popupHost = new PopupProxyHost(); await popupHost.prepare(); - const popup = popupHost.createPopup(null, 0); - popup.setChildrenSupported(false); + this.popup = popupHost.getOrCreatePopup(); + this.popup.setChildrenSupported(false); - this.frontend = new Frontend(popup); + this.popupSetCustomOuterCssOld = this.popup.setCustomOuterCss; + this.popup.setCustomOuterCss = (...args) => this.popupSetCustomOuterCss(...args); - this.frontend.setEnabled = function () {}; - this.frontend.searchClear = function () {}; + this.frontend = new Frontend(this.popup); - await this.frontend.prepare(); + this.frontend.setEnabled = () => {}; + this.frontend.searchClear = () => {}; - // Overwrite popup - Popup.injectOuterStylesheet = (...args) => this.popupInjectOuterStylesheet(...args); + await this.frontend.prepare(); // Update search this.updateSearch(); @@ -82,20 +85,21 @@ class SettingsPopupPreview { return options; } - popupInjectOuterStylesheet(...args) { + async popupSetCustomOuterCss(...args) { // This simulates the stylesheet priorities when injecting using the web extension API. - const result = this.popupInjectOuterStylesheetOld(...args); + const result = await this.popupSetCustomOuterCssOld.call(this.popup, ...args); - const outerStylesheet = Popup.outerStylesheet; const node = document.querySelector('#client-css'); - if (node !== null && outerStylesheet !== null) { - node.parentNode.insertBefore(outerStylesheet, node); + if (node !== null && result !== null) { + node.parentNode.insertBefore(result, node); } return result; } onMessage(e) { + if (e.origin !== this._targetOrigin) { return; } + const {action, params} = e.data; const handler = SettingsPopupPreview._messageHandlers.get(action); if (typeof handler !== 'function') { return; } @@ -136,7 +140,7 @@ class SettingsPopupPreview { setCustomOuterCss(css) { if (this.frontend === null) { return; } - this.frontend.popup.setCustomOuterCss(css, true); + this.frontend.popup.setCustomOuterCss(css, false); } async updateSearch() { |