diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-05-08 19:04:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-08 19:04:53 -0400 |
commit | b936c3e4b1bc993e535b02dee91bf6afc15a3564 (patch) | |
tree | 389b05a78e4b1d8f4d6184516d8418b0816f3d63 /ext/fg/js/content-script-main.js | |
parent | b972f8cbf671c0e09603d54153a6344b105f41d9 (diff) |
Popup proxy host refactor (#516)
* Rename PopupProxyHost to PopupFactory
* Update FrontendApiReceiver to support non-async handlers
* Make some functions non-async
* Make setCustomCss non-async
* Make setContentScale non-async
* Remove static
* Rename variables
* Pass frameId into PopupFactory's constructor
* Change FrontendApiReceiver source from popup-proxy-host to popup-factor
* Rename _invokeHostApi to _invoke
* Rename PopupProxy.getHostUrl to getUrl
Diffstat (limited to 'ext/fg/js/content-script-main.js')
-rw-r--r-- | ext/fg/js/content-script-main.js | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/ext/fg/js/content-script-main.js b/ext/fg/js/content-script-main.js index 277e6567..3afc9648 100644 --- a/ext/fg/js/content-script-main.js +++ b/ext/fg/js/content-script-main.js @@ -19,10 +19,11 @@ * DOM * FrameOffsetForwarder * Frontend + * PopupFactory * PopupProxy - * PopupProxyHost * apiBroadcastTab * apiForwardLogsToBackend + * apiFrameInformationGet * apiOptionsGet */ @@ -47,10 +48,17 @@ async function createIframePopupProxy(frameOffsetForwarder, setDisabled) { } async function getOrCreatePopup(depth) { - const popupHost = new PopupProxyHost(); - await popupHost.prepare(); + const {frameId} = await apiFrameInformationGet(); + if (typeof frameId !== 'number') { + const error = new Error('Failed to get frameId'); + yomichan.logError(error); + throw error; + } - const popup = popupHost.getOrCreatePopup(null, null, depth); + const popupFactory = new PopupFactory(frameId); + await popupFactory.prepare(); + + const popup = popupFactory.getOrCreatePopup(null, null, depth); return popup; } @@ -89,20 +97,20 @@ async function createPopupProxy(depth, id, parentFrameId) { }; let urlUpdatedAt = 0; - let proxyHostUrlCached = url; - const getProxyHostUrl = async () => { + let popupProxyUrlCached = url; + const getPopupProxyUrl = async () => { const now = Date.now(); if (popups.proxy !== null && now - urlUpdatedAt > 500) { - proxyHostUrlCached = await popups.proxy.getHostUrl(); + popupProxyUrlCached = await popups.proxy.getUrl(); urlUpdatedAt = now; } - return proxyHostUrlCached; + return popupProxyUrlCached; }; const applyOptions = async () => { const optionsContext = { depth: isSearchPage ? 0 : depth, - url: proxy ? await getProxyHostUrl() : window.location.href + url: proxy ? await getPopupProxyUrl() : window.location.href }; const options = await apiOptionsGet(optionsContext); @@ -124,7 +132,7 @@ async function createPopupProxy(depth, id, parentFrameId) { } if (frontend === null) { - const getUrl = proxy ? getProxyHostUrl : null; + const getUrl = proxy ? getPopupProxyUrl : null; frontend = new Frontend(popup, getUrl); frontendPreparePromise = frontend.prepare(); await frontendPreparePromise; |