browser(firefox): make sure response is sent when context is closed (#3553)

This commit is contained in:
Yury Semikhatsky 2020-08-20 13:26:04 -07:00 committed by GitHub
parent db2e66aa76
commit 5ba0254c99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -1,2 +1,2 @@
1164
Changed: yurys@chromium.org Thu Aug 20 10:30:04 PDT 2020
1165
Changed: yurys@chromium.org Thu Aug 20 13:05:37 PDT 2020

View file

@ -134,7 +134,8 @@ class TargetRegistry {
if (!target)
return;
target.emit('crashed');
this._destroyTarget(target).catch(e => dump(`Failed to destroy target: ${e}`));
if (target)
target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));
}
}, 'oop-frameloader-crashed');
@ -202,7 +203,8 @@ class TargetRegistry {
const tab = event.target;
const linkedBrowser = tab.linkedBrowser;
const target = this._browserToTarget.get(linkedBrowser);
this._destroyTarget(target).catch(e => dump(`Failed to destroy target: ${e}`));
if (target)
target.dispose().catch(e => dump(`Failed to destroy target: ${e}`));
};
Services.wm.addListener({
@ -240,16 +242,6 @@ class TargetRegistry {
extHelperAppSvc.setDownloadInterceptor(new DownloadInterceptor(this));
}
async _destroyTarget(target) {
if (!target)
return;
const event = { pendingActivity: [], target };
this.emit(TargetRegistry.Events.TargetWillBeDestroyed, event);
await Promise.all(event.pendingActivity);
target.dispose();
this.emit(TargetRegistry.Events.TargetDestroyed, target);
}
setBrowserProxy(proxy) {
this._browserProxy = proxy;
}
@ -468,12 +460,18 @@ class PageTarget {
return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
}
dispose() {
async dispose() {
this._disposed = true;
this._browserContext.pages.delete(this);
this._registry._browserToTarget.delete(this._linkedBrowser);
this._registry._browserBrowsingContextToTarget.delete(this._linkedBrowser.browsingContext);
helper.removeListeners(this._eventListeners);
const event = { pendingActivity: [], target: this };
this._registry.emit(TargetRegistry.Events.TargetWillBeDestroyed, event);
await Promise.all(event.pendingActivity);
this._browserContext.pages.delete(this);
this._registry.emit(TargetRegistry.Events.TargetDestroyed, this);
}
}