Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 11 |
| 11 import 'package:observatory/service_common.dart'; | 12 import 'package:observatory/service_common.dart'; |
| 12 | 13 |
| 13 // Export the service library. | 14 // Export the service library. |
| 14 export 'package:observatory/service_common.dart'; | 15 export 'package:observatory/service_common.dart'; |
| 15 | 16 |
| 16 class _HtmlWebSocket implements CommonWebSocket { | 17 class _HtmlWebSocket implements CommonWebSocket { |
| 17 WebSocket _webSocket; | 18 WebSocket _webSocket; |
| 18 | 19 |
| 19 void connect(String address, | 20 void connect(String address, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 30 | 31 |
| 31 bool get isOpen => _webSocket.readyState == WebSocket.OPEN; | 32 bool get isOpen => _webSocket.readyState == WebSocket.OPEN; |
| 32 | 33 |
| 33 void send(dynamic data) { | 34 void send(dynamic data) { |
| 34 _webSocket.send(data); | 35 _webSocket.send(data); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void close() { | 38 void close() { |
| 38 _webSocket.close(); | 39 _webSocket.close(); |
| 39 } | 40 } |
| 41 | |
| 42 Future<ByteData> nonStringToByteData(dynamic data) { | |
| 43 assert(data is Blob); | |
| 44 FileReader fileReader = new FileReader(); | |
| 45 fileReader.readAsArrayBuffer(data); | |
| 46 return fileReader.onLoadEnd.first.then((e) | |
| 47 => new ByteData.view(fileReader.result)); | |
| 48 } | |
| 40 } | 49 } |
| 41 | 50 |
| 42 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM | 51 /// The [WebSocketVM] communicates with a Dart VM over WebSocket. The Dart VM |
| 43 /// can be embedded in Chromium or standalone. In the case of Chromium, we | 52 /// can be embedded in Chromium or standalone. In the case of Chromium, we |
| 44 /// make the service requests via the Chrome Remote Debugging Protocol. | 53 /// make the service requests via the Chrome Remote Debugging Protocol. |
| 45 class WebSocketVM extends CommonWebSocketVM { | 54 class WebSocketVM extends CommonWebSocketVM { |
| 46 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket()); | 55 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket()); |
| 47 } | 56 } |
| 48 | 57 |
| 49 // A VM that communicates with the service via posting messages from DevTools. | 58 // A VM that communicates with the service via posting messages from DevTools. |
| 50 class PostMessageVM extends VM { | 59 class PostMessageVM extends VM { |
|
Cutch
2014/08/15 21:33:58
Dartium needs to support binary messages too, righ
koda
2014/08/15 22:20:53
Per our discussion offline, Dartium doesn't suppor
| |
| 51 final Completer _connected = new Completer(); | 60 final Completer _connected = new Completer(); |
| 52 final Completer _disconnected = new Completer(); | 61 final Completer _disconnected = new Completer(); |
| 53 void disconnect() { /* nope */ } | 62 void disconnect() { /* nope */ } |
| 54 Future get onConnect => _connected.future; | 63 Future get onConnect => _connected.future; |
| 55 Future get onDisconnect => _disconnected.future; | 64 Future get onDisconnect => _disconnected.future; |
| 56 final Map<String, Completer> _pendingRequests = | 65 final Map<String, Completer> _pendingRequests = |
| 57 new Map<String, Completer>(); | 66 new Map<String, Completer>(); |
| 58 int _requestSerial = 0; | 67 int _requestSerial = 0; |
| 59 | 68 |
| 60 PostMessageVM() : super() { | 69 PostMessageVM() : super() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 81 message['id'] = idString; | 90 message['id'] = idString; |
| 82 message['method'] = 'observatoryQuery'; | 91 message['method'] = 'observatoryQuery'; |
| 83 message['query'] = '$path'; | 92 message['query'] = '$path'; |
| 84 _requestSerial++; | 93 _requestSerial++; |
| 85 var completer = new Completer(); | 94 var completer = new Completer(); |
| 86 _pendingRequests[idString] = completer; | 95 _pendingRequests[idString] = completer; |
| 87 window.parent.postMessage(JSON.encode(message), '*'); | 96 window.parent.postMessage(JSON.encode(message), '*'); |
| 88 return completer.future; | 97 return completer.future; |
| 89 } | 98 } |
| 90 } | 99 } |
| OLD | NEW |