diff --git a/web/app.js b/web/app.js index b009ad9f874b1..124320a73236d 100644 --- a/web/app.js +++ b/web/app.js @@ -597,7 +597,7 @@ let PDFViewerApplication = { args = { length, }; } if (originalURL !== undefined) { - file = { file: url, originalURL, }; + file = { url, originalURL, }; } PDFViewerApplication.open(file, args); }, diff --git a/web/chromecom.js b/web/chromecom.js index 173ca02ab7cb3..11c52511942a8 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -91,7 +91,7 @@ let ChromeCom = { if (isAllowedAccess) { callback(file); } else { - requestAccessToLocalFile(file, overlayManager); + requestAccessToLocalFile(file, overlayManager, callback); } }); }); @@ -137,7 +137,7 @@ function reloadIfRuntimeIsUnavailable() { } let chromeFileAccessOverlayPromise; -function requestAccessToLocalFile(fileUrl, overlayManager) { +function requestAccessToLocalFile(fileUrl, overlayManager, callback) { let onCloseOverlay = null; if (top !== window) { // When the extension reloads after receiving new permissions, the pages @@ -197,6 +197,29 @@ function requestAccessToLocalFile(fileUrl, overlayManager) { // why this permission request is shown. document.getElementById('chrome-url-of-local-file').textContent = fileUrl; + document.getElementById('chrome-file-fallback').onchange = function() { + let file = this.files[0]; + if (file) { + let originalFilename = decodeURIComponent(fileUrl.split('/').pop()); + let originalURL = fileUrl; + if (originalFilename !== file.name) { + let msg = 'The selected file does not match the original file.' + + '\nOriginal: ' + originalFilename + + '\nSelected: ' + file.name + + '\nDo you want to open the selected file?'; + if (!confirm(msg)) { + this.value = ''; + return; + } + // 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); + } + callback(URL.createObjectURL(file), file.size, originalURL); + overlayManager.close('chromeFileAccessOverlay'); + } + }; + overlayManager.open('chromeFileAccessOverlay'); }); } diff --git a/web/viewer-snippet-chrome-overlays.html b/web/viewer-snippet-chrome-overlays.html index 9e03fe577564f..7f8e03f55220b 100644 --- a/web/viewer-snippet-chrome-overlays.html +++ b/web/viewer-snippet-chrome-overlays.html @@ -22,5 +22,11 @@ to view this PDF file.

+
+

+ or select the file again: + +

+