Skip to content

Commit 61e6c5b

Browse files
Pi Songkunthamgrouma
authored andcommitted
Removed tabConnection from ChromeProxyService. (#504)
* Removed tabConnection from ChromeProxyService. * Used WipDebugger to sendCommand directly
1 parent 85b04ee commit 61e6c5b

File tree

4 files changed

+25
-29
lines changed

4 files changed

+25
-29
lines changed

dwds/lib/src/connections/debug_connection.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class DebugConnection {
1717
final _onDoneCompleter = Completer();
1818

1919
DebugConnection(this._appDebugServices) {
20-
_appDebugServices.chromeProxyService.tabConnection.onClose.first.then((_) {
20+
_appDebugServices.chromeProxyService.wipDebugger.connection.onClose.first
21+
.then((_) {
2122
close();
2223
});
2324
}
@@ -33,7 +34,7 @@ class DebugConnection {
3334

3435
Future<void> close() async {
3536
if (!_onDoneCompleter.isCompleted) _onDoneCompleter.complete();
36-
await _appDebugServices.chromeProxyService.tabConnection.close();
37+
await _appDebugServices.chromeProxyService.wipDebugger.connection.close();
3738
await _appDebugServices.close();
3839
}
3940

dwds/lib/src/dwds_vm_client.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DwdsVmClient {
4040

4141
client.registerServiceCallback('hotRestart', (request) async {
4242
await _removeBreakpointsAndResume(client);
43-
var response = await chromeProxyService.tabConnection.runtime.sendCommand(
43+
var response = await chromeProxyService.wipDebugger.sendCommand(
4444
'Runtime.evaluate',
4545
params: {'expression': r'$dartHotRestart();', 'awaitPromise': true});
4646
var exceptionDetails = response.result['exceptionDetails'];
@@ -59,17 +59,17 @@ class DwdsVmClient {
5959
await client.registerService('hotRestart', 'DWDS fullReload');
6060

6161
client.registerServiceCallback('fullReload', (_) async {
62-
await chromeProxyService.tabConnection.page.enable();
62+
await chromeProxyService.wipDebugger.connection.page.enable();
6363
// TODO: use built in `page.reload` once it works,
6464
// https://github.com/google/webkit_inspection_protocol.dart/issues/44
65-
await chromeProxyService.tabConnection.sendCommand('Page.reload');
65+
await chromeProxyService.wipDebugger.sendCommand('Page.reload');
6666
return {'result': Success().toJson()};
6767
});
6868
await client.registerService('fullReload', 'DWDS');
6969

7070
client.registerServiceCallback('ext.dwds.screenshot', (_) async {
71-
await chromeProxyService.tabConnection.page.enable();
72-
var response = await chromeProxyService.tabConnection.page
71+
await chromeProxyService.wipDebugger.connection.page.enable();
72+
var response = await chromeProxyService.wipDebugger
7373
.sendCommand('Page.captureScreenshot');
7474
return {'result': response.result};
7575
});

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class DevHandler {
162162
// If you load the same app in a different tab then we need to throw
163163
// away our old services and start new ones.
164164
if (!(await _isCorrectTab(message.instanceId,
165-
appServices.chromeProxyService.tabConnection))) {
165+
appServices.chromeProxyService.wipDebugger.connection))) {
166166
unawaited(appServices.close());
167167
unawaited(_servicesByAppId.remove(message.appId));
168168
appServices =
@@ -173,8 +173,8 @@ class DevHandler {
173173
serializers.serialize(DevToolsResponse((b) => b..success = true))));
174174

175175
appServices.connectedInstanceId = message.instanceId;
176-
await appServices.chromeProxyService.tabConnection
177-
.sendCommand('Target.createTarget', {
176+
await appServices.chromeProxyService.wipDebugger
177+
.sendCommand('Target.createTarget', params: {
178178
'newWindow': true,
179179
'url': 'http://${_devTools.hostname}:${_devTools.port}'
180180
'/?hide=none&uri=${appServices.debugService.wsUri}',
@@ -193,8 +193,8 @@ class DevHandler {
193193
if (services != null && services.connectedInstanceId == null) {
194194
// Re-connect to the previous instance if its in the same tab,
195195
// otherwise do nothing for now.
196-
if (await _isCorrectTab(
197-
message.instanceId, services.chromeProxyService.tabConnection)) {
196+
if (await _isCorrectTab(message.instanceId,
197+
services.chromeProxyService.wipDebugger.connection)) {
198198
services.connectedInstanceId = message.instanceId;
199199
await services.chromeProxyService.createIsolate();
200200
}
@@ -241,8 +241,9 @@ class DevHandler {
241241
var webdevClient = await DwdsVmClient.create(debugService);
242242
var appServices = AppDebugServices(debugService, webdevClient);
243243

244-
unawaited(
245-
appServices.chromeProxyService.tabConnection.onClose.first.then((_) {
244+
unawaited(appServices
245+
.chromeProxyService.wipDebugger.connection.onClose.first
246+
.then((_) {
246247
appServices.close();
247248
_servicesByAppId.remove(appId);
248249
_logWriter(

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ class ChromeProxyService implements VmServiceInterface {
4242
/// The actual chrome tab running this app.
4343
final ChromeTab _tab;
4444

45-
/// The connection with the chrome debug service for the tab.
46-
// TODO(grouma) - This should be class private.
47-
final WipConnection tabConnection;
48-
49-
final WipDebugger _wipDebugger;
45+
final WipDebugger wipDebugger;
5046

5147
final AssetHandler _assetHandler;
5248

@@ -61,9 +57,8 @@ class ChromeProxyService implements VmServiceInterface {
6157
ChromeProxyService._(
6258
this._vm,
6359
this._tab,
64-
this.tabConnection,
6560
this._assetHandler,
66-
this._wipDebugger,
61+
this.wipDebugger,
6762
);
6863

6964
static Future<ChromeProxyService> create(
@@ -98,8 +93,7 @@ class ChromeProxyService implements VmServiceInterface {
9893
..name = 'ChromeDebugProxy'
9994
..startTime = DateTime.now().millisecondsSinceEpoch
10095
..version = Platform.version;
101-
var service = ChromeProxyService._(
102-
vm, appTab, tabConnection, assetHandler, wipDebugger);
96+
var service = ChromeProxyService._(vm, appTab, assetHandler, wipDebugger);
10397
await service._initialize();
10498
await service.createIsolate();
10599
return service;
@@ -108,7 +102,7 @@ class ChromeProxyService implements VmServiceInterface {
108102
Future<Null> _initialize() async {
109103
_debugger = await Debugger.create(
110104
_assetHandler,
111-
tabConnection,
105+
wipDebugger.connection,
112106
_streamNotify,
113107
_appInspectorProvider,
114108
uri,
@@ -130,7 +124,7 @@ class ChromeProxyService implements VmServiceInterface {
130124
}
131125

132126
_inspector = await AppInspector.initialize(
133-
_wipDebugger,
127+
wipDebugger,
134128
_assetHandler,
135129
_debugger,
136130
uri,
@@ -215,7 +209,7 @@ class ChromeProxyService implements VmServiceInterface {
215209
require("dart_sdk").developer.invokeExtension(
216210
"$method", JSON.stringify(${jsonEncode(stringArgs)}));
217211
''';
218-
var response = await _wipDebugger.sendCommand('Runtime.evaluate', params: {
212+
var response = await wipDebugger.sendCommand('Runtime.evaluate', params: {
219213
'expression': expression,
220214
'awaitPromise': true,
221215
});
@@ -478,7 +472,7 @@ require("dart_sdk").developer.invokeExtension(
478472
exceptionsSubscription?.cancel();
479473
}, onListen: () {
480474
chromeConsoleSubscription =
481-
tabConnection.runtime.onConsoleAPICalled.listen((e) {
475+
wipDebugger.connection.runtime.onConsoleAPICalled.listen((e) {
482476
var isolate = _inspector?.isolate;
483477
if (isolate == null) return;
484478
if (!filter(e)) return;
@@ -493,7 +487,7 @@ require("dart_sdk").developer.invokeExtension(
493487
});
494488
if (includeExceptions) {
495489
exceptionsSubscription =
496-
tabConnection.runtime.onExceptionThrown.listen((e) {
490+
wipDebugger.connection.runtime.onExceptionThrown.listen((e) {
497491
var isolate = _inspector?.isolate;
498492
if (isolate == null) return;
499493
controller.add(Event()
@@ -509,7 +503,7 @@ require("dart_sdk").developer.invokeExtension(
509503

510504
/// Listens for chrome console events and handles the ones we care about.
511505
void _setUpChromeConsoleListeners(IsolateRef isolateRef) {
512-
_consoleSubscription = tabConnection.runtime.onConsoleAPICalled
506+
_consoleSubscription = wipDebugger.connection.runtime.onConsoleAPICalled
513507
.listen((ConsoleAPIEvent event) {
514508
var isolate = _inspector?.isolate;
515509
if (isolate == null) return;

0 commit comments

Comments
 (0)