From 84920f39b2a213383224484b17620972ec58fa90 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 17 Jun 2018 13:25:22 +0200 Subject: [PATCH 1/2] Change the casing of the `originalURL` parameter, to `originalUrl`, in the `onOpenWithURL` method The `onOpenWithURL` method, in `PDFViewerApplication.initPassiveLoading`, accepts a `originalURL` parameter which is then passed on to `PDFViewerApplication.open` as is. However, the latter method expects the name of the parameter to be `originalUrl` (note the casing), meaning that `getDocument` will fail in this case. For consistency, and to avoid confusion, the renaming is done in `web/chromecom.js` as well. --- web/app.js | 6 +++--- web/chromecom.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/web/app.js b/web/app.js index 97a0d9c9f..f183880db 100644 --- a/web/app.js +++ b/web/app.js @@ -593,13 +593,13 @@ let PDFViewerApplication = { onOpenWithData(data) { PDFViewerApplication.open(data); }, - onOpenWithURL(url, length, originalURL) { + onOpenWithURL(url, length, originalUrl) { let file = url, args = null; if (length !== undefined) { args = { length, }; } - if (originalURL !== undefined) { - file = { url, originalURL, }; + if (originalUrl !== undefined) { + file = { url, originalUrl, }; } PDFViewerApplication.open(file, args); }, diff --git a/web/chromecom.js b/web/chromecom.js index 11c525119..55dec5be8 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -201,7 +201,7 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) { let file = this.files[0]; if (file) { let originalFilename = decodeURIComponent(fileUrl.split('/').pop()); - let originalURL = fileUrl; + let originalUrl = fileUrl; if (originalFilename !== file.name) { let msg = 'The selected file does not match the original file.' + '\nOriginal: ' + originalFilename + @@ -213,9 +213,9 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) { } // There is no way to retrieve the original URL from the File object. // So just generate a fake path. - originalURL = 'file:///fakepath/to/' + encodeURIComponent(file.name); + originalUrl = 'file:///fakepath/to/' + encodeURIComponent(file.name); } - callback(URL.createObjectURL(file), file.size, originalURL); + callback(URL.createObjectURL(file), file.size, originalUrl); overlayManager.close('chromeFileAccessOverlay'); } }; @@ -384,8 +384,8 @@ ChromeExternalServices.initPassiveLoading = function(callbacks) { let { overlayManager, } = PDFViewerApplication; // defaultUrl is set in viewer.js ChromeCom.resolvePDFFile(AppOptions.get('defaultUrl'), overlayManager, - function(url, length, originalURL) { - callbacks.onOpenWithURL(url, length, originalURL); + function(url, length, originalUrl) { + callbacks.onOpenWithURL(url, length, originalUrl); }); }; ChromeExternalServices.createDownloadManager = function(options) { From 3e4a159a45196a244d05aaa2c8505c278a3b8bb4 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 17 Jun 2018 13:44:35 +0200 Subject: [PATCH 2/2] Set the correct document title when opening a new file in the `GENERIC` default viewer --- web/app.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/app.js b/web/app.js index f183880db..9242cf995 100644 --- a/web/app.js +++ b/web/app.js @@ -615,7 +615,7 @@ let PDFViewerApplication = { }); }, - setTitleUsingUrl(url) { + setTitleUsingUrl(url = '') { this.url = url; this.baseUrl = url.split('#')[0]; let title = getPDFFileNameFromURL(url, ''); @@ -1928,8 +1928,13 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { let file = evt.fileInput.files[0]; if (URL.createObjectURL && !AppOptions.get('disableCreateObjectURL')) { - PDFViewerApplication.open(URL.createObjectURL(file)); + let url = URL.createObjectURL(file); + if (file.name) { + url = { url, originalUrl: file.name, }; + } + PDFViewerApplication.open(url); } else { + PDFViewerApplication.setTitleUsingUrl(file.name); // Read the local file into a Uint8Array. let fileReader = new FileReader(); fileReader.onload = function webViewerChangeFileReaderOnload(evt) { @@ -1939,8 +1944,6 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { fileReader.readAsArrayBuffer(file); } - PDFViewerApplication.setTitleUsingUrl(file.name); - // URL does not reflect proper document location - hiding some icons. let appConfig = PDFViewerApplication.appConfig; appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');