aboutsummaryrefslogtreecommitdiff
path: root/ext/fg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-24 14:00:32 -0400
committerGitHub <noreply@github.com>2020-05-24 14:00:32 -0400
commit3c4c82dcfc66a1b24a3df3d4b15283235c72cf66 (patch)
tree5ab01e468ed2154dda504d908127049c3e40c88a /ext/fg
parent13f57cccba5a29ff9e270a3fc2b2d7fee6e46b51 (diff)
Ensure single popup factory (#554)
* Add createPopupFactory * Ensure only a single PopupFactory is generated
Diffstat (limited to 'ext/fg')
-rw-r--r--ext/fg/js/content-script-main.js42
1 files changed, 26 insertions, 16 deletions
diff --git a/ext/fg/js/content-script-main.js b/ext/fg/js/content-script-main.js
index b057ae3d..cebda2d7 100644
--- a/ext/fg/js/content-script-main.js
+++ b/ext/fg/js/content-script-main.js
@@ -24,6 +24,19 @@
* api
*/
+async function createPopupFactory() {
+ const {frameId} = await api.frameInformationGet();
+ if (typeof frameId !== 'number') {
+ const error = new Error('Failed to get frameId');
+ yomichan.logError(error);
+ throw error;
+ }
+
+ const popupFactory = new PopupFactory(frameId);
+ await popupFactory.prepare();
+ return popupFactory;
+}
+
async function createIframePopupProxy(frameOffsetForwarder, setDisabled) {
const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
chrome.runtime.onMessage,
@@ -44,20 +57,8 @@ async function createIframePopupProxy(frameOffsetForwarder, setDisabled) {
return popup;
}
-async function getOrCreatePopup(depth) {
- const {frameId} = await api.frameInformationGet();
- if (typeof frameId !== 'number') {
- const error = new Error('Failed to get frameId');
- yomichan.logError(error);
- throw error;
- }
-
- const popupFactory = new PopupFactory(frameId);
- await popupFactory.prepare();
-
- const popup = popupFactory.getOrCreatePopup(null, null, depth);
-
- return popup;
+async function getOrCreatePopup(depth, popupFactory) {
+ return popupFactory.getOrCreatePopup(null, null, depth);
}
async function createPopupProxy(depth, id, parentFrameId) {
@@ -85,6 +86,7 @@ async function createPopupProxy(depth, id, parentFrameId) {
let frontend = null;
let frontendPreparePromise = null;
let frameOffsetForwarder = null;
+ let popupFactoryPromise = null;
let iframePopupsInRootFrameAvailable = true;
@@ -124,8 +126,16 @@ async function createPopupProxy(depth, id, parentFrameId) {
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId);
popups.proxy = popup;
} else {
- popup = popups.normal || await getOrCreatePopup(depth);
- popups.normal = popup;
+ popup = popups.normal;
+ if (!popup) {
+ if (popupFactoryPromise === null) {
+ popupFactoryPromise = createPopupFactory();
+ }
+ const popupFactory = await popupFactoryPromise;
+ const popupNormal = await getOrCreatePopup(depth, popupFactory);
+ popups.normal = popupNormal;
+ popup = popupNormal;
+ }
}
if (frontend === null) {