@ -663,19 +663,25 @@ var WorkerMessageHandler = {
@@ -663,19 +663,25 @@ var WorkerMessageHandler = {
return pdfManagerCapability . promise ;
}
var setupDoc = function ( data ) {
var onSuccess = function ( doc ) {
function setupDoc ( data ) {
function onSuccess ( doc ) {
ensureNotTerminated ( ) ;
handler . send ( 'GetDoc' , { pdfInfo : doc } ) ;
} ;
}
var onFailure = function ( e ) {
function onFailure ( e ) {
if ( e instanceof PasswordException ) {
if ( e . code === PasswordResponses . NEED _PASSWORD ) {
handler . send ( 'NeedPassword' , e ) ;
} else if ( e . code === PasswordResponses . INCORRECT _PASSWORD ) {
handler . send ( 'IncorrectPassword' , e ) ;
}
var task = new WorkerTask ( 'PasswordException: response ' + e . code ) ;
startWorkerTask ( task ) ;
handler . sendWithPromise ( 'PasswordRequest' , e ) . then ( function ( data ) {
finishWorkerTask ( task ) ;
pdfManager . updatePassword ( data . password ) ;
pdfManagerReady ( ) ;
} ) . catch ( function ( ex ) {
finishWorkerTask ( task ) ;
handler . send ( 'PasswordException' , ex ) ;
} . bind ( null , e ) ) ;
} else if ( e instanceof InvalidPDFException ) {
handler . send ( 'InvalidPDF' , e ) ;
} else if ( e instanceof MissingPDFException ) {
@ -686,7 +692,27 @@ var WorkerMessageHandler = {
@@ -686,7 +692,27 @@ var WorkerMessageHandler = {
handler . send ( 'UnknownError' ,
new UnknownErrorException ( e . message , e . toString ( ) ) ) ;
}
} ;
}
function pdfManagerReady ( ) {
ensureNotTerminated ( ) ;
loadDocument ( false ) . then ( onSuccess , function loadFailure ( ex ) {
ensureNotTerminated ( ) ;
// Try again with recoveryMode == true
if ( ! ( ex instanceof XRefParseException ) ) {
onFailure ( ex ) ;
return ;
}
pdfManager . requestLoadedStream ( ) ;
pdfManager . onLoadedStream ( ) . then ( function ( ) {
ensureNotTerminated ( ) ;
loadDocument ( true ) . then ( onSuccess , onFailure ) ;
} ) ;
} , onFailure ) ;
}
ensureNotTerminated ( ) ;
@ -714,33 +740,8 @@ var WorkerMessageHandler = {
@@ -714,33 +740,8 @@ var WorkerMessageHandler = {
pdfManager . onLoadedStream ( ) . then ( function ( stream ) {
handler . send ( 'DataLoaded' , { length : stream . bytes . byteLength } ) ;
} ) ;
} ) . then ( function pdfManagerReady ( ) {
ensureNotTerminated ( ) ;
loadDocument ( false ) . then ( onSuccess , function loadFailure ( ex ) {
ensureNotTerminated ( ) ;
// Try again with recoveryMode == true
if ( ! ( ex instanceof XRefParseException ) ) {
if ( ex instanceof PasswordException ) {
// after password exception prepare to receive a new password
// to repeat loading
pdfManager . passwordChanged ( ) . then ( pdfManagerReady ) ;
}
onFailure ( ex ) ;
return ;
}
pdfManager . requestLoadedStream ( ) ;
pdfManager . onLoadedStream ( ) . then ( function ( ) {
ensureNotTerminated ( ) ;
loadDocument ( true ) . then ( onSuccess , onFailure ) ;
} ) ;
} , onFailure ) ;
} , onFailure ) ;
} ;
} ) . then ( pdfManagerReady , onFailure ) ;
}
handler . on ( 'GetPage' , function wphSetupGetPage ( data ) {
return pdfManager . getPage ( data . pageIndex ) . then ( function ( page ) {
@ -824,10 +825,6 @@ var WorkerMessageHandler = {
@@ -824,10 +825,6 @@ var WorkerMessageHandler = {
}
) ;
handler . on ( 'UpdatePassword' , function wphSetupUpdatePassword ( data ) {
pdfManager . updatePassword ( data ) ;
} ) ;
handler . on ( 'GetAnnotations' , function wphSetupGetAnnotations ( data ) {
return pdfManager . getPage ( data . pageIndex ) . then ( function ( page ) {
return pdfManager . ensure ( page , 'getAnnotationsData' , [ data . intent ] ) ;