From 53549411b4f502eadbcc908efdbd626cdb246b82 Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Wed, 18 Dec 2013 13:39:03 -0800 Subject: [PATCH] Add verbosity as an api setting. --- src/core/worker.js | 1 + src/display/api.js | 15 ++++++++++++++- src/shared/util.js | 13 ++++++++----- web/viewer.js | 4 ++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 455227bea..0db5b5a9b 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -230,6 +230,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = { PDFJS.maxImageSize = data.maxImageSize === undefined ? -1 : data.maxImageSize; PDFJS.disableFontFace = data.disableFontFace; + PDFJS.verbosity = data.verbosity; getPdfManager(data).then(function pdfManagerReady() { loadDocument(false).then(onSuccess, function loadFailure(ex) { diff --git a/src/display/api.js b/src/display/api.js index 2a2587e04..17764e5be 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -93,6 +93,18 @@ PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug; */ PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers; + +/** + * Controls the logging level. + * The constants from PDFJS.VERBOSITY_LEVELS should be used: + * - errors + * - warnings [default] + * - infos + * @var {Number} + */ +PDFJS.verbosity = PDFJS.verbosity === undefined ? + PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity; + /** * This is the main entry point for loading a PDF and interacting with it. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR) @@ -864,7 +876,8 @@ var WorkerTransport = (function WorkerTransportClosure() { source: source, disableRange: PDFJS.disableRange, maxImageSize: PDFJS.maxImageSize, - disableFontFace: PDFJS.disableFontFace + disableFontFace: PDFJS.disableFontFace, + verbosity: PDFJS.verbosity }); }, diff --git a/src/shared/util.js b/src/shared/util.js index 744b9ad21..598674990 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -22,9 +22,6 @@ var globalScope = (typeof window === 'undefined') ? this : window; var isWorker = (typeof window == 'undefined'); -var ERRORS = 0, WARNINGS = 1, INFOS = 5; -var verbosity = WARNINGS; - var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; var TextRenderingMode = { @@ -49,6 +46,12 @@ if (!globalScope.PDFJS) { globalScope.PDFJS.pdfBug = false; +PDFJS.VERBOSITY_LEVELS = { + errors: 0, + warnings: 1, + infos: 5 +}; + // All the possible operations for an operator list. var OPS = PDFJS.OPS = { // Intentionally start from 1 so it is easy to spot bad operators that will be @@ -157,7 +160,7 @@ var log = (function() { // for things that are helpful to devs, such as warning that Workers were // disabled, which is important to devs but not end users. function info(msg) { - if (verbosity >= INFOS) { + if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) { log('Info: ' + msg); PDFJS.LogManager.notify('info', msg); } @@ -165,7 +168,7 @@ function info(msg) { // Non-fatal warnings that should trigger the fallback UI. function warn(msg) { - if (verbosity >= WARNINGS) { + if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) { log('Warning: ' + msg); PDFJS.LogManager.notify('warn', msg); } diff --git a/web/viewer.js b/web/viewer.js index c359d3129..c80a4bcae 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1603,6 +1603,10 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) { USE_ONLY_CSS_ZOOM = (hashParams['useOnlyCssZoom'] === 'true'); } + if ('verbosity' in hashParams) { + PDFJS.verbosity = hashParams['verbosity'] | 0; + } + //#if !(FIREFOX || MOZCENTRAL) var locale = navigator.language; if ('locale' in hashParams)