| 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 import 'dart:typed_data'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 void close() { | 38 void close() { |
| 39 _webSocket.close(); | 39 _webSocket.close(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 Future<ByteData> nonStringToByteData(dynamic data) { | 42 Future<ByteData> nonStringToByteData(dynamic data) { |
| 43 assert(data is Blob); | 43 assert(data is Blob); |
| 44 FileReader fileReader = new FileReader(); | 44 FileReader fileReader = new FileReader(); |
| 45 fileReader.readAsArrayBuffer(data); | 45 fileReader.readAsArrayBuffer(data); |
| 46 return fileReader.onLoadEnd.first.then((e) | 46 return fileReader.onLoadEnd.first.then((e) { |
| 47 => new ByteData.view(fileReader.result)); | 47 var result = fileReader.result; |
| 48 return new ByteData.view(result.buffer, |
| 49 result.offsetInBytes, |
| 50 result.length); |
| 51 }); |
| 48 } | 52 } |
| 49 } | 53 } |
| 50 | 54 |
| 51 /// 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 |
| 52 /// 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 |
| 53 /// make the service requests via the Chrome Remote Debugging Protocol. | 57 /// make the service requests via the Chrome Remote Debugging Protocol. |
| 54 class WebSocketVM extends CommonWebSocketVM { | 58 class WebSocketVM extends CommonWebSocketVM { |
| 55 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket()); | 59 WebSocketVM(WebSocketVMTarget target) : super(target, new _HtmlWebSocket()); |
| 56 } | 60 } |
| 57 | 61 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 message['id'] = idString; | 94 message['id'] = idString; |
| 91 message['method'] = 'observatoryQuery'; | 95 message['method'] = 'observatoryQuery'; |
| 92 message['query'] = '$path'; | 96 message['query'] = '$path'; |
| 93 _requestSerial++; | 97 _requestSerial++; |
| 94 var completer = new Completer(); | 98 var completer = new Completer(); |
| 95 _pendingRequests[idString] = completer; | 99 _pendingRequests[idString] = completer; |
| 96 window.parent.postMessage(JSON.encode(message), '*'); | 100 window.parent.postMessage(JSON.encode(message), '*'); |
| 97 return completer.future; | 101 return completer.future; |
| 98 } | 102 } |
| 99 } | 103 } |
| OLD | NEW |