Refactor the DownloadManager
initialization in GENERIC
/CHROME
builds again (PR 8203 follow-up)
In the first commit in PR 8203, I changed how the `DownloadManager` was included/initialized in `GENERIC`/`CHROME` builds. The change was prompted by the fact that you cannot have conditional `import`s with ES6 modules, and I wanted to avoid bundling the general `DownloadManager` into the various Firefox specific build targets. What I completely missed though, is that the new code meant that `download_manager.js` will now be pulling in the *entire* viewer (through `app.js`). This is a *really* stupid mistake on my part, since it causes the `dist/build/pdf_viewer.js` used with the viewer components to now include basically the entire default viewer. The simplest solution that I could come up with, is to add a `genericcom.js` file (similar to the `firefoxcom.js`/`chromecom.js` files) which will be responsible for importing/initializing the `DownloadManager`.
This commit is contained in:
parent
bd0e4dc4e3
commit
594e8c05ef
@ -15,6 +15,7 @@
|
||||
/* globals chrome */
|
||||
|
||||
import { DefaultExternalServices, PDFViewerApplication } from './app';
|
||||
import { DownloadManager } from './download_manager';
|
||||
import { OverlayManager } from './overlay_manager';
|
||||
import { PDFJS } from './pdfjs';
|
||||
import { Preferences } from './preferences';
|
||||
@ -341,6 +342,9 @@ ChromeExternalServices.initPassiveLoading = function (callbacks) {
|
||||
callbacks.onOpenWithURL(url, length, originalURL);
|
||||
});
|
||||
};
|
||||
ChromeExternalServices.createDownloadManager = function() {
|
||||
return new DownloadManager();
|
||||
};
|
||||
PDFViewerApplication.externalServices = ChromeExternalServices;
|
||||
|
||||
export {
|
||||
|
@ -13,10 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
createObjectURL, createValidAbsoluteUrl, PDFJS
|
||||
} from './pdfjs';
|
||||
import { DefaultExternalServices, PDFViewerApplication } from './app';
|
||||
import { createObjectURL, createValidAbsoluteUrl, PDFJS } from './pdfjs';
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('CHROME || GENERIC')) {
|
||||
throw new Error('Module "pdfjs-web/download_manager" shall not be used ' +
|
||||
@ -101,12 +98,6 @@ DownloadManager.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
var GenericExternalServices = Object.create(DefaultExternalServices);
|
||||
GenericExternalServices.createDownloadManager = function () {
|
||||
return new DownloadManager();
|
||||
};
|
||||
PDFViewerApplication.externalServices = GenericExternalServices;
|
||||
|
||||
export {
|
||||
DownloadManager,
|
||||
};
|
||||
|
34
web/genericcom.js
Normal file
34
web/genericcom.js
Normal file
@ -0,0 +1,34 @@
|
||||
/* Copyright 2017 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DefaultExternalServices, PDFViewerApplication } from './app';
|
||||
import { DownloadManager } from './download_manager';
|
||||
|
||||
if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
||||
throw new Error('Module "pdfjs-web/genericcom" shall not be used outside ' +
|
||||
'GENERIC build.');
|
||||
}
|
||||
|
||||
var GenericCom = {};
|
||||
|
||||
var GenericExternalServices = Object.create(DefaultExternalServices);
|
||||
GenericExternalServices.createDownloadManager = function () {
|
||||
return new DownloadManager();
|
||||
};
|
||||
PDFViewerApplication.externalServices = GenericExternalServices;
|
||||
|
||||
export {
|
||||
GenericCom,
|
||||
};
|
@ -45,12 +45,14 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||
window.FirefoxCom = require('./firefoxcom.js').FirefoxCom;
|
||||
require('./firefox_print_service.js');
|
||||
}
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
|
||||
require('./genericcom.js');
|
||||
}
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
|
||||
require('./chromecom.js');
|
||||
}
|
||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME || GENERIC')) {
|
||||
require('./pdf_print_service.js');
|
||||
require('./download_manager.js');
|
||||
}
|
||||
|
||||
function getViewerConfiguration() {
|
||||
@ -172,10 +174,11 @@ function getViewerConfiguration() {
|
||||
function webViewerLoad() {
|
||||
var config = getViewerConfiguration();
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
Promise.all([SystemJS.import('pdfjs-web/app'),
|
||||
SystemJS.import('pdfjs-web/pdf_print_service'),
|
||||
SystemJS.import('pdfjs-web/download_manager')])
|
||||
.then(function (modules) {
|
||||
Promise.all([
|
||||
SystemJS.import('pdfjs-web/app'),
|
||||
SystemJS.import('pdfjs-web/genericcom'),
|
||||
SystemJS.import('pdfjs-web/pdf_print_service'),
|
||||
]).then(function (modules) {
|
||||
var app = modules[0];
|
||||
window.PDFViewerApplication = app.PDFViewerApplication;
|
||||
app.PDFViewerApplication.run(config);
|
||||
|
Loading…
x
Reference in New Issue
Block a user