1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

Fixes password for range request loading

This commit is contained in:
Yury Delendik 2013-05-09 17:35:23 -05:00
parent 220c827e9e
commit 61a7738a5d
6 changed files with 73 additions and 29 deletions

View file

@ -1048,30 +1048,27 @@ var PDFView = {
this.pdfDocument = null;
var self = this;
self.loading = true;
PDFJS.getDocument(parameters, pdfDataRangeTransport).then(
var passwordNeeded = function passwordNeeded(updatePassword, reason) {
var promptString = mozL10n.get('request_password', null,
'PDF is protected by a password:');
if (reason === PDFJS.PasswordResponses.INCORRECT_PASSWORD) {
promptString += '\n' + mozL10n.get('invalid_password', null,
'Invalid Password.');
}
password = prompt(promptString);
if (password && password.length > 0) {
return updatePassword(password);
}
};
PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded).then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
self.loading = false;
},
function getDocumentError(message, exception) {
if (exception && exception.name === 'PasswordException') {
if (exception.code === 'needpassword' ||
exception.code === 'incorrectpassword') {
var promptString = mozL10n.get('request_password', null,
'PDF is protected by a password:');
if (exception.code === 'incorrectpassword') {
promptString += '\n' + mozL10n.get('invalid_password', null,
'Invalid Password.');
}
password = prompt(promptString);
if (password && password.length > 0) {
return PDFView.open(url, scale, password);
}
}
}
var loadingErrorMessage = mozL10n.get('loading_error', null,
'An error occurred while loading the PDF.');