Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

close tab if the download is the initial navigation #9623

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,19 @@ function updateDownloadState (downloadId, item, state) {

function registerForDownloadListener (session) {
session.on('will-download', function (event, item, webContents) {
const win = BrowserWindow.getFocusedWindow()
if (webContents.isDestroyed()) {
event.preventDefault()
return
}

const hostWebContents = webContents.hostWebContents || webContents
const win = BrowserWindow.fromWebContents(hostWebContents) || BrowserWindow.getFocusedWindow()

// TODO(bridiver) - move this fix to muon
const controller = webContents.controller()
if (controller && controller.isValid() && controller.isInitialNavigation()) {
webContents.forceClose()
}

// special handling for data URLs where another 'will-download' event handler is trying to suggest a filename via item.setSavePath
// see the IPC handler for RENDER_URL_TO_PDF in app/index.js for example
Expand Down