pdfjs-dist 2.2.228 → 2.3.200

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 (84) hide show
  1. package/bower.json +1 -1
  2. package/build/pdf.js +8851 -8582
  3. package/build/pdf.js.map +1 -1
  4. package/build/pdf.min.js +1 -1
  5. package/build/pdf.worker.js +8717 -8394
  6. package/build/pdf.worker.js.map +1 -1
  7. package/build/pdf.worker.min.js +1 -1
  8. package/image_decoders/pdf.image_decoders.js +3014 -2864
  9. package/image_decoders/pdf.image_decoders.js.map +1 -1
  10. package/image_decoders/pdf.image_decoders.min.js +1 -1
  11. package/lib/core/annotation.js +203 -39
  12. package/lib/core/chunked_stream.js +32 -9
  13. package/lib/core/core_utils.js +48 -22
  14. package/lib/core/document.js +44 -33
  15. package/lib/core/evaluator.js +68 -32
  16. package/lib/core/fonts.js +2 -2
  17. package/lib/core/glyphlist.js +1 -0
  18. package/lib/core/image.js +1 -1
  19. package/lib/core/jbig2.js +23 -6
  20. package/lib/core/jpg.js +54 -23
  21. package/lib/core/jpx.js +23 -6
  22. package/lib/core/obj.js +18 -16
  23. package/lib/core/operator_list.js +17 -14
  24. package/lib/core/parser.js +9 -12
  25. package/lib/core/pattern.js +22 -7
  26. package/lib/core/pdf_manager.js +4 -4
  27. package/lib/core/primitives.js +63 -42
  28. package/lib/core/stream.js +14 -0
  29. package/lib/core/type1_parser.js +9 -1
  30. package/lib/core/worker.js +17 -56
  31. package/lib/display/annotation_layer.js +194 -85
  32. package/lib/display/api.js +331 -213
  33. package/lib/display/canvas.js +6 -1
  34. package/lib/display/content_disposition.js +1 -1
  35. package/lib/display/display_utils.js +48 -18
  36. package/lib/display/network_utils.js +6 -0
  37. package/lib/display/pattern_helper.js +22 -5
  38. package/lib/display/svg.js +1 -1
  39. package/lib/display/text_layer.js +62 -53
  40. package/lib/display/xml_parser.js +1 -1
  41. package/lib/pdf.js +2 -3
  42. package/lib/pdf.worker.js +2 -2
  43. package/lib/shared/compatibility.js +23 -19
  44. package/lib/shared/message_handler.js +163 -196
  45. package/lib/shared/streams_polyfill.js +1 -1
  46. package/lib/shared/util.js +288 -196
  47. package/lib/test/unit/annotation_spec.js +687 -93
  48. package/lib/test/unit/api_spec.js +72 -27
  49. package/lib/test/unit/display_utils_spec.js +1 -1
  50. package/lib/test/unit/evaluator_spec.js +21 -5
  51. package/lib/test/unit/fetch_stream_spec.js +3 -1
  52. package/lib/test/unit/message_handler_spec.js +10 -6
  53. package/lib/test/unit/network_spec.js +3 -1
  54. package/lib/test/unit/network_utils_spec.js +14 -0
  55. package/lib/test/unit/node_stream_spec.js +3 -3
  56. package/lib/test/unit/primitives_spec.js +2 -2
  57. package/lib/test/unit/type1_parser_spec.js +1 -1
  58. package/lib/test/unit/ui_utils_spec.js +1 -1
  59. package/lib/test/unit/util_spec.js +10 -10
  60. package/lib/web/app.js +47 -35
  61. package/lib/web/app_options.js +4 -4
  62. package/lib/web/base_viewer.js +36 -12
  63. package/lib/web/chromecom.js +1 -3
  64. package/lib/web/download_manager.js +1 -1
  65. package/lib/web/firefox_print_service.js +7 -4
  66. package/lib/web/firefoxcom.js +10 -5
  67. package/lib/web/interfaces.js +4 -0
  68. package/lib/web/pdf_document_properties.js +1 -1
  69. package/lib/web/pdf_history.js +1 -1
  70. package/lib/web/pdf_link_service.js +7 -3
  71. package/lib/web/pdf_outline_viewer.js +2 -1
  72. package/lib/web/pdf_page_view.js +12 -16
  73. package/lib/web/pdf_print_service.js +3 -5
  74. package/lib/web/pdf_sidebar.js +3 -0
  75. package/lib/web/pdf_viewer.component.js +2 -2
  76. package/lib/web/toolbar.js +2 -0
  77. package/lib/web/ui_utils.js +1 -1
  78. package/package.json +1 -1
  79. package/web/pdf_viewer.css +5 -9
  80. package/web/pdf_viewer.js +60 -45
  81. package/web/pdf_viewer.js.map +1 -1
  82. package/external/streams/streams-lib.js +0 -3962
  83. package/external/url/url-lib.js +0 -627
  84. package/lib/shared/url_polyfill.js +0 -56
