Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update {PDFLinkService, PDFDocumentProperties}.setDocument to make the "url" parameter optional #10114

Merged
merged 2 commits into from
Sep 30, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions test/unit/ui_utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ describe('ui_utils', function() {
expect(getPDFFileNameFromURL('/pdfs/file3.txt', '')).toEqual('');
});

it('gets fallback filename when url is not a string', function() {
expect(getPDFFileNameFromURL(null)).toEqual('document.pdf');

expect(getPDFFileNameFromURL(null, 'file.pdf')).toEqual('file.pdf');
});

it('gets PDF filename from URL containing leading/trailing whitespace',
function() {
// Relative URL
Expand Down
4 changes: 2 additions & 2 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ let PDFViewerApplication = {

this.pdfThumbnailViewer.setDocument(null);
this.pdfViewer.setDocument(null);
this.pdfLinkService.setDocument(null, null);
this.pdfDocumentProperties.setDocument(null, null);
this.pdfLinkService.setDocument(null);
this.pdfDocumentProperties.setDocument(null);
}
this.store = null;
this.isInitialViewSet = false;
Expand Down
4 changes: 2 additions & 2 deletions web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class PDFDocumentProperties {
return Promise.all([
info,
metadata,
contentDispositionFilename || getPDFFileNameFromURL(this.url),
contentDispositionFilename || getPDFFileNameFromURL(this.url || ''),
this._parseFileSize(this.maybeFileSize),
this._parseDate(info.CreationDate),
this._parseDate(info.ModDate),
Expand Down Expand Up @@ -187,7 +187,7 @@ class PDFDocumentProperties {
* @param {Object} pdfDocument - A reference to the PDF document.
* @param {string} url - The URL of the document.
*/
setDocument(pdfDocument, url) {
setDocument(pdfDocument, url = null) {
if (this.pdfDocument) {
this._reset();
this._updateUI(true);
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_link_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PDFLinkService {
this._pagesRefCache = null;
}

setDocument(pdfDocument, baseUrl) {
setDocument(pdfDocument, baseUrl = null) {
this.baseUrl = baseUrl;
this.pdfDocument = pdfDocument;
this._pagesRefCache = Object.create(null);
Expand Down
3 changes: 3 additions & 0 deletions web/ui_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,9 @@ function isDataSchema(url) {
* @returns {string} Guessed PDF filename.
*/
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
if (typeof url !== 'string') {
return defaultFilename;
}
if (isDataSchema(url)) {
console.warn('getPDFFileNameFromURL: ' +
'ignoring "data:" URL for performance reasons.');
Expand Down