summaryrefslogtreecommitdiff
path: root/ext/fg/js/frontend-initialize.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-05 21:19:28 +0300
committerGitHub <noreply@github.com>2020-04-05 21:19:28 +0300
commit3df78904cf734da208c6fd1b6ae1cd6612323148 (patch)
tree398951de43ca77acd6174c5846313e1b269422c7 /ext/fg/js/frontend-initialize.js
parent3684a479c5e12efe63c54e5532a264d157a6816d (diff)
parent22a97d916fc6ecab1200b0ffea18cf2d5c9923d4 (diff)
Merge pull request #417 from siikamiika/iframe-popups-2
Show iframe popups on root page
Diffstat (limited to 'ext/fg/js/frontend-initialize.js')
-rw-r--r--ext/fg/js/frontend-initialize.js30
1 files changed, 29 insertions, 1 deletions
diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js
index 3a191247..4a1409db 100644
--- a/ext/fg/js/frontend-initialize.js
+++ b/ext/fg/js/frontend-initialize.js
@@ -17,9 +17,12 @@
*/
/* global
+ * FrameOffsetForwarder
* Frontend
* PopupProxy
* PopupProxyHost
+ * apiForward
+ * apiOptionsGet
*/
async function main() {
@@ -28,10 +31,35 @@ async function main() {
const data = window.frontendInitializationData || {};
const {id, depth=0, parentFrameId, url, proxy=false} = data;
+ const optionsContext = {depth, url};
+ const options = await apiOptionsGet(optionsContext);
+
let popup;
- if (proxy) {
+ if (!proxy && (window !== window.parent) && options.general.showIframePopupsInRootFrame) {
+ const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
+ chrome.runtime.onMessage,
+ ({action, params}, {resolve}) => {
+ if (action === 'rootPopupInformation') {
+ resolve(params);
+ }
+ }
+ );
+ apiForward('rootPopupRequestInformationBroadcast');
+ const {popupId, frameId} = await rootPopupInformationPromise;
+
+ const frameOffsetForwarder = new FrameOffsetForwarder();
+ frameOffsetForwarder.start();
+ const getFrameOffset = frameOffsetForwarder.getOffset.bind(frameOffsetForwarder);
+
+ popup = new PopupProxy(popupId, 0, null, frameId, url, getFrameOffset);
+ await popup.prepare();
+ } else if (proxy) {
popup = new PopupProxy(null, depth + 1, id, parentFrameId, url);
+ await popup.prepare();
} else {
+ const frameOffsetForwarder = new FrameOffsetForwarder();
+ frameOffsetForwarder.start();
+
const popupHost = new PopupProxyHost();
await popupHost.prepare();