Skip to content

Commit

Permalink
Proxy global PDFJS.verbosity to properly configure shared/util.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Mar 23, 2016
1 parent a488847 commit c44c7b3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
7 changes: 4 additions & 3 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -696,9 +700,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
Expand Down
17 changes: 5 additions & 12 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -456,7 +446,6 @@ function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
cMapPacked: PDFJS.cMapPacked,
disableFontFace: PDFJS.disableFontFace,
disableCreateObjectURL: PDFJS.disableCreateObjectURL,
verbosity: PDFJS.verbosity,
postMessageTransfers: PDFJS.postMessageTransfers,
}).then(function (workerId) {
if (worker.destroyed) {
Expand Down Expand Up @@ -1327,6 +1316,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();
Expand Down
7 changes: 7 additions & 0 deletions src/display/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/doc_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c44c7b3

Please sign in to comment.