pdfjs-dist 2.0.487 → 2.1.266

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.

Files changed (161) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +15564 -9476
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +46644 -36309
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/external/url/url-lib.js +627 -0
  9. package/image_decoders/pdf.image_decoders.js +11430 -0
  10. package/image_decoders/pdf.image_decoders.js.map +1 -0
  11. package/image_decoders/pdf.image_decoders.min.js +1 -0
  12. package/lib/core/annotation.js +406 -131
  13. package/lib/core/arithmetic_decoder.js +275 -245
  14. package/lib/core/bidi.js +65 -6
  15. package/lib/core/ccitt.js +173 -18
  16. package/lib/core/ccitt_stream.js +15 -6
  17. package/lib/core/cff_parser.js +376 -53
  18. package/lib/core/charsets.js +5 -4
  19. package/lib/core/chunked_stream.js +387 -149
  20. package/lib/core/cmap.js +310 -75
  21. package/lib/core/colorspace.js +874 -594
  22. package/lib/core/crypto.js +290 -45
  23. package/lib/core/document.js +545 -260
  24. package/lib/core/encodings.js +19 -10
  25. package/lib/core/evaluator.js +725 -147
  26. package/lib/core/font_renderer.js +360 -91
  27. package/lib/core/fonts.js +791 -186
  28. package/lib/core/function.js +284 -71
  29. package/lib/core/glyphlist.js +3 -2
  30. package/lib/core/image.js +168 -61
  31. package/lib/core/jbig2.js +479 -66
  32. package/lib/core/jbig2_stream.js +19 -8
  33. package/lib/core/jpeg_stream.js +38 -13
  34. package/lib/core/jpg.js +252 -29
  35. package/lib/core/jpx.js +396 -6
  36. package/lib/core/jpx_stream.js +18 -6
  37. package/lib/core/metrics.js +4 -4
  38. package/lib/core/murmurhash3.js +24 -6
  39. package/lib/core/obj.js +1137 -475
  40. package/lib/core/operator_list.js +108 -6
  41. package/lib/core/parser.js +321 -68
  42. package/lib/core/pattern.js +145 -13
  43. package/lib/core/pdf_manager.js +321 -133
  44. package/lib/core/primitives.js +75 -22
  45. package/lib/core/ps_parser.js +134 -45
  46. package/lib/core/standard_fonts.js +10 -10
  47. package/lib/core/stream.js +313 -34
  48. package/lib/core/type1_parser.js +143 -13
  49. package/lib/core/unicode.js +31 -4
  50. package/lib/core/worker.js +210 -66
  51. package/lib/display/annotation_layer.js +361 -123
  52. package/lib/display/api.js +1454 -729
  53. package/lib/display/api_compatibility.js +11 -13
  54. package/lib/display/canvas.js +324 -29
  55. package/lib/display/content_disposition.js +83 -32
  56. package/lib/display/dom_utils.js +226 -41
  57. package/lib/display/fetch_stream.js +208 -84
  58. package/lib/display/font_loader.js +465 -236
  59. package/lib/display/metadata.js +38 -16
  60. package/lib/display/network.js +216 -51
  61. package/lib/display/network_utils.js +32 -19
  62. package/lib/display/node_stream.js +352 -169
  63. package/lib/display/pattern_helper.js +58 -7
  64. package/lib/display/svg.js +242 -29
  65. package/lib/display/text_layer.js +132 -18
  66. package/lib/display/transport_stream.js +171 -42
  67. package/lib/display/webgl.js +64 -18
  68. package/lib/display/worker_options.js +5 -4
  69. package/lib/display/xml_parser.js +166 -53
  70. package/lib/examples/node/domstubs.js +57 -4
  71. package/lib/pdf.js +21 -4
  72. package/lib/pdf.worker.js +5 -3
  73. package/lib/shared/compatibility.js +158 -564
  74. package/lib/shared/global_scope.js +2 -2
  75. package/lib/shared/is_node.js +4 -4
  76. package/lib/shared/message_handler.js +521 -0
  77. package/lib/shared/streams_polyfill.js +21 -17
  78. package/lib/shared/url_polyfill.js +56 -0
  79. package/lib/shared/util.js +295 -650
  80. package/lib/test/unit/annotation_spec.js +629 -345
  81. package/lib/test/unit/api_spec.js +555 -253
  82. package/lib/test/unit/bidi_spec.js +7 -7
  83. package/lib/test/unit/cff_parser_spec.js +40 -11
  84. package/lib/test/unit/clitests_helper.js +9 -7
  85. package/lib/test/unit/cmap_spec.js +80 -26
  86. package/lib/test/unit/colorspace_spec.js +99 -52
  87. package/lib/test/unit/crypto_spec.js +17 -5
  88. package/lib/test/unit/custom_spec.js +41 -53
  89. package/lib/test/unit/display_svg_spec.js +33 -17
  90. package/lib/test/unit/document_spec.js +3 -3
  91. package/lib/test/unit/dom_utils_spec.js +9 -9
  92. package/lib/test/unit/encodings_spec.js +25 -45
  93. package/lib/test/unit/evaluator_spec.js +34 -9
  94. package/lib/test/unit/function_spec.js +17 -5
  95. package/lib/test/unit/jasmine-boot.js +31 -18
  96. package/lib/test/unit/{util_stream_spec.js → message_handler_spec.js} +41 -69
  97. package/lib/test/unit/metadata_spec.js +71 -11
  98. package/lib/test/unit/murmurhash3_spec.js +3 -3
  99. package/lib/test/unit/network_spec.js +20 -5
  100. package/lib/test/unit/network_utils_spec.js +41 -14
  101. package/lib/test/unit/node_stream_spec.js +51 -27
  102. package/lib/test/unit/parser_spec.js +35 -8
  103. package/lib/test/unit/pdf_find_controller_spec.js +230 -0
  104. package/lib/test/unit/pdf_find_utils_spec.js +63 -0
  105. package/lib/test/unit/pdf_history_spec.js +21 -9
  106. package/lib/test/unit/primitives_spec.js +24 -4
  107. package/lib/test/unit/stream_spec.js +12 -4
  108. package/lib/test/unit/test_utils.js +90 -27
  109. package/lib/test/unit/testreporter.js +21 -3
  110. package/lib/test/unit/type1_parser_spec.js +8 -6
  111. package/lib/test/unit/ui_utils_spec.js +452 -14
  112. package/lib/test/unit/unicode_spec.js +14 -11
  113. package/lib/test/unit/util_spec.js +131 -9
  114. package/lib/web/annotation_layer_builder.js +39 -22
  115. package/lib/web/app.js +1240 -582
  116. package/lib/web/app_options.js +71 -41
  117. package/lib/web/base_viewer.js +508 -179
  118. package/lib/web/chromecom.js +261 -117
  119. package/lib/web/debugger.js +166 -22
  120. package/lib/web/download_manager.js +31 -13
  121. package/lib/web/firefox_print_service.js +17 -9
  122. package/lib/web/firefoxcom.js +283 -79
  123. package/lib/web/genericcom.js +89 -30
  124. package/lib/web/genericl10n.js +142 -30
  125. package/lib/web/grab_to_pan.js +26 -4
  126. package/lib/web/interfaces.js +170 -47
  127. package/lib/web/overlay_manager.js +235 -85
  128. package/lib/web/password_prompt.js +21 -13
  129. package/lib/web/pdf_attachment_viewer.js +38 -18
  130. package/lib/web/pdf_cursor_tools.js +39 -16
  131. package/lib/web/pdf_document_properties.js +80 -30
  132. package/lib/web/pdf_find_bar.js +84 -40
  133. package/lib/web/pdf_find_controller.js +495 -184
  134. package/lib/web/pdf_find_utils.js +111 -0
  135. package/lib/web/pdf_history.js +190 -53
  136. package/lib/web/pdf_link_service.js +137 -76
  137. package/lib/web/pdf_outline_viewer.js +73 -22
  138. package/lib/web/pdf_page_view.js +196 -63
  139. package/lib/web/pdf_presentation_mode.js +99 -34
  140. package/lib/web/pdf_print_service.js +57 -11
  141. package/lib/web/pdf_rendering_queue.js +27 -5
  142. package/lib/web/pdf_sidebar.js +120 -67
  143. package/lib/web/pdf_sidebar_resizer.js +42 -16
  144. package/lib/web/pdf_single_page_viewer.js +74 -66
  145. package/lib/web/pdf_thumbnail_view.js +103 -32
  146. package/lib/web/pdf_thumbnail_viewer.js +64 -24
  147. package/lib/web/pdf_viewer.component.js +112 -32
  148. package/lib/web/pdf_viewer.js +91 -52
  149. package/lib/web/preferences.js +275 -80
  150. package/lib/web/secondary_toolbar.js +165 -40
  151. package/lib/web/text_layer_builder.js +162 -65
  152. package/lib/web/toolbar.js +78 -43
  153. package/lib/web/ui_utils.js +462 -136
  154. package/lib/web/view_history.js +215 -67
  155. package/lib/web/viewer_compatibility.js +4 -13
  156. package/package.json +5 -4
  157. package/web/pdf_viewer.css +58 -1
  158. package/web/pdf_viewer.js +6346 -3919
  159. package/web/pdf_viewer.js.map +1 -1
  160. package/lib/test/unit/fonts_spec.js +0 -81
  161. 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 2017 Mozilla Foundation
5
+ * Copyright 2018 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
- 'use strict';
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 : {};
@@ -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 2017 Mozilla Foundation
5
+ * Copyright 2018 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
- 'use strict';
22
+ "use strict";
23
23
 
24
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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 === 'undefined' ? 'undefined' : _typeof(process)) === 'object' && process + '' === '[object process]';
27
+ return (typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && process + '' === '[object process]' && !process.versions['nw'];
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 2018 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");
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, this);
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 2017 Mozilla Foundation
5
+ * Copyright 2018 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
- 'use strict';
22
+ "use strict";
23
23
 
24
- var isReadableStreamSupported = false;
25
- if (typeof ReadableStream !== 'undefined') {
26
- try {
27
- new ReadableStream({
28
- start: function start(controller) {
29
- controller.close();
30
- }
31
- });
32
- isReadableStreamSupported = true;
33
- } catch (e) {}
34
- }
35
- if (isReadableStreamSupported) {
36
- exports.ReadableStream = ReadableStream;
37
- } else {
38
- exports.ReadableStream = require('../../external/streams/streams-lib').ReadableStream;
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 2018 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
+ }