Re-factor setPDFNetworkStreamFactory, in src/display/api.js, to also accept an asynchronous function
				
					
				
			As part of trying to reduce the usage of SystemJS in the development viewer, this patch is a necessary step that will allow removal of some `require` statements. Currently this uses `SystemJS.import` in non-PRODUCTION mode, but it should be possible to replace those with standard *dynamic* `import` calls in the future.
This commit is contained in:
		
							parent
							
								
									0960e6c0b5
								
							
						
					
					
						commit
						d4d933538b
					
				| @ -65,7 +65,8 @@ const RENDERING_CANCELLED_TIMEOUT = 100; // ms | ||||
|  * @typedef {function} IPDFStreamFactory | ||||
|  * @param {DocumentInitParameters} params - The document initialization | ||||
|  *   parameters. The "url" key is always present. | ||||
|  * @returns {IPDFStream} | ||||
|  * @returns {Promise} A promise, which is resolved with an instance of | ||||
|  *   {IPDFStream}. | ||||
|  * @ignore | ||||
|  */ | ||||
| 
 | ||||
| @ -80,7 +81,7 @@ let createPDFNetworkStream; | ||||
|  * data transport. | ||||
|  * @param {IPDFStreamFactory} pdfNetworkStreamFactory - The factory function | ||||
|  *   that takes document initialization parameters (including a "url") and | ||||
|  *   returns an instance of {IPDFStream}. | ||||
|  *   returns a promise which is resolved with an instance of {IPDFStream}. | ||||
|  * @ignore | ||||
|  */ | ||||
| function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { | ||||
| @ -313,12 +314,14 @@ function getDocument(src) { | ||||
|       if (task.destroyed) { | ||||
|         throw new Error("Loading aborted"); | ||||
|       } | ||||
|       return _fetchDocument(worker, params, rangeTransport, docId).then( | ||||
|         function (workerId) { | ||||
|           if (task.destroyed) { | ||||
|             throw new Error("Loading aborted"); | ||||
|           } | ||||
| 
 | ||||
|       const workerIdPromise = _fetchDocument( | ||||
|         worker, | ||||
|         params, | ||||
|         rangeTransport, | ||||
|         docId | ||||
|       ); | ||||
|       const networkStreamPromise = new Promise(function (resolve) { | ||||
|         let networkStream; | ||||
|         if (rangeTransport) { | ||||
|           networkStream = new PDFDataTransportStream( | ||||
| @ -342,6 +345,14 @@ function getDocument(src) { | ||||
|             disableStream: params.disableStream, | ||||
|           }); | ||||
|         } | ||||
|         resolve(networkStream); | ||||
|       }); | ||||
| 
 | ||||
|       return Promise.all([workerIdPromise, networkStreamPromise]).then( | ||||
|         function ([workerId, networkStream]) { | ||||
|           if (task.destroyed) { | ||||
|             throw new Error("Loading aborted"); | ||||
|           } | ||||
| 
 | ||||
|           const messageHandler = new MessageHandler( | ||||
|             docId, | ||||
|  | ||||
| @ -26,6 +26,12 @@ import { | ||||
|   validateResponseStatus, | ||||
| } from "./network_utils.js"; | ||||
| 
 | ||||
| if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { | ||||
|   throw new Error( | ||||
|     'Module "./fetch_stream.js" shall not be used with MOZCENTRAL builds.' | ||||
|   ); | ||||
| } | ||||
| 
 | ||||
| function createFetchOptions(headers, withCredentials, abortController) { | ||||
|   return { | ||||
|     method: "GET", | ||||
|  | ||||
| @ -14,11 +14,6 @@ | ||||
|  */ | ||||
| /* globals __non_webpack_require__ */ | ||||
| 
 | ||||
| const fs = __non_webpack_require__("fs"); | ||||
| const http = __non_webpack_require__("http"); | ||||
| const https = __non_webpack_require__("https"); | ||||
| const url = __non_webpack_require__("url"); | ||||
| 
 | ||||
| import { | ||||
|   AbortException, | ||||
|   assert, | ||||
| @ -30,6 +25,17 @@ import { | ||||
|   validateRangeRequestCapabilities, | ||||
| } from "./network_utils.js"; | ||||
| 
 | ||||
| if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) { | ||||
|   throw new Error( | ||||
|     'Module "./node_stream.js" shall not be used with MOZCENTRAL builds.' | ||||
|   ); | ||||
| } | ||||
| 
 | ||||
| const fs = __non_webpack_require__("fs"); | ||||
| const http = __non_webpack_require__("http"); | ||||
| const https = __non_webpack_require__("https"); | ||||
| const url = __non_webpack_require__("url"); | ||||
| 
 | ||||
| const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//; | ||||
| 
 | ||||
| function parseUrl(sourceUrl) { | ||||
|  | ||||
							
								
								
									
										19
									
								
								src/pdf.js
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/pdf.js
									
									
									
									
									
								
							| @ -30,7 +30,24 @@ var pdfjsDisplaySVG = require("./display/svg.js"); | ||||
| const pdfjsDisplayWorkerOptions = require("./display/worker_options.js"); | ||||
| const pdfjsDisplayAPICompatibility = require("./display/api_compatibility.js"); | ||||
| 
 | ||||
| if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { | ||||
| if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { | ||||
|   const streamsPromise = Promise.all([ | ||||
|     SystemJS.import("pdfjs/display/network.js"), | ||||
|     SystemJS.import("pdfjs/display/fetch_stream.js"), | ||||
|   ]); | ||||
|   pdfjsDisplayAPI.setPDFNetworkStreamFactory(params => { | ||||
|     return streamsPromise.then(streams => { | ||||
|       const [{ PDFNetworkStream }, { PDFFetchStream }] = streams; | ||||
|       if ( | ||||
|         pdfjsDisplayDisplayUtils.isFetchSupported() && | ||||
|         pdfjsDisplayDisplayUtils.isValidFetchUrl(params.url) | ||||
|       ) { | ||||
|         return new PDFFetchStream(params); | ||||
|       } | ||||
|       return new PDFNetworkStream(params); | ||||
|     }); | ||||
|   }); | ||||
| } else if (PDFJSDev.test("GENERIC")) { | ||||
|   const { isNodeJS } = require("./shared/is_node.js"); | ||||
|   if (isNodeJS) { | ||||
|     const PDFNodeStream = require("./display/node_stream.js").PDFNodeStream; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user