Merge pull request #10470 from Snuffleupagus/mozcentral-streams
Try to, completely, avoid loading the `ReadableStream` polyfill in MOZCENTRAL builds
This commit is contained in:
commit
66acc7397f
19
extensions/firefox/content/streams_polyfill.js
Normal file
19
extensions/firefox/content/streams_polyfill.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* Copyright 2018 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (typeof ReadableStream === "undefined") {
|
||||||
|
require("../../../src/shared/global_scope").ReadableStream =
|
||||||
|
require("../../../external/streams/streams-lib").ReadableStream;
|
||||||
|
}
|
12
gulpfile.js
12
gulpfile.js
@ -766,6 +766,16 @@ function preprocessDefaultPreferences(content) {
|
|||||||
content + '\n');
|
content + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createMozcentralStreamsPolyfillBundle(defines) {
|
||||||
|
var streamsPolyfillOutputName = 'streams_polyfill.js';
|
||||||
|
|
||||||
|
var streamsPolyfillFileConfig = createWebpackConfig(defines, {
|
||||||
|
filename: streamsPolyfillOutputName,
|
||||||
|
});
|
||||||
|
return gulp.src('./extensions/firefox/content/streams_polyfill.js')
|
||||||
|
.pipe(webpack2Stream(streamsPolyfillFileConfig));
|
||||||
|
}
|
||||||
|
|
||||||
gulp.task('mozcentral-pre', gulp.series('buildnumber', 'locale', function () {
|
gulp.task('mozcentral-pre', gulp.series('buildnumber', 'locale', function () {
|
||||||
console.log();
|
console.log();
|
||||||
console.log('### Building mozilla-central extension');
|
console.log('### Building mozilla-central extension');
|
||||||
@ -787,6 +797,8 @@ gulp.task('mozcentral-pre', gulp.series('buildnumber', 'locale', function () {
|
|||||||
return merge([
|
return merge([
|
||||||
createBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'build')),
|
createBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'build')),
|
||||||
createWebBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'web')),
|
createWebBundle(defines).pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'web')),
|
||||||
|
createMozcentralStreamsPolyfillBundle(defines)
|
||||||
|
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'build')),
|
||||||
gulp.src(COMMON_WEB_FILES, { base: 'web/', })
|
gulp.src(COMMON_WEB_FILES, { base: 'web/', })
|
||||||
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'web')),
|
.pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + 'web')),
|
||||||
gulp.src(['external/bcmaps/*.bcmap', 'external/bcmaps/LICENSE'],
|
gulp.src(['external/bcmaps/*.bcmap', 'external/bcmaps/LICENSE'],
|
||||||
|
12
src/pdf.worker.js
vendored
12
src/pdf.worker.js
vendored
@ -12,13 +12,17 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint-disable no-unused-vars */
|
/* eslint-disable no-restricted-globals, no-unused-vars */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
|
if (PDFJSDev.test('MOZCENTRAL') && typeof ReadableStream === 'undefined') {
|
||||||
var pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
|
importScripts('./streams_polyfill.js');
|
||||||
|
}
|
||||||
|
|
||||||
var pdfjsCoreWorker = require('./core/worker.js');
|
const pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION');
|
||||||
|
const pdfjsBuild = PDFJSDev.eval('BUNDLE_BUILD');
|
||||||
|
|
||||||
|
const pdfjsCoreWorker = require('./core/worker.js');
|
||||||
|
|
||||||
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
|
exports.WorkerMessageHandler = pdfjsCoreWorker.WorkerMessageHandler;
|
||||||
|
@ -14,8 +14,15 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable no-restricted-globals */
|
/* eslint-disable no-restricted-globals */
|
||||||
|
|
||||||
let isReadableStreamSupported = false;
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('MOZCENTRAL')) {
|
||||||
if (typeof ReadableStream !== 'undefined') {
|
// On the main-thread the `streams_polyfill.js` file is loaded using a
|
||||||
|
// <script> tag; see `web/viewer-snippet-firefox-extension.html`.
|
||||||
|
// On the worker-thread the `streams_polyfill.js` file is (conditionally)
|
||||||
|
// loaded using `importScripts`; see `src/pdf.worker.js`.
|
||||||
|
exports.ReadableStream = ReadableStream;
|
||||||
|
} else {
|
||||||
|
let isReadableStreamSupported = false;
|
||||||
|
if (typeof ReadableStream !== 'undefined') {
|
||||||
// MS Edge may say it has ReadableStream but they are not up to spec yet.
|
// MS Edge may say it has ReadableStream but they are not up to spec yet.
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-new
|
// eslint-disable-next-line no-new
|
||||||
@ -28,11 +35,11 @@ if (typeof ReadableStream !== 'undefined') {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// The ReadableStream constructor cannot be used.
|
// The ReadableStream constructor cannot be used.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isReadableStreamSupported) {
|
if (isReadableStreamSupported) {
|
||||||
exports.ReadableStream = ReadableStream;
|
exports.ReadableStream = ReadableStream;
|
||||||
} else {
|
} else if (typeof PDFJSDev !== 'undefined' &&
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
PDFJSDev.test('IMAGE_DECODERS')) {
|
||||||
class DummyReadableStream {
|
class DummyReadableStream {
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new Error('The current image decoders are synchronous, ' +
|
throw new Error('The current image decoders are synchronous, ' +
|
||||||
|
@ -32,8 +32,8 @@ if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
|||||||
|
|
||||||
if (isURLSupported) {
|
if (isURLSupported) {
|
||||||
exports.URL = URL;
|
exports.URL = URL;
|
||||||
} else {
|
} else if (typeof PDFJSDev !== 'undefined' &&
|
||||||
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('IMAGE_DECODERS')) {
|
PDFJSDev.test('IMAGE_DECODERS')) {
|
||||||
class DummyURL {
|
class DummyURL {
|
||||||
constructor() {
|
constructor() {
|
||||||
throw new Error('The current image decoders doesn\'t utilize the ' +
|
throw new Error('The current image decoders doesn\'t utilize the ' +
|
||||||
@ -59,5 +59,4 @@ if (typeof PDFJSDev !== 'undefined' && !PDFJSDev.test('GENERIC')) {
|
|||||||
}
|
}
|
||||||
exports.URL = PolyfillURL;
|
exports.URL = PolyfillURL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
<!-- This snippet is used in the Firefox extension (included from viewer.html) -->
|
<!-- This snippet is used in the Firefox extension (included from viewer.html) -->
|
||||||
<base href="resource://pdf.js/web/">
|
<base href="resource://pdf.js/web/">
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
if (typeof ReadableStream === "undefined") {
|
||||||
|
document.write("<script src=\"../build/streams_polyfill.js\"><\/script>");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
<script src="../build/pdf.js"></script>
|
<script src="../build/pdf.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user