Skip to content

Commit

Permalink
browser(firefox): make sure response is sent when context is closed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored Aug 20, 2020
1 parent db2e66a commit 5ba0254
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1164
Changed: [email protected] Thu Aug 20 10:30:04 PDT 2020
1165
Changed: [email protected] Thu Aug 20 13:05:37 PDT 2020
26 changes: 12 additions & 14 deletions browser_patches/firefox/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 5ba0254

Please sign in to comment.