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

Add new severity log info(). Change severity of some log messages. Trigger fallback on errors and warnings for extension.

This commit is contained in:
Brendan Dahl 2012-05-14 17:19:09 -07:00
parent fca6f352e4
commit 034583e1a1
11 changed files with 128 additions and 62 deletions

View file

@ -221,6 +221,7 @@ var PDFView = {
initialBookmark: document.location.hash.substring(1),
container: null,
initialized: false,
fellback: false,
// called once when the document is loaded
initialize: function pdfViewInitialize() {
this.container = document.getElementById('viewerContainer');
@ -375,6 +376,11 @@ var PDFView = {
},
fallback: function pdfViewDownload() {
// Only trigger the fallback once so we don't spam the user with messages
// for one PDF.
if (this.fellback)
return;
this.fellback = true;
var url = this.url.split('#')[0];
FirefoxCom.request('fallback', url);
},
@ -441,6 +447,34 @@ var PDFView = {
* and optionally a 'stack' property.
*/
error: function pdfViewError(message, moreInfo) {
var moreInfoText = mozL10n.get('error_build', {build: PDFJS.build},
'PDF.JS Build: {{build}}') + '\n';
if (moreInfo) {
moreInfoText +=
mozL10n.get('error_message', {message: moreInfo.message},
'Message: {{message}}');
if (moreInfo.stack) {
moreInfoText += '\n' +
mozL10n.get('error_stack', {stack: moreInfo.stack},
'Stack: {{stack}}');
} else {
if (moreInfo.filename) {
moreInfoText += '\n' +
mozL10n.get('error_file', {file: moreInfo.filename},
'File: {{file}}');
}
if (moreInfo.lineNumber) {
moreInfoText += '\n' +
mozL10n.get('error_line', {line: moreInfo.lineNumber},
'Line: {{line}}');
}
}
}
if (PDFJS.isFirefoxExtension) {
console.error(message + '\n' + moreInfoText);
this.fallback();
return;
}
var errorWrapper = document.getElementById('errorWrapper');
errorWrapper.removeAttribute('hidden');
@ -467,32 +501,9 @@ var PDFView = {
};
moreInfoButton.removeAttribute('hidden');
lessInfoButton.setAttribute('hidden', 'true');
errorMoreInfo.value =
mozL10n.get('error_build', {build: PDFJS.build},
'PDF.JS Build: {{build}}') + '\n';
errorMoreInfo.value = moreInfoText;
if (moreInfo) {
errorMoreInfo.value +=
mozL10n.get('error_message', {message: moreInfo.message},
'Message: {{message}}');
if (moreInfo.stack) {
errorMoreInfo.value += '\n' +
mozL10n.get('error_stack', {stack: moreInfo.stack},
'Stack: {{stack}}');
} else {
if (moreInfo.filename) {
errorMoreInfo.value += '\n' +
mozL10n.get('error_file', {file: moreInfo.filename},
'File: {{file}}');
}
if (moreInfo.lineNumber) {
errorMoreInfo.value += '\n' +
mozL10n.get('error_line', {line: moreInfo.lineNumber},
'Line: {{line}}');
}
}
}
errorMoreInfo.rows = errorMoreInfo.value.split('\n').length - 1;
errorMoreInfo.rows = moreInfoText.split('\n').length - 1;
},
progress: function pdfViewProgress(level) {
@ -1385,6 +1396,14 @@ window.addEventListener('load', function webViewerLoad(evt) {
PDFBug.init();
}
// Listen for warnings to trigger the fallback UI. Errors should be caught
// and call PDFView.error() so we don't need to listen for those.
PDFJS.LogManager.addLogger({
warn: function() {
PDFView.fallback();
}
});
var thumbsView = document.getElementById('thumbnailView');
thumbsView.addEventListener('scroll', updateThumbViewArea, true);