| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import '../../util/io.dart'; | 9 import '../../util/io.dart'; |
| 10 import '../../utils.dart'; | 10 import '../../utils.dart'; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 if (executable == null) executable = _defaultExecutable(); | 34 if (executable == null) executable = _defaultExecutable(); |
| 35 | 35 |
| 36 var tryPort = ([int port]) async { | 36 var tryPort = ([int port]) async { |
| 37 var args = ["--dump-render-tree", url.toString()]; | 37 var args = ["--dump-render-tree", url.toString()]; |
| 38 if (port != null) args.add("--remote-debugging-port=$port"); | 38 if (port != null) args.add("--remote-debugging-port=$port"); |
| 39 | 39 |
| 40 var process = await Process.start(executable, args, | 40 var process = await Process.start(executable, args, |
| 41 environment: {"DART_FLAGS": "--checked"}); | 41 environment: {"DART_FLAGS": "--checked"}); |
| 42 | 42 |
| 43 if (debug) { | 43 if (debug) { |
| 44 observatoryCompleter.complete(lineSplitter.bind(process.stdout) | 44 observatoryCompleter.complete(transformUtf8ToLines(process.stdout) |
| 45 .map((line) { | 45 .map((line) { |
| 46 var match = _observatoryRegExp.firstMatch(line); | 46 var match = _observatoryRegExp.firstMatch(line); |
| 47 if (match == null) return null; | 47 if (match == null) return null; |
| 48 return Uri.parse(match[1]); | 48 return Uri.parse(match[1]); |
| 49 }).where((uri) => uri != null).first); | 49 }).where((uri) => uri != null).first); |
| 50 } else { | 50 } else { |
| 51 observatoryCompleter.complete(null); | 51 observatoryCompleter.complete(null); |
| 52 } | 52 } |
| 53 | 53 |
| 54 var stderr = new StreamIterator(lineSplitter.bind(process.stderr)); | 54 var stderr = new StreamIterator(transformUtf8ToLines(process.stderr)); |
| 55 | 55 |
| 56 // Before we can consider content_shell started successfully, we have to | 56 // Before we can consider content_shell started successfully, we have to |
| 57 // make sure it's not expired and that the remote debugging port worked. | 57 // make sure it's not expired and that the remote debugging port worked. |
| 58 // Any errors from this will always come before the "Running without | 58 // Any errors from this will always come before the "Running without |
| 59 // renderer sanxbox" message. | 59 // renderer sanxbox" message. |
| 60 while (await stderr.moveNext() && | 60 while (await stderr.moveNext() && |
| 61 !stderr.current.endsWith("Running without renderer sandbox")) { | 61 !stderr.current.endsWith("Running without renderer sandbox")) { |
| 62 if (stderr.current == "[dartToStderr]: Dartium build has expired") { | 62 if (stderr.current == "[dartToStderr]: Dartium build has expired") { |
| 63 stderr.cancel(); | 63 stderr.cancel(); |
| 64 process.kill(); | 64 process.kill(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 /// Returns the full URL of the remote debugger for the host page. | 98 /// Returns the full URL of the remote debugger for the host page. |
| 99 /// | 99 /// |
| 100 /// This takes the base remote debugger URL (which points to a browser-wide | 100 /// This takes the base remote debugger URL (which points to a browser-wide |
| 101 /// page) and uses its JSON API to find the resolved URL for debugging the | 101 /// page) and uses its JSON API to find the resolved URL for debugging the |
| 102 /// host page. | 102 /// host page. |
| 103 static Future<Uri> _getRemoteDebuggerUrl(Uri base) async { | 103 static Future<Uri> _getRemoteDebuggerUrl(Uri base) async { |
| 104 try { | 104 try { |
| 105 var client = new HttpClient(); | 105 var client = new HttpClient(); |
| 106 var request = await client.getUrl(base.resolve("/json/list")); | 106 var request = await client.getUrl(base.resolve("/json/list")); |
| 107 var response = await request.close(); | 107 var response = await request.close(); |
| 108 var json = await JSON.fuse(UTF8).decoder.bind(response).single; | 108 var json = await JSON.fuse(UTF8).decoder.bind(response).single as List; |
| 109 return base.resolve(json.first["devtoolsFrontendUrl"]); | 109 return base.resolve(json.first["devtoolsFrontendUrl"]); |
| 110 } catch (_) { | 110 } catch (_) { |
| 111 // If we fail to talk to the remote debugger protocol, give up and return | 111 // If we fail to talk to the remote debugger protocol, give up and return |
| 112 // the raw URL rather than crashing. | 112 // the raw URL rather than crashing. |
| 113 return base; | 113 return base; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 ContentShell._(Future<Process> startBrowser(), this.observatoryUrl, | 117 ContentShell._(Future<Process> startBrowser(), this.observatoryUrl, |
| 118 this.remoteDebuggerUrl) | 118 this.remoteDebuggerUrl) |
| 119 : super(startBrowser); | 119 : super(startBrowser); |
| 120 | 120 |
| 121 /// Return the default executable for the current operating system. | 121 /// Return the default executable for the current operating system. |
| 122 static String _defaultExecutable() => | 122 static String _defaultExecutable() => |
| 123 Platform.isWindows ? "content_shell.exe" : "content_shell"; | 123 Platform.isWindows ? "content_shell.exe" : "content_shell"; |
| 124 } | 124 } |
| OLD | NEW |