From 1558d64000522fedcbebcf303babd753605bf795 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Thu, 3 Mar 2016 10:13:37 -0600 Subject: [PATCH] Proxy global PDFJS.verbosity to properly configure shared/util. --- src/core/worker.js | 7 ++++--- src/display/api.js | 17 +++++------------ src/display/global.js | 7 +++++++ src/doc_helper.js | 10 ++++++++++ 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/core/worker.js b/src/core/worker.js index 0f22e85ffbdd70..98a14088bd044f 100644 --- a/src/core/worker.js +++ b/src/core/worker.js @@ -462,6 +462,10 @@ var WorkerMessageHandler = { }); }); + handler.on('configure', function wphConfigure(data) { + setVerbosityLevel(data.verbosity); + }); + handler.on('GetDocRequest', function wphSetupDoc(data) { return WorkerMessageHandler.createDocumentHandler(data, port); }); @@ -691,9 +695,6 @@ var WorkerMessageHandler = { cmapOptions: cmapOptions }; - // TODO move it to the worker options synchronization place (vs document). - setVerbosityLevel(data.verbosity); - getPdfManager(data, evaluatorOptions).then(function (newPdfManager) { if (terminated) { // We were in a process of setting up the manager, but it got diff --git a/src/display/api.js b/src/display/api.js index c6cf7a0d226573..3cc6a09e533085 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -48,6 +48,7 @@ var createPromiseCapability = sharedUtil.createPromiseCapability; var combineUrl = sharedUtil.combineUrl; var error = sharedUtil.error; var deprecated = sharedUtil.deprecated; +var getVerbosityLevel = sharedUtil.getVerbosityLevel; var info = sharedUtil.info; var isArrayBuffer = sharedUtil.isArrayBuffer; var isSameOrigin = sharedUtil.isSameOrigin; @@ -200,17 +201,6 @@ PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ? PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ? false : PDFJS.useOnlyCssZoom); -/** - * 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); - /** * The maximum supported canvas size in total pixels e.g. width * height. * The default value is 4096 * 4096. Use -1 for no limit. @@ -456,7 +446,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { cMapPacked: PDFJS.cMapPacked, disableFontFace: PDFJS.disableFontFace, disableCreateObjectURL: PDFJS.disableCreateObjectURL, - verbosity: PDFJS.verbosity }).then(function (workerId) { if (worker.destroyed) { throw new Error('Worker was destroyed'); @@ -1326,6 +1315,10 @@ var PDFWorker = (function PDFWorkerClosure() { PDFJS.postMessageTransfers = false; } this._readyCapability.resolve(); + // Send global PDFJS setting, e.g. verbosity level. + messageHandler.send('configure', { + verbosity: getVerbosityLevel() + }); } else { this._setupFakeWorker(); messageHandler.destroy(); diff --git a/src/display/global.js b/src/display/global.js index ca751d6f3ff5c9..f449e5ffc6de6f 100644 --- a/src/display/global.js +++ b/src/display/global.js @@ -50,6 +50,13 @@ if (PDFJS.verbosity !== undefined) { sharedUtil.setVerbosityLevel(PDFJS.verbosity); } + delete PDFJS.verbosity; + Object.defineProperty(PDFJS, 'verbosity', { + get: function () { return sharedUtil.getVerbosityLevel(); }, + set: function (level) { sharedUtil.setVerbosityLevel(level); }, + enumerable: true, + configurable: true + }); PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS; PDFJS.OPS = sharedUtil.OPS; diff --git a/src/doc_helper.js b/src/doc_helper.js index 00b770920c81b1..86632b455fa507 100644 --- a/src/doc_helper.js +++ b/src/doc_helper.js @@ -27,6 +27,16 @@ function PDFJS() { // Mock class constructor. See src/display/api.js. } +/** + * Controls the logging level. + * The constants from PDFJS.VERBOSITY_LEVELS should be used: + * - errors + * - warnings [default] + * - infos + * @var {number} + */ +PDFJS.verbosity = PDFJS.VERBOSITY_LEVELS.warnings; + /** * Represents the eventual result of an asynchronous operation. * @external Promise