Skip to content

Commit

Permalink
Merge pull request mozilla#9385 from Snuffleupagus/rm-SINGLE_FILE
Browse files Browse the repository at this point in the history
[api-major] Remove the `SINGLE_FILE` build target and the `PDFJS.disableWorker` option
  • Loading branch information
Snuffleupagus authored Feb 2, 2018
2 parents f4426bb + f8d83b7 commit 2ed4128
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 106 deletions.
3 changes: 0 additions & 3 deletions examples/browserify/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ var pdfPath = '../helloworld/helloworld.pdf';
// Setting worker path to worker bundle.
PDFJS.workerSrc = '../../build/browserify/pdf.worker.bundle.js';

// It is also possible to disable workers via `PDFJS.disableWorker = true`,
// however that might degrade the UI performance in web browsers.

// Loading a document.
var loadingTask = PDFJS.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
Expand Down
7 changes: 0 additions & 7 deletions examples/learning/helloworld.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ <h1>'Hello, world!' example</h1>
//
var url = './helloworld.pdf';

//
// Disable workers to avoid yet another cross-origin issue (workers need
// the URL of the script to be loaded, and dynamically loading a cross-origin
// script does not work).
//
// PDFJS.disableWorker = true;

//
// The workerSrc property shall be specified.
//
Expand Down
6 changes: 0 additions & 6 deletions examples/learning/helloworld64.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ <h1>'Hello, world!' example</h1>
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');

// Disable workers to avoid yet another cross-origin issue (workers need
// the URL of the script to be loaded, and dynamically loading a cross-origin
// script does not work).
//
// PDFJS.disableWorker = true;

//
// The workerSrc property shall be specified.
//
Expand Down
8 changes: 0 additions & 8 deletions examples/learning/prevnext.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ <h1>'Previous/Next' example</h1>
//
var url = '../../web/compressed.tracemonkey-pldi-09.pdf';


//
// Disable workers to avoid yet another cross-origin issue (workers need
// the URL of the script to be loaded, and dynamically loading a cross-origin
// script does not work).
//
// PDFJS.disableWorker = true;

//
// In cases when the pdf.worker.js is located at the different folder than the
// pdf.js's one, or the pdf.js is executed via eval(), the workerSrc property
Expand Down
3 changes: 0 additions & 3 deletions examples/webpack/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ var pdfPath = '../helloworld/helloworld.pdf';
// Setting worker path to worker bundle.
pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';

// It is also possible to disable workers via `PDFJS.disableWorker = true`,
// however that might degrade the UI performance in web browsers.

