diff --git a/atom/browser/api/atom_api_download_item.cc b/atom/browser/api/atom_api_download_item.cc index d11e5a3add72..240444d1ee3d 100644 --- a/atom/browser/api/atom_api_download_item.cc +++ b/atom/browser/api/atom_api_download_item.cc @@ -135,7 +135,7 @@ std::string DownloadItem::GetFilename() const { std::string(), download_item_->GetSuggestedFilename(), GetMimeType(), - std::string()).LossyDisplayName()); + "download").LossyDisplayName()); } std::string DownloadItem::GetContentDisposition() const { diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a48e8dd60119..d9b47d055528 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -134,6 +134,7 @@ struct Converter { case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break; case NEW_BACKGROUND_TAB: disposition = "background-tab"; break; case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break; + case SAVE_TO_DISK: disposition = "save-to-disk"; break; default: break; } return mate::ConvertToV8(isolate, disposition); diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index 7f5605052a02..0213216697a1 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -60,7 +60,7 @@ void AtomDownloadManagerDelegate::CreateDownloadPath( std::string(), suggested_filename, mime_type, - std::string()); + "download"); if (!base::PathExists(default_download_path)) base::CreateDirectory(default_download_path); diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 47aa43bcddfe..55cbfc63c33f 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -144,7 +144,7 @@ Returns: * `url` String * `frameName` String * `disposition` String - Can be `default`, `foreground-tab`, `background-tab`, - `new-window` and `other`. + `new-window`, `save-to-disk` and `other`. * `options` Object - The options which will be used for creating the new `BrowserWindow`. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index bda4858e85f7..61f0ebd655ab 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -670,7 +670,7 @@ Returns: * `url` String * `frameName` String * `disposition` String - Can be `default`, `foreground-tab`, `background-tab`, - `new-window` and `other`. + `new-window`, `save-to-disk` and `other`. * `options` Object - The options which should be used for creating the new `BrowserWindow`. diff --git a/spec/api-session-spec.js b/spec/api-session-spec.js index 2eb696ea7e8c..00bc3cfd3f01 100644 --- a/spec/api-session-spec.js +++ b/spec/api-session-spec.js @@ -252,6 +252,9 @@ describe('session module', function () { var contentDisposition = 'inline; filename="mock.pdf"' var downloadFilePath = path.join(fixtures, 'mock.pdf') var downloadServer = http.createServer(function (req, res) { + if (req.url === '/?testFilename') { + contentDisposition = 'inline' + } res.writeHead(200, { 'Content-Length': mockPDF.length, 'Content-Type': 'application/pdf', @@ -320,6 +323,23 @@ describe('session module', function () { }) }) + it('can generate a default filename', function (done) { + downloadServer.listen(0, '127.0.0.1', function () { + var port = downloadServer.address().port + ipcRenderer.sendSync('set-download-option', true, false) + w.loadURL(url + ':' + port + '/?testFilename') + ipcRenderer.once('download-done', function (event, state, url, mimeType, receivedBytes, totalBytes, disposition, filename) { + assert.equal(state, 'cancelled') + assert.equal(filename, 'download.pdf') + assert.equal(mimeType, 'application/pdf') + assert.equal(receivedBytes, 0) + assert.equal(totalBytes, mockPDF.length) + assert.equal(disposition, contentDisposition) + done() + }) + }) + }) + describe('when a save path is specified and the URL is unavailable', function () { it('does not display a save dialog and reports the done state as interrupted', function (done) { ipcRenderer.sendSync('set-download-option', false, false)