Proxy global PDFJS.verbosity to properly configure shared/util.

This commit is contained in:
Yury Delendik 2016-03-03 10:13:37 -06:00
parent a8e5912cb1
commit 2fa4dd6f40
4 changed files with 26 additions and 15 deletions

View File

@ -462,6 +462,10 @@ var WorkerMessageHandler = {
}); });
}); });
handler.on('configure', function wphConfigure(data) {
setVerbosityLevel(data.verbosity);
});
handler.on('GetDocRequest', function wphSetupDoc(data) { handler.on('GetDocRequest', function wphSetupDoc(data) {
return WorkerMessageHandler.createDocumentHandler(data, port); return WorkerMessageHandler.createDocumentHandler(data, port);
}); });
@ -696,9 +700,6 @@ var WorkerMessageHandler = {
cMapOptions: cMapOptions cMapOptions: cMapOptions
}; };
// TODO move it to the worker options synchronization place (vs document).
setVerbosityLevel(data.verbosity);
getPdfManager(data, evaluatorOptions).then(function (newPdfManager) { getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
if (terminated) { if (terminated) {
// We were in a process of setting up the manager, but it got // We were in a process of setting up the manager, but it got

View File

@ -48,6 +48,7 @@ var createPromiseCapability = sharedUtil.createPromiseCapability;
var combineUrl = sharedUtil.combineUrl; var combineUrl = sharedUtil.combineUrl;
var error = sharedUtil.error; var error = sharedUtil.error;
var deprecated = sharedUtil.deprecated; var deprecated = sharedUtil.deprecated;
var getVerbosityLevel = sharedUtil.getVerbosityLevel;
var info = sharedUtil.info; var info = sharedUtil.info;
var isArrayBuffer = sharedUtil.isArrayBuffer; var isArrayBuffer = sharedUtil.isArrayBuffer;
var isSameOrigin = sharedUtil.isSameOrigin; var isSameOrigin = sharedUtil.isSameOrigin;
@ -200,17 +201,6 @@ PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ? PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
false : PDFJS.useOnlyCssZoom); 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 maximum supported canvas size in total pixels e.g. width * height.
* The default value is 4096 * 4096. Use -1 for no limit. * The default value is 4096 * 4096. Use -1 for no limit.
@ -456,7 +446,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
cMapPacked: PDFJS.cMapPacked, cMapPacked: PDFJS.cMapPacked,
disableFontFace: PDFJS.disableFontFace, disableFontFace: PDFJS.disableFontFace,
disableCreateObjectURL: PDFJS.disableCreateObjectURL, disableCreateObjectURL: PDFJS.disableCreateObjectURL,
verbosity: PDFJS.verbosity,
postMessageTransfers: PDFJS.postMessageTransfers, postMessageTransfers: PDFJS.postMessageTransfers,
}).then(function (workerId) { }).then(function (workerId) {
if (worker.destroyed) { if (worker.destroyed) {
@ -1327,6 +1316,10 @@ var PDFWorker = (function PDFWorkerClosure() {
PDFJS.postMessageTransfers = false; PDFJS.postMessageTransfers = false;
} }
this._readyCapability.resolve(); this._readyCapability.resolve();
// Send global PDFJS setting, e.g. verbosity level.
messageHandler.send('configure', {
verbosity: getVerbosityLevel()
});
} else { } else {
this._setupFakeWorker(); this._setupFakeWorker();
messageHandler.destroy(); messageHandler.destroy();

View File

@ -50,6 +50,13 @@
if (PDFJS.verbosity !== undefined) { if (PDFJS.verbosity !== undefined) {
sharedUtil.setVerbosityLevel(PDFJS.verbosity); 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.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
PDFJS.OPS = sharedUtil.OPS; PDFJS.OPS = sharedUtil.OPS;

View File

@ -27,6 +27,16 @@ function PDFJS() {
// Mock class constructor. See src/display/api.js. // 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. * Represents the eventual result of an asynchronous operation.
* @external Promise * @external Promise