// Loading a document.
var loadingTask = pdfjsLib.getDocument(pdfPath);
loadingTask.promise.then(function (pdfDocument) {
Expand Down
2 changes: 0 additions & 2 deletions external/dist/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ var PdfjsWorker = require('worker-loader!./build/pdf.worker.js');

if (typeof window !== 'undefined' && 'Worker' in window) {
pdfjs.PDFJS.workerPort = new PdfjsWorker();
} else {
pdfjs.PDFJS.disableWorker = true;
}

module.exports = pdfjs;
27 changes: 1 addition & 26 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ var BASELINE_DIR = BUILD_DIR + 'baseline/';
var MOZCENTRAL_BASELINE_DIR = BUILD_DIR + 'mozcentral.baseline/';
var GENERIC_DIR = BUILD_DIR + 'generic/';
var COMPONENTS_DIR = BUILD_DIR + 'components/';
var SINGLE_FILE_DIR = BUILD_DIR + 'singlefile/';
var MINIFIED_DIR = BUILD_DIR + 'minified/';
var FIREFOX_BUILD_DIR = BUILD_DIR + 'firefox/';
var CHROME_BUILD_DIR = BUILD_DIR + 'chromium/';
Expand Down Expand Up @@ -79,7 +78,6 @@ var DEFINES = {
MOZCENTRAL: false,
CHROME: false,
MINIFIED: false,
SINGLE_FILE: false,
COMPONENTS: false,
LIB: false,
SKIP_BABEL: false,
Expand Down Expand Up @@ -235,10 +233,6 @@ function createBundle(defines) {

var mainAMDName = 'pdfjs-dist/build/pdf';
var mainOutputName = 'pdf.js';
if (defines.SINGLE_FILE) {
mainAMDName = 'pdfjs-dist/build/pdf.combined';
mainOutputName = 'pdf.combined.js';
}

var mainFileConfig = createWebpackConfig(defines, {
filename: mainOutputName,
Expand All @@ -250,9 +244,6 @@ function createBundle(defines) {
.pipe(webpack2Stream(mainFileConfig))
.pipe(replaceWebpackRequire())
.pipe(replaceJSRootName(mainAMDName));
if (defines.SINGLE_FILE) {
return mainOutput; // don't need a worker file.
}

var workerAMDName = 'pdfjs-dist/build/pdf.worker';
var workerOutputName = 'pdf.worker.js';
Expand Down Expand Up @@ -634,18 +625,6 @@ gulp.task('components', ['buildnumber'], function () {
]);
});

gulp.task('singlefile', ['buildnumber'], function () {
console.log();
console.log('### Creating singlefile build');
var defines = builder.merge(DEFINES, { SINGLE_FILE: true, });

var SINGLE_FILE_BUILD_DIR = SINGLE_FILE_DIR + 'build/';

rimraf.sync(SINGLE_FILE_DIR);

return createBundle(defines).pipe(gulp.dest(SINGLE_FILE_BUILD_DIR));
});

gulp.task('minified-pre', ['buildnumber', 'locale'], function () {
console.log();
console.log('### Creating minified viewer');
Expand Down Expand Up @@ -1275,9 +1254,7 @@ gulp.task('gh-pages-git', ['gh-pages-prepare', 'wintersmith'], function () {

gulp.task('web', ['gh-pages-prepare', 'wintersmith', 'gh-pages-git']);

gulp.task('dist-pre',
['generic', 'singlefile', 'components', 'lib', 'minified'],
function () {
gulp.task('dist-pre', ['generic', 'components', 'lib', 'minified'], function() {
var VERSION = getVersionJSON().version;

console.log();
Expand Down Expand Up @@ -1359,8 +1336,6 @@ gulp.task('dist-pre',
GENERIC_DIR + 'build/pdf.js.map',
GENERIC_DIR + 'build/pdf.worker.js',
GENERIC_DIR + 'build/pdf.worker.js.map',
SINGLE_FILE_DIR + 'build/pdf.combined.js',
SINGLE_FILE_DIR + 'build/pdf.combined.js.map',
SRC_DIR + 'pdf.worker.entry.js',
]).pipe(gulp.dest(DIST_DIR + 'build/')),
gulp.src(MINIFIED_DIR + 'build/pdf.js')
Expand Down
53 changes: 34 additions & 19 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ var pdfjsFilePath =

var fakeWorkerFilesLoader = null;
var useRequireEnsure = false;
if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('GENERIC && !SINGLE_FILE')) {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
// For GENERIC build we need add support of different fake file loaders
// for different frameworks.
if (typeof window === 'undefined') {
Expand Down Expand Up @@ -1217,39 +1216,52 @@ var PDFWorker = (function PDFWorkerClosure() {
throw new Error('No PDFJS.workerSrc specified');
}

function getMainThreadWorkerMessageHandler() {
if (typeof window === 'undefined') {
return null;
}
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
return (window.pdfjsNonProductionPdfWorker &&
window.pdfjsNonProductionPdfWorker.WorkerMessageHandler);
}
// PRODUCTION
return (window.pdfjsDistBuildPdfWorker &&
window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
}

let fakeWorkerFilesLoadedCapability;

// Loads worker code into main thread.
function setupFakeWorkerGlobal() {
var WorkerMessageHandler;
if (fakeWorkerFilesLoadedCapability) {
return fakeWorkerFilesLoadedCapability.promise;
}
fakeWorkerFilesLoadedCapability = createPromiseCapability();
// In the developer build load worker_loader which in turn loads all the

let mainWorkerMessageHandler = getMainThreadWorkerMessageHandler();
if (mainWorkerMessageHandler) {
// The worker was already loaded using a `<script>` tag.
fakeWorkerFilesLoadedCapability.resolve(mainWorkerMessageHandler);
return fakeWorkerFilesLoadedCapability.promise;
}
// In the developer build load worker_loader.js which in turn loads all the
// other files and resolves the promise. In production only the
// pdf.worker.js file is needed.
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
if (typeof SystemJS === 'object') {
SystemJS.import('pdfjs/core/worker').then((worker) => {
WorkerMessageHandler = worker.WorkerMessageHandler;
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
fakeWorkerFilesLoadedCapability.resolve(worker.WorkerMessageHandler);
});
} else if (typeof require === 'function') {
var worker = require('../core/worker.js');
WorkerMessageHandler = worker.WorkerMessageHandler;
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
let worker = require('../core/worker.js');
fakeWorkerFilesLoadedCapability.resolve(worker.WorkerMessageHandler);
} else {
throw new Error(
'SystemJS or CommonJS must be used to load fake worker.');
}
} else if (PDFJSDev.test('SINGLE_FILE')) {
var pdfjsCoreWorker = require('../core/worker.js');
WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
} else {
var loader = fakeWorkerFilesLoader || function (callback) {
Util.loadScript(getWorkerSrc(), function () {
let loader = fakeWorkerFilesLoader || function(callback) {
Util.loadScript(getWorkerSrc(), function() {
callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler);
});
};
Expand Down Expand Up @@ -1320,9 +1332,8 @@ var PDFWorker = (function PDFWorkerClosure() {
// all requirements to run parts of pdf.js in a web worker.
// Right now, the requirement is, that an Uint8Array is still an
// Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
if ((typeof PDFJSDev === 'undefined' || !PDFJSDev.test('SINGLE_FILE')) &&
!isWorkerDisabled && !getDefaultSetting('disableWorker') &&
typeof Worker !== 'undefined') {
if (typeof Worker !== 'undefined' && !isWorkerDisabled &&
!getMainThreadWorkerMessageHandler()) {
var workerSrc = getWorkerSrc();

try {
Expand Down Expand Up @@ -1433,7 +1444,7 @@ var PDFWorker = (function PDFWorkerClosure() {
},

_setupFakeWorker: function PDFWorker_setupFakeWorker() {
if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) {
if (!isWorkerDisabled) {
warn('Setting up fake worker.');
isWorkerDisabled = true;
}
Expand Down Expand Up @@ -1491,6 +1502,10 @@ var PDFWorker = (function PDFWorkerClosure() {
return new PDFWorker(null, port);
};

PDFWorker.getWorkerSrc = function() {
return getWorkerSrc();
};

return PDFWorker;
})();

Expand Down
2 changes: 0 additions & 2 deletions src/display/dom_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ function getDefaultSetting(id) {
return globalSettings ? globalSettings.workerPort : null;
case 'workerSrc':
return globalSettings ? globalSettings.workerSrc : null;
case 'disableWorker':
return globalSettings ? globalSettings.disableWorker : false;
case 'maxImageSize':
return globalSettings ? globalSettings.maxImageSize : -1;
case 'imageResourcesPath':
Expand Down
12 changes: 1 addition & 11 deletions src/display/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
'' : PDFJS.imageResourcesPath);

/**
* Disable the web worker and run all code on the main thread. This will
* happen automatically if the browser doesn't support workers or sending
* typed arrays to workers.
* @var {boolean}
*/
PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
false : PDFJS.disableWorker);

/**
* Path and filename of the worker file. Required when the worker is enabled
* in development mode. If unspecified in the production build, the worker
Expand All @@ -148,8 +139,7 @@ PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);

/**
* Defines global port for worker process. Overrides workerSrc and
* disableWorker setting.
* Defines global port for worker process. Overrides `workerSrc` setting.
*/
PDFJS.workerPort = (PDFJS.workerPort === undefined ? null : PDFJS.workerPort);

Expand Down
3 changes: 1 addition & 2 deletions src/display/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ var SVGGraphics = function() {
throw new Error('Not implemented: SVGGraphics');
};

if (typeof PDFJSDev === 'undefined' ||
PDFJSDev.test('GENERIC || SINGLE_FILE')) {
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {

var SVG_DEFAULTS = {
fontStyle: 'normal',
Expand Down
5 changes: 2 additions & 3 deletions src/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var pdfjsDisplayAnnotationLayer = require('./display/annotation_layer.js');
var pdfjsDisplayDOMUtils = require('./display/dom_utils.js');
var pdfjsDisplaySVG = require('./display/svg.js');

if (typeof PDFJSDev === 'undefined' ||
!PDFJSDev.test('FIREFOX || MOZCENTRAL || CHROME')) {
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
const isNodeJS = require('./shared/is_node.js');
if (isNodeJS()) {
let PDFNodeStream = require('./display/node_stream.js').PDFNodeStream;
Expand All @@ -43,7 +42,7 @@ if (typeof PDFJSDev === 'undefined' ||
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
return new PDFFetchStream(params);
});
} else {
} else {
let PDFNetworkStream = require('./display/network.js').PDFNetworkStream;
pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => {
return new PDFNetworkStream(params);
Expand Down
23 changes: 13 additions & 10 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
DOMCanvasFactory, RenderingCancelledException
} from '../../src/display/dom_utils';
import {
getDocument, PDFDocumentProxy, PDFPageProxy
getDocument, PDFDocumentProxy, PDFPageProxy, PDFWorker
} from '../../src/display/api';
import isNodeJS from '../../src/shared/is_node';
import { PDFJS } from '../../src/display/global';
Expand Down Expand Up @@ -122,16 +122,14 @@ describe('api', function() {
path: TEST_PDFS_PATH.node + basicApiFileName,
});
} else {
var nonBinaryRequest = PDFJS.disableWorker;
var request = new XMLHttpRequest();
let nonBinaryRequest = false;
let request = new XMLHttpRequest();
request.open('GET', TEST_PDFS_PATH.dom + basicApiFileName, false);
if (!nonBinaryRequest) {
try {
request.responseType = 'arraybuffer';
nonBinaryRequest = request.responseType !== 'arraybuffer';
} catch (e) {
nonBinaryRequest = true;
}
try {
request.responseType = 'arraybuffer';
nonBinaryRequest = request.responseType !== 'arraybuffer';
} catch (e) {
nonBinaryRequest = true;
}
if (nonBinaryRequest && request.overrideMimeType) {
request.overrideMimeType('text/plain; charset=x-user-defined');
Expand Down Expand Up @@ -405,6 +403,11 @@ describe('api', function() {
done.fail(reason);
});
});
it('gets current workerSrc', function() {
let workerSrc = PDFWorker.getWorkerSrc();
expect(typeof workerSrc).toEqual('string');
expect(workerSrc).toEqual(PDFJS.workerSrc);
});
});
describe('PDFDocument', function() {
var loadingTask;
Expand Down
Loading

0 comments on commit 2ed4128

Please sign in to comment.