Merge pull request #2298 from zalun/show_alert_on_invalid_pdf_structure
Display an error on Invalid PDF
This commit is contained in:
commit
ee87a44c03
@ -96,6 +96,7 @@ page_scale_actual=Actual Size
|
|||||||
# Loading indicator messages
|
# Loading indicator messages
|
||||||
loading_error_indicator=Error
|
loading_error_indicator=Error
|
||||||
loading_error=An error occurred while loading the PDF.
|
loading_error=An error occurred while loading the PDF.
|
||||||
|
invalid_file_error=Invalid or corrupted PDF file.
|
||||||
|
|
||||||
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
|
# LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip.
|
||||||
# "{{type}}" will be replaced with an annotation type from a list defined in
|
# "{{type}}" will be replaced with an annotation type from a list defined in
|
||||||
|
@ -23,6 +23,7 @@ outline.title=Wyświetl konspekt dokumentu
|
|||||||
loading=Wczytywanie... {{percent}}%
|
loading=Wczytywanie... {{percent}}%
|
||||||
loading_error_indicator=Błąd
|
loading_error_indicator=Błąd
|
||||||
loading_error=Wystąpił błąd podczas wczytywania pliku PDF.
|
loading_error=Wystąpił błąd podczas wczytywania pliku PDF.
|
||||||
|
invalid_file_error=Błędny lub zepsuty plik PDF.
|
||||||
rendering_error=Wystąpił błąd podczas wyświetlania strony.
|
rendering_error=Wystąpił błąd podczas wyświetlania strony.
|
||||||
page_label=Strona:
|
page_label=Strona:
|
||||||
page_of=z {{pageCount}}
|
page_of=z {{pageCount}}
|
||||||
|
@ -539,6 +539,14 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
|
||||||
|
this.workerReadyPromise.reject(data.exception.name, data.exception);
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
messageHandler.on('UnknownError', function transportUnknownError(data) {
|
||||||
|
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
||||||
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('GetPage', function transportPage(data) {
|
messageHandler.on('GetPage', function transportPage(data) {
|
||||||
var pageInfo = data.pageInfo;
|
var pageInfo = data.pageInfo;
|
||||||
var page = new PDFPageProxy(pageInfo, this);
|
var page = new PDFPageProxy(pageInfo, this);
|
||||||
|
@ -574,7 +574,8 @@ var XRef = (function XRefClosure() {
|
|||||||
if (dict)
|
if (dict)
|
||||||
return dict;
|
return dict;
|
||||||
// nothing helps
|
// nothing helps
|
||||||
error('Invalid PDF structure');
|
// calling error() would reject worker with an UnknownErrorException.
|
||||||
|
throw new InvalidPDFException('Invalid PDF structure');
|
||||||
},
|
},
|
||||||
readXRef: function XRef_readXRef(startXRef, recoveryMode) {
|
readXRef: function XRef_readXRef(startXRef, recoveryMode) {
|
||||||
var stream = this.stream;
|
var stream = this.stream;
|
||||||
|
25
src/util.js
25
src/util.js
@ -148,6 +148,31 @@ var PasswordException = (function PasswordExceptionClosure() {
|
|||||||
return PasswordException;
|
return PasswordException;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
var UnknownErrorException = (function UnknownErrorExceptionClosure() {
|
||||||
|
function UnknownErrorException(msg, details) {
|
||||||
|
this.name = 'UnknownErrorException';
|
||||||
|
this.message = msg;
|
||||||
|
this.details = details;
|
||||||
|
}
|
||||||
|
|
||||||
|
UnknownErrorException.prototype = new Error();
|
||||||
|
UnknownErrorException.constructor = UnknownErrorException;
|
||||||
|
|
||||||
|
return UnknownErrorException;
|
||||||
|
})();
|
||||||
|
|
||||||
|
var InvalidPDFException = (function InvalidPDFExceptionClosure() {
|
||||||
|
function InvalidPDFException(msg) {
|
||||||
|
this.name = 'InvalidPDFException';
|
||||||
|
this.message = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
InvalidPDFException.prototype = new Error();
|
||||||
|
InvalidPDFException.constructor = InvalidPDFException;
|
||||||
|
|
||||||
|
return InvalidPDFException;
|
||||||
|
})();
|
||||||
|
|
||||||
function bytesToString(bytes) {
|
function bytesToString(bytes) {
|
||||||
var str = '';
|
var str = '';
|
||||||
var length = bytes.length;
|
var length = bytes.length;
|
||||||
|
@ -124,9 +124,19 @@ var WorkerMessageHandler = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else if (e instanceof InvalidPDFException) {
|
||||||
|
handler.send('InvalidPDF', {
|
||||||
|
exception: e
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
handler.send('UnknownError', {
|
||||||
|
exception: new UnknownErrorException(e.message, e.toString())
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var doc = {
|
var doc = {
|
||||||
@ -331,4 +341,3 @@ if (typeof window === 'undefined') {
|
|||||||
var handler = new MessageHandler('worker_processor', this);
|
var handler = new MessageHandler('worker_processor', this);
|
||||||
WorkerMessageHandler.setup(handler);
|
WorkerMessageHandler.setup(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -949,14 +949,26 @@ var PDFView = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var loadingErrorMessage = mozL10n.get('loading_error', null,
|
||||||
|
'An error occurred while loading the PDF.');
|
||||||
|
|
||||||
|
if (exception && exception.name === 'InvalidPDFException') {
|
||||||
|
// change error message also for other builds
|
||||||
|
var loadingErrorMessage = mozL10n.get('invalid_file_error', null,
|
||||||
|
'Invalid or corrupted PDF file.');
|
||||||
|
//#if B2G
|
||||||
|
// window.alert(loadingErrorMessage);
|
||||||
|
// return window.close();
|
||||||
|
//#endif
|
||||||
|
}
|
||||||
|
|
||||||
var loadingIndicator = document.getElementById('loading');
|
var loadingIndicator = document.getElementById('loading');
|
||||||
loadingIndicator.textContent = mozL10n.get('loading_error_indicator',
|
loadingIndicator.textContent = mozL10n.get('loading_error_indicator',
|
||||||
null, 'Error');
|
null, 'Error');
|
||||||
var moreInfo = {
|
var moreInfo = {
|
||||||
message: message
|
message: message
|
||||||
};
|
};
|
||||||
self.error(mozL10n.get('loading_error', null,
|
self.error(loadingErrorMessage, moreInfo);
|
||||||
'An error occurred while loading the PDF.'), moreInfo);
|
|
||||||
self.loading = false;
|
self.loading = false;
|
||||||
},
|
},
|
||||||
function getDocumentProgress(progressData) {
|
function getDocumentProgress(progressData) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user