pdfjs-dist 2.0.489 → 2.2.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfjs-dist might be problematic. Click here for more details.
- package/CODE_OF_CONDUCT.md +15 -0
- package/bower.json +1 -1
- package/build/pdf.js +18515 -11402
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +1 -1
- package/build/pdf.worker.js +48266 -37137
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +1 -1
- package/external/url/url-lib.js +627 -0
- package/image_decoders/pdf.image_decoders.js +11350 -0
- package/image_decoders/pdf.image_decoders.js.map +1 -0
- package/image_decoders/pdf.image_decoders.min.js +1 -0
- package/lib/core/annotation.js +587 -242
- package/lib/core/arithmetic_decoder.js +275 -245
- package/lib/core/bidi.js +65 -6
- package/lib/core/ccitt.js +173 -18
- package/lib/core/ccitt_stream.js +15 -6
- package/lib/core/cff_parser.js +433 -61
- package/lib/core/charsets.js +5 -4
- package/lib/core/chunked_stream.js +400 -152
- package/lib/core/cmap.js +326 -87
- package/lib/core/colorspace.js +874 -594
- package/lib/core/core_utils.js +147 -0
- package/lib/core/crypto.js +290 -45
- package/lib/core/document.js +560 -268
- package/lib/core/encodings.js +19 -10
- package/lib/core/evaluator.js +1005 -360
- package/lib/core/font_renderer.js +331 -97
- package/lib/core/fonts.js +812 -195
- package/lib/core/function.js +284 -71
- package/lib/core/glyphlist.js +4 -3
- package/lib/core/image.js +169 -62
- package/lib/core/image_utils.js +111 -0
- package/lib/core/jbig2.js +479 -66
- package/lib/core/jbig2_stream.js +19 -8
- package/lib/core/jpeg_stream.js +38 -13
- package/lib/core/jpg.js +253 -29
- package/lib/core/jpx.js +396 -6
- package/lib/core/jpx_stream.js +18 -6
- package/lib/core/metrics.js +15 -15
- package/lib/core/murmurhash3.js +56 -34
- package/lib/core/obj.js +1354 -488
- package/lib/core/operator_list.js +144 -31
- package/lib/core/parser.js +539 -191
- package/lib/core/pattern.js +148 -14
- package/lib/core/pdf_manager.js +323 -133
- package/lib/core/primitives.js +111 -24
- package/lib/core/ps_parser.js +134 -45
- package/lib/core/standard_fonts.js +17 -17
- package/lib/core/stream.js +313 -34
- package/lib/core/type1_parser.js +143 -13
- package/lib/core/unicode.js +32 -5
- package/lib/core/worker.js +217 -190
- package/lib/core/worker_stream.js +277 -0
- package/lib/display/annotation_layer.js +450 -133
- package/lib/display/api.js +1597 -784
- package/lib/display/api_compatibility.js +11 -13
- package/lib/display/canvas.js +360 -44
- package/lib/display/content_disposition.js +83 -32
- package/lib/display/display_utils.js +747 -0
- package/lib/display/fetch_stream.js +221 -90
- package/lib/display/font_loader.js +468 -236
- package/lib/display/metadata.js +38 -16
- package/lib/display/network.js +635 -428
- package/lib/display/network_utils.js +32 -19
- package/lib/display/node_stream.js +367 -175
- package/lib/display/pattern_helper.js +81 -31
- package/lib/display/svg.js +1235 -519
- package/lib/display/text_layer.js +153 -29
- package/lib/display/transport_stream.js +345 -94
- package/lib/display/webgl.js +64 -18
- package/lib/display/worker_options.js +5 -4
- package/lib/display/xml_parser.js +166 -53
- package/lib/examples/node/domstubs.js +60 -4
- package/lib/pdf.js +36 -14
- package/lib/pdf.worker.js +5 -3
- package/lib/shared/compatibility.js +158 -564
- package/lib/shared/global_scope.js +2 -2
- package/lib/shared/is_node.js +4 -4
- package/lib/shared/message_handler.js +521 -0
- package/lib/shared/streams_polyfill.js +21 -17
- package/lib/shared/url_polyfill.js +56 -0
- package/lib/shared/util.js +243 -710
- package/lib/test/unit/annotation_spec.js +870 -401
- package/lib/test/unit/api_spec.js +657 -345
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +54 -11
- package/lib/test/unit/clitests_helper.js +10 -8
- package/lib/test/unit/cmap_spec.js +95 -41
- package/lib/test/unit/colorspace_spec.js +115 -63
- package/lib/test/unit/core_utils_spec.js +191 -0
- package/lib/test/unit/crypto_spec.js +17 -5
- package/lib/test/unit/custom_spec.js +43 -55
- package/lib/test/unit/display_svg_spec.js +34 -18
- package/lib/test/unit/display_utils_spec.js +273 -0
- package/lib/test/unit/document_spec.js +8 -13
- package/lib/test/unit/encodings_spec.js +25 -45
- package/lib/test/unit/evaluator_spec.js +38 -15
- package/lib/test/unit/fetch_stream_spec.js +109 -0
- package/lib/test/unit/function_spec.js +17 -5
- package/lib/test/unit/jasmine-boot.js +33 -20
- package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
- package/lib/test/unit/metadata_spec.js +71 -11
- package/lib/test/unit/murmurhash3_spec.js +3 -3
- package/lib/test/unit/network_spec.js +19 -54
- package/lib/test/unit/network_utils_spec.js +91 -14
- package/lib/test/unit/node_stream_spec.js +56 -32
- package/lib/test/unit/parser_spec.js +162 -71
- package/lib/test/unit/pdf_find_controller_spec.js +230 -0
- package/lib/test/unit/pdf_find_utils_spec.js +63 -0
- package/lib/test/unit/pdf_history_spec.js +21 -9
- package/lib/test/unit/primitives_spec.js +53 -20
- package/lib/test/unit/stream_spec.js +12 -4
- package/lib/test/unit/test_utils.js +273 -56
- package/lib/test/unit/testreporter.js +21 -3
- package/lib/test/unit/type1_parser_spec.js +8 -6
- package/lib/test/unit/ui_utils_spec.js +454 -16
- package/lib/test/unit/unicode_spec.js +18 -15
- package/lib/test/unit/util_spec.js +87 -128
- package/lib/web/annotation_layer_builder.js +39 -22
- package/lib/web/app.js +1290 -588
- package/lib/web/app_options.js +100 -62
- package/lib/web/base_viewer.js +511 -182
- package/lib/web/chromecom.js +261 -117
- package/lib/web/debugger.js +166 -22
- package/lib/web/download_manager.js +32 -13
- package/lib/web/firefox_print_service.js +20 -10
- package/lib/web/firefoxcom.js +315 -80
- package/lib/web/genericcom.js +89 -30
- package/lib/web/genericl10n.js +142 -30
- package/lib/web/grab_to_pan.js +28 -4
- package/lib/web/interfaces.js +170 -47
- package/lib/web/overlay_manager.js +235 -85
- package/lib/web/password_prompt.js +22 -14
- package/lib/web/pdf_attachment_viewer.js +38 -18
- package/lib/web/pdf_cursor_tools.js +39 -16
- package/lib/web/pdf_document_properties.js +255 -136
- package/lib/web/pdf_find_bar.js +84 -40
- package/lib/web/pdf_find_controller.js +495 -184
- package/lib/web/pdf_find_utils.js +111 -0
- package/lib/web/pdf_history.js +190 -53
- package/lib/web/pdf_link_service.js +138 -77
- package/lib/web/pdf_outline_viewer.js +122 -46
- package/lib/web/pdf_page_view.js +191 -67
- package/lib/web/pdf_presentation_mode.js +99 -34
- package/lib/web/pdf_print_service.js +61 -13
- package/lib/web/pdf_rendering_queue.js +28 -9
- package/lib/web/pdf_sidebar.js +141 -81
- package/lib/web/pdf_sidebar_resizer.js +42 -16
- package/lib/web/pdf_single_page_viewer.js +74 -66
- package/lib/web/pdf_thumbnail_view.js +104 -33
- package/lib/web/pdf_thumbnail_viewer.js +66 -26
- package/lib/web/pdf_viewer.component.js +112 -32
- package/lib/web/pdf_viewer.js +91 -52
- package/lib/web/preferences.js +284 -89
- package/lib/web/secondary_toolbar.js +165 -40
- package/lib/web/text_layer_builder.js +134 -59
- package/lib/web/toolbar.js +78 -43
- package/lib/web/ui_utils.js +462 -136
- package/lib/web/view_history.js +215 -67
- package/lib/web/viewer_compatibility.js +4 -13
- package/package.json +5 -4
- package/web/pdf_viewer.css +79 -11
- package/web/pdf_viewer.js +6107 -3748
- package/web/pdf_viewer.js.map +1 -1
- package/lib/display/dom_utils.js +0 -309
- package/lib/test/unit/dom_utils_spec.js +0 -89
- package/lib/test/unit/fonts_spec.js +0 -81
- package/lib/web/dom_events.js +0 -137
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,6 +19,6 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
24
|
module.exports = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : {};
|
package/lib/shared/is_node.js
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,10 +19,10 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
|
24
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
25
25
|
|
26
26
|
module.exports = function isNodeJS() {
|
27
|
-
return (typeof process ===
|
27
|
+
return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process + '' === '[object process]' && !process.versions['nw'] && !process.versions['electron'];
|
28
28
|
};
|
@@ -0,0 +1,521 @@
|
|
1
|
+
/**
|
2
|
+
* @licstart The following is the entire license notice for the
|
3
|
+
* Javascript code in this page
|
4
|
+
*
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
* @licend The above is the entire license notice for the
|
20
|
+
* Javascript code in this page
|
21
|
+
*/
|
22
|
+
"use strict";
|
23
|
+
|
24
|
+
Object.defineProperty(exports, "__esModule", {
|
25
|
+
value: true
|
26
|
+
});
|
27
|
+
exports.MessageHandler = MessageHandler;
|
28
|
+
|
29
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
30
|
+
|
31
|
+
var _util = require("./util");
|
32
|
+
|
33
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
34
|
+
|
35
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
36
|
+
|
37
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
38
|
+
|
39
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
40
|
+
|
41
|
+
function resolveCall(_x, _x2) {
|
42
|
+
return _resolveCall.apply(this, arguments);
|
43
|
+
}
|
44
|
+
|
45
|
+
function _resolveCall() {
|
46
|
+
_resolveCall = _asyncToGenerator(
|
47
|
+
/*#__PURE__*/
|
48
|
+
_regenerator["default"].mark(function _callee(fn, args) {
|
49
|
+
var thisArg,
|
50
|
+
_args = arguments;
|
51
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
52
|
+
while (1) {
|
53
|
+
switch (_context.prev = _context.next) {
|
54
|
+
case 0:
|
55
|
+
thisArg = _args.length > 2 && _args[2] !== undefined ? _args[2] : null;
|
56
|
+
|
57
|
+
if (fn) {
|
58
|
+
_context.next = 3;
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
|
62
|
+
return _context.abrupt("return", undefined);
|
63
|
+
|
64
|
+
case 3:
|
65
|
+
return _context.abrupt("return", fn.apply(thisArg, args));
|
66
|
+
|
67
|
+
case 4:
|
68
|
+
case "end":
|
69
|
+
return _context.stop();
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}, _callee);
|
73
|
+
}));
|
74
|
+
return _resolveCall.apply(this, arguments);
|
75
|
+
}
|
76
|
+
|
77
|
+
function wrapReason(reason) {
|
78
|
+
if (_typeof(reason) !== 'object') {
|
79
|
+
return reason;
|
80
|
+
}
|
81
|
+
|
82
|
+
switch (reason.name) {
|
83
|
+
case 'AbortException':
|
84
|
+
return new _util.AbortException(reason.message);
|
85
|
+
|
86
|
+
case 'MissingPDFException':
|
87
|
+
return new _util.MissingPDFException(reason.message);
|
88
|
+
|
89
|
+
case 'UnexpectedResponseException':
|
90
|
+
return new _util.UnexpectedResponseException(reason.message, reason.status);
|
91
|
+
|
92
|
+
default:
|
93
|
+
return new _util.UnknownErrorException(reason.message, reason.details);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
function makeReasonSerializable(reason) {
|
98
|
+
if (!(reason instanceof Error) || reason instanceof _util.AbortException || reason instanceof _util.MissingPDFException || reason instanceof _util.UnexpectedResponseException || reason instanceof _util.UnknownErrorException) {
|
99
|
+
return reason;
|
100
|
+
}
|
101
|
+
|
102
|
+
return new _util.UnknownErrorException(reason.message, reason.toString());
|
103
|
+
}
|
104
|
+
|
105
|
+
function resolveOrReject(capability, success, reason) {
|
106
|
+
if (success) {
|
107
|
+
capability.resolve();
|
108
|
+
} else {
|
109
|
+
capability.reject(reason);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
function finalize(promise) {
|
114
|
+
return Promise.resolve(promise)["catch"](function () {});
|
115
|
+
}
|
116
|
+
|
117
|
+
function MessageHandler(sourceName, targetName, comObj) {
|
118
|
+
var _this = this;
|
119
|
+
|
120
|
+
this.sourceName = sourceName;
|
121
|
+
this.targetName = targetName;
|
122
|
+
this.comObj = comObj;
|
123
|
+
this.callbackId = 1;
|
124
|
+
this.streamId = 1;
|
125
|
+
this.postMessageTransfers = true;
|
126
|
+
this.streamSinks = Object.create(null);
|
127
|
+
this.streamControllers = Object.create(null);
|
128
|
+
var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
|
129
|
+
var ah = this.actionHandler = Object.create(null);
|
130
|
+
|
131
|
+
this._onComObjOnMessage = function (event) {
|
132
|
+
var data = event.data;
|
133
|
+
|
134
|
+
if (data.targetName !== _this.sourceName) {
|
135
|
+
return;
|
136
|
+
}
|
137
|
+
|
138
|
+
if (data.stream) {
|
139
|
+
_this._processStreamMessage(data);
|
140
|
+
} else if (data.isReply) {
|
141
|
+
var callbackId = data.callbackId;
|
142
|
+
|
143
|
+
if (data.callbackId in callbacksCapabilities) {
|
144
|
+
var callback = callbacksCapabilities[callbackId];
|
145
|
+
delete callbacksCapabilities[callbackId];
|
146
|
+
|
147
|
+
if ('error' in data) {
|
148
|
+
callback.reject(wrapReason(data.error));
|
149
|
+
} else {
|
150
|
+
callback.resolve(data.data);
|
151
|
+
}
|
152
|
+
} else {
|
153
|
+
throw new Error("Cannot resolve callback ".concat(callbackId));
|
154
|
+
}
|
155
|
+
} else if (data.action in ah) {
|
156
|
+
var action = ah[data.action];
|
157
|
+
|
158
|
+
if (data.callbackId) {
|
159
|
+
var _sourceName = _this.sourceName;
|
160
|
+
var _targetName = data.sourceName;
|
161
|
+
Promise.resolve().then(function () {
|
162
|
+
return action[0].call(action[1], data.data);
|
163
|
+
}).then(function (result) {
|
164
|
+
comObj.postMessage({
|
165
|
+
sourceName: _sourceName,
|
166
|
+
targetName: _targetName,
|
167
|
+
isReply: true,
|
168
|
+
callbackId: data.callbackId,
|
169
|
+
data: result
|
170
|
+
});
|
171
|
+
}, function (reason) {
|
172
|
+
comObj.postMessage({
|
173
|
+
sourceName: _sourceName,
|
174
|
+
targetName: _targetName,
|
175
|
+
isReply: true,
|
176
|
+
callbackId: data.callbackId,
|
177
|
+
error: makeReasonSerializable(reason)
|
178
|
+
});
|
179
|
+
});
|
180
|
+
} else if (data.streamId) {
|
181
|
+
_this._createStreamSink(data);
|
182
|
+
} else {
|
183
|
+
action[0].call(action[1], data.data);
|
184
|
+
}
|
185
|
+
} else {
|
186
|
+
throw new Error("Unknown action from worker: ".concat(data.action));
|
187
|
+
}
|
188
|
+
};
|
189
|
+
|
190
|
+
comObj.addEventListener('message', this._onComObjOnMessage);
|
191
|
+
}
|
192
|
+
|
193
|
+
MessageHandler.prototype = {
|
194
|
+
on: function on(actionName, handler, scope) {
|
195
|
+
var ah = this.actionHandler;
|
196
|
+
|
197
|
+
if (ah[actionName]) {
|
198
|
+
throw new Error("There is already an actionName called \"".concat(actionName, "\""));
|
199
|
+
}
|
200
|
+
|
201
|
+
ah[actionName] = [handler, scope];
|
202
|
+
},
|
203
|
+
send: function send(actionName, data, transfers) {
|
204
|
+
var message = {
|
205
|
+
sourceName: this.sourceName,
|
206
|
+
targetName: this.targetName,
|
207
|
+
action: actionName,
|
208
|
+
data: data
|
209
|
+
};
|
210
|
+
this.postMessage(message, transfers);
|
211
|
+
},
|
212
|
+
sendWithPromise: function sendWithPromise(actionName, data, transfers) {
|
213
|
+
var callbackId = this.callbackId++;
|
214
|
+
var message = {
|
215
|
+
sourceName: this.sourceName,
|
216
|
+
targetName: this.targetName,
|
217
|
+
action: actionName,
|
218
|
+
data: data,
|
219
|
+
callbackId: callbackId
|
220
|
+
};
|
221
|
+
var capability = (0, _util.createPromiseCapability)();
|
222
|
+
this.callbacksCapabilities[callbackId] = capability;
|
223
|
+
|
224
|
+
try {
|
225
|
+
this.postMessage(message, transfers);
|
226
|
+
} catch (e) {
|
227
|
+
capability.reject(e);
|
228
|
+
}
|
229
|
+
|
230
|
+
return capability.promise;
|
231
|
+
},
|
232
|
+
sendWithStream: function sendWithStream(actionName, data, queueingStrategy, transfers) {
|
233
|
+
var _this2 = this;
|
234
|
+
|
235
|
+
var streamId = this.streamId++;
|
236
|
+
var sourceName = this.sourceName;
|
237
|
+
var targetName = this.targetName;
|
238
|
+
return new _util.ReadableStream({
|
239
|
+
start: function start(controller) {
|
240
|
+
var startCapability = (0, _util.createPromiseCapability)();
|
241
|
+
_this2.streamControllers[streamId] = {
|
242
|
+
controller: controller,
|
243
|
+
startCall: startCapability,
|
244
|
+
isClosed: false
|
245
|
+
};
|
246
|
+
|
247
|
+
_this2.postMessage({
|
248
|
+
sourceName: sourceName,
|
249
|
+
targetName: targetName,
|
250
|
+
action: actionName,
|
251
|
+
streamId: streamId,
|
252
|
+
data: data,
|
253
|
+
desiredSize: controller.desiredSize
|
254
|
+
});
|
255
|
+
|
256
|
+
return startCapability.promise;
|
257
|
+
},
|
258
|
+
pull: function pull(controller) {
|
259
|
+
var pullCapability = (0, _util.createPromiseCapability)();
|
260
|
+
_this2.streamControllers[streamId].pullCall = pullCapability;
|
261
|
+
|
262
|
+
_this2.postMessage({
|
263
|
+
sourceName: sourceName,
|
264
|
+
targetName: targetName,
|
265
|
+
stream: 'pull',
|
266
|
+
streamId: streamId,
|
267
|
+
desiredSize: controller.desiredSize
|
268
|
+
});
|
269
|
+
|
270
|
+
return pullCapability.promise;
|
271
|
+
},
|
272
|
+
cancel: function cancel(reason) {
|
273
|
+
var cancelCapability = (0, _util.createPromiseCapability)();
|
274
|
+
_this2.streamControllers[streamId].cancelCall = cancelCapability;
|
275
|
+
_this2.streamControllers[streamId].isClosed = true;
|
276
|
+
|
277
|
+
_this2.postMessage({
|
278
|
+
sourceName: sourceName,
|
279
|
+
targetName: targetName,
|
280
|
+
stream: 'cancel',
|
281
|
+
reason: reason,
|
282
|
+
streamId: streamId
|
283
|
+
});
|
284
|
+
|
285
|
+
return cancelCapability.promise;
|
286
|
+
}
|
287
|
+
}, queueingStrategy);
|
288
|
+
},
|
289
|
+
_createStreamSink: function _createStreamSink(data) {
|
290
|
+
var _this3 = this;
|
291
|
+
|
292
|
+
var self = this;
|
293
|
+
var action = this.actionHandler[data.action];
|
294
|
+
var streamId = data.streamId;
|
295
|
+
var desiredSize = data.desiredSize;
|
296
|
+
var sourceName = this.sourceName;
|
297
|
+
var targetName = data.sourceName;
|
298
|
+
var capability = (0, _util.createPromiseCapability)();
|
299
|
+
|
300
|
+
var sendStreamRequest = function sendStreamRequest(_ref) {
|
301
|
+
var stream = _ref.stream,
|
302
|
+
chunk = _ref.chunk,
|
303
|
+
transfers = _ref.transfers,
|
304
|
+
success = _ref.success,
|
305
|
+
reason = _ref.reason;
|
306
|
+
|
307
|
+
_this3.postMessage({
|
308
|
+
sourceName: sourceName,
|
309
|
+
targetName: targetName,
|
310
|
+
stream: stream,
|
311
|
+
streamId: streamId,
|
312
|
+
chunk: chunk,
|
313
|
+
success: success,
|
314
|
+
reason: reason
|
315
|
+
}, transfers);
|
316
|
+
};
|
317
|
+
|
318
|
+
var streamSink = {
|
319
|
+
enqueue: function enqueue(chunk) {
|
320
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
321
|
+
var transfers = arguments.length > 2 ? arguments[2] : undefined;
|
322
|
+
|
323
|
+
if (this.isCancelled) {
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
|
327
|
+
var lastDesiredSize = this.desiredSize;
|
328
|
+
this.desiredSize -= size;
|
329
|
+
|
330
|
+
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
331
|
+
this.sinkCapability = (0, _util.createPromiseCapability)();
|
332
|
+
this.ready = this.sinkCapability.promise;
|
333
|
+
}
|
334
|
+
|
335
|
+
sendStreamRequest({
|
336
|
+
stream: 'enqueue',
|
337
|
+
chunk: chunk,
|
338
|
+
transfers: transfers
|
339
|
+
});
|
340
|
+
},
|
341
|
+
close: function close() {
|
342
|
+
if (this.isCancelled) {
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
this.isCancelled = true;
|
347
|
+
sendStreamRequest({
|
348
|
+
stream: 'close'
|
349
|
+
});
|
350
|
+
delete self.streamSinks[streamId];
|
351
|
+
},
|
352
|
+
error: function error(reason) {
|
353
|
+
if (this.isCancelled) {
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
|
357
|
+
this.isCancelled = true;
|
358
|
+
sendStreamRequest({
|
359
|
+
stream: 'error',
|
360
|
+
reason: reason
|
361
|
+
});
|
362
|
+
},
|
363
|
+
sinkCapability: capability,
|
364
|
+
onPull: null,
|
365
|
+
onCancel: null,
|
366
|
+
isCancelled: false,
|
367
|
+
desiredSize: desiredSize,
|
368
|
+
ready: null
|
369
|
+
};
|
370
|
+
streamSink.sinkCapability.resolve();
|
371
|
+
streamSink.ready = streamSink.sinkCapability.promise;
|
372
|
+
this.streamSinks[streamId] = streamSink;
|
373
|
+
resolveCall(action[0], [data.data, streamSink], action[1]).then(function () {
|
374
|
+
sendStreamRequest({
|
375
|
+
stream: 'start_complete',
|
376
|
+
success: true
|
377
|
+
});
|
378
|
+
}, function (reason) {
|
379
|
+
sendStreamRequest({
|
380
|
+
stream: 'start_complete',
|
381
|
+
success: false,
|
382
|
+
reason: reason
|
383
|
+
});
|
384
|
+
});
|
385
|
+
},
|
386
|
+
_processStreamMessage: function _processStreamMessage(data) {
|
387
|
+
var _this4 = this;
|
388
|
+
|
389
|
+
var sourceName = this.sourceName;
|
390
|
+
var targetName = data.sourceName;
|
391
|
+
var streamId = data.streamId;
|
392
|
+
|
393
|
+
var sendStreamResponse = function sendStreamResponse(_ref2) {
|
394
|
+
var stream = _ref2.stream,
|
395
|
+
success = _ref2.success,
|
396
|
+
reason = _ref2.reason;
|
397
|
+
|
398
|
+
_this4.comObj.postMessage({
|
399
|
+
sourceName: sourceName,
|
400
|
+
targetName: targetName,
|
401
|
+
stream: stream,
|
402
|
+
success: success,
|
403
|
+
streamId: streamId,
|
404
|
+
reason: reason
|
405
|
+
});
|
406
|
+
};
|
407
|
+
|
408
|
+
var deleteStreamController = function deleteStreamController() {
|
409
|
+
Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) {
|
410
|
+
return capability && finalize(capability.promise);
|
411
|
+
})).then(function () {
|
412
|
+
delete _this4.streamControllers[data.streamId];
|
413
|
+
});
|
414
|
+
};
|
415
|
+
|
416
|
+
switch (data.stream) {
|
417
|
+
case 'start_complete':
|
418
|
+
resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason));
|
419
|
+
break;
|
420
|
+
|
421
|
+
case 'pull_complete':
|
422
|
+
resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason));
|
423
|
+
break;
|
424
|
+
|
425
|
+
case 'pull':
|
426
|
+
if (!this.streamSinks[data.streamId]) {
|
427
|
+
sendStreamResponse({
|
428
|
+
stream: 'pull_complete',
|
429
|
+
success: true
|
430
|
+
});
|
431
|
+
break;
|
432
|
+
}
|
433
|
+
|
434
|
+
if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) {
|
435
|
+
this.streamSinks[data.streamId].sinkCapability.resolve();
|
436
|
+
}
|
437
|
+
|
438
|
+
this.streamSinks[data.streamId].desiredSize = data.desiredSize;
|
439
|
+
resolveCall(this.streamSinks[data.streamId].onPull).then(function () {
|
440
|
+
sendStreamResponse({
|
441
|
+
stream: 'pull_complete',
|
442
|
+
success: true
|
443
|
+
});
|
444
|
+
}, function (reason) {
|
445
|
+
sendStreamResponse({
|
446
|
+
stream: 'pull_complete',
|
447
|
+
success: false,
|
448
|
+
reason: reason
|
449
|
+
});
|
450
|
+
});
|
451
|
+
break;
|
452
|
+
|
453
|
+
case 'enqueue':
|
454
|
+
(0, _util.assert)(this.streamControllers[data.streamId], 'enqueue should have stream controller');
|
455
|
+
|
456
|
+
if (!this.streamControllers[data.streamId].isClosed) {
|
457
|
+
this.streamControllers[data.streamId].controller.enqueue(data.chunk);
|
458
|
+
}
|
459
|
+
|
460
|
+
break;
|
461
|
+
|
462
|
+
case 'close':
|
463
|
+
(0, _util.assert)(this.streamControllers[data.streamId], 'close should have stream controller');
|
464
|
+
|
465
|
+
if (this.streamControllers[data.streamId].isClosed) {
|
466
|
+
break;
|
467
|
+
}
|
468
|
+
|
469
|
+
this.streamControllers[data.streamId].isClosed = true;
|
470
|
+
this.streamControllers[data.streamId].controller.close();
|
471
|
+
deleteStreamController();
|
472
|
+
break;
|
473
|
+
|
474
|
+
case 'error':
|
475
|
+
(0, _util.assert)(this.streamControllers[data.streamId], 'error should have stream controller');
|
476
|
+
this.streamControllers[data.streamId].controller.error(wrapReason(data.reason));
|
477
|
+
deleteStreamController();
|
478
|
+
break;
|
479
|
+
|
480
|
+
case 'cancel_complete':
|
481
|
+
resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason));
|
482
|
+
deleteStreamController();
|
483
|
+
break;
|
484
|
+
|
485
|
+
case 'cancel':
|
486
|
+
if (!this.streamSinks[data.streamId]) {
|
487
|
+
break;
|
488
|
+
}
|
489
|
+
|
490
|
+
resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () {
|
491
|
+
sendStreamResponse({
|
492
|
+
stream: 'cancel_complete',
|
493
|
+
success: true
|
494
|
+
});
|
495
|
+
}, function (reason) {
|
496
|
+
sendStreamResponse({
|
497
|
+
stream: 'cancel_complete',
|
498
|
+
success: false,
|
499
|
+
reason: reason
|
500
|
+
});
|
501
|
+
});
|
502
|
+
this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason));
|
503
|
+
this.streamSinks[data.streamId].isCancelled = true;
|
504
|
+
delete this.streamSinks[data.streamId];
|
505
|
+
break;
|
506
|
+
|
507
|
+
default:
|
508
|
+
throw new Error('Unexpected stream case');
|
509
|
+
}
|
510
|
+
},
|
511
|
+
postMessage: function postMessage(message, transfers) {
|
512
|
+
if (transfers && this.postMessageTransfers) {
|
513
|
+
this.comObj.postMessage(message, transfers);
|
514
|
+
} else {
|
515
|
+
this.comObj.postMessage(message);
|
516
|
+
}
|
517
|
+
},
|
518
|
+
destroy: function destroy() {
|
519
|
+
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
520
|
+
}
|
521
|
+
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* @licstart The following is the entire license notice for the
|
3
3
|
* Javascript code in this page
|
4
4
|
*
|
5
|
-
* Copyright
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
6
|
*
|
7
7
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
* you may not use this file except in compliance with the License.
|
@@ -19,21 +19,25 @@
|
|
19
19
|
* @licend The above is the entire license notice for the
|
20
20
|
* Javascript code in this page
|
21
21
|
*/
|
22
|
-
|
22
|
+
"use strict";
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
{
|
25
|
+
var isReadableStreamSupported = false;
|
26
|
+
|
27
|
+
if (typeof ReadableStream !== 'undefined') {
|
28
|
+
try {
|
29
|
+
new ReadableStream({
|
30
|
+
start: function start(controller) {
|
31
|
+
controller.close();
|
32
|
+
}
|
33
|
+
});
|
34
|
+
isReadableStreamSupported = true;
|
35
|
+
} catch (e) {}
|
36
|
+
}
|
37
|
+
|
38
|
+
if (isReadableStreamSupported) {
|
39
|
+
exports.ReadableStream = ReadableStream;
|
40
|
+
} else {
|
41
|
+
exports.ReadableStream = require('../../external/streams/streams-lib').ReadableStream;
|
42
|
+
}
|
39
43
|
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/**
|
2
|
+
* @licstart The following is the entire license notice for the
|
3
|
+
* Javascript code in this page
|
4
|
+
*
|
5
|
+
* Copyright 2019 Mozilla Foundation
|
6
|
+
*
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
* you may not use this file except in compliance with the License.
|
9
|
+
* You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
*
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
* See the License for the specific language governing permissions and
|
17
|
+
* limitations under the License.
|
18
|
+
*
|
19
|
+
* @licend The above is the entire license notice for the
|
20
|
+
* Javascript code in this page
|
21
|
+
*/
|
22
|
+
"use strict";
|
23
|
+
|
24
|
+
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
25
|
+
|
26
|
+
{
|
27
|
+
var isURLSupported = false;
|
28
|
+
|
29
|
+
try {
|
30
|
+
if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) {
|
31
|
+
var u = new URL('b', 'http://a');
|
32
|
+
u.pathname = 'c%20d';
|
33
|
+
isURLSupported = u.href === 'http://a/c%20d';
|
34
|
+
}
|
35
|
+
} catch (ex) {}
|
36
|
+
|
37
|
+
if (isURLSupported) {
|
38
|
+
exports.URL = URL;
|
39
|
+
} else {
|
40
|
+
var PolyfillURL = require('../../external/url/url-lib').URL;
|
41
|
+
|
42
|
+
var OriginalURL = require('./global_scope').URL;
|
43
|
+
|
44
|
+
if (OriginalURL) {
|
45
|
+
PolyfillURL.createObjectURL = function (blob) {
|
46
|
+
return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
|
47
|
+
};
|
48
|
+
|
49
|
+
PolyfillURL.revokeObjectURL = function (url) {
|
50
|
+
OriginalURL.revokeObjectURL(url);
|
51
|
+
};
|
52
|
+
}
|
53
|
+
|
54
|
+
exports.URL = PolyfillURL;
|
55
|
+
}
|
56
|
+
}
|