Skip to content

Commit

Permalink
Find target for new window downloads based on the channel
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Apr 28, 2020
1 parent a731ae9 commit 0e1ee1a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@ class DownloadInterceptor {
constructor(registry) {
this._registry = registry
this._handlerToUuid = new Map();
helper.addObserver(this._onRequest.bind(this), 'http-on-modify-request');
}

_onRequest(httpChannel, topic) {
let loadContext = helper.getLoadContext(httpChannel);
if (!loadContext)
return;
if (!loadContext.topFrameElement)
return;
const target = this._registry.targetForBrowser(loadContext.topFrameElement);
if (!target)
return;
target._channelIds.add(httpChannel.channelId);
}

//
// nsIDownloadInterceptor implementation.
//
interceptDownloadRequest(externalAppHandler, request, browsingContext, outFile) {
const pageTarget = this._registry._browserBrowsingContextToTarget.get(browsingContext);
let pageTarget = this._registry._browserBrowsingContextToTarget.get(browsingContext);
// New page downloads won't have browsing contex.
if (!pageTarget)
pageTarget = this._registry._targetForChannel(request);
if (!pageTarget)
return false;

Expand Down Expand Up @@ -284,6 +300,15 @@ class TargetRegistry {
targetForBrowser(browser) {
return this._browserToTarget.get(browser);
}

_targetForChannel(channel) {
const channelId = channel.channelId;
for (const target of this._browserToTarget.values()) {
if (target._channelIds.has(channelId))
return target;
}
return null;
}
}

class PageTarget {
Expand All @@ -299,6 +324,7 @@ class PageTarget {
this._url = '';
this._openerId = opener ? opener.id() : undefined;
this._channel = SimpleChannel.createForMessageManager(`browser::page[${this._targetId}]`, this._linkedBrowser.messageManager);
this._channelIds = new Set();

const navigationListener = {
QueryInterface: ChromeUtils.generateQI([ Ci.nsIWebProgressListener]),
Expand Down
2 changes: 1 addition & 1 deletion juggler/content/FrameTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class FrameTree {
// Always report download navigation as failure to match other browsers.
const errorText = isDownload ? 'Will download to file' : helper.getNetworkErrorStatusText(status);
this.emit(FrameTree.Events.NavigationAborted, frame, navigationId, errorText);
if (frame === this._mainFrame && status !== Cr.NS_BINDING_ABORTED)
if (frame === this._mainFrame && status !== Cr.NS_BINDING_ABORTED && !isDownload)
this.forcePageReady();
}
}
Expand Down

0 comments on commit 0e1ee1a

Please sign in to comment.