Remove and unload the popup frame if an unexpected load occurs (#490)
* Remove and unload the popup frame if an unexpected load occurs * Remove unused fields * Only update _injectPromiseComplete if the promise is the most recent one * Remove redundant this._injectPromise !== null check
This commit is contained in:
parent
8a368aaddc
commit
efa7a5ecc3
@ -31,6 +31,7 @@ class Popup {
|
|||||||
this._child = null;
|
this._child = null;
|
||||||
this._childrenSupported = true;
|
this._childrenSupported = true;
|
||||||
this._injectPromise = null;
|
this._injectPromise = null;
|
||||||
|
this._injectPromiseComplete = false;
|
||||||
this._visible = false;
|
this._visible = false;
|
||||||
this._visibleOverride = null;
|
this._visibleOverride = null;
|
||||||
this._options = null;
|
this._options = null;
|
||||||
@ -47,6 +48,7 @@ class Popup {
|
|||||||
this._container.addEventListener('scroll', (e) => e.stopPropagation());
|
this._container.addEventListener('scroll', (e) => e.stopPropagation());
|
||||||
this._container.style.width = '0px';
|
this._container.style.width = '0px';
|
||||||
this._container.style.height = '0px';
|
this._container.style.height = '0px';
|
||||||
|
this._container.addEventListener('load', this._onFrameLoad.bind(this));
|
||||||
|
|
||||||
this._fullscreenEventListeners = new EventListenerCollection();
|
this._fullscreenEventListeners = new EventListenerCollection();
|
||||||
|
|
||||||
@ -199,10 +201,19 @@ class Popup {
|
|||||||
// Private functions
|
// Private functions
|
||||||
|
|
||||||
_inject() {
|
_inject() {
|
||||||
if (this._injectPromise === null) {
|
let injectPromise = this._injectPromise;
|
||||||
this._injectPromise = this._createInjectPromise();
|
if (injectPromise === null) {
|
||||||
|
injectPromise = this._createInjectPromise();
|
||||||
|
this._injectPromise = injectPromise;
|
||||||
|
injectPromise.then(
|
||||||
|
() => {
|
||||||
|
if (injectPromise !== this._injectPromise) { return; }
|
||||||
|
this._injectPromiseComplete = true;
|
||||||
|
},
|
||||||
|
() => { this._resetFrame(); }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return this._injectPromise;
|
return injectPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _createInjectPromise() {
|
async _createInjectPromise() {
|
||||||
@ -243,6 +254,23 @@ class Popup {
|
|||||||
return popupPreparedPromise;
|
return popupPreparedPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onFrameLoad() {
|
||||||
|
if (!this._injectPromiseComplete) { return; }
|
||||||
|
this._resetFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
_resetFrame() {
|
||||||
|
const parent = this._container.parentNode;
|
||||||
|
if (parent !== null) {
|
||||||
|
parent.removeChild(this._container);
|
||||||
|
}
|
||||||
|
this._container.removeAttribute('src');
|
||||||
|
this._container.removeAttribute('srcdoc');
|
||||||
|
|
||||||
|
this._injectPromise = null;
|
||||||
|
this._injectPromiseComplete = false;
|
||||||
|
}
|
||||||
|
|
||||||
async _injectStyles() {
|
async _injectStyles() {
|
||||||
try {
|
try {
|
||||||
await Popup._injectStylesheet('yomichan-popup-outer-stylesheet', 'file', '/fg/css/client.css', true);
|
await Popup._injectStylesheet('yomichan-popup-outer-stylesheet', 'file', '/fg/css/client.css', true);
|
||||||
|
Loading…
Reference in New Issue
Block a user