@@ -685,8 +685,107 @@ const PDFViewerApplication = {
685685 }
686686 } ,
687687
688- run ( config ) {
689- this . initialize ( config ) . then ( webViewerInitialized ) ;
688+ async run ( config ) {
689+ await this . initialize ( config ) ;
690+
691+ const { appConfig, eventBus, l10n } = this ;
692+ let file ;
693+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
694+ const queryString = document . location . search . substring ( 1 ) ;
695+ const params = parseQueryString ( queryString ) ;
696+ file = params . get ( "file" ) ?? AppOptions . get ( "defaultUrl" ) ;
697+ validateFileURL ( file ) ;
698+ } else if ( PDFJSDev . test ( "MOZCENTRAL" ) ) {
699+ file = window . location . href ;
700+ } else if ( PDFJSDev . test ( "CHROME" ) ) {
701+ file = AppOptions . get ( "defaultUrl" ) ;
702+ }
703+
704+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
705+ const fileInput = appConfig . openFileInput ;
706+ fileInput . value = null ;
707+
708+ fileInput . addEventListener ( "change" , function ( evt ) {
709+ const { files } = evt . target ;
710+ if ( ! files || files . length === 0 ) {
711+ return ;
712+ }
713+ eventBus . dispatch ( "fileinputchange" , {
714+ source : this ,
715+ fileInput : evt . target ,
716+ } ) ;
717+ } ) ;
718+
719+ // Enable dragging-and-dropping a new PDF file onto the viewerContainer.
720+ appConfig . mainContainer . addEventListener ( "dragover" , function ( evt ) {
721+ evt . preventDefault ( ) ;
722+
723+ evt . dataTransfer . dropEffect =
724+ evt . dataTransfer . effectAllowed === "copy" ? "copy" : "move" ;
725+ } ) ;
726+ appConfig . mainContainer . addEventListener ( "drop" , function ( evt ) {
727+ evt . preventDefault ( ) ;
728+
729+ const { files } = evt . dataTransfer ;
730+ if ( ! files || files . length === 0 ) {
731+ return ;
732+ }
733+ eventBus . dispatch ( "fileinputchange" , {
734+ source : this ,
735+ fileInput : evt . dataTransfer ,
736+ } ) ;
737+ } ) ;
738+ }
739+
740+ if ( ! this . supportsDocumentFonts ) {
741+ AppOptions . set ( "disableFontFace" , true ) ;
742+ l10n . get ( "web_fonts_disabled" ) . then ( msg => {
743+ console . warn ( msg ) ;
744+ } ) ;
745+ }
746+
747+ if ( ! this . supportsPrinting ) {
748+ appConfig . toolbar ?. print ?. classList . add ( "hidden" ) ;
749+ appConfig . secondaryToolbar ?. printButton . classList . add ( "hidden" ) ;
750+ }
751+
752+ if ( ! this . supportsFullscreen ) {
753+ appConfig . secondaryToolbar ?. presentationModeButton . classList . add (
754+ "hidden"
755+ ) ;
756+ }
757+
758+ if ( this . supportsIntegratedFind ) {
759+ appConfig . toolbar ?. viewFind ?. classList . add ( "hidden" ) ;
760+ }
761+
762+ appConfig . mainContainer . addEventListener (
763+ "transitionend" ,
764+ function ( evt ) {
765+ if ( evt . target === /* mainContainer */ this ) {
766+ eventBus . dispatch ( "resize" , { source : this } ) ;
767+ }
768+ } ,
769+ true
770+ ) ;
771+
772+ try {
773+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
774+ if ( file ) {
775+ this . open ( { url : file } ) ;
776+ } else {
777+ this . _hideViewBookmark ( ) ;
778+ }
779+ } else if ( PDFJSDev . test ( "MOZCENTRAL || CHROME" ) ) {
780+ this . initPassiveLoading ( file ) ;
781+ } else {
782+ throw new Error ( "Not implemented: run" ) ;
783+ }
784+ } catch ( reason ) {
785+ l10n . get ( "loading_error" ) . then ( msg => {
786+ this . _documentError ( msg , reason ) ;
787+ } ) ;
788+ }
690789 } ,
691790
692791 get initialized ( ) {
@@ -768,13 +867,15 @@ const PDFViewerApplication = {
768867 return this . externalServices . supportedMouseWheelZoomModifierKeys ;
769868 } ,
770869
771- initPassiveLoading ( ) {
870+ initPassiveLoading ( file ) {
772871 if (
773872 typeof PDFJSDev === "undefined" ||
774873 ! PDFJSDev . test ( "MOZCENTRAL || CHROME" )
775874 ) {
776875 throw new Error ( "Not implemented: initPassiveLoading" ) ;
777876 }
877+ this . setTitleUsingUrl ( file , /* downloadUrl = */ file ) ;
878+
778879 this . externalServices . initPassiveLoading ( {
779880 onOpenWithTransport : range => {
780881 this . open ( { range } ) ;
@@ -2197,106 +2298,6 @@ function reportPageStatsPDFBug({ pageNumber }) {
21972298 globalThis . Stats . add ( pageNumber , pageView ?. pdfPage ?. stats ) ;
21982299}
21992300
2200- function webViewerInitialized ( ) {
2201- const { appConfig, eventBus, l10n } = PDFViewerApplication ;
2202- let file ;
2203- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2204- const queryString = document . location . search . substring ( 1 ) ;
2205- const params = parseQueryString ( queryString ) ;
2206- file = params . get ( "file" ) ?? AppOptions . get ( "defaultUrl" ) ;
2207- validateFileURL ( file ) ;
2208- } else if ( PDFJSDev . test ( "MOZCENTRAL" ) ) {
2209- file = window . location . href ;
2210- } else if ( PDFJSDev . test ( "CHROME" ) ) {
2211- file = AppOptions . get ( "defaultUrl" ) ;
2212- }
2213-
2214- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2215- const fileInput = appConfig . openFileInput ;
2216- fileInput . value = null ;
2217-
2218- fileInput . addEventListener ( "change" , function ( evt ) {
2219- const { files } = evt . target ;
2220- if ( ! files || files . length === 0 ) {
2221- return ;
2222- }
2223- eventBus . dispatch ( "fileinputchange" , {
2224- source : this ,
2225- fileInput : evt . target ,
2226- } ) ;
2227- } ) ;
2228-
2229- // Enable dragging-and-dropping a new PDF file onto the viewerContainer.
2230- appConfig . mainContainer . addEventListener ( "dragover" , function ( evt ) {
2231- evt . preventDefault ( ) ;
2232-
2233- evt . dataTransfer . dropEffect =
2234- evt . dataTransfer . effectAllowed === "copy" ? "copy" : "move" ;
2235- } ) ;
2236- appConfig . mainContainer . addEventListener ( "drop" , function ( evt ) {
2237- evt . preventDefault ( ) ;
2238-
2239- const { files } = evt . dataTransfer ;
2240- if ( ! files || files . length === 0 ) {
2241- return ;
2242- }
2243- eventBus . dispatch ( "fileinputchange" , {
2244- source : this ,
2245- fileInput : evt . dataTransfer ,
2246- } ) ;
2247- } ) ;
2248- }
2249-
2250- if ( ! PDFViewerApplication . supportsDocumentFonts ) {
2251- AppOptions . set ( "disableFontFace" , true ) ;
2252- l10n . get ( "web_fonts_disabled" ) . then ( msg => {
2253- console . warn ( msg ) ;
2254- } ) ;
2255- }
2256-
2257- if ( ! PDFViewerApplication . supportsPrinting ) {
2258- appConfig . toolbar ?. print ?. classList . add ( "hidden" ) ;
2259- appConfig . secondaryToolbar ?. printButton . classList . add ( "hidden" ) ;
2260- }
2261-
2262- if ( ! PDFViewerApplication . supportsFullscreen ) {
2263- appConfig . secondaryToolbar ?. presentationModeButton . classList . add ( "hidden" ) ;
2264- }
2265-
2266- if ( PDFViewerApplication . supportsIntegratedFind ) {
2267- appConfig . toolbar ?. viewFind ?. classList . add ( "hidden" ) ;
2268- }
2269-
2270- appConfig . mainContainer . addEventListener (
2271- "transitionend" ,
2272- function ( evt ) {
2273- if ( evt . target === /* mainContainer */ this ) {
2274- eventBus . dispatch ( "resize" , { source : this } ) ;
2275- }
2276- } ,
2277- true
2278- ) ;
2279-
2280- try {
2281- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2282- if ( file ) {
2283- PDFViewerApplication . open ( { url : file } ) ;
2284- } else {
2285- PDFViewerApplication . _hideViewBookmark ( ) ;
2286- }
2287- } else if ( PDFJSDev . test ( "MOZCENTRAL || CHROME" ) ) {
2288- PDFViewerApplication . setTitleUsingUrl ( file , /* downloadUrl = */ file ) ;
2289- PDFViewerApplication . initPassiveLoading ( ) ;
2290- } else {
2291- throw new Error ( "Not implemented: webViewerInitialized" ) ;
2292- }
2293- } catch ( reason ) {
2294- l10n . get ( "loading_error" ) . then ( msg => {
2295- PDFViewerApplication . _documentError ( msg , reason ) ;
2296- } ) ;
2297- }
2298- }
2299-
23002301function webViewerPageRender ( { pageNumber } ) {
23012302 // If the page is (the most) visible when it starts rendering,
23022303 // ensure that the page number input loading indicator is displayed.
0 commit comments