@@ -208,6 +208,35 @@ std::unique_ptr<protocol::Network::Response> createResponseFromObject(
208
208
.build ();
209
209
}
210
210
211
+ std::unique_ptr<protocol::Network::WebSocketResponse> createWebSocketResponse (
212
+ v8::Local<v8::Context> context, Local<Object> response) {
213
+ HandleScope handle_scope (context->GetIsolate ());
214
+ int status;
215
+ if (!ObjectGetInt (context, response, " status" ).To (&status)) {
216
+ return {};
217
+ }
218
+ protocol::String statusText;
219
+ if (!ObjectGetProtocolString (context, response, " statusText" )
220
+ .To (&statusText)) {
221
+ return {};
222
+ }
223
+ Local<Object> headers_obj;
224
+ if (!ObjectGetObject (context, response, " headers" ).ToLocal (&headers_obj)) {
225
+ return {};
226
+ }
227
+ std::unique_ptr<protocol::Network::Headers> headers =
228
+ createHeadersFromObject (context, headers_obj);
229
+ if (!headers) {
230
+ return {};
231
+ }
232
+
233
+ return protocol::Network::WebSocketResponse::create ()
234
+ .setStatus (status)
235
+ .setStatusText (statusText)
236
+ .setHeaders (std::move (headers))
237
+ .build ();
238
+ }
239
+
211
240
NetworkAgent::NetworkAgent (
212
241
NetworkInspector* inspector,
213
242
v8_inspector::V8Inspector* v8_inspector,
@@ -223,6 +252,64 @@ NetworkAgent::NetworkAgent(
223
252
event_notifier_map_[" loadingFinished" ] = &NetworkAgent::loadingFinished;
224
253
event_notifier_map_[" dataSent" ] = &NetworkAgent::dataSent;
225
254
event_notifier_map_[" dataReceived" ] = &NetworkAgent::dataReceived;
255
+ event_notifier_map_[" webSocketCreated" ] = &NetworkAgent::webSocketCreated;
256
+ event_notifier_map_[" webSocketClosed" ] = &NetworkAgent::webSocketClosed;
257
+ event_notifier_map_[" webSocketHandshakeResponseReceived" ] =
258
+ &NetworkAgent::webSocketHandshakeResponseReceived;
259
+ }
260
+
261
+ void NetworkAgent::webSocketCreated (v8::Local<v8::Context> context,
262
+ v8::Local<v8::Object> params) {
263
+ protocol::String request_id;
264
+ if (!ObjectGetProtocolString (context, params, " requestId" ).To (&request_id)) {
265
+ return ;
266
+ }
267
+ protocol::String url;
268
+ if (!ObjectGetProtocolString (context, params, " url" ).To (&url)) {
269
+ return ;
270
+ }
271
+ std::unique_ptr<protocol::Network::Initiator> initiator =
272
+ protocol::Network::Initiator::create ()
273
+ .setType (protocol::Network::Initiator::TypeEnum::Script)
274
+ .setStack (
275
+ v8_inspector_->captureStackTrace (true )->buildInspectorObject (0 ))
276
+ .build ();
277
+ frontend_->webSocketCreated (request_id, url, std::move (initiator));
278
+ }
279
+
280
+ void NetworkAgent::webSocketClosed (v8::Local<v8::Context> context,
281
+ v8::Local<v8::Object> params) {
282
+ protocol::String request_id;
283
+ if (!ObjectGetProtocolString (context, params, " requestId" ).To (&request_id)) {
284
+ return ;
285
+ }
286
+ double timestamp;
287
+ if (!ObjectGetDouble (context, params, " timestamp" ).To (×tamp)) {
288
+ return ;
289
+ }
290
+ frontend_->webSocketClosed (request_id, timestamp);
291
+ }
292
+
293
+ void NetworkAgent::webSocketHandshakeResponseReceived (
294
+ v8::Local<v8::Context> context, v8::Local<v8::Object> params) {
295
+ protocol::String request_id;
296
+ if (!ObjectGetProtocolString (context, params, " requestId" ).To (&request_id)) {
297
+ return ;
298
+ }
299
+ double timestamp;
300
+ if (!ObjectGetDouble (context, params, " timestamp" ).To (×tamp)) {
301
+ return ;
302
+ }
303
+ Local<Object> response_obj;
304
+ if (!ObjectGetObject (context, params, " response" ).ToLocal (&response_obj)) {
305
+ return ;
306
+ }
307
+ auto response = createWebSocketResponse (context, response_obj);
308
+ if (!response) {
309
+ return ;
310
+ }
311
+ frontend_->webSocketHandshakeResponseReceived (
312
+ request_id, timestamp, std::move (response));
226
313
}
227
314
228
315
void NetworkAgent::emitNotification (v8::Local<v8::Context> context,
0 commit comments