@@ -741,19 +741,16 @@ const PDFViewerApplication = {
741
741
}
742
742
this . externalServices . initPassiveLoading ( {
743
743
onOpenWithTransport : ( url , length , transport ) => {
744
- this . open ( url , { length, range : transport } ) ;
744
+ this . open ( { url, length, range : transport } ) ;
745
745
} ,
746
746
onOpenWithData : ( data , contentDispositionFilename ) => {
747
747
if ( isPdfFile ( contentDispositionFilename ) ) {
748
748
this . _contentDispositionFilename = contentDispositionFilename ;
749
749
}
750
- this . open ( data ) ;
750
+ this . open ( { data } ) ;
751
751
} ,
752
752
onOpenWithURL : ( url , length , originalUrl ) => {
753
- const file = originalUrl !== undefined ? { url, originalUrl } : url ;
754
- const args = length !== undefined ? { length } : null ;
755
-
756
- this . open ( file , args ) ;
753
+ this . open ( { url, length, originalUrl } ) ;
757
754
} ,
758
755
onError : err => {
759
756
this . l10n . get ( "loading_error" ) . then ( msg => {
@@ -890,15 +887,28 @@ const PDFViewerApplication = {
890
887
} ,
891
888
892
889
/**
893
- * Opens PDF document specified by URL or array with additional arguments.
894
- * @param {string|TypedArray|ArrayBuffer } file - PDF location or binary data.
895
- * @param {Object } [args] - Additional arguments for the getDocument call,
896
- * e.g. HTTP headers ('httpHeaders') or alternative
897
- * data transport ('range').
898
- * @returns {Promise } - Returns the promise, which is resolved when document
899
- * is opened.
890
+ * Opens a new PDF document.
891
+ * @param {Object } args - Accepts any/all of the properties from
892
+ * {@link DocumentInitParameters}, and also a `originalUrl` string.
893
+ * @returns {Promise } - Promise that is resolved when the document is opened.
900
894
*/
901
- async open ( file , args ) {
895
+ async open ( args ) {
896
+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
897
+ let deprecatedArgs = false ;
898
+ if ( typeof args === "string" ) {
899
+ args = { url : args } ; // URL
900
+ deprecatedArgs = true ;
901
+ } else if ( args ?. byteLength ) {
902
+ args = { data : args } ; // ArrayBuffer
903
+ deprecatedArgs = true ;
904
+ }
905
+ if ( deprecatedArgs ) {
906
+ console . error (
907
+ "The `PDFViewerApplication.open` signature was updated, please use an object instead."
908
+ ) ;
909
+ }
910
+ }
911
+
902
912
if ( this . pdfLoadingTask ) {
903
913
// We need to destroy already opened document.
904
914
await this . close ( ) ;
@@ -910,36 +920,36 @@ const PDFViewerApplication = {
910
920
}
911
921
912
922
const parameters = Object . create ( null ) ;
913
- if ( typeof file === "string" ) {
914
- // URL
915
- this . setTitleUsingUrl ( file , /* downloadUrl = */ file ) ;
916
- parameters . url = file ;
917
- } else if ( file && "byteLength" in file ) {
918
- // ArrayBuffer
919
- parameters . data = file ;
920
- } else if ( file . url && file . originalUrl ) {
921
- this . setTitleUsingUrl ( file . originalUrl , /* downloadUrl = */ file . url ) ;
922
- parameters . url = file . url ;
923
+ if (
924
+ ( typeof PDFJSDev === "undefined" || ! PDFJSDev . test ( "MOZCENTRAL" ) ) &&
925
+ args . url
926
+ ) {
927
+ // The Firefox built-in viewer always calls `setTitleUsingUrl`, before
928
+ // `initPassiveLoading`, and it never provides an `originalUrl` here.
929
+ if ( args . originalUrl ) {
930
+ this . setTitleUsingUrl ( args . originalUrl , /* downloadUrl = */ args . url ) ;
931
+ delete args . originalUrl ;
932
+ } else {
933
+ this . setTitleUsingUrl ( args . url , /* downloadUrl = */ args . url ) ;
934
+ }
923
935
}
924
936
// Set the necessary API parameters, using the available options.
925
937
const apiParameters = AppOptions . getAll ( OptionKind . API ) ;
926
938
for ( const key in apiParameters ) {
927
939
let value = apiParameters [ key ] ;
928
940
929
- if ( key === "docBaseUrl" && ! value ) {
941
+ if ( key === "docBaseUrl" ) {
930
942
if ( typeof PDFJSDev === "undefined" || ! PDFJSDev . test ( "PRODUCTION" ) ) {
931
- value = document . URL . split ( "#" ) [ 0 ] ;
943
+ value || = document . URL . split ( "#" ) [ 0 ] ;
932
944
} else if ( PDFJSDev . test ( "MOZCENTRAL || CHROME" ) ) {
933
- value = this . baseUrl ;
945
+ value || = this . baseUrl ;
934
946
}
935
947
}
936
948
parameters [ key ] = value ;
937
949
}
938
- // Finally, update the API parameters with the arguments (if they exist).
939
- if ( args ) {
940
- for ( const key in args ) {
941
- parameters [ key ] = args [ key ] ;
942
- }
950
+ // Finally, update the API parameters with the arguments.
951
+ for ( const key in args ) {
952
+ parameters [ key ] = args [ key ] ;
943
953
}
944
954
945
955
const loadingTask = getDocument ( parameters ) ;
@@ -2242,7 +2252,7 @@ function webViewerInitialized() {
2242
2252
try {
2243
2253
if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2244
2254
if ( file ) {
2245
- PDFViewerApplication . open ( file ) ;
2255
+ PDFViewerApplication . open ( { url : file } ) ;
2246
2256
} else {
2247
2257
PDFViewerApplication . _hideViewBookmark ( ) ;
2248
2258
}
@@ -2452,11 +2462,10 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
2452
2462
}
2453
2463
const file = evt . fileInput . files [ 0 ] ;
2454
2464
2455
- let url = URL . createObjectURL ( file ) ;
2456
- if ( file . name ) {
2457
- url = { url, originalUrl : file . name } ;
2458
- }
2459
- PDFViewerApplication . open ( url ) ;
2465
+ PDFViewerApplication . open ( {
2466
+ url : URL . createObjectURL ( file ) ,
2467
+ originalUrl : file . name ,
2468
+ } ) ;
2460
2469
} ;
2461
2470
2462
2471
// eslint-disable-next-line no-var
0 commit comments