@@ -183,11 +183,9 @@ std::unique_ptr<protocol::Network::Response> createResponseFromObject(
183183}
184184
185185NetworkAgent::NetworkAgent (NetworkInspector* inspector,
186- v8_inspector::V8Inspector* v8_inspector,
187- Environment* env)
186+ v8_inspector::V8Inspector* v8_inspector)
188187 : inspector_(inspector),
189- v8_inspector_ (v8_inspector),
190- env_(env) {
188+ v8_inspector_ (v8_inspector) {
191189 event_notifier_map_[" requestWillBeSent" ] = &NetworkAgent::requestWillBeSent;
192190 event_notifier_map_[" responseReceived" ] = &NetworkAgent::responseReceived;
193191 event_notifier_map_[" loadingFailed" ] = &NetworkAgent::loadingFailed;
@@ -244,105 +242,6 @@ protocol::DispatchResponse NetworkAgent::streamResourceContent(
244242 return protocol::DispatchResponse::Success ();
245243}
246244
247- std::tuple<int , std::string, std::string> NetworkAgent::spawnFetchProcess (
248- std::string_view code, Environment* env, std::string_view url) {
249- std::string stdout_result;
250- std::string stderr_result;
251- uv_loop_t * loop = new uv_loop_t ;
252- uv_loop_init (loop);
253- uv_process_t child;
254- uv_pipe_t stdout_pipe;
255- uv_pipe_init (loop, &stdout_pipe, 0 );
256- uv_pipe_t stderr_pipe;
257- uv_pipe_init (loop, &stderr_pipe, 0 );
258-
259- uv_process_options_t uv_process_options;
260- std::string command =
261- env->exec_path () + " --eval \" " + code.data () + " \" -- " + url.data ();
262-
263- const char * file = env->exec_path ().c_str ();
264- char * args[] = {const_cast <char *>(file),
265- const_cast <char *>(" --eval" ),
266- reinterpret_cast <char *>(const_cast <char *>(code.data ())),
267- reinterpret_cast <char *>(const_cast <char *>(url.data ())),
268- nullptr };
269-
270- uv_stdio_container_t stdio[3 ];
271- uv_process_options.file = file;
272- uv_process_options.args = args;
273- uv_process_options.flags = 0 ;
274- uv_process_options.stdio_count = 3 ;
275- uv_process_options.stdio = stdio;
276- uv_process_options.cwd = nullptr ;
277- uv_process_options.env = nullptr ;
278-
279- uv_process_options.exit_cb =
280- [](uv_process_t * req, int64_t exit_status, int term_signal) {
281- uv_close (reinterpret_cast <uv_handle_t *>(req), nullptr );
282- };
283-
284- stdio[0 ].flags = UV_INHERIT_FD;
285- stdio[0 ].data .fd = 0 ;
286- stdio[1 ].flags =
287- static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
288- stdio[1 ].data .stream = reinterpret_cast <uv_stream_t *>(&stdout_pipe);
289- stdio[2 ].flags =
290- static_cast <uv_stdio_flags>(UV_CREATE_PIPE | UV_WRITABLE_PIPE);
291- stdio[2 ].data .stream = reinterpret_cast <uv_stream_t *>(&stderr_pipe);
292-
293- int r = uv_spawn (loop, &child, &uv_process_options);
294-
295- if (r != 0 ) {
296- uv_loop_close (loop);
297- delete loop;
298- return {r, stdout_result, stderr_result};
299- }
300-
301- auto alloc_cb =
302- [](uv_handle_t * handle, size_t suggested_size, uv_buf_t * buf) {
303- buf->base = static_cast <char *>(malloc (suggested_size));
304- buf->len = suggested_size;
305- };
306-
307- auto read_cb = [](uv_stream_t * stream, ssize_t nread, const uv_buf_t * buf) {
308- auto * response = static_cast <std::string*>(stream->data );
309- if (nread > 0 ) {
310- response->append (buf->base , nread);
311- } else if (nread < 0 ) {
312- if (!response->empty () && response->back () == ' \n ' ) {
313- response->pop_back ();
314- }
315- uv_close (reinterpret_cast <uv_handle_t *>(stream), nullptr );
316- }
317- if (buf->base ) free (buf->base );
318- };
319-
320- stdout_pipe.data = &stdout_result;
321- uv_read_start (
322- reinterpret_cast <uv_stream_t *>(&stdout_pipe), alloc_cb, read_cb);
323-
324- stderr_pipe.data = &stderr_result;
325- uv_read_start (
326- reinterpret_cast <uv_stream_t *>(&stderr_pipe), alloc_cb, read_cb);
327-
328- uv_run (loop, UV_RUN_DEFAULT);
329-
330- uv_walk (
331- loop,
332- [](uv_handle_t * handle, void *) {
333- if (!uv_is_closing (handle)) {
334- uv_close (handle, nullptr );
335- }
336- },
337- nullptr );
338-
339- uv_run (loop, UV_RUN_DEFAULT);
340-
341- uv_loop_close (loop);
342- delete loop;
343- return {r, stdout_result, stderr_result};
344- }
345-
346245protocol::DispatchResponse NetworkAgent::loadNetworkResource (
347246 const protocol::String& in_url,
348247 std::unique_ptr<protocol::Network::LoadNetworkResourcePageResult>*
0 commit comments