mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Limit PDFFetchStream to http(s) in the Chrome extension
The `fetch` API is only supported for http(s), even in Chrome extensions. Because of this limitation, we should use the XMLHttpRequest API when the requested URL is not a http(s) URL. Fixes #9361
This commit is contained in:
parent
a7cb560f17
commit
1c8cacd6b9
3 changed files with 51 additions and 17 deletions
|
@ -83,15 +83,25 @@ if (typeof PDFJSDev !== 'undefined' &&
|
|||
}) : null;
|
||||
}
|
||||
|
||||
/** @type IPDFStream */
|
||||
var PDFNetworkStream;
|
||||
/**
|
||||
* @typedef {function} IPDFStreamFactory
|
||||
* @param {DocumentInitParameters} params The document initialization
|
||||
* parameters. The "url" key is always present.
|
||||
* @return {IPDFStream}
|
||||
*/
|
||||
|
||||
/** @type IPDFStreamFactory */
|
||||
var createPDFNetworkStream;
|
||||
|
||||
/**
|
||||
* Sets PDFNetworkStream class to be used as alternative PDF data transport.
|
||||
* @param {IPDFStream} cls - the PDF data transport.
|
||||
* Sets the function that instantiates a IPDFStream as an alternative PDF data
|
||||
* transport.
|
||||
* @param {IPDFStreamFactory} pdfNetworkStreamFactory - the factory function
|
||||
* that takes document initialization parameters (including a "url") and returns
|
||||
* an instance of IPDFStream.
|
||||
*/
|
||||
function setPDFNetworkStreamClass(cls) {
|
||||
PDFNetworkStream = cls;
|
||||
function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) {
|
||||
createPDFNetworkStream = pdfNetworkStreamFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -252,7 +262,7 @@ function getDocument(src) {
|
|||
if (rangeTransport) {
|
||||
networkStream = new PDFDataTransportStream(params, rangeTransport);
|
||||
} else if (!params.data) {
|
||||
networkStream = new PDFNetworkStream(params);
|
||||
networkStream = createPDFNetworkStream(params);
|
||||
}
|
||||
|
||||
var messageHandler = new MessageHandler(docId, workerId, worker.port);
|
||||
|
@ -2344,7 +2354,7 @@ export {
|
|||
PDFWorker,
|
||||
PDFDocumentProxy,
|
||||
PDFPageProxy,
|
||||
setPDFNetworkStreamClass,
|
||||
setPDFNetworkStreamFactory,
|
||||
version,
|
||||
build,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue