Merge pull request #10114 from Snuffleupagus/setDocument-optional-url
Update `{PDFLinkService, PDFDocumentProperties}.setDocument` to make the "url" parameter optional
This commit is contained in:
commit
8d4c79c99c
@ -80,6 +80,12 @@ describe('ui_utils', function() {
|
|||||||
expect(getPDFFileNameFromURL('/pdfs/file3.txt', '')).toEqual('');
|
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',
|
it('gets PDF filename from URL containing leading/trailing whitespace',
|
||||||
function() {
|
function() {
|
||||||
// Relative URL
|
// Relative URL
|
||||||
|
@ -595,8 +595,8 @@ let PDFViewerApplication = {
|
|||||||
|
|
||||||
this.pdfThumbnailViewer.setDocument(null);
|
this.pdfThumbnailViewer.setDocument(null);
|
||||||
this.pdfViewer.setDocument(null);
|
this.pdfViewer.setDocument(null);
|
||||||
this.pdfLinkService.setDocument(null, null);
|
this.pdfLinkService.setDocument(null);
|
||||||
this.pdfDocumentProperties.setDocument(null, null);
|
this.pdfDocumentProperties.setDocument(null);
|
||||||
}
|
}
|
||||||
this.store = null;
|
this.store = null;
|
||||||
this.isInitialViewSet = false;
|
this.isInitialViewSet = false;
|
||||||
|
@ -120,7 +120,7 @@ class PDFDocumentProperties {
|
|||||||
return Promise.all([
|
return Promise.all([
|
||||||
info,
|
info,
|
||||||
metadata,
|
metadata,
|
||||||
contentDispositionFilename || getPDFFileNameFromURL(this.url),
|
contentDispositionFilename || getPDFFileNameFromURL(this.url || ''),
|
||||||
this._parseFileSize(this.maybeFileSize),
|
this._parseFileSize(this.maybeFileSize),
|
||||||
this._parseDate(info.CreationDate),
|
this._parseDate(info.CreationDate),
|
||||||
this._parseDate(info.ModDate),
|
this._parseDate(info.ModDate),
|
||||||
@ -187,7 +187,7 @@ class PDFDocumentProperties {
|
|||||||
* @param {Object} pdfDocument - A reference to the PDF document.
|
* @param {Object} pdfDocument - A reference to the PDF document.
|
||||||
* @param {string} url - The URL of the document.
|
* @param {string} url - The URL of the document.
|
||||||
*/
|
*/
|
||||||
setDocument(pdfDocument, url) {
|
setDocument(pdfDocument, url = null) {
|
||||||
if (this.pdfDocument) {
|
if (this.pdfDocument) {
|
||||||
this._reset();
|
this._reset();
|
||||||
this._updateUI(true);
|
this._updateUI(true);
|
||||||
|
@ -49,7 +49,7 @@ class PDFLinkService {
|
|||||||
this._pagesRefCache = null;
|
this._pagesRefCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
setDocument(pdfDocument, baseUrl) {
|
setDocument(pdfDocument, baseUrl = null) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
this._pagesRefCache = Object.create(null);
|
this._pagesRefCache = Object.create(null);
|
||||||
|
@ -548,6 +548,9 @@ function isDataSchema(url) {
|
|||||||
* @returns {string} Guessed PDF filename.
|
* @returns {string} Guessed PDF filename.
|
||||||
*/
|
*/
|
||||||
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
|
function getPDFFileNameFromURL(url, defaultFilename = 'document.pdf') {
|
||||||
|
if (typeof url !== 'string') {
|
||||||
|
return defaultFilename;
|
||||||
|
}
|
||||||
if (isDataSchema(url)) {
|
if (isDataSchema(url)) {
|
||||||
console.warn('getPDFFileNameFromURL: ' +
|
console.warn('getPDFFileNameFromURL: ' +
|
||||||
'ignoring "data:" URL for performance reasons.');
|
'ignoring "data:" URL for performance reasons.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user