Merge pull request #4728 from Snuffleupagus/remove-LegacyPromise-worker.js
Remove LegacyPromise in src/core/worker.js
This commit is contained in:
commit
5fb42f6962
@ -67,11 +67,16 @@ var BasePdfManager = (function BasePdfManagerClosure() {
|
|||||||
|
|
||||||
updatePassword: function BasePdfManager_updatePassword(password) {
|
updatePassword: function BasePdfManager_updatePassword(password) {
|
||||||
this.pdfDocument.xref.password = this.password = password;
|
this.pdfDocument.xref.password = this.password = password;
|
||||||
if (this.passwordChangedPromise) {
|
if (this._passwordChangedCapability) {
|
||||||
this.passwordChangedPromise.resolve();
|
this._passwordChangedCapability.resolve();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
passwordChanged: function BasePdfManager_passwordChanged() {
|
||||||
|
this._passwordChangedCapability = createPromiseCapability();
|
||||||
|
return this._passwordChangedCapability.promise;
|
||||||
|
},
|
||||||
|
|
||||||
terminate: function BasePdfManager_terminate() {
|
terminate: function BasePdfManager_terminate() {
|
||||||
return new NotImplementedException();
|
return new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
/* globals error, globalScope, InvalidPDFException, info,
|
/* globals error, globalScope, InvalidPDFException, info,
|
||||||
MissingPDFException, PasswordException, PDFJS, Promise,
|
MissingPDFException, PasswordException, PDFJS, Promise,
|
||||||
UnknownErrorException, NetworkManager, LocalPdfManager,
|
UnknownErrorException, NetworkManager, LocalPdfManager,
|
||||||
NetworkPdfManager, XRefParseException, LegacyPromise,
|
NetworkPdfManager, XRefParseException, createPromiseCapability,
|
||||||
isInt, PasswordResponses, MessageHandler, Ref, RANGE_CHUNK_SIZE */
|
isInt, PasswordResponses, MessageHandler, Ref, RANGE_CHUNK_SIZE */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -27,7 +27,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
var pdfManager;
|
var pdfManager;
|
||||||
|
|
||||||
function loadDocument(recoveryMode) {
|
function loadDocument(recoveryMode) {
|
||||||
var loadDocumentPromise = new LegacyPromise();
|
var loadDocumentCapability = createPromiseCapability();
|
||||||
|
|
||||||
var parseSuccess = function parseSuccess() {
|
var parseSuccess = function parseSuccess() {
|
||||||
var numPagesPromise = pdfManager.ensureDoc('numPages');
|
var numPagesPromise = pdfManager.ensureDoc('numPages');
|
||||||
@ -50,13 +50,13 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
encrypted: !!results[5],
|
encrypted: !!results[5],
|
||||||
javaScript: results[6]
|
javaScript: results[6]
|
||||||
};
|
};
|
||||||
loadDocumentPromise.resolve(doc);
|
loadDocumentCapability.resolve(doc);
|
||||||
},
|
},
|
||||||
parseFailure);
|
parseFailure);
|
||||||
};
|
};
|
||||||
|
|
||||||
var parseFailure = function parseFailure(e) {
|
var parseFailure = function parseFailure(e) {
|
||||||
loadDocumentPromise.reject(e);
|
loadDocumentCapability.reject(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
pdfManager.ensureDoc('checkHeader', []).then(function() {
|
pdfManager.ensureDoc('checkHeader', []).then(function() {
|
||||||
@ -66,30 +66,30 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
}, parseFailure);
|
}, parseFailure);
|
||||||
}, parseFailure);
|
}, parseFailure);
|
||||||
|
|
||||||
return loadDocumentPromise;
|
return loadDocumentCapability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPdfManager(data) {
|
function getPdfManager(data) {
|
||||||
var pdfManagerPromise = new LegacyPromise();
|
var pdfManagerCapability = createPromiseCapability();
|
||||||
|
|
||||||
var source = data.source;
|
var source = data.source;
|
||||||
var disableRange = data.disableRange;
|
var disableRange = data.disableRange;
|
||||||
if (source.data) {
|
if (source.data) {
|
||||||
try {
|
try {
|
||||||
pdfManager = new LocalPdfManager(source.data, source.password);
|
pdfManager = new LocalPdfManager(source.data, source.password);
|
||||||
pdfManagerPromise.resolve();
|
pdfManagerCapability.resolve();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerPromise.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
return pdfManagerPromise;
|
return pdfManagerCapability.promise;
|
||||||
} else if (source.chunkedViewerLoading) {
|
} else if (source.chunkedViewerLoading) {
|
||||||
try {
|
try {
|
||||||
pdfManager = new NetworkPdfManager(source, handler);
|
pdfManager = new NetworkPdfManager(source, handler);
|
||||||
pdfManagerPromise.resolve();
|
pdfManagerCapability.resolve();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerPromise.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
return pdfManagerPromise;
|
return pdfManagerCapability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
var networkManager = new NetworkManager(source.url, {
|
var networkManager = new NetworkManager(source.url, {
|
||||||
@ -134,9 +134,9 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
pdfManager = new NetworkPdfManager(source, handler);
|
pdfManager = new NetworkPdfManager(source, handler);
|
||||||
pdfManagerPromise.resolve(pdfManager);
|
pdfManagerCapability.resolve(pdfManager);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerPromise.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -144,9 +144,9 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
// the data is array, instantiating directly from it
|
// the data is array, instantiating directly from it
|
||||||
try {
|
try {
|
||||||
pdfManager = new LocalPdfManager(args.chunk, source.password);
|
pdfManager = new LocalPdfManager(args.chunk, source.password);
|
||||||
pdfManagerPromise.resolve();
|
pdfManagerCapability.resolve();
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
pdfManagerPromise.reject(ex);
|
pdfManagerCapability.reject(ex);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return pdfManagerPromise;
|
return pdfManagerCapability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.on('test', function wphSetupTest(data) {
|
handler.on('test', function wphSetupTest(data) {
|
||||||
@ -253,8 +253,7 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
if (ex instanceof PasswordException) {
|
if (ex instanceof PasswordException) {
|
||||||
// after password exception prepare to receive a new password
|
// after password exception prepare to receive a new password
|
||||||
// to repeat loading
|
// to repeat loading
|
||||||
pdfManager.passwordChangedPromise = new LegacyPromise();
|
pdfManager.passwordChanged().then(pdfManagerReady);
|
||||||
pdfManager.passwordChangedPromise.then(pdfManagerReady);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onFailure(ex);
|
onFailure(ex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user