Merge pull request #9595 from Rob--W/crx-ftp-file

Disable ftp support in Chrome 59+, add file chooser at file
This commit is contained in:
Brendan Dahl 2018-06-15 14:48:19 -07:00 committed by GitHub
commit 7892122201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 7 deletions

View File

@ -153,10 +153,16 @@ chrome.webRequest.onBeforeRequest.addListener(
urls: [ urls: [
'file://*/*.pdf', 'file://*/*.pdf',
'file://*/*.PDF', 'file://*/*.PDF',
// Note: Chrome 59 has disabled ftp resource loading by default: ...(
// https://www.chromestatus.com/feature/5709390967472128 // Duck-typing: MediaError.prototype.message was added in Chrome 59.
'ftp://*/*.pdf', MediaError.prototype.hasOwnProperty('message') ? [] :
'ftp://*/*.PDF', [
// Note: Chrome 59 has disabled ftp resource loading by default:
// https://www.chromestatus.com/feature/5709390967472128
'ftp://*/*.pdf',
'ftp://*/*.PDF',
]
),
], ],
types: ['main_frame', 'sub_frame'], types: ['main_frame', 'sub_frame'],
}, },

View File

@ -599,7 +599,7 @@ let PDFViewerApplication = {
args = { length, }; args = { length, };
} }
if (originalURL !== undefined) { if (originalURL !== undefined) {
file = { file: url, originalURL, }; file = { url, originalURL, };
} }
PDFViewerApplication.open(file, args); PDFViewerApplication.open(file, args);
}, },

View File

@ -91,7 +91,7 @@ let ChromeCom = {
if (isAllowedAccess) { if (isAllowedAccess) {
callback(file); callback(file);
} else { } else {
requestAccessToLocalFile(file, overlayManager); requestAccessToLocalFile(file, overlayManager, callback);
} }
}); });
}); });
@ -137,7 +137,7 @@ function reloadIfRuntimeIsUnavailable() {
} }
let chromeFileAccessOverlayPromise; let chromeFileAccessOverlayPromise;
function requestAccessToLocalFile(fileUrl, overlayManager) { function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
let onCloseOverlay = null; let onCloseOverlay = null;
if (top !== window) { if (top !== window) {
// When the extension reloads after receiving new permissions, the pages // When the extension reloads after receiving new permissions, the pages
@ -197,6 +197,29 @@ function requestAccessToLocalFile(fileUrl, overlayManager) {
// why this permission request is shown. // why this permission request is shown.
document.getElementById('chrome-url-of-local-file').textContent = fileUrl; 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'); overlayManager.open('chromeFileAccessOverlay');
}); });
} }

View File

@ -22,5 +22,11 @@
to view <span id="chrome-url-of-local-file">this PDF file.</span> to view <span id="chrome-url-of-local-file">this PDF file.</span>
</p> </p>
</div> </div>
<div class="row">
<p>
or select the file again:
<input type="file" id="chrome-file-fallback" accept=".pdf">
</p>
</div>
</div> </div>
</div> </div>