mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Improve suggested filename on download
For all of the following URLs, "file.pdf" will be suggested: http://.../file.pdf http://.../download.aspx?file=file.pdf&whatever http://.../get.pdf?name=file.pdf&whatever http://.../single-page-app#view=file.pdf http://.../download.aspx?file=%2Fpath%2Fto%2Ffile.pdf&whatever Fixes #3161
This commit is contained in:
parent
69a64d45bc
commit
84ae29c21d
2 changed files with 41 additions and 5 deletions
|
@ -206,6 +206,10 @@ ChromeActions.prototype = {
|
|||
// The data may not be downloaded so we need just retry getting the pdf with
|
||||
// the original url.
|
||||
var originalUri = NetUtil.newURI(data.originalUrl);
|
||||
var filename = data.filename;
|
||||
if (typeof filename !== 'string' || !/\.pdf$/i.test(filename)) {
|
||||
filename = 'document.pdf';
|
||||
}
|
||||
var blobUri = data.blobUrl ? NetUtil.newURI(data.blobUrl) : originalUri;
|
||||
var extHelperAppSvc =
|
||||
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
|
||||
|
@ -234,7 +238,9 @@ ChromeActions.prototype = {
|
|||
// contentDisposition/contentDispositionFilename is readonly before FF18
|
||||
channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT;
|
||||
if (self.contentDispositionFilename) {
|
||||
channel.contentDispositionFilename = self.contentDispositionFilename;
|
||||
channel.contentDispositionFilename = self.contentDispositionFilename;
|
||||
} else {
|
||||
channel.contentDispositionFilename = filename;
|
||||
}
|
||||
} catch (e) {}
|
||||
channel.setURI(originalUri);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue