diff --git a/dwds/lib/dwds.dart b/dwds/lib/dwds.dart index f76b640a6..ca9459921 100644 --- a/dwds/lib/dwds.dart +++ b/dwds/lib/dwds.dart @@ -58,6 +58,7 @@ class Dwds { LogWriter logWriter, bool verbose, bool enableDebugExtension, + WipDebugger wipDebugger, }) async { hostname ??= 'localhost'; reloadConfiguration ??= ReloadConfiguration.none; @@ -99,6 +100,7 @@ class Dwds { hostname, verbose, logWriter, + wipDebugger, ); cascade = cascade.add(devHandler.handler).add(assetHandler.handler); diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index fb53579ec..351cb2f97 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -38,7 +38,7 @@ class AppInspector extends Domain { /// Map of [ScriptRef] id to containing [LibraryRef] id. final _scriptIdToLibraryId = {}; - final WipConnection _tabConnection; + final WipDebugger _wipDebugger; final AssetHandler _assetHandler; final Debugger _debugger; final Isolate isolate; @@ -49,10 +49,10 @@ class AppInspector extends Domain { AppInspector._( this.isolate, - this._tabConnection, this._assetHandler, this._debugger, this._root, + this._wipDebugger, ) : isolateRef = _toIsolateRef(isolate), super.forInspector(); @@ -81,7 +81,7 @@ class AppInspector extends Domain { ..number = isolate.number; static Future initialize( - WipConnection tabConnection, + WipDebugger wipDebugger, AssetHandler assetHandler, Debugger debugger, String root, @@ -96,7 +96,7 @@ class AppInspector extends Domain { ..libraries = [] ..extensionRPCs = []; var inspector = - AppInspector._(isolate, tabConnection, assetHandler, debugger, root); + AppInspector._(isolate, assetHandler, debugger, root, wipDebugger); await inspector._initialize(); return inspector; } @@ -123,7 +123,7 @@ class AppInspector extends Domain { return library.$expression; })(); '''; - result = await _tabConnection.runtime.sendCommand('Runtime.evaluate', + result = await _wipDebugger.sendCommand('Runtime.evaluate', params: {'expression': evalExpression}); handleErrorIfPresent(result, evalContents: evalExpression, @@ -139,8 +139,8 @@ function($argsString) { return library.$expression; } '''; - result = await _tabConnection.runtime - .sendCommand('Runtime.callFunctionOn', params: { + result = + await _wipDebugger.sendCommand('Runtime.callFunctionOn', params: { 'functionDeclaration': evalExpression, 'arguments': arguments, // TODO(jakemac): Use the executionContext instead, or possibly the @@ -265,7 +265,7 @@ function($argsString) { return result; })() '''; - var result = await _tabConnection.runtime.sendCommand('Runtime.evaluate', + var result = await _wipDebugger.sendCommand('Runtime.evaluate', params: {'expression': expression, 'returnByValue': true}); handleErrorIfPresent(result, evalContents: expression); var classDescriptors = (result.result['result']['value']['classes'] as List) @@ -405,8 +405,7 @@ function($argsString) { Future> _getLibraryRefs() async { if (_libraryRefs.isNotEmpty) return _libraryRefs.values.toList(); var expression = "require('dart_sdk').dart.getLibraries();"; - var librariesResult = await _tabConnection.runtime.sendCommand( - 'Runtime.evaluate', + var librariesResult = await _wipDebugger.sendCommand('Runtime.evaluate', params: {'expression': expression, 'returnByValue': true}); handleErrorIfPresent(librariesResult, evalContents: expression); var libraries = @@ -424,8 +423,7 @@ function($argsString) { /// Runs an eval on the page to compute all existing registered extensions. Future> _getExtensionRpcs() async { var expression = "require('dart_sdk').developer._extensions.keys.toList();"; - var extensionsResult = await _tabConnection.runtime.sendCommand( - 'Runtime.evaluate', + var extensionsResult = await _wipDebugger.sendCommand('Runtime.evaluate', params: {'expression': expression, 'returnByValue': true}); handleErrorIfPresent(extensionsResult, evalContents: expression); return List.from(extensionsResult.result['result']['value'] as List); diff --git a/dwds/lib/src/handlers/dev_handler.dart b/dwds/lib/src/handlers/dev_handler.dart index f15ecf361..94f55b60d 100644 --- a/dwds/lib/src/handlers/dev_handler.dart +++ b/dwds/lib/src/handlers/dev_handler.dart @@ -39,6 +39,7 @@ class DevHandler { final bool _verbose; final void Function(Level, String) _logWriter; final Future Function() _chromeConnection; + final WipDebugger _wipDebugger; Stream get connectedApps => _connectedApps.stream; @@ -50,6 +51,7 @@ class DevHandler { this._hostname, this._verbose, this._logWriter, + this._wipDebugger, ) { _sub = buildResults.listen(_emitBuildResults); _listen(); @@ -87,6 +89,7 @@ class DevHandler { chromeConnection, _assetHandler.getRelativeAsset, appInstanceId, + _wipDebugger, onResponse: _verbose ? (response) { if (response['error'] == null) return; diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart index 269fe260c..36cd3e542 100644 --- a/dwds/lib/src/services/chrome_proxy_service.dart +++ b/dwds/lib/src/services/chrome_proxy_service.dart @@ -46,6 +46,8 @@ class ChromeProxyService implements VmServiceInterface { // TODO(grouma) - This should be class private. final WipConnection tabConnection; + final WipDebugger _wipDebugger; + final AssetHandler _assetHandler; /// Provides debugger-related functionality. @@ -61,10 +63,14 @@ class ChromeProxyService implements VmServiceInterface { this._tab, this.tabConnection, this._assetHandler, + this._wipDebugger, ); - static Future create(ChromeConnection chromeConnection, - AssetHandler assetHandler, String appInstanceId) async { + static Future create( + ChromeConnection chromeConnection, + AssetHandler assetHandler, + String appInstanceId, + WipDebugger wipDebugger) async { ChromeTab appTab; for (var tab in await chromeConnection.getTabs()) { if (tab.url.startsWith('chrome-extensions:')) continue; @@ -84,13 +90,16 @@ class ChromeProxyService implements VmServiceInterface { var tabConnection = await appTab.connect(); await tabConnection.runtime.enable(); + wipDebugger = WipDebugger(tabConnection); + // TODO: What about `architectureBits`, `targetCPU`, `hostCPU` and `pid`? final vm = VM() ..isolates = [] ..name = 'ChromeDebugProxy' ..startTime = DateTime.now().millisecondsSinceEpoch ..version = Platform.version; - var service = ChromeProxyService._(vm, appTab, tabConnection, assetHandler); + var service = ChromeProxyService._( + vm, appTab, tabConnection, assetHandler, wipDebugger); await service._initialize(); await service.createIsolate(); return service; @@ -121,7 +130,7 @@ class ChromeProxyService implements VmServiceInterface { } _inspector = await AppInspector.initialize( - tabConnection, + _wipDebugger, _assetHandler, _debugger, uri, @@ -206,8 +215,7 @@ class ChromeProxyService implements VmServiceInterface { require("dart_sdk").developer.invokeExtension( "$method", JSON.stringify(${jsonEncode(stringArgs)})); '''; - var response = - await tabConnection.runtime.sendCommand('Runtime.evaluate', params: { + var response = await _wipDebugger.sendCommand('Runtime.evaluate', params: { 'expression': expression, 'awaitPromise': true, }); diff --git a/dwds/lib/src/services/debug_service.dart b/dwds/lib/src/services/debug_service.dart index 440eae83f..2d02b64f9 100644 --- a/dwds/lib/src/services/debug_service.dart +++ b/dwds/lib/src/services/debug_service.dart @@ -75,12 +75,13 @@ class DebugService { String hostname, ChromeConnection chromeConnection, Future Function(String) assetHandler, - String appInstanceId, { + String appInstanceId, + WipDebugger wipDebugger, { void Function(Map) onRequest, void Function(Map) onResponse, }) async { var chromeProxyService = await ChromeProxyService.create( - chromeConnection, assetHandler, appInstanceId); + chromeConnection, assetHandler, appInstanceId, wipDebugger); var serviceExtensionRegistry = ServiceExtensionRegistry(); var authToken = _makeAuthToken(); var innerHandler = webSocketHandler(_createNewConnectionHandler( diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index 65f405958..07b103f4e 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -9,6 +9,7 @@ import 'package:build_daemon/client.dart'; import 'package:build_daemon/data/build_status.dart'; import 'package:build_daemon/data/build_target.dart'; import 'package:dwds/dwds.dart'; +import 'package:dwds/src/servers/extension_backend.dart'; import 'package:dwds/src/services/chrome_proxy_service.dart'; import 'package:dwds/src/utilities/shared.dart'; import 'package:http/http.dart' as http; @@ -30,6 +31,8 @@ class TestContext { AppConnection appConnection; DebugConnection debugConnection; ChromeProxyService chromeProxyService; + ExtensionBackend extensionBackend; + WipDebugger wipDebugger; int port; File _entryFile; String _entryContents; @@ -99,6 +102,7 @@ class TestContext { () async => connection, reloadConfiguration, serveDevTools, + wipDebugger, ); appUrl = 'http://localhost:$port/$path'; @@ -115,8 +119,8 @@ class TestContext { var result = await http.get('http://localhost:$port/$path'); return result.body; }; - chromeProxyService = await ChromeProxyService.create( - connection, assetHandler, appConnection.request.instanceId); + chromeProxyService = await ChromeProxyService.create(connection, + assetHandler, appConnection.request.instanceId, wipDebugger); } Future tearDown() async { diff --git a/dwds/test/fixtures/server.dart b/dwds/test/fixtures/server.dart index c793d44a0..8cceb691e 100644 --- a/dwds/test/fixtures/server.dart +++ b/dwds/test/fixtures/server.dart @@ -48,6 +48,7 @@ class TestServer { Future Function() chromeConnection, ReloadConfiguration reloadConfiguration, bool serveDevTools, + WipDebugger wipDebugger, ) async { var pipeline = const Pipeline(); @@ -64,6 +65,7 @@ class TestServer { reloadConfiguration: reloadConfiguration, serveDevTools: serveDevTools, verbose: true, + wipDebugger: wipDebugger, ); var server = await HttpMultiServer.bind('localhost', port);