pdfjs-dist 2.3.200 → 2.4.456
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/README.md +4 -0
- package/bower.json +1 -1
- package/build/pdf.js +6499 -17971
- package/build/pdf.js.map +1 -1
- package/build/pdf.min.js +22 -1
- package/build/pdf.worker.entry.js +5 -3
- package/build/pdf.worker.js +19303 -29896
- package/build/pdf.worker.js.map +1 -1
- package/build/pdf.worker.min.js +22 -1
- package/es5/build/pdf.js +25473 -0
- package/es5/build/pdf.js.map +1 -0
- package/{lib/shared/global_scope.js → es5/build/pdf.worker.entry.js} +5 -10
- package/es5/build/pdf.worker.js +57878 -0
- package/es5/build/pdf.worker.js.map +1 -0
- package/es5/web/images/annotation-check.svg +11 -0
- package/es5/web/images/annotation-comment.svg +16 -0
- package/es5/web/images/annotation-help.svg +26 -0
- package/es5/web/images/annotation-insert.svg +10 -0
- package/es5/web/images/annotation-key.svg +11 -0
- package/es5/web/images/annotation-newparagraph.svg +11 -0
- package/es5/web/images/annotation-noicon.svg +7 -0
- package/es5/web/images/annotation-note.svg +42 -0
- package/es5/web/images/annotation-paragraph.svg +16 -0
- package/es5/web/images/loading-icon.gif +0 -0
- package/es5/web/images/shadow.png +0 -0
- package/es5/web/images/texture.png +0 -0
- package/es5/web/pdf_viewer.css +407 -0
- package/es5/web/pdf_viewer.js +7757 -0
- package/es5/web/pdf_viewer.js.map +1 -0
- package/image_decoders/pdf.image_decoders.js +1333 -4839
- package/image_decoders/pdf.image_decoders.js.map +1 -1
- package/image_decoders/pdf.image_decoders.min.js +22 -1
- package/lib/README.md +7 -0
- package/lib/core/annotation.js +683 -1066
- package/lib/core/arithmetic_decoder.js +81 -97
- package/lib/core/bidi.js +54 -46
- package/lib/core/ccitt.js +88 -81
- package/lib/core/ccitt_stream.js +15 -14
- package/lib/core/cff_parser.js +196 -193
- package/lib/core/charsets.js +4 -4
- package/lib/core/chunked_stream.js +441 -569
- package/lib/core/cmap.js +220 -279
- package/lib/core/colorspace.js +699 -863
- package/lib/core/core_utils.js +59 -80
- package/lib/core/crypto.js +379 -437
- package/lib/core/document.js +564 -673
- package/lib/core/encodings.js +15 -15
- package/lib/core/evaluator.js +983 -889
- package/lib/core/font_renderer.js +128 -171
- package/lib/core/fonts.js +451 -400
- package/lib/core/function.js +289 -285
- package/lib/core/glyphlist.js +4527 -4527
- package/lib/core/image.js +138 -117
- package/lib/core/image_utils.js +46 -63
- package/lib/core/jbig2.js +324 -332
- package/lib/core/jbig2_stream.js +18 -17
- package/lib/core/jpeg_stream.js +133 -24
- package/lib/core/jpg.js +238 -210
- package/lib/core/jpx.js +158 -157
- package/lib/core/jpx_stream.js +28 -28
- package/lib/core/metrics.js +2928 -2928
- package/lib/core/murmurhash3.js +87 -102
- package/lib/core/obj.js +1111 -1302
- package/lib/core/operator_list.js +55 -42
- package/lib/core/parser.js +956 -987
- package/lib/core/pattern.js +69 -69
- package/lib/core/pdf_manager.js +149 -316
- package/lib/core/primitives.js +45 -77
- package/lib/core/ps_parser.js +175 -214
- package/lib/core/standard_fonts.js +237 -236
- package/lib/core/stream.js +83 -77
- package/lib/core/type1_parser.js +78 -68
- package/lib/core/unicode.js +1654 -1654
- package/lib/core/worker.js +148 -196
- package/lib/core/worker_stream.js +101 -210
- package/lib/display/annotation_layer.js +733 -1155
- package/lib/display/api.js +1539 -1928
- package/lib/display/api_compatibility.js +10 -8
- package/lib/display/canvas.js +159 -158
- package/lib/display/content_disposition.js +36 -55
- package/lib/display/display_utils.js +298 -551
- package/lib/display/fetch_stream.js +181 -305
- package/lib/display/font_loader.js +273 -416
- package/lib/display/metadata.js +86 -98
- package/lib/display/network.js +376 -511
- package/lib/display/network_utils.js +20 -19
- package/lib/display/node_stream.js +276 -460
- package/lib/display/pattern_helper.js +76 -44
- package/lib/display/svg.js +1137 -1405
- package/lib/display/text_layer.js +75 -82
- package/lib/display/transport_stream.js +236 -374
- package/lib/display/webgl.js +70 -83
- package/lib/display/worker_options.js +3 -3
- package/lib/display/xml_parser.js +303 -392
- package/lib/examples/node/domstubs.js +37 -37
- package/lib/pdf.js +22 -21
- package/lib/pdf.worker.js +5 -5
- package/lib/shared/compatibility.js +2 -251
- package/lib/shared/is_node.js +7 -6
- package/lib/shared/message_handler.js +222 -194
- package/lib/shared/util.js +269 -405
- package/lib/test/unit/annotation_spec.js +1089 -1014
- package/lib/test/unit/api_spec.js +617 -544
- package/lib/test/unit/bidi_spec.js +7 -7
- package/lib/test/unit/cff_parser_spec.js +63 -62
- package/lib/test/unit/clitests_helper.js +7 -9
- package/lib/test/unit/cmap_spec.js +84 -86
- package/lib/test/unit/colorspace_spec.js +154 -154
- package/lib/test/unit/core_utils_spec.js +125 -105
- package/lib/test/unit/crypto_spec.js +181 -181
- package/lib/test/unit/custom_spec.js +22 -24
- package/lib/test/unit/display_svg_spec.js +35 -36
- package/lib/test/unit/display_utils_spec.js +139 -149
- package/lib/test/unit/document_spec.js +16 -16
- package/lib/test/unit/encodings_spec.js +12 -34
- package/lib/test/unit/evaluator_spec.js +81 -95
- package/lib/test/unit/fetch_stream_spec.js +30 -30
- package/lib/test/unit/function_spec.js +206 -204
- package/lib/test/unit/jasmine-boot.js +48 -32
- package/lib/test/unit/message_handler_spec.js +172 -162
- package/lib/test/unit/metadata_spec.js +69 -69
- package/lib/test/unit/murmurhash3_spec.js +12 -12
- package/lib/test/unit/network_spec.js +12 -12
- package/lib/test/unit/network_utils_spec.js +152 -152
- package/lib/test/unit/node_stream_spec.js +74 -90
- package/lib/test/unit/parser_spec.js +107 -113
- package/lib/test/unit/pdf_find_controller_spec.js +55 -86
- package/lib/test/unit/pdf_find_utils_spec.js +32 -32
- package/lib/test/unit/pdf_history_spec.js +32 -32
- package/lib/test/unit/primitives_spec.js +117 -115
- package/lib/test/unit/stream_spec.js +16 -14
- package/lib/test/unit/test_utils.js +119 -285
- package/lib/test/unit/testreporter.js +19 -19
- package/lib/test/unit/type1_parser_spec.js +41 -41
- package/lib/test/unit/ui_utils_spec.js +318 -426
- package/lib/test/unit/unicode_spec.js +42 -42
- package/lib/test/unit/util_spec.js +122 -143
- package/lib/web/annotation_layer_builder.js +66 -103
- package/lib/web/app.js +1166 -1196
- package/lib/web/app_options.js +61 -77
- package/lib/web/base_viewer.js +804 -850
- package/lib/web/chromecom.js +164 -249
- package/lib/web/debugger.js +149 -205
- package/lib/web/download_manager.js +38 -57
- package/lib/web/firefox_print_service.js +35 -30
- package/lib/web/firefoxcom.js +175 -374
- package/lib/web/genericcom.js +26 -108
- package/lib/web/genericl10n.js +24 -153
- package/lib/web/grab_to_pan.js +30 -30
- package/lib/web/interfaces.js +80 -258
- package/lib/web/overlay_manager.js +70 -246
- package/lib/web/password_prompt.js +38 -64
- package/lib/web/pdf_attachment_viewer.js +105 -130
- package/lib/web/pdf_cursor_tools.js +75 -102
- package/lib/web/pdf_document_properties.js +227 -376
- package/lib/web/pdf_find_bar.js +137 -171
- package/lib/web/pdf_find_controller.js +492 -549
- package/lib/web/pdf_find_utils.js +13 -13
- package/lib/web/pdf_history.js +395 -406
- package/lib/web/pdf_link_service.js +302 -349
- package/lib/web/pdf_outline_viewer.js +148 -209
- package/lib/web/pdf_page_view.js +449 -507
- package/lib/web/pdf_presentation_mode.js +304 -357
- package/lib/web/pdf_print_service.js +90 -104
- package/lib/web/pdf_rendering_queue.js +87 -108
- package/lib/web/pdf_sidebar.js +264 -304
- package/lib/web/pdf_sidebar_resizer.js +92 -119
- package/lib/web/pdf_single_page_viewer.js +77 -126
- package/lib/web/pdf_thumbnail_view.js +276 -297
- package/lib/web/pdf_thumbnail_viewer.js +186 -206
- package/lib/web/pdf_viewer.component.js +20 -21
- package/lib/web/pdf_viewer.js +55 -115
- package/lib/web/preferences.js +66 -273
- package/lib/web/secondary_toolbar.js +164 -196
- package/lib/web/text_layer_builder.js +284 -317
- package/lib/web/toolbar.js +216 -211
- package/lib/web/ui_utils.js +303 -404
- package/lib/web/view_history.js +49 -222
- package/lib/web/viewer_compatibility.js +7 -5
- package/package.json +2 -9
- package/web/pdf_viewer.css +25 -18
- package/web/pdf_viewer.js +3481 -4764
- package/web/pdf_viewer.js.map +1 -1
- package/webpack.js +14 -5
- package/lib/shared/streams_polyfill.js +0 -43
@@ -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 2020 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.
|
@@ -24,13 +24,16 @@
|
|
24
24
|
Object.defineProperty(exports, "__esModule", {
|
25
25
|
value: true
|
26
26
|
});
|
27
|
-
exports.MessageHandler =
|
27
|
+
exports.MessageHandler = void 0;
|
28
28
|
|
29
|
-
var _util = require("./util");
|
29
|
+
var _util = require("./util.js");
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
const CallbackKind = {
|
32
|
+
UNKNOWN: 0,
|
33
|
+
DATA: 1,
|
34
|
+
ERROR: 2
|
35
|
+
};
|
36
|
+
const StreamKind = {
|
34
37
|
UNKNOWN: 0,
|
35
38
|
CANCEL: 1,
|
36
39
|
CANCEL_COMPLETE: 2,
|
@@ -43,21 +46,21 @@ var StreamKind = {
|
|
43
46
|
};
|
44
47
|
|
45
48
|
function wrapReason(reason) {
|
46
|
-
if (
|
49
|
+
if (typeof reason !== "object" || reason === null) {
|
47
50
|
return reason;
|
48
51
|
}
|
49
52
|
|
50
53
|
switch (reason.name) {
|
51
|
-
case
|
54
|
+
case "AbortException":
|
52
55
|
return new _util.AbortException(reason.message);
|
53
56
|
|
54
|
-
case
|
57
|
+
case "MissingPDFException":
|
55
58
|
return new _util.MissingPDFException(reason.message);
|
56
59
|
|
57
|
-
case
|
60
|
+
case "UnexpectedResponseException":
|
58
61
|
return new _util.UnexpectedResponseException(reason.message, reason.status);
|
59
62
|
|
60
|
-
case
|
63
|
+
case "UnknownErrorException":
|
61
64
|
return new _util.UnknownErrorException(reason.message, reason.details);
|
62
65
|
|
63
66
|
default:
|
@@ -65,195 +68,205 @@ function wrapReason(reason) {
|
|
65
68
|
}
|
66
69
|
}
|
67
70
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
71
|
+
class MessageHandler {
|
72
|
+
constructor(sourceName, targetName, comObj) {
|
73
|
+
this.sourceName = sourceName;
|
74
|
+
this.targetName = targetName;
|
75
|
+
this.comObj = comObj;
|
76
|
+
this.callbackId = 1;
|
77
|
+
this.streamId = 1;
|
78
|
+
this.postMessageTransfers = true;
|
79
|
+
this.streamSinks = Object.create(null);
|
80
|
+
this.streamControllers = Object.create(null);
|
81
|
+
this.callbackCapabilities = Object.create(null);
|
82
|
+
this.actionHandler = Object.create(null);
|
83
|
+
|
84
|
+
this._onComObjOnMessage = event => {
|
85
|
+
const data = event.data;
|
86
|
+
|
87
|
+
if (data.targetName !== this.sourceName) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
if (data.stream) {
|
92
|
+
this._processStreamMessage(data);
|
88
93
|
|
89
|
-
|
90
|
-
|
91
|
-
} else if (data.isReply) {
|
92
|
-
var callbackId = data.callbackId;
|
94
|
+
return;
|
95
|
+
}
|
93
96
|
|
94
|
-
if (data.
|
95
|
-
|
96
|
-
|
97
|
+
if (data.callback) {
|
98
|
+
const callbackId = data.callbackId;
|
99
|
+
const capability = this.callbackCapabilities[callbackId];
|
97
100
|
|
98
|
-
if (
|
99
|
-
callback
|
101
|
+
if (!capability) {
|
102
|
+
throw new Error(`Cannot resolve callback ${callbackId}`);
|
103
|
+
}
|
104
|
+
|
105
|
+
delete this.callbackCapabilities[callbackId];
|
106
|
+
|
107
|
+
if (data.callback === CallbackKind.DATA) {
|
108
|
+
capability.resolve(data.data);
|
109
|
+
} else if (data.callback === CallbackKind.ERROR) {
|
110
|
+
capability.reject(wrapReason(data.reason));
|
100
111
|
} else {
|
101
|
-
callback
|
112
|
+
throw new Error("Unexpected callback case");
|
102
113
|
}
|
103
|
-
|
104
|
-
|
114
|
+
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
const action = this.actionHandler[data.action];
|
119
|
+
|
120
|
+
if (!action) {
|
121
|
+
throw new Error(`Unknown action from worker: ${data.action}`);
|
105
122
|
}
|
106
|
-
} else if (data.action in ah) {
|
107
|
-
var action = ah[data.action];
|
108
123
|
|
109
124
|
if (data.callbackId) {
|
110
|
-
|
111
|
-
|
125
|
+
const sourceName = this.sourceName;
|
126
|
+
const targetName = data.sourceName;
|
112
127
|
new Promise(function (resolve) {
|
113
128
|
resolve(action(data.data));
|
114
129
|
}).then(function (result) {
|
115
130
|
comObj.postMessage({
|
116
|
-
sourceName
|
117
|
-
targetName
|
118
|
-
|
131
|
+
sourceName,
|
132
|
+
targetName,
|
133
|
+
callback: CallbackKind.DATA,
|
119
134
|
callbackId: data.callbackId,
|
120
135
|
data: result
|
121
136
|
});
|
122
137
|
}, function (reason) {
|
123
138
|
comObj.postMessage({
|
124
|
-
sourceName
|
125
|
-
targetName
|
126
|
-
|
139
|
+
sourceName,
|
140
|
+
targetName,
|
141
|
+
callback: CallbackKind.ERROR,
|
127
142
|
callbackId: data.callbackId,
|
128
143
|
reason: wrapReason(reason)
|
129
144
|
});
|
130
145
|
});
|
131
|
-
|
132
|
-
_this._createStreamSink(data);
|
133
|
-
} else {
|
134
|
-
action(data.data);
|
146
|
+
return;
|
135
147
|
}
|
136
|
-
} else {
|
137
|
-
throw new Error("Unknown action from worker: ".concat(data.action));
|
138
|
-
}
|
139
|
-
};
|
140
148
|
|
141
|
-
|
142
|
-
|
149
|
+
if (data.streamId) {
|
150
|
+
this._createStreamSink(data);
|
143
151
|
|
144
|
-
|
145
|
-
|
146
|
-
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
|
155
|
+
action(data.data);
|
156
|
+
};
|
157
|
+
|
158
|
+
comObj.addEventListener("message", this._onComObjOnMessage);
|
159
|
+
}
|
160
|
+
|
161
|
+
on(actionName, handler) {
|
162
|
+
const ah = this.actionHandler;
|
147
163
|
|
148
164
|
if (ah[actionName]) {
|
149
|
-
throw new Error(
|
165
|
+
throw new Error(`There is already an actionName called "${actionName}"`);
|
150
166
|
}
|
151
167
|
|
152
168
|
ah[actionName] = handler;
|
153
|
-
}
|
154
|
-
|
155
|
-
|
169
|
+
}
|
170
|
+
|
171
|
+
send(actionName, data, transfers) {
|
172
|
+
this._postMessage({
|
156
173
|
sourceName: this.sourceName,
|
157
174
|
targetName: this.targetName,
|
158
175
|
action: actionName,
|
159
|
-
data
|
176
|
+
data
|
160
177
|
}, transfers);
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
178
|
+
}
|
179
|
+
|
180
|
+
sendWithPromise(actionName, data, transfers) {
|
181
|
+
const callbackId = this.callbackId++;
|
182
|
+
const capability = (0, _util.createPromiseCapability)();
|
183
|
+
this.callbackCapabilities[callbackId] = capability;
|
166
184
|
|
167
185
|
try {
|
168
|
-
this.
|
186
|
+
this._postMessage({
|
169
187
|
sourceName: this.sourceName,
|
170
188
|
targetName: this.targetName,
|
171
189
|
action: actionName,
|
172
|
-
callbackId
|
173
|
-
data
|
190
|
+
callbackId,
|
191
|
+
data
|
174
192
|
}, transfers);
|
175
193
|
} catch (ex) {
|
176
194
|
capability.reject(ex);
|
177
195
|
}
|
178
196
|
|
179
197
|
return capability.promise;
|
180
|
-
}
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
controller: controller,
|
198
|
+
}
|
199
|
+
|
200
|
+
sendWithStream(actionName, data, queueingStrategy, transfers) {
|
201
|
+
const streamId = this.streamId++;
|
202
|
+
const sourceName = this.sourceName;
|
203
|
+
const targetName = this.targetName;
|
204
|
+
const comObj = this.comObj;
|
205
|
+
return new ReadableStream({
|
206
|
+
start: controller => {
|
207
|
+
const startCapability = (0, _util.createPromiseCapability)();
|
208
|
+
this.streamControllers[streamId] = {
|
209
|
+
controller,
|
193
210
|
startCall: startCapability,
|
194
211
|
pullCall: null,
|
195
212
|
cancelCall: null,
|
196
213
|
isClosed: false
|
197
214
|
};
|
198
215
|
|
199
|
-
|
200
|
-
sourceName
|
201
|
-
targetName
|
216
|
+
this._postMessage({
|
217
|
+
sourceName,
|
218
|
+
targetName,
|
202
219
|
action: actionName,
|
203
|
-
streamId
|
204
|
-
data
|
220
|
+
streamId,
|
221
|
+
data,
|
205
222
|
desiredSize: controller.desiredSize
|
206
223
|
}, transfers);
|
207
224
|
|
208
225
|
return startCapability.promise;
|
209
226
|
},
|
210
|
-
pull:
|
211
|
-
|
212
|
-
|
227
|
+
pull: controller => {
|
228
|
+
const pullCapability = (0, _util.createPromiseCapability)();
|
229
|
+
this.streamControllers[streamId].pullCall = pullCapability;
|
213
230
|
comObj.postMessage({
|
214
|
-
sourceName
|
215
|
-
targetName
|
231
|
+
sourceName,
|
232
|
+
targetName,
|
216
233
|
stream: StreamKind.PULL,
|
217
|
-
streamId
|
234
|
+
streamId,
|
218
235
|
desiredSize: controller.desiredSize
|
219
236
|
});
|
220
237
|
return pullCapability.promise;
|
221
238
|
},
|
222
|
-
cancel:
|
223
|
-
(0, _util.assert)(reason instanceof Error,
|
224
|
-
|
225
|
-
|
226
|
-
|
239
|
+
cancel: reason => {
|
240
|
+
(0, _util.assert)(reason instanceof Error, "cancel must have a valid reason");
|
241
|
+
const cancelCapability = (0, _util.createPromiseCapability)();
|
242
|
+
this.streamControllers[streamId].cancelCall = cancelCapability;
|
243
|
+
this.streamControllers[streamId].isClosed = true;
|
227
244
|
comObj.postMessage({
|
228
|
-
sourceName
|
229
|
-
targetName
|
245
|
+
sourceName,
|
246
|
+
targetName,
|
230
247
|
stream: StreamKind.CANCEL,
|
231
|
-
streamId
|
248
|
+
streamId,
|
232
249
|
reason: wrapReason(reason)
|
233
250
|
});
|
234
251
|
return cancelCapability.promise;
|
235
252
|
}
|
236
253
|
}, queueingStrategy);
|
237
|
-
}
|
238
|
-
_createStreamSink: function _createStreamSink(data) {
|
239
|
-
var self = this;
|
240
|
-
var action = this.actionHandler[data.action];
|
241
|
-
var streamId = data.streamId;
|
242
|
-
var desiredSize = data.desiredSize;
|
243
|
-
var sourceName = this.sourceName;
|
244
|
-
var targetName = data.sourceName;
|
245
|
-
var capability = (0, _util.createPromiseCapability)();
|
246
|
-
var comObj = this.comObj;
|
247
|
-
var streamSink = {
|
248
|
-
enqueue: function enqueue(chunk) {
|
249
|
-
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
250
|
-
var transfers = arguments.length > 2 ? arguments[2] : undefined;
|
254
|
+
}
|
251
255
|
|
256
|
+
_createStreamSink(data) {
|
257
|
+
const self = this;
|
258
|
+
const action = this.actionHandler[data.action];
|
259
|
+
const streamId = data.streamId;
|
260
|
+
const sourceName = this.sourceName;
|
261
|
+
const targetName = data.sourceName;
|
262
|
+
const comObj = this.comObj;
|
263
|
+
const streamSink = {
|
264
|
+
enqueue(chunk, size = 1, transfers) {
|
252
265
|
if (this.isCancelled) {
|
253
266
|
return;
|
254
267
|
}
|
255
268
|
|
256
|
-
|
269
|
+
const lastDesiredSize = this.desiredSize;
|
257
270
|
this.desiredSize -= size;
|
258
271
|
|
259
272
|
if (lastDesiredSize > 0 && this.desiredSize <= 0) {
|
@@ -261,30 +274,32 @@ MessageHandler.prototype = {
|
|
261
274
|
this.ready = this.sinkCapability.promise;
|
262
275
|
}
|
263
276
|
|
264
|
-
self.
|
265
|
-
sourceName
|
266
|
-
targetName
|
277
|
+
self._postMessage({
|
278
|
+
sourceName,
|
279
|
+
targetName,
|
267
280
|
stream: StreamKind.ENQUEUE,
|
268
|
-
streamId
|
269
|
-
chunk
|
281
|
+
streamId,
|
282
|
+
chunk
|
270
283
|
}, transfers);
|
271
284
|
},
|
272
|
-
|
285
|
+
|
286
|
+
close() {
|
273
287
|
if (this.isCancelled) {
|
274
288
|
return;
|
275
289
|
}
|
276
290
|
|
277
291
|
this.isCancelled = true;
|
278
292
|
comObj.postMessage({
|
279
|
-
sourceName
|
280
|
-
targetName
|
293
|
+
sourceName,
|
294
|
+
targetName,
|
281
295
|
stream: StreamKind.CLOSE,
|
282
|
-
streamId
|
296
|
+
streamId
|
283
297
|
});
|
284
298
|
delete self.streamSinks[streamId];
|
285
299
|
},
|
286
|
-
|
287
|
-
|
300
|
+
|
301
|
+
error(reason) {
|
302
|
+
(0, _util.assert)(reason instanceof Error, "error must have a valid reason");
|
288
303
|
|
289
304
|
if (this.isCancelled) {
|
290
305
|
return;
|
@@ -292,18 +307,19 @@ MessageHandler.prototype = {
|
|
292
307
|
|
293
308
|
this.isCancelled = true;
|
294
309
|
comObj.postMessage({
|
295
|
-
sourceName
|
296
|
-
targetName
|
310
|
+
sourceName,
|
311
|
+
targetName,
|
297
312
|
stream: StreamKind.ERROR,
|
298
|
-
streamId
|
313
|
+
streamId,
|
299
314
|
reason: wrapReason(reason)
|
300
315
|
});
|
301
316
|
},
|
302
|
-
|
317
|
+
|
318
|
+
sinkCapability: (0, _util.createPromiseCapability)(),
|
303
319
|
onPull: null,
|
304
320
|
onCancel: null,
|
305
321
|
isCancelled: false,
|
306
|
-
desiredSize: desiredSize,
|
322
|
+
desiredSize: data.desiredSize,
|
307
323
|
ready: null
|
308
324
|
};
|
309
325
|
streamSink.sinkCapability.resolve();
|
@@ -313,37 +329,28 @@ MessageHandler.prototype = {
|
|
313
329
|
resolve(action(data.data, streamSink));
|
314
330
|
}).then(function () {
|
315
331
|
comObj.postMessage({
|
316
|
-
sourceName
|
317
|
-
targetName
|
332
|
+
sourceName,
|
333
|
+
targetName,
|
318
334
|
stream: StreamKind.START_COMPLETE,
|
319
|
-
streamId
|
335
|
+
streamId,
|
320
336
|
success: true
|
321
337
|
});
|
322
338
|
}, function (reason) {
|
323
339
|
comObj.postMessage({
|
324
|
-
sourceName
|
325
|
-
targetName
|
340
|
+
sourceName,
|
341
|
+
targetName,
|
326
342
|
stream: StreamKind.START_COMPLETE,
|
327
|
-
streamId
|
343
|
+
streamId,
|
328
344
|
reason: wrapReason(reason)
|
329
345
|
});
|
330
346
|
});
|
331
|
-
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
var comObj = this.comObj;
|
339
|
-
|
340
|
-
var deleteStreamController = function deleteStreamController() {
|
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 () {});
|
343
|
-
})).then(function () {
|
344
|
-
delete _this3.streamControllers[streamId];
|
345
|
-
});
|
346
|
-
};
|
347
|
+
}
|
348
|
+
|
349
|
+
_processStreamMessage(data) {
|
350
|
+
const streamId = data.streamId;
|
351
|
+
const sourceName = this.sourceName;
|
352
|
+
const targetName = data.sourceName;
|
353
|
+
const comObj = this.comObj;
|
347
354
|
|
348
355
|
switch (data.stream) {
|
349
356
|
case StreamKind.START_COMPLETE:
|
@@ -367,10 +374,10 @@ MessageHandler.prototype = {
|
|
367
374
|
case StreamKind.PULL:
|
368
375
|
if (!this.streamSinks[streamId]) {
|
369
376
|
comObj.postMessage({
|
370
|
-
sourceName
|
371
|
-
targetName
|
377
|
+
sourceName,
|
378
|
+
targetName,
|
372
379
|
stream: StreamKind.PULL_COMPLETE,
|
373
|
-
streamId
|
380
|
+
streamId,
|
374
381
|
success: true
|
375
382
|
});
|
376
383
|
break;
|
@@ -381,30 +388,32 @@ MessageHandler.prototype = {
|
|
381
388
|
}
|
382
389
|
|
383
390
|
this.streamSinks[streamId].desiredSize = data.desiredSize;
|
384
|
-
|
391
|
+
const {
|
392
|
+
onPull
|
393
|
+
} = this.streamSinks[data.streamId];
|
385
394
|
new Promise(function (resolve) {
|
386
395
|
resolve(onPull && onPull());
|
387
396
|
}).then(function () {
|
388
397
|
comObj.postMessage({
|
389
|
-
sourceName
|
390
|
-
targetName
|
398
|
+
sourceName,
|
399
|
+
targetName,
|
391
400
|
stream: StreamKind.PULL_COMPLETE,
|
392
|
-
streamId
|
401
|
+
streamId,
|
393
402
|
success: true
|
394
403
|
});
|
395
404
|
}, function (reason) {
|
396
405
|
comObj.postMessage({
|
397
|
-
sourceName
|
398
|
-
targetName
|
406
|
+
sourceName,
|
407
|
+
targetName,
|
399
408
|
stream: StreamKind.PULL_COMPLETE,
|
400
|
-
streamId
|
409
|
+
streamId,
|
401
410
|
reason: wrapReason(reason)
|
402
411
|
});
|
403
412
|
});
|
404
413
|
break;
|
405
414
|
|
406
415
|
case StreamKind.ENQUEUE:
|
407
|
-
(0, _util.assert)(this.streamControllers[streamId],
|
416
|
+
(0, _util.assert)(this.streamControllers[streamId], "enqueue should have stream controller");
|
408
417
|
|
409
418
|
if (this.streamControllers[streamId].isClosed) {
|
410
419
|
break;
|
@@ -414,7 +423,7 @@ MessageHandler.prototype = {
|
|
414
423
|
break;
|
415
424
|
|
416
425
|
case StreamKind.CLOSE:
|
417
|
-
(0, _util.assert)(this.streamControllers[streamId],
|
426
|
+
(0, _util.assert)(this.streamControllers[streamId], "close should have stream controller");
|
418
427
|
|
419
428
|
if (this.streamControllers[streamId].isClosed) {
|
420
429
|
break;
|
@@ -422,13 +431,17 @@ MessageHandler.prototype = {
|
|
422
431
|
|
423
432
|
this.streamControllers[streamId].isClosed = true;
|
424
433
|
this.streamControllers[streamId].controller.close();
|
425
|
-
|
434
|
+
|
435
|
+
this._deleteStreamController(streamId);
|
436
|
+
|
426
437
|
break;
|
427
438
|
|
428
439
|
case StreamKind.ERROR:
|
429
|
-
(0, _util.assert)(this.streamControllers[streamId],
|
440
|
+
(0, _util.assert)(this.streamControllers[streamId], "error should have stream controller");
|
430
441
|
this.streamControllers[streamId].controller.error(wrapReason(data.reason));
|
431
|
-
|
442
|
+
|
443
|
+
this._deleteStreamController(streamId);
|
444
|
+
|
432
445
|
break;
|
433
446
|
|
434
447
|
case StreamKind.CANCEL_COMPLETE:
|
@@ -438,7 +451,8 @@ MessageHandler.prototype = {
|
|
438
451
|
this.streamControllers[streamId].cancelCall.reject(wrapReason(data.reason));
|
439
452
|
}
|
440
453
|
|
441
|
-
|
454
|
+
this._deleteStreamController(streamId);
|
455
|
+
|
442
456
|
break;
|
443
457
|
|
444
458
|
case StreamKind.CANCEL:
|
@@ -446,23 +460,25 @@ MessageHandler.prototype = {
|
|
446
460
|
break;
|
447
461
|
}
|
448
462
|
|
449
|
-
|
463
|
+
const {
|
464
|
+
onCancel
|
465
|
+
} = this.streamSinks[data.streamId];
|
450
466
|
new Promise(function (resolve) {
|
451
467
|
resolve(onCancel && onCancel(wrapReason(data.reason)));
|
452
468
|
}).then(function () {
|
453
469
|
comObj.postMessage({
|
454
|
-
sourceName
|
455
|
-
targetName
|
470
|
+
sourceName,
|
471
|
+
targetName,
|
456
472
|
stream: StreamKind.CANCEL_COMPLETE,
|
457
|
-
streamId
|
473
|
+
streamId,
|
458
474
|
success: true
|
459
475
|
});
|
460
476
|
}, function (reason) {
|
461
477
|
comObj.postMessage({
|
462
|
-
sourceName
|
463
|
-
targetName
|
478
|
+
sourceName,
|
479
|
+
targetName,
|
464
480
|
stream: StreamKind.CANCEL_COMPLETE,
|
465
|
-
streamId
|
481
|
+
streamId,
|
466
482
|
reason: wrapReason(reason)
|
467
483
|
});
|
468
484
|
});
|
@@ -472,17 +488,29 @@ MessageHandler.prototype = {
|
|
472
488
|
break;
|
473
489
|
|
474
490
|
default:
|
475
|
-
throw new Error(
|
491
|
+
throw new Error("Unexpected stream case");
|
476
492
|
}
|
477
|
-
}
|
478
|
-
|
493
|
+
}
|
494
|
+
|
495
|
+
async _deleteStreamController(streamId) {
|
496
|
+
await Promise.allSettled([this.streamControllers[streamId].startCall, this.streamControllers[streamId].pullCall, this.streamControllers[streamId].cancelCall].map(function (capability) {
|
497
|
+
return capability && capability.promise;
|
498
|
+
}));
|
499
|
+
delete this.streamControllers[streamId];
|
500
|
+
}
|
501
|
+
|
502
|
+
_postMessage(message, transfers) {
|
479
503
|
if (transfers && this.postMessageTransfers) {
|
480
504
|
this.comObj.postMessage(message, transfers);
|
481
505
|
} else {
|
482
506
|
this.comObj.postMessage(message);
|
483
507
|
}
|
484
|
-
},
|
485
|
-
destroy: function destroy() {
|
486
|
-
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
487
508
|
}
|
488
|
-
|
509
|
+
|
510
|
+
destroy() {
|
511
|
+
this.comObj.removeEventListener("message", this._onComObjOnMessage);
|
512
|
+
}
|
513
|
+
|
514
|
+
}
|
515
|
+
|
516
|
+
exports.MessageHandler = MessageHandler;
|