From 4124ed337dda2b640b436cead8b18a0719746cf9 Mon Sep 17 00:00:00 2001 From: Pi Songkuntham Date: Thu, 18 Jul 2019 18:17:37 -0700 Subject: [PATCH 1/2] Removed tabConnection from ChromeProxyService. --- .../lib/src/connections/debug_connection.dart | 5 ++-- dwds/lib/src/dwds_vm_client.dart | 11 +++++---- dwds/lib/src/handlers/dev_handler.dart | 13 +++++----- .../src/services/chrome_proxy_service.dart | 24 +++++++------------ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/dwds/lib/src/connections/debug_connection.dart b/dwds/lib/src/connections/debug_connection.dart index 7683147b4..4e6237448 100644 --- a/dwds/lib/src/connections/debug_connection.dart +++ b/dwds/lib/src/connections/debug_connection.dart @@ -17,7 +17,8 @@ class DebugConnection { final _onDoneCompleter = Completer(); DebugConnection(this._appDebugServices) { - _appDebugServices.chromeProxyService.tabConnection.onClose.first.then((_) { + _appDebugServices.chromeProxyService.wipDebugger.connection.onClose.first + .then((_) { close(); }); } @@ -33,7 +34,7 @@ class DebugConnection { Future close() async { if (!_onDoneCompleter.isCompleted) _onDoneCompleter.complete(); - await _appDebugServices.chromeProxyService.tabConnection.close(); + await _appDebugServices.chromeProxyService.wipDebugger.connection.close(); await _appDebugServices.close(); } diff --git a/dwds/lib/src/dwds_vm_client.dart b/dwds/lib/src/dwds_vm_client.dart index 954bf5477..e752dddc1 100644 --- a/dwds/lib/src/dwds_vm_client.dart +++ b/dwds/lib/src/dwds_vm_client.dart @@ -40,7 +40,7 @@ class DwdsVmClient { client.registerServiceCallback('hotRestart', (request) async { await _removeBreakpointsAndResume(client); - var response = await chromeProxyService.tabConnection.runtime.sendCommand( + var response = await chromeProxyService.wipDebugger.sendCommand( 'Runtime.evaluate', params: {'expression': r'$dartHotRestart();', 'awaitPromise': true}); var exceptionDetails = response.result['exceptionDetails']; @@ -59,17 +59,18 @@ class DwdsVmClient { await client.registerService('hotRestart', 'DWDS fullReload'); client.registerServiceCallback('fullReload', (_) async { - await chromeProxyService.tabConnection.page.enable(); + await chromeProxyService.wipDebugger.connection.page.enable(); // TODO: use built in `page.reload` once it works, // https://github.com/google/webkit_inspection_protocol.dart/issues/44 - await chromeProxyService.tabConnection.sendCommand('Page.reload'); + await chromeProxyService.wipDebugger.connection + .sendCommand('Page.reload'); return {'result': Success().toJson()}; }); await client.registerService('fullReload', 'DWDS'); client.registerServiceCallback('ext.dwds.screenshot', (_) async { - await chromeProxyService.tabConnection.page.enable(); - var response = await chromeProxyService.tabConnection.page + await chromeProxyService.wipDebugger.connection.page.enable(); + var response = await chromeProxyService.wipDebugger.connection.page .sendCommand('Page.captureScreenshot'); return {'result': response.result}; }); diff --git a/dwds/lib/src/handlers/dev_handler.dart b/dwds/lib/src/handlers/dev_handler.dart index 94f55b60d..82ec63658 100644 --- a/dwds/lib/src/handlers/dev_handler.dart +++ b/dwds/lib/src/handlers/dev_handler.dart @@ -162,7 +162,7 @@ class DevHandler { // If you load the same app in a different tab then we need to throw // away our old services and start new ones. if (!(await _isCorrectTab(message.instanceId, - appServices.chromeProxyService.tabConnection))) { + appServices.chromeProxyService.wipDebugger.connection))) { unawaited(appServices.close()); unawaited(_servicesByAppId.remove(message.appId)); appServices = @@ -173,7 +173,7 @@ class DevHandler { serializers.serialize(DevToolsResponse((b) => b..success = true)))); appServices.connectedInstanceId = message.instanceId; - await appServices.chromeProxyService.tabConnection + await appServices.chromeProxyService.wipDebugger.connection .sendCommand('Target.createTarget', { 'newWindow': true, 'url': 'http://${_devTools.hostname}:${_devTools.port}' @@ -193,8 +193,8 @@ class DevHandler { if (services != null && services.connectedInstanceId == null) { // Re-connect to the previous instance if its in the same tab, // otherwise do nothing for now. - if (await _isCorrectTab( - message.instanceId, services.chromeProxyService.tabConnection)) { + if (await _isCorrectTab(message.instanceId, + services.chromeProxyService.wipDebugger.connection)) { services.connectedInstanceId = message.instanceId; await services.chromeProxyService.createIsolate(); } @@ -241,8 +241,9 @@ class DevHandler { var webdevClient = await DwdsVmClient.create(debugService); var appServices = AppDebugServices(debugService, webdevClient); - unawaited( - appServices.chromeProxyService.tabConnection.onClose.first.then((_) { + unawaited(appServices + .chromeProxyService.wipDebugger.connection.onClose.first + .then((_) { appServices.close(); _servicesByAppId.remove(appId); _logWriter( diff --git a/dwds/lib/src/services/chrome_proxy_service.dart b/dwds/lib/src/services/chrome_proxy_service.dart index 36cd3e542..ee7ff1a5c 100644 --- a/dwds/lib/src/services/chrome_proxy_service.dart +++ b/dwds/lib/src/services/chrome_proxy_service.dart @@ -42,11 +42,7 @@ class ChromeProxyService implements VmServiceInterface { /// The actual chrome tab running this app. final ChromeTab _tab; - /// The connection with the chrome debug service for the tab. - // TODO(grouma) - This should be class private. - final WipConnection tabConnection; - - final WipDebugger _wipDebugger; + final WipDebugger wipDebugger; final AssetHandler _assetHandler; @@ -61,9 +57,8 @@ class ChromeProxyService implements VmServiceInterface { ChromeProxyService._( this._vm, this._tab, - this.tabConnection, this._assetHandler, - this._wipDebugger, + this.wipDebugger, ); static Future create( @@ -98,8 +93,7 @@ class ChromeProxyService implements VmServiceInterface { ..name = 'ChromeDebugProxy' ..startTime = DateTime.now().millisecondsSinceEpoch ..version = Platform.version; - var service = ChromeProxyService._( - vm, appTab, tabConnection, assetHandler, wipDebugger); + var service = ChromeProxyService._(vm, appTab, assetHandler, wipDebugger); await service._initialize(); await service.createIsolate(); return service; @@ -108,7 +102,7 @@ class ChromeProxyService implements VmServiceInterface { Future _initialize() async { _debugger = await Debugger.create( _assetHandler, - tabConnection, + wipDebugger.connection, _streamNotify, _appInspectorProvider, uri, @@ -130,7 +124,7 @@ class ChromeProxyService implements VmServiceInterface { } _inspector = await AppInspector.initialize( - _wipDebugger, + wipDebugger, _assetHandler, _debugger, uri, @@ -215,7 +209,7 @@ class ChromeProxyService implements VmServiceInterface { require("dart_sdk").developer.invokeExtension( "$method", JSON.stringify(${jsonEncode(stringArgs)})); '''; - var response = await _wipDebugger.sendCommand('Runtime.evaluate', params: { + var response = await wipDebugger.sendCommand('Runtime.evaluate', params: { 'expression': expression, 'awaitPromise': true, }); @@ -478,7 +472,7 @@ require("dart_sdk").developer.invokeExtension( exceptionsSubscription?.cancel(); }, onListen: () { chromeConsoleSubscription = - tabConnection.runtime.onConsoleAPICalled.listen((e) { + wipDebugger.connection.runtime.onConsoleAPICalled.listen((e) { var isolate = _inspector?.isolate; if (isolate == null) return; if (!filter(e)) return; @@ -493,7 +487,7 @@ require("dart_sdk").developer.invokeExtension( }); if (includeExceptions) { exceptionsSubscription = - tabConnection.runtime.onExceptionThrown.listen((e) { + wipDebugger.connection.runtime.onExceptionThrown.listen((e) { var isolate = _inspector?.isolate; if (isolate == null) return; controller.add(Event() @@ -509,7 +503,7 @@ require("dart_sdk").developer.invokeExtension( /// Listens for chrome console events and handles the ones we care about. void _setUpChromeConsoleListeners(IsolateRef isolateRef) { - _consoleSubscription = tabConnection.runtime.onConsoleAPICalled + _consoleSubscription = wipDebugger.connection.runtime.onConsoleAPICalled .listen((ConsoleAPIEvent event) { var isolate = _inspector?.isolate; if (isolate == null) return; From e2a19baa6abe4c294715797354f3afeb605d75fe Mon Sep 17 00:00:00 2001 From: Pi Songkuntham Date: Thu, 18 Jul 2019 18:54:06 -0700 Subject: [PATCH 2/2] Used WipDebugger to sendCommand directly --- dwds/lib/src/dwds_vm_client.dart | 5 ++--- dwds/lib/src/handlers/dev_handler.dart | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/dwds/lib/src/dwds_vm_client.dart b/dwds/lib/src/dwds_vm_client.dart index e752dddc1..3362c69c7 100644 --- a/dwds/lib/src/dwds_vm_client.dart +++ b/dwds/lib/src/dwds_vm_client.dart @@ -62,15 +62,14 @@ class DwdsVmClient { await chromeProxyService.wipDebugger.connection.page.enable(); // TODO: use built in `page.reload` once it works, // https://github.com/google/webkit_inspection_protocol.dart/issues/44 - await chromeProxyService.wipDebugger.connection - .sendCommand('Page.reload'); + await chromeProxyService.wipDebugger.sendCommand('Page.reload'); return {'result': Success().toJson()}; }); await client.registerService('fullReload', 'DWDS'); client.registerServiceCallback('ext.dwds.screenshot', (_) async { await chromeProxyService.wipDebugger.connection.page.enable(); - var response = await chromeProxyService.wipDebugger.connection.page + var response = await chromeProxyService.wipDebugger .sendCommand('Page.captureScreenshot'); return {'result': response.result}; }); diff --git a/dwds/lib/src/handlers/dev_handler.dart b/dwds/lib/src/handlers/dev_handler.dart index 82ec63658..1b6774d7b 100644 --- a/dwds/lib/src/handlers/dev_handler.dart +++ b/dwds/lib/src/handlers/dev_handler.dart @@ -173,8 +173,8 @@ class DevHandler { serializers.serialize(DevToolsResponse((b) => b..success = true)))); appServices.connectedInstanceId = message.instanceId; - await appServices.chromeProxyService.wipDebugger.connection - .sendCommand('Target.createTarget', { + await appServices.chromeProxyService.wipDebugger + .sendCommand('Target.createTarget', params: { 'newWindow': true, 'url': 'http://${_devTools.hostname}:${_devTools.port}' '/?hide=none&uri=${appServices.debugService.wsUri}',