@@ -26,53 +26,21 @@ Object.defineProperty(exports, "__esModule", {
26
26
  });
27
27
  exports.MessageHandler = MessageHandler;
28
28
 
29
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
30
-
31
29
  var _util = require("./util");
32
30
 
33
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
34
-
35
31
  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
32
 
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
- }
33
+ var StreamKind = {
34
+ UNKNOWN: 0,
35
+ CANCEL: 1,
36
+ CANCEL_COMPLETE: 2,
37
+ CLOSE: 3,
38
+ ENQUEUE: 4,
39
+ ERROR: 5,
40
+ PULL: 6,
41
+ PULL_COMPLETE: 7,
42
+ START_COMPLETE: 8
43
+ };
76
44
 
77
45
  function wrapReason(reason) {
78
46
  if (_typeof(reason) !== 'object') {
@@ -89,31 +57,14 @@ function wrapReason(reason) {
89
57
  case 'UnexpectedResponseException':
90
58
  return new _util.UnexpectedResponseException(reason.message, reason.status);
91
59
 
92
- default:
60
+ case 'UnknownErrorException':
93
61
  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
62
 
105
- function resolveOrReject(capability, success, reason) {
106
- if (success) {
107
- capability.resolve();
108
- } else {
109
- capability.reject(reason);
63
+ default:
64
+ return new _util.UnknownErrorException(reason.message, reason.toString());
110
65
  }
111
66
  }
112
67
 
113
- function finalize(promise) {
114
- return Promise.resolve(promise)["catch"](function () {});
115
- }
116
-
117
68
  function MessageHandler(sourceName, targetName, comObj) {
118
69
  var _this = this;
119
70
 
@@ -144,8 +95,8 @@ function MessageHandler(sourceName, targetName, comObj) {
144
95
  var callback = callbacksCapabilities[callbackId];
145
96
  delete callbacksCapabilities[callbackId];
146
97
 
147
- if ('error' in data) {
148
- callback.reject(wrapReason(data.error));
98
+ if ('reason' in data) {
99
+ callback.reject(wrapReason(data.reason));
149
100
  } else {
150
101
  callback.resolve(data.data);
151
102
  }
@@ -158,8 +109,8 @@ function MessageHandler(sourceName, targetName, comObj) {
158
109
  if (data.callbackId) {
159
110
  var _sourceName = _this.sourceName;
160
111
  var _targetName = data.sourceName;
161
- Promise.resolve().then(function () {
162
- return action[0].call(action[1], data.data);
112
+ new Promise(function (resolve) {
113
+ resolve(action(data.data));
163
114
  }).then(function (result) {
164
115
  comObj.postMessage({
165
116
  sourceName: _sourceName,
@@ -174,13 +125,13 @@ function MessageHandler(sourceName, targetName, comObj) {
174
125
  targetName: _targetName,
175
126
  isReply: true,
176
127
  callbackId: data.callbackId,
177
- error: makeReasonSerializable(reason)
128
+ reason: wrapReason(reason)
178
129
  });
179
130
  });
180
131
  } else if (data.streamId) {
181
132
  _this._createStreamSink(data);
182
133
  } else {
183
- action[0].call(action[1], data.data);
134
+ action(data.data);
184
135
  }
185
136
  } else {
186
137
  throw new Error("Unknown action from worker: ".concat(data.action));
@@ -191,40 +142,38 @@ function MessageHandler(sourceName, targetName, comObj) {
191
142
  }
192
143
 
193
144
  MessageHandler.prototype = {
194
- on: function on(actionName, handler, scope) {
145
+ on: function on(actionName, handler) {
195
146
  var ah = this.actionHandler;
196
147
 
197
148
  if (ah[actionName]) {
198
149
  throw new Error("There is already an actionName called \"".concat(actionName, "\""));
199
150
  }
200
151
 
201
- ah[actionName] = [handler, scope];
152
+ ah[actionName] = handler;
202
153
  },
203
154
  send: function send(actionName, data, transfers) {
204
- var message = {
155
+ this.postMessage({
205
156
  sourceName: this.sourceName,
206
157
  targetName: this.targetName,
207
158
  action: actionName,
208
159
  data: data
209
- };
210
- this.postMessage(message, transfers);
160
+ }, transfers);
211
161
  },
212
162
  sendWithPromise: function sendWithPromise(actionName, data, transfers) {
213
163
  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
164
  var capability = (0, _util.createPromiseCapability)();
222
165
  this.callbacksCapabilities[callbackId] = capability;
223
166
 
224
167
  try {
225
- this.postMessage(message, transfers);
226
- } catch (e) {
227
- capability.reject(e);
168
+ this.postMessage({
169
+ sourceName: this.sourceName,
170
+ targetName: this.targetName,
171
+ action: actionName,
172
+ callbackId: callbackId,
173
+ data: data
174
+ }, transfers);
175
+ } catch (ex) {
176
+ capability.reject(ex);
228
177
  }
229
178
 
230
179
  return capability.promise;
@@ -235,12 +184,15 @@ MessageHandler.prototype = {
235
184
  var streamId = this.streamId++;
236
185
  var sourceName = this.sourceName;
237
186
  var targetName = this.targetName;
187
+ var comObj = this.comObj;
238
188
  return new _util.ReadableStream({
239
189
  start: function start(controller) {
240
190
  var startCapability = (0, _util.createPromiseCapability)();
241
191
  _this2.streamControllers[streamId] = {
242
192
  controller: controller,
243
193
  startCall: startCapability,
194
+ pullCall: null,
195
+ cancelCall: null,
244
196
  isClosed: false
245
197
  };
246
198
 
@@ -251,44 +203,39 @@ MessageHandler.prototype = {
251
203
  streamId: streamId,
252
204
  data: data,
253
205
  desiredSize: controller.desiredSize
254
- });
206
+ }, transfers);
255
207
 
256
208
  return startCapability.promise;
257
209
  },
258
210
  pull: function pull(controller) {
259
211
  var pullCapability = (0, _util.createPromiseCapability)();
260
212
  _this2.streamControllers[streamId].pullCall = pullCapability;
261
-
262
- _this2.postMessage({
213
+ comObj.postMessage({
263
214
  sourceName: sourceName,
264
215
  targetName: targetName,
265
- stream: 'pull',
216
+ stream: StreamKind.PULL,
266
217
  streamId: streamId,
267
218
  desiredSize: controller.desiredSize
268
219
  });
269
-
270
220
  return pullCapability.promise;
271
221
  },
272
222
  cancel: function cancel(reason) {
223
+ (0, _util.assert)(reason instanceof Error, 'cancel must have a valid reason');
273
224
  var cancelCapability = (0, _util.createPromiseCapability)();
274
225
  _this2.streamControllers[streamId].cancelCall = cancelCapability;
275
226
  _this2.streamControllers[streamId].isClosed = true;
276
-
277
- _this2.postMessage({
227
+ comObj.postMessage({
278
228
  sourceName: sourceName,
279
229
  targetName: targetName,
280
- stream: 'cancel',
281
- reason: reason,
282
- streamId: streamId
230
+ stream: StreamKind.CANCEL,
231
+ streamId: streamId,
232
+ reason: wrapReason(reason)
283
233
  });
284
-
285
234
  return cancelCapability.promise;
286
235
  }
287
236
  }, queueingStrategy);
288
237
  },
289
238
  _createStreamSink: function _createStreamSink(data) {
290
- var _this3 = this;
291
-
292
239
  var self = this;
293
240
  var action = this.actionHandler[data.action];
294
241
  var streamId = data.streamId;
@@ -296,25 +243,7 @@ MessageHandler.prototype = {
296
243
  var sourceName = this.sourceName;
297
244
  var targetName = data.sourceName;
298
245
  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
-
246
+ var comObj = this.comObj;
318
247
  var streamSink = {
319
248
  enqueue: function enqueue(chunk) {
320
249
  var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
@@ -332,11 +261,13 @@ MessageHandler.prototype = {
332
261
  this.ready = this.sinkCapability.promise;
333
262
  }
334
263
 
335
- sendStreamRequest({
336
- stream: 'enqueue',
337
- chunk: chunk,
338
- transfers: transfers
339
- });
264
+ self.postMessage({
265
+ sourceName: sourceName,
266
+ targetName: targetName,
267
+ stream: StreamKind.ENQUEUE,
268
+ streamId: streamId,
269
+ chunk: chunk
270
+ }, transfers);
340
271
  },
341
272
  close: function close() {
342
273
  if (this.isCancelled) {
@@ -344,20 +275,28 @@ MessageHandler.prototype = {
344
275
  }
345
276
 
346
277
  this.isCancelled = true;
347
- sendStreamRequest({
348
- stream: 'close'
278
+ comObj.postMessage({
279
+ sourceName: sourceName,
280
+ targetName: targetName,
281
+ stream: StreamKind.CLOSE,
282
+ streamId: streamId
349
283
  });
350
284
  delete self.streamSinks[streamId];
351
285
  },
352
286
  error: function error(reason) {
287
+ (0, _util.assert)(reason instanceof Error, 'error must have a valid reason');
288
+
353
289
  if (this.isCancelled) {
354
290
  return;
355
291
  }
356
292
 
357
293
  this.isCancelled = true;
358
- sendStreamRequest({
359
- stream: 'error',
360
- reason: reason
294
+ comObj.postMessage({
295
+ sourceName: sourceName,
296
+ targetName: targetName,
297
+ stream: StreamKind.ERROR,
298
+ streamId: streamId,
299
+ reason: wrapReason(reason)
361
300
  });
362
301
  },
363
302
  sinkCapability: capability,
@@ -370,138 +309,166 @@ MessageHandler.prototype = {
370
309
  streamSink.sinkCapability.resolve();
371
310
  streamSink.ready = streamSink.sinkCapability.promise;
372
311
  this.streamSinks[streamId] = streamSink;
373
- resolveCall(action[0], [data.data, streamSink], action[1]).then(function () {
374
- sendStreamRequest({
375
- stream: 'start_complete',
312
+ new Promise(function (resolve) {
313
+ resolve(action(data.data, streamSink));
314
+ }).then(function () {
315
+ comObj.postMessage({
316
+ sourceName: sourceName,
317
+ targetName: targetName,
318
+ stream: StreamKind.START_COMPLETE,
319
+ streamId: streamId,
376
320
  success: true
377
321
  });
378
322
  }, function (reason) {
379
- sendStreamRequest({
380
- stream: 'start_complete',
381
- success: false,
382
- reason: reason
323
+ comObj.postMessage({
324
+ sourceName: sourceName,
325
+ targetName: targetName,
326
+ stream: StreamKind.START_COMPLETE,
327
+ streamId: streamId,
328
+ reason: wrapReason(reason)
383
329
  });
384
330
  });
385
331
  },
386
332
  _processStreamMessage: function _processStreamMessage(data) {
387
- var _this4 = this;
333
+ var _this3 = this;
388
334
 
389
335
  var sourceName = this.sourceName;
390
336
  var targetName = data.sourceName;
391
337
  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
- };
338
+ var comObj = this.comObj;
407
339
 
408
340
  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);
341
+ Promise.all([_this3.streamControllers[streamId].startCall, _this3.streamControllers[streamId].pullCall, _this3.streamControllers[streamId].cancelCall].map(function (capability) {
342
+ return capability && capability.promise["catch"](function () {});
411
343
  })).then(function () {
412
- delete _this4.streamControllers[data.streamId];
344
+ delete _this3.streamControllers[streamId];
413
345
  });
414
346
  };
415
347
 
416
348
  switch (data.stream) {
417
- case 'start_complete':
418
- resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason));
349
+ case StreamKind.START_COMPLETE:
350
+ if (data.success) {
351
+ this.streamControllers[streamId].startCall.resolve();
352
+ } else {
353
+ this.streamControllers[streamId].startCall.reject(wrapReason(data.reason));
354
+ }
355
+
419
356
  break;
420
357
 
421
- case 'pull_complete':
422
- resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason));
358
+ case StreamKind.PULL_COMPLETE:
359
+ if (data.success) {
360
+ this.streamControllers[streamId].pullCall.resolve();
361
+ } else {
362
+ this.streamControllers[streamId].pullCall.reject(wrapReason(data.reason));
363
+ }
364
+
423
365
  break;
424
366
 
425
- case 'pull':
426
- if (!this.streamSinks[data.streamId]) {
427
- sendStreamResponse({
428
- stream: 'pull_complete',
367
+ case StreamKind.PULL:
368
+ if (!this.streamSinks[streamId]) {
369
+ comObj.postMessage({
370
+ sourceName: sourceName,
371
+ targetName: targetName,
372
+ stream: StreamKind.PULL_COMPLETE,
373
+ streamId: streamId,
429
374
  success: true
430
375
  });
431
376
  break;
432
377
  }
433
378
 
434
- if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) {
435
- this.streamSinks[data.streamId].sinkCapability.resolve();
379
+ if (this.streamSinks[streamId].desiredSize <= 0 && data.desiredSize > 0) {
380
+ this.streamSinks[streamId].sinkCapability.resolve();
436
381
  }
437
382
 
438
- this.streamSinks[data.streamId].desiredSize = data.desiredSize;
439
- resolveCall(this.streamSinks[data.streamId].onPull).then(function () {
440
- sendStreamResponse({
441
- stream: 'pull_complete',
383
+ this.streamSinks[streamId].desiredSize = data.desiredSize;
384
+ var onPull = this.streamSinks[data.streamId].onPull;
385
+ new Promise(function (resolve) {
386
+ resolve(onPull && onPull());
387
+ }).then(function () {
388
+ comObj.postMessage({
389
+ sourceName: sourceName,
390
+ targetName: targetName,
391
+ stream: StreamKind.PULL_COMPLETE,
392
+ streamId: streamId,
442
393
  success: true
443
394
  });
444
395
  }, function (reason) {
445
- sendStreamResponse({
446
- stream: 'pull_complete',
447
- success: false,
448
- reason: reason
396
+ comObj.postMessage({
397
+ sourceName: sourceName,
398
+ targetName: targetName,
399
+ stream: StreamKind.PULL_COMPLETE,
400
+ streamId: streamId,
401
+ reason: wrapReason(reason)
449
402
  });
450
403
  });
451
404
  break;
452
405
 
453
- case 'enqueue':
454
- (0, _util.assert)(this.streamControllers[data.streamId], 'enqueue should have stream controller');
406
+ case StreamKind.ENQUEUE:
407
+ (0, _util.assert)(this.streamControllers[streamId], 'enqueue should have stream controller');
455
408
 
456
- if (!this.streamControllers[data.streamId].isClosed) {
457
- this.streamControllers[data.streamId].controller.enqueue(data.chunk);
409
+ if (this.streamControllers[streamId].isClosed) {
410
+ break;
458
411
  }
459
412
 
413
+ this.streamControllers[streamId].controller.enqueue(data.chunk);
460
414
  break;
461
415
 
462
- case 'close':
463
- (0, _util.assert)(this.streamControllers[data.streamId], 'close should have stream controller');
416
+ case StreamKind.CLOSE:
417
+ (0, _util.assert)(this.streamControllers[streamId], 'close should have stream controller');
464
418
 
465
- if (this.streamControllers[data.streamId].isClosed) {
419
+ if (this.streamControllers[streamId].isClosed) {
466
420
  break;
467
421
  }
468
422
 
469
- this.streamControllers[data.streamId].isClosed = true;
470
- this.streamControllers[data.streamId].controller.close();
423
+ this.streamControllers[streamId].isClosed = true;
424
+ this.streamControllers[streamId].controller.close();
471
425
  deleteStreamController();
472
426
  break;
473
427
 
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));
428
+ case StreamKind.ERROR:
429
+ (0, _util.assert)(this.streamControllers[streamId], 'error should have stream controller');
430
+ this.streamControllers[streamId].controller.error(wrapReason(data.reason));
477
431
  deleteStreamController();
478
432
  break;
479
433
 
480
- case 'cancel_complete':
481
- resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason));
434
+ case StreamKind.CANCEL_COMPLETE:
435
+ if (data.success) {
436
+ this.streamControllers[streamId].cancelCall.resolve();
437
+ } else {
438
+ this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
439
+ }
440
+
482
441
  deleteStreamController();
483
442
  break;
484
443
 
485
- case 'cancel':
486
- if (!this.streamSinks[data.streamId]) {
444
+ case StreamKind.CANCEL:
445
+ if (!this.streamSinks[streamId]) {
487
446
  break;
488
447
  }
489
448
 
490
- resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () {
491
- sendStreamResponse({
492
- stream: 'cancel_complete',
449
+ var onCancel = this.streamSinks[data.streamId].onCancel;
450
+ new Promise(function (resolve) {
451
+ resolve(onCancel && onCancel(wrapReason(data.reason)));
452
+ }).then(function () {
453
+ comObj.postMessage({
454
+ sourceName: sourceName,
455
+ targetName: targetName,
456
+ stream: StreamKind.CANCEL_COMPLETE,
457
+ streamId: streamId,
493
458
  success: true
494
459
  });
495
460
  }, function (reason) {
496
- sendStreamResponse({
497
- stream: 'cancel_complete',
498
- success: false,
499
- reason: reason
461
+ comObj.postMessage({
462
+ sourceName: sourceName,
463
+ targetName: targetName,
464
+ stream: StreamKind.CANCEL_COMPLETE,
465
+ streamId: streamId,
466
+ reason: wrapReason(reason)
500
467
  });
501
468
  });
502
- this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason));
503
- this.streamSinks[data.streamId].isCancelled = true;
504
- delete this.streamSinks[data.streamId];
469
+ this.streamSinks[streamId].sinkCapability.reject(wrapReason(data.reason));
470
+ this.streamSinks[streamId].isCancelled = true;
471
+ delete this.streamSinks[streamId];
505
472
  break;
506
473
 
507
474
  default:
@@ -38,6 +38,6 @@
38
38
  if (isReadableStreamSupported) {
39
39
  exports.ReadableStream = ReadableStream;
40
40
  } else {
41
- exports.ReadableStream = require('../../external/streams/streams-lib').ReadableStream;
41
+ exports.ReadableStream = require('web-streams-polyfill/dist/ponyfill').ReadableStream;
42
42
  }
43
43
  }