Cleanup: removing main thread loading fallback code
This commit is contained in:
parent
0dd445bf18
commit
0b1111f368
34
src/api.js
34
src/api.js
@ -480,34 +480,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
this.workerReadyPromise.resolve(pdfDocument);
|
this.workerReadyPromise.resolve(pdfDocument);
|
||||||
}, this);
|
}, 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) {
|
messageHandler.on('NeedPassword', function transportPassword(data) {
|
||||||
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
this.workerReadyPromise.reject(data.exception.message, data.exception);
|
||||||
}, this);
|
}, 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) {
|
fetchDocument: function WorkerTransport_fetchDocument(source) {
|
||||||
this.messageHandler.send('FetchDocRequest', {source: source});
|
this.messageHandler.send('GetDocRequest', {source: source});
|
||||||
},
|
},
|
||||||
|
|
||||||
getData: function WorkerTransport_getData(promise) {
|
getData: function WorkerTransport_getData(promise) {
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var useMainThreadToDownload = false;
|
|
||||||
|
|
||||||
function MessageHandler(name, comObj) {
|
function MessageHandler(name, comObj) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.comObj = comObj;
|
this.comObj = comObj;
|
||||||
@ -85,9 +83,8 @@ MessageHandler.prototype = {
|
|||||||
var WorkerMessageHandler = {
|
var WorkerMessageHandler = {
|
||||||
setup: function wphSetup(handler) {
|
setup: function wphSetup(handler) {
|
||||||
var pdfModel = null;
|
var pdfModel = null;
|
||||||
var pdfModelSource = null;
|
|
||||||
|
|
||||||
function loadDocument(pdfData) {
|
function loadDocument(pdfData, pdfModelSource) {
|
||||||
// Create only the model of the PDFDoc, which is enough for
|
// Create only the model of the PDFDoc, which is enough for
|
||||||
// processing the content of the pdf.
|
// processing the content of the pdf.
|
||||||
var pdfPassword = pdfModelSource.password;
|
var pdfPassword = pdfModelSource.password;
|
||||||
@ -127,28 +124,13 @@ var WorkerMessageHandler = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
handler.on('GetDocRequest', function wphSetupDoc(data) {
|
handler.on('GetDocRequest', function wphSetupDoc(data) {
|
||||||
var pdfData = data.data;
|
|
||||||
loadDocument(pdfData);
|
|
||||||
});
|
|
||||||
|
|
||||||
handler.on('FetchDocRequest', function wphSetupFetchDoc(data) {
|
|
||||||
var source = data.source;
|
var source = data.source;
|
||||||
pdfModelSource = source;
|
|
||||||
|
|
||||||
if (source.data) {
|
if (source.data) {
|
||||||
// the data is array, instantiating directly from it
|
// the data is array, instantiating directly from it
|
||||||
loadDocument(source.data);
|
loadDocument(source.data, source);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useMainThreadToDownload) {
|
|
||||||
// fallback to main thread to download PDF
|
|
||||||
handler.send('FetchDoc', {
|
|
||||||
url: source.url,
|
|
||||||
httpHeaders: source.httpHeaders
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
PDFJS.getPdf(
|
PDFJS.getPdf(
|
||||||
{
|
{
|
||||||
url: source.url,
|
url: source.url,
|
||||||
@ -167,7 +149,7 @@ var WorkerMessageHandler = {
|
|||||||
headers: source.httpHeaders
|
headers: source.httpHeaders
|
||||||
},
|
},
|
||||||
function getPDFLoad(data) {
|
function getPDFLoad(data) {
|
||||||
loadDocument(data);
|
loadDocument(data, source);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user