Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: runtime/observatory/lib/service_html.dart

Issue 823403004: Begin migrating the vm service from a rest-style interface to a json-rpc style interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: remove old-style standalone tests. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library service_html; 5 library service_html;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:html'; 9 import 'dart:html';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 }); 51 });
52 } 52 }
53 } 53 }
54 54
55 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM 55 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM
56 /// can be embedded in Chromium or standalone. In the case of Chromium, we 56 /// can be embedded in Chromium or standalone. In the case of Chromium, we
57 /// make the service requests via the Chrome Remote Debugging Protocol. 57 /// make the service requests via the Chrome Remote Debugging Protocol.
58 class WebSocketVM extends CommonWebSocketVM { 58 class WebSocketVM extends CommonWebSocketVM {
59 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket()); 59 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket());
60 } 60 }
61
62 // A VM that communicates with the service via posting messages from DevTools.
63 class PostMessageVM extends VM {
64 final Completer _connected = new Completer();
65 final Completer _disconnected = new Completer();
66 void disconnect() { /* nope */ }
67 Future get onConnect => _connected.future;
68 Future get onDisconnect => _disconnected.future;
69 final Map<String, Completer> _pendingRequests =
70 new Map<String, Completer>();
71 int _requestSerial = 0;
72
73 PostMessageVM() : super() {
74 window.onMessage.listen(_messageHandler);
75 _connected.complete(this);
76 }
77
78 void _messageHandler(msg) {
79 var id = msg.data['id'];
80 var name = msg.data['name'];
81 var data = msg.data['data'];
82 if (name != 'observatoryData') {
83 return;
84 }
85 var completer = _pendingRequests[id];
86 assert(completer != null);
87 _pendingRequests.remove(id);
88 completer.complete(data);
89 }
90
91 Future<String> getString(String path) {
92 var idString = '$_requestSerial';
93 Map message = {};
94 message['id'] = idString;
95 message['method'] = 'observatoryQuery';
96 message['query'] = '$path';
97 _requestSerial++;
98 var completer = new Completer();
99 _pendingRequests[idString] = completer;
100 window.parent.postMessage(JSON.encode(message), '*');
101 return completer.future;
102 }
103 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/service_common.dart ('k') | runtime/observatory/lib/src/app/application.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698