diff --git a/examples/browserify/main.js b/examples/browserify/main.js index 46a921a59..42c640ef0 100644 --- a/examples/browserify/main.js +++ b/examples/browserify/main.js @@ -10,9 +10,6 @@ var pdfPath = '../helloworld/helloworld.pdf'; // Setting worker path to worker bundle. PDFJS.workerSrc = '../../build/browserify/pdf.worker.bundle.js'; -// It is also possible to disable workers via `PDFJS.disableWorker = true`, -// however that might degrade the UI performance in web browsers. - // Loading a document. var loadingTask = PDFJS.getDocument(pdfPath); loadingTask.promise.then(function (pdfDocument) { diff --git a/examples/learning/helloworld.html b/examples/learning/helloworld.html index 4142ef6f5..c2988c287 100644 --- a/examples/learning/helloworld.html +++ b/examples/learning/helloworld.html @@ -19,13 +19,6 @@ // var url = './helloworld.pdf'; - // - // Disable workers to avoid yet another cross-origin issue (workers need - // the URL of the script to be loaded, and dynamically loading a cross-origin - // script does not work). - // - // PDFJS.disableWorker = true; - // // The workerSrc property shall be specified. // diff --git a/examples/learning/helloworld64.html b/examples/learning/helloworld64.html index 58890fe87..69420495a 100644 --- a/examples/learning/helloworld64.html +++ b/examples/learning/helloworld64.html @@ -31,12 +31,6 @@ 'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' + 'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'); - // Disable workers to avoid yet another cross-origin issue (workers need - // the URL of the script to be loaded, and dynamically loading a cross-origin - // script does not work). - // - // PDFJS.disableWorker = true; - // // The workerSrc property shall be specified. // diff --git a/examples/learning/prevnext.html b/examples/learning/prevnext.html index 463527a3d..f7e68f2b5 100644 --- a/examples/learning/prevnext.html +++ b/examples/learning/prevnext.html @@ -28,14 +28,6 @@ // var url = '../../web/compressed.tracemonkey-pldi-09.pdf'; - - // - // Disable workers to avoid yet another cross-origin issue (workers need - // the URL of the script to be loaded, and dynamically loading a cross-origin - // script does not work). - // - // PDFJS.disableWorker = true; - // // In cases when the pdf.worker.js is located at the different folder than the // pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property diff --git a/examples/webpack/main.js b/examples/webpack/main.js index d0466b86d..d1beb101c 100644 --- a/examples/webpack/main.js +++ b/examples/webpack/main.js @@ -10,9 +10,6 @@ var pdfPath = '../helloworld/helloworld.pdf'; // Setting worker path to worker bundle. pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js'; -// It is also possible to disable workers via `PDFJS.disableWorker = true`, -// however that might degrade the UI performance in web browsers. - // Loading a document. var loadingTask = pdfjsLib.getDocument(pdfPath); loadingTask.promise.then(function (pdfDocument) { diff --git a/external/dist/webpack.js b/external/dist/webpack.js index f2c4a6400..af3979439 100644 --- a/external/dist/webpack.js +++ b/external/dist/webpack.js @@ -19,8 +19,6 @@ var PdfjsWorker = require('worker-loader!./build/pdf.worker.js'); if (typeof window !== 'undefined' && 'Worker' in window) { pdfjs.PDFJS.workerPort = new PdfjsWorker(); -} else { - pdfjs.PDFJS.disableWorker = true; } module.exports = pdfjs; diff --git a/src/display/api.js b/src/display/api.js index afc08c047..c62c3e7c1 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1216,6 +1216,19 @@ var PDFWorker = (function PDFWorkerClosure() { throw new Error('No PDFJS.workerSrc specified'); } + function getMainThreadWorkerMessageHandler() { + if (typeof window === 'undefined') { + return null; + } + if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { + return (window.pdfjsNonProductionPdfWorker && + window.pdfjsNonProductionPdfWorker.WorkerMessageHandler); + } + // PRODUCTION + return (window.pdfjsDistBuildPdfWorker && + window.pdfjsDistBuildPdfWorker.WorkerMessageHandler); + } + let fakeWorkerFilesLoadedCapability; // Loads worker code into main thread. @@ -1225,6 +1238,13 @@ var PDFWorker = (function PDFWorkerClosure() { return fakeWorkerFilesLoadedCapability.promise; } fakeWorkerFilesLoadedCapability = createPromiseCapability(); + + let mainWorkerMessageHandler = getMainThreadWorkerMessageHandler(); + if (mainWorkerMessageHandler) { + // The worker was already loaded using a `