From 0b1111f368ca323904a026d47e268dfe2a30fd8d Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Sat, 23 Jun 2012 15:49:17 -0500 Subject: [PATCH] Cleanup: removing main thread loading fallback code --- src/api.js | 34 +--------------------------------- src/worker.js | 24 +++--------------------- 2 files changed, 4 insertions(+), 54 deletions(-) diff --git a/src/api.js b/src/api.js index 51d42b4c1..b49241fe9 100644 --- a/src/api.js +++ b/src/api.js @@ -480,34 +480,6 @@ var WorkerTransport = (function WorkerTransportClosure() { this.workerReadyPromise.resolve(pdfDocument); }, this); - messageHandler.on('FetchDoc', function transportFetchDoc(data) { - var url = data.url; - var headers = data.httpHeaders; - var password = data.password; - - var promise = this.workerReadyPromise; - var transport = this; - PDFJS.getPdf( - { - url: url, - progress: function getPDFProgress(evt) { - if (evt.lengthComputable) - promise.progress({ - loaded: evt.loaded, - total: evt.total - }); - }, - error: function getPDFError(e) { - promise.reject('Unexpected server response of ' + - e.target.status + '.'); - }, - headers: headers - }, - function getPDFLoad(data) { - transport.sendData(data); - }); - }, this); - messageHandler.on('NeedPassword', function transportPassword(data) { this.workerReadyPromise.reject(data.exception.message, data.exception); }, this); @@ -629,12 +601,8 @@ var WorkerTransport = (function WorkerTransportClosure() { }); }, - sendData: function WorkerTransport_sendData(data) { - this.messageHandler.send('GetDocRequest', {data: data}); - }, - fetchDocument: function WorkerTransport_fetchDocument(source) { - this.messageHandler.send('FetchDocRequest', {source: source}); + this.messageHandler.send('GetDocRequest', {source: source}); }, getData: function WorkerTransport_getData(promise) { diff --git a/src/worker.js b/src/worker.js index 54bdf024f..94d009334 100644 --- a/src/worker.js +++ b/src/worker.js @@ -3,8 +3,6 @@ 'use strict'; -var useMainThreadToDownload = false; - function MessageHandler(name, comObj) { this.name = name; this.comObj = comObj; @@ -85,9 +83,8 @@ MessageHandler.prototype = { var WorkerMessageHandler = { setup: function wphSetup(handler) { var pdfModel = null; - var pdfModelSource = null; - function loadDocument(pdfData) { + function loadDocument(pdfData, pdfModelSource) { // Create only the model of the PDFDoc, which is enough for // processing the content of the pdf. var pdfPassword = pdfModelSource.password; @@ -127,28 +124,13 @@ var WorkerMessageHandler = { }); handler.on('GetDocRequest', function wphSetupDoc(data) { - var pdfData = data.data; - loadDocument(pdfData); - }); - - handler.on('FetchDocRequest', function wphSetupFetchDoc(data) { var source = data.source; - pdfModelSource = source; - if (source.data) { // the data is array, instantiating directly from it - loadDocument(source.data); + loadDocument(source.data, source); return; } - if (useMainThreadToDownload) { - // fallback to main thread to download PDF - handler.send('FetchDoc', { - url: source.url, - httpHeaders: source.httpHeaders - }); - } - PDFJS.getPdf( { url: source.url, @@ -167,7 +149,7 @@ var WorkerMessageHandler = { headers: source.httpHeaders }, function getPDFLoad(data) { - loadDocument(data); + loadDocument(data, source); }); });