Merge pull request #9821 from Snuffleupagus/onOpenWithURL-originalUrl
Set the correct document title when opening a new file in the `GENERIC` default viewer
This commit is contained in:
commit
3b07147d98
17
web/app.js
17
web/app.js
@ -593,13 +593,13 @@ let PDFViewerApplication = {
|
|||||||
onOpenWithData(data) {
|
onOpenWithData(data) {
|
||||||
PDFViewerApplication.open(data);
|
PDFViewerApplication.open(data);
|
||||||
},
|
},
|
||||||
onOpenWithURL(url, length, originalURL) {
|
onOpenWithURL(url, length, originalUrl) {
|
||||||
let file = url, args = null;
|
let file = url, args = null;
|
||||||
if (length !== undefined) {
|
if (length !== undefined) {
|
||||||
args = { length, };
|
args = { length, };
|
||||||
}
|
}
|
||||||
if (originalURL !== undefined) {
|
if (originalUrl !== undefined) {
|
||||||
file = { url, originalURL, };
|
file = { url, originalUrl, };
|
||||||
}
|
}
|
||||||
PDFViewerApplication.open(file, args);
|
PDFViewerApplication.open(file, args);
|
||||||
},
|
},
|
||||||
@ -615,7 +615,7 @@ let PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
setTitleUsingUrl(url) {
|
setTitleUsingUrl(url = '') {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.baseUrl = url.split('#')[0];
|
this.baseUrl = url.split('#')[0];
|
||||||
let title = getPDFFileNameFromURL(url, '');
|
let title = getPDFFileNameFromURL(url, '');
|
||||||
@ -1928,8 +1928,13 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||||||
let file = evt.fileInput.files[0];
|
let file = evt.fileInput.files[0];
|
||||||
|
|
||||||
if (URL.createObjectURL && !AppOptions.get('disableCreateObjectURL')) {
|
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 {
|
} else {
|
||||||
|
PDFViewerApplication.setTitleUsingUrl(file.name);
|
||||||
// Read the local file into a Uint8Array.
|
// Read the local file into a Uint8Array.
|
||||||
let fileReader = new FileReader();
|
let fileReader = new FileReader();
|
||||||
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
fileReader.onload = function webViewerChangeFileReaderOnload(evt) {
|
||||||
@ -1939,8 +1944,6 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||||||
fileReader.readAsArrayBuffer(file);
|
fileReader.readAsArrayBuffer(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFViewerApplication.setTitleUsingUrl(file.name);
|
|
||||||
|
|
||||||
// URL does not reflect proper document location - hiding some icons.
|
// URL does not reflect proper document location - hiding some icons.
|
||||||
let appConfig = PDFViewerApplication.appConfig;
|
let appConfig = PDFViewerApplication.appConfig;
|
||||||
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
|
appConfig.toolbar.viewBookmark.setAttribute('hidden', 'true');
|
||||||
|
@ -201,7 +201,7 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
|
|||||||
let file = this.files[0];
|
let file = this.files[0];
|
||||||
if (file) {
|
if (file) {
|
||||||
let originalFilename = decodeURIComponent(fileUrl.split('/').pop());
|
let originalFilename = decodeURIComponent(fileUrl.split('/').pop());
|
||||||
let originalURL = fileUrl;
|
let originalUrl = fileUrl;
|
||||||
if (originalFilename !== file.name) {
|
if (originalFilename !== file.name) {
|
||||||
let msg = 'The selected file does not match the original file.' +
|
let msg = 'The selected file does not match the original file.' +
|
||||||
'\nOriginal: ' + originalFilename +
|
'\nOriginal: ' + originalFilename +
|
||||||
@ -213,9 +213,9 @@ function requestAccessToLocalFile(fileUrl, overlayManager, callback) {
|
|||||||
}
|
}
|
||||||
// There is no way to retrieve the original URL from the File object.
|
// There is no way to retrieve the original URL from the File object.
|
||||||
// So just generate a fake path.
|
// 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');
|
overlayManager.close('chromeFileAccessOverlay');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -384,8 +384,8 @@ ChromeExternalServices.initPassiveLoading = function(callbacks) {
|
|||||||
let { overlayManager, } = PDFViewerApplication;
|
let { overlayManager, } = PDFViewerApplication;
|
||||||
// defaultUrl is set in viewer.js
|
// defaultUrl is set in viewer.js
|
||||||
ChromeCom.resolvePDFFile(AppOptions.get('defaultUrl'), overlayManager,
|
ChromeCom.resolvePDFFile(AppOptions.get('defaultUrl'), overlayManager,
|
||||||
function(url, length, originalURL) {
|
function(url, length, originalUrl) {
|
||||||
callbacks.onOpenWithURL(url, length, originalURL);
|
callbacks.onOpenWithURL(url, length, originalUrl);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
ChromeExternalServices.createDownloadManager = function(options) {
|
ChromeExternalServices.createDownloadManager = function(options) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user