| 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 10 matching lines...) Expand all Loading... |
| 21 /// | 21 /// |
| 22 /// Any errors starting or running the process are reported through [onExit]. | 22 /// Any errors starting or running the process are reported through [onExit]. |
| 23 class ContentShell extends Browser { | 23 class ContentShell extends Browser { |
| 24 final name = "Content Shell"; | 24 final name = "Content Shell"; |
| 25 | 25 |
| 26 final Future<Uri> observatoryUrl; | 26 final Future<Uri> observatoryUrl; |
| 27 | 27 |
| 28 final Future<Uri> remoteDebuggerUrl; | 28 final Future<Uri> remoteDebuggerUrl; |
| 29 | 29 |
| 30 factory ContentShell(url, {String executable, bool debug: false}) { | 30 factory ContentShell(url, {String executable, bool debug: false}) { |
| 31 var observatoryCompleter = new Completer.sync(); | 31 var observatoryCompleter = new Completer<Uri>.sync(); |
| 32 var remoteDebuggerCompleter = new Completer.sync(); | 32 var remoteDebuggerCompleter = new Completer<Uri>.sync(); |
| 33 return new ContentShell._(() { | 33 return new ContentShell._(() { |
| 34 if (executable == null) executable = _defaultExecutable(); | 34 if (executable == null) executable = _defaultExecutable(); |
| 35 | 35 |
| 36 tryPort([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(lineSplitter.bind(process.stdout) |
| 45 .map((line) { | 45 .map((line) { |
| 46 var match = _observatoryRegExp.firstMatch(line); | 46 var match = _observatoryRegExp.firstMatch(line); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 if (port != null) { | 82 if (port != null) { |
| 83 remoteDebuggerCompleter.complete( | 83 remoteDebuggerCompleter.complete( |
| 84 _getRemoteDebuggerUrl(Uri.parse("http://localhost:$port"))); | 84 _getRemoteDebuggerUrl(Uri.parse("http://localhost:$port"))); |
| 85 } else { | 85 } else { |
| 86 remoteDebuggerCompleter.complete(null); | 86 remoteDebuggerCompleter.complete(null); |
| 87 } | 87 } |
| 88 | 88 |
| 89 stderr.cancel(); | 89 stderr.cancel(); |
| 90 return process; | 90 return process; |
| 91 } | 91 }; |
| 92 | 92 |
| 93 if (!debug) return tryPort(); | 93 if (!debug) return tryPort(); |
| 94 return getUnusedPort(tryPort); | 94 return getUnusedPort/*<Future<Process>>*/(tryPort); |
| 95 }, observatoryCompleter.future, remoteDebuggerCompleter.future); | 95 }, observatoryCompleter.future, remoteDebuggerCompleter.future); |
| 96 } | 96 } |
| 97 | 97 |
| 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 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 |