Merge pull request #7169 from deepak1556/download_defaultname_patch
browser: provide a default filename when unable to generate from download data
This commit is contained in:
commit
9dad9478fa
6 changed files with 25 additions and 4 deletions
|
@ -135,7 +135,7 @@ std::string DownloadItem::GetFilename() const {
|
||||||
std::string(),
|
std::string(),
|
||||||
download_item_->GetSuggestedFilename(),
|
download_item_->GetSuggestedFilename(),
|
||||||
GetMimeType(),
|
GetMimeType(),
|
||||||
std::string()).LossyDisplayName());
|
"download").LossyDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DownloadItem::GetContentDisposition() const {
|
std::string DownloadItem::GetContentDisposition() const {
|
||||||
|
|
|
@ -134,6 +134,7 @@ struct Converter<WindowOpenDisposition> {
|
||||||
case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break;
|
case NEW_FOREGROUND_TAB: disposition = "foreground-tab"; break;
|
||||||
case NEW_BACKGROUND_TAB: disposition = "background-tab"; break;
|
case NEW_BACKGROUND_TAB: disposition = "background-tab"; break;
|
||||||
case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break;
|
case NEW_POPUP: case NEW_WINDOW: disposition = "new-window"; break;
|
||||||
|
case SAVE_TO_DISK: disposition = "save-to-disk"; break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return mate::ConvertToV8(isolate, disposition);
|
return mate::ConvertToV8(isolate, disposition);
|
||||||
|
|
|
@ -60,7 +60,7 @@ void AtomDownloadManagerDelegate::CreateDownloadPath(
|
||||||
std::string(),
|
std::string(),
|
||||||
suggested_filename,
|
suggested_filename,
|
||||||
mime_type,
|
mime_type,
|
||||||
std::string());
|
"download");
|
||||||
|
|
||||||
if (!base::PathExists(default_download_path))
|
if (!base::PathExists(default_download_path))
|
||||||
base::CreateDirectory(default_download_path);
|
base::CreateDirectory(default_download_path);
|
||||||
|
|
|
@ -144,7 +144,7 @@ Returns:
|
||||||
* `url` String
|
* `url` String
|
||||||
* `frameName` String
|
* `frameName` String
|
||||||
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
* `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
|
* `options` Object - The options which will be used for creating the new
|
||||||
`BrowserWindow`.
|
`BrowserWindow`.
|
||||||
|
|
||||||
|
|
|
@ -670,7 +670,7 @@ Returns:
|
||||||
* `url` String
|
* `url` String
|
||||||
* `frameName` String
|
* `frameName` String
|
||||||
* `disposition` String - Can be `default`, `foreground-tab`, `background-tab`,
|
* `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
|
* `options` Object - The options which should be used for creating the new
|
||||||
`BrowserWindow`.
|
`BrowserWindow`.
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,9 @@ describe('session module', function () {
|
||||||
var contentDisposition = 'inline; filename="mock.pdf"'
|
var contentDisposition = 'inline; filename="mock.pdf"'
|
||||||
var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
var downloadFilePath = path.join(fixtures, 'mock.pdf')
|
||||||
var downloadServer = http.createServer(function (req, res) {
|
var downloadServer = http.createServer(function (req, res) {
|
||||||
|
if (req.url === '/?testFilename') {
|
||||||
|
contentDisposition = 'inline'
|
||||||
|
}
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Length': mockPDF.length,
|
'Content-Length': mockPDF.length,
|
||||||
'Content-Type': 'application/pdf',
|
'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 () {
|
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) {
|
it('does not display a save dialog and reports the done state as interrupted', function (done) {
|
||||||
ipcRenderer.sendSync('set-download-option', false, false)
|
ipcRenderer.sendSync('set-download-option', false, false)
|
||||||
|
|
Loading…
Reference in a new issue