Skip to content

Commit 1837b9a

Browse files
Pi Songkunthamgrouma
authored andcommitted
Replaced WipConnection with WipDebugger. (#502)
1 parent 24b8d43 commit 1837b9a

File tree

7 files changed

+40
-22
lines changed

7 files changed

+40
-22
lines changed

dwds/lib/dwds.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Dwds {
5858
LogWriter logWriter,
5959
bool verbose,
6060
bool enableDebugExtension,
61+
WipDebugger wipDebugger,
6162
}) async {
6263
hostname ??= 'localhost';
6364
reloadConfiguration ??= ReloadConfiguration.none;
@@ -99,6 +100,7 @@ class Dwds {
99100
hostname,
100101
verbose,
101102
logWriter,
103+
wipDebugger,
102104
);
103105
cascade = cascade.add(devHandler.handler).add(assetHandler.handler);
104106

dwds/lib/src/debugging/inspector.dart

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AppInspector extends Domain {
3838
/// Map of [ScriptRef] id to containing [LibraryRef] id.
3939
final _scriptIdToLibraryId = <String, String>{};
4040

41-
final WipConnection _tabConnection;
41+
final WipDebugger _wipDebugger;
4242
final AssetHandler _assetHandler;
4343
final Debugger _debugger;
4444
final Isolate isolate;
@@ -49,10 +49,10 @@ class AppInspector extends Domain {
4949

5050
AppInspector._(
5151
this.isolate,
52-
this._tabConnection,
5352
this._assetHandler,
5453
this._debugger,
5554
this._root,
55+
this._wipDebugger,
5656
) : isolateRef = _toIsolateRef(isolate),
5757
super.forInspector();
5858

@@ -81,7 +81,7 @@ class AppInspector extends Domain {
8181
..number = isolate.number;
8282

8383
static Future<AppInspector> initialize(
84-
WipConnection tabConnection,
84+
WipDebugger wipDebugger,
8585
AssetHandler assetHandler,
8686
Debugger debugger,
8787
String root,
@@ -96,7 +96,7 @@ class AppInspector extends Domain {
9696
..libraries = []
9797
..extensionRPCs = [];
9898
var inspector =
99-
AppInspector._(isolate, tabConnection, assetHandler, debugger, root);
99+
AppInspector._(isolate, assetHandler, debugger, root, wipDebugger);
100100
await inspector._initialize();
101101
return inspector;
102102
}
@@ -123,7 +123,7 @@ class AppInspector extends Domain {
123123
return library.$expression;
124124
})();
125125
''';
126-
result = await _tabConnection.runtime.sendCommand('Runtime.evaluate',
126+
result = await _wipDebugger.sendCommand('Runtime.evaluate',
127127
params: {'expression': evalExpression});
128128
handleErrorIfPresent(result,
129129
evalContents: evalExpression,
@@ -139,8 +139,8 @@ function($argsString) {
139139
return library.$expression;
140140
}
141141
''';
142-
result = await _tabConnection.runtime
143-
.sendCommand('Runtime.callFunctionOn', params: {
142+
result =
143+
await _wipDebugger.sendCommand('Runtime.callFunctionOn', params: {
144144
'functionDeclaration': evalExpression,
145145
'arguments': arguments,
146146
// TODO(jakemac): Use the executionContext instead, or possibly the
@@ -265,7 +265,7 @@ function($argsString) {
265265
return result;
266266
})()
267267
''';
268-
var result = await _tabConnection.runtime.sendCommand('Runtime.evaluate',
268+
var result = await _wipDebugger.sendCommand('Runtime.evaluate',
269269
params: {'expression': expression, 'returnByValue': true});
270270
handleErrorIfPresent(result, evalContents: expression);
271271
var classDescriptors = (result.result['result']['value']['classes'] as List)
@@ -405,8 +405,7 @@ function($argsString) {
405405
Future<List<LibraryRef>> _getLibraryRefs() async {
406406
if (_libraryRefs.isNotEmpty) return _libraryRefs.values.toList();
407407
var expression = "require('dart_sdk').dart.getLibraries();";
408-
var librariesResult = await _tabConnection.runtime.sendCommand(
409-
'Runtime.evaluate',
408+
var librariesResult = await _wipDebugger.sendCommand('Runtime.evaluate',
410409
params: {'expression': expression, 'returnByValue': true});
411410
handleErrorIfPresent(librariesResult, evalContents: expression);
412411
var libraries =
@@ -424,8 +423,7 @@ function($argsString) {
424423
/// Runs an eval on the page to compute all existing registered extensions.
425424
Future<List<String>> _getExtensionRpcs() async {
426425
var expression = "require('dart_sdk').developer._extensions.keys.toList();";
427-
var extensionsResult = await _tabConnection.runtime.sendCommand(
428-
'Runtime.evaluate',
426+
var extensionsResult = await _wipDebugger.sendCommand('Runtime.evaluate',
429427
params: {'expression': expression, 'returnByValue': true});
430428
handleErrorIfPresent(extensionsResult, evalContents: expression);
431429
return List.from(extensionsResult.result['result']['value'] as List);

dwds/lib/src/handlers/dev_handler.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class DevHandler {
3939
final bool _verbose;
4040
final void Function(Level, String) _logWriter;
4141
final Future<ChromeConnection> Function() _chromeConnection;
42+
final WipDebugger _wipDebugger;
4243

4344
Stream<AppConnection> get connectedApps => _connectedApps.stream;
4445

@@ -50,6 +51,7 @@ class DevHandler {
5051
this._hostname,
5152
this._verbose,
5253
this._logWriter,
54+
this._wipDebugger,
5355
) {
5456
_sub = buildResults.listen(_emitBuildResults);
5557
_listen();
@@ -87,6 +89,7 @@ class DevHandler {
8789
chromeConnection,
8890
_assetHandler.getRelativeAsset,
8991
appInstanceId,
92+
_wipDebugger,
9093
onResponse: _verbose
9194
? (response) {
9295
if (response['error'] == null) return;

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ChromeProxyService implements VmServiceInterface {
4646
// TODO(grouma) - This should be class private.
4747
final WipConnection tabConnection;
4848

49+
final WipDebugger _wipDebugger;
50+
4951
final AssetHandler _assetHandler;
5052

5153
/// Provides debugger-related functionality.
@@ -61,10 +63,14 @@ class ChromeProxyService implements VmServiceInterface {
6163
this._tab,
6264
this.tabConnection,
6365
this._assetHandler,
66+
this._wipDebugger,
6467
);
6568

66-
static Future<ChromeProxyService> create(ChromeConnection chromeConnection,
67-
AssetHandler assetHandler, String appInstanceId) async {
69+
static Future<ChromeProxyService> create(
70+
ChromeConnection chromeConnection,
71+
AssetHandler assetHandler,
72+
String appInstanceId,
73+
WipDebugger wipDebugger) async {
6874
ChromeTab appTab;
6975
for (var tab in await chromeConnection.getTabs()) {
7076
if (tab.url.startsWith('chrome-extensions:')) continue;
@@ -84,13 +90,16 @@ class ChromeProxyService implements VmServiceInterface {
8490
var tabConnection = await appTab.connect();
8591
await tabConnection.runtime.enable();
8692

93+
wipDebugger = WipDebugger(tabConnection);
94+
8795
// TODO: What about `architectureBits`, `targetCPU`, `hostCPU` and `pid`?
8896
final vm = VM()
8997
..isolates = []
9098
..name = 'ChromeDebugProxy'
9199
..startTime = DateTime.now().millisecondsSinceEpoch
92100
..version = Platform.version;
93-
var service = ChromeProxyService._(vm, appTab, tabConnection, assetHandler);
101+
var service = ChromeProxyService._(
102+
vm, appTab, tabConnection, assetHandler, wipDebugger);
94103
await service._initialize();
95104
await service.createIsolate();
96105
return service;
@@ -121,7 +130,7 @@ class ChromeProxyService implements VmServiceInterface {
121130
}
122131

123132
_inspector = await AppInspector.initialize(
124-
tabConnection,
133+
_wipDebugger,
125134
_assetHandler,
126135
_debugger,
127136
uri,
@@ -206,8 +215,7 @@ class ChromeProxyService implements VmServiceInterface {
206215
require("dart_sdk").developer.invokeExtension(
207216
"$method", JSON.stringify(${jsonEncode(stringArgs)}));
208217
''';
209-
var response =
210-
await tabConnection.runtime.sendCommand('Runtime.evaluate', params: {
218+
var response = await _wipDebugger.sendCommand('Runtime.evaluate', params: {
211219
'expression': expression,
212220
'awaitPromise': true,
213221
});

dwds/lib/src/services/debug_service.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ class DebugService {
7575
String hostname,
7676
ChromeConnection chromeConnection,
7777
Future<String> Function(String) assetHandler,
78-
String appInstanceId, {
78+
String appInstanceId,
79+
WipDebugger wipDebugger, {
7980
void Function(Map<String, dynamic>) onRequest,
8081
void Function(Map<String, dynamic>) onResponse,
8182
}) async {
8283
var chromeProxyService = await ChromeProxyService.create(
83-
chromeConnection, assetHandler, appInstanceId);
84+
chromeConnection, assetHandler, appInstanceId, wipDebugger);
8485
var serviceExtensionRegistry = ServiceExtensionRegistry();
8586
var authToken = _makeAuthToken();
8687
var innerHandler = webSocketHandler(_createNewConnectionHandler(

dwds/test/fixtures/context.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:build_daemon/client.dart';
99
import 'package:build_daemon/data/build_status.dart';
1010
import 'package:build_daemon/data/build_target.dart';
1111
import 'package:dwds/dwds.dart';
12+
import 'package:dwds/src/servers/extension_backend.dart';
1213
import 'package:dwds/src/services/chrome_proxy_service.dart';
1314
import 'package:dwds/src/utilities/shared.dart';
1415
import 'package:http/http.dart' as http;
@@ -30,6 +31,8 @@ class TestContext {
3031
AppConnection appConnection;
3132
DebugConnection debugConnection;
3233
ChromeProxyService chromeProxyService;
34+
ExtensionBackend extensionBackend;
35+
WipDebugger wipDebugger;
3336
int port;
3437
File _entryFile;
3538
String _entryContents;
@@ -99,6 +102,7 @@ class TestContext {
99102
() async => connection,
100103
reloadConfiguration,
101104
serveDevTools,
105+
wipDebugger,
102106
);
103107

104108
appUrl = 'http://localhost:$port/$path';
@@ -115,8 +119,8 @@ class TestContext {
115119
var result = await http.get('http://localhost:$port/$path');
116120
return result.body;
117121
};
118-
chromeProxyService = await ChromeProxyService.create(
119-
connection, assetHandler, appConnection.request.instanceId);
122+
chromeProxyService = await ChromeProxyService.create(connection,
123+
assetHandler, appConnection.request.instanceId, wipDebugger);
120124
}
121125

122126
Future<Null> tearDown() async {

dwds/test/fixtures/server.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TestServer {
4848
Future<ChromeConnection> Function() chromeConnection,
4949
ReloadConfiguration reloadConfiguration,
5050
bool serveDevTools,
51+
WipDebugger wipDebugger,
5152
) async {
5253
var pipeline = const Pipeline();
5354

@@ -64,6 +65,7 @@ class TestServer {
6465
reloadConfiguration: reloadConfiguration,
6566
serveDevTools: serveDevTools,
6667
verbose: true,
68+
wipDebugger: wipDebugger,
6769
);
6870

6971
var server = await HttpMultiServer.bind('localhost', port);

0 commit comments

Comments
 (0)