mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Move the disableCreateObjectURL
option from the global PDFJS
object and into getDocument
instead
This commit is contained in:
parent
05c05bdef5
commit
1d03ad0060
11 changed files with 54 additions and 36 deletions
|
@ -13,13 +13,18 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createObjectURL, createValidAbsoluteUrl, PDFJS } from 'pdfjs-lib';
|
||||
import {
|
||||
apiCompatibilityParams, createObjectURL, createValidAbsoluteUrl
|
||||
} from 'pdfjs-lib';
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('CHROME || GENERIC')) {
|
||||
throw new Error('Module "pdfjs-web/download_manager" shall not be used ' +
|
||||
'outside CHROME and GENERIC builds.');
|
||||
}
|
||||
|
||||
const DISABLE_CREATE_OBJECT_URL =
|
||||
apiCompatibilityParams.disableCreateObjectURL || false;
|
||||
|
||||
function download(blobUrl, filename) {
|
||||
let a = document.createElement('a');
|
||||
if (!a.click) {
|
||||
|
@ -40,6 +45,10 @@ function download(blobUrl, filename) {
|
|||
}
|
||||
|
||||
class DownloadManager {
|
||||
constructor({ disableCreateObjectURL = DISABLE_CREATE_OBJECT_URL, }) {
|
||||
this.disableCreateObjectURL = disableCreateObjectURL;
|
||||
}
|
||||
|
||||
downloadUrl(url, filename) {
|
||||
if (!createValidAbsoluteUrl(url, 'http://example.com')) {
|
||||
return; // restricted/invalid URL
|
||||
|
@ -53,7 +62,7 @@ class DownloadManager {
|
|||
filename);
|
||||
}
|
||||
let blobUrl = createObjectURL(data, contentType,
|
||||
PDFJS.disableCreateObjectURL);
|
||||
this.disableCreateObjectURL);
|
||||
download(blobUrl, filename);
|
||||
}
|
||||
|
||||
|
@ -66,7 +75,7 @@ class DownloadManager {
|
|||
return;
|
||||
}
|
||||
|
||||
if (PDFJS.disableCreateObjectURL) {
|
||||
if (this.disableCreateObjectURL) {
|
||||
// URL.createObjectURL is not supported
|
||||
this.downloadUrl(url, filename);
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue