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 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 // that the Observatory is loaded from. | 25 // that the Observatory is loaded from. |
| 26 host = 'http://${window.location.host}/'; | 26 host = 'http://${window.location.host}/'; |
| 27 } else { | 27 } else { |
| 28 // Otherwise, assume we are running from the Dart Editor and | 28 // Otherwise, assume we are running from the Dart Editor and |
| 29 // want to connect on the default port. | 29 // want to connect on the default port. |
| 30 host = 'http://127.0.0.1:8181/'; | 30 host = 'http://127.0.0.1:8181/'; |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 Future<String> getString(String id) { | 34 Future<String> getString(String id) { |
| 35 // Ensure we don't request host//id. | |
| 36 if (host.endsWith('/') && id.startsWith('/')) { | |
| 37 id = id.substring(1); | |
| 38 } | |
| 35 Logger.root.info('Fetching $id from $host'); | 39 Logger.root.info('Fetching $id from $host'); |
| 36 return HttpRequest.getString(host + id).catchError((error) { | 40 return HttpRequest.request(host + id, |
| 41 requestHeaders: { | |
| 42 'observatory': 'observatory' | |
|
turnidge
2014/06/04 18:02:24
Header names are usually Dashed-With-Capital-Lette
Cutch
2014/06/04 20:28:57
Done.
| |
| 43 }).then((HttpRequest request) { | |
| 44 return request.responseText; | |
| 45 }).catchError((error) { | |
| 37 // If we get an error here, the network request has failed. | 46 // If we get an error here, the network request has failed. |
| 38 Logger.root.severe('HttpRequest.getString failed.'); | 47 Logger.root.severe('HttpRequest.request failed.'); |
| 39 var request = error.target; | 48 var request = error.target; |
| 40 return JSON.encode({ | 49 return JSON.encode({ |
| 41 'type': 'ServiceException', | 50 'type': 'ServiceException', |
| 42 'id': '', | 51 'id': '', |
| 43 'response': error.target.responseText, | 52 'response': request.responseText, |
| 44 'kind': 'NetworkException', | 53 'kind': 'NetworkException', |
| 45 'message': 'Could not connect to service. Check that you started the' | 54 'message': 'Could not connect to service (${request.statusText}). ' |
| 46 ' VM with the following flags:\n --enable-vm-service' | 55 'Check that you started the VM with the following flags: ' |
| 47 ' --pause-isolates-on-exit' | 56 '--observe' |
| 48 }); | 57 }); |
| 49 }); | 58 }); |
| 50 } | 59 } |
| 51 } | 60 } |
| 52 | 61 |
| 53 class DartiumVM extends VM { | 62 class DartiumVM extends VM { |
| 54 final Map _outstandingRequests = new Map(); | 63 final Map _outstandingRequests = new Map(); |
| 55 int _requestSerial = 0; | 64 int _requestSerial = 0; |
| 56 | 65 |
| 57 DartiumVM() : super() { | 66 DartiumVM() : super() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 78 message['id'] = idString; | 87 message['id'] = idString; |
| 79 message['method'] = 'observatoryQuery'; | 88 message['method'] = 'observatoryQuery'; |
| 80 message['query'] = '/$path'; | 89 message['query'] = '/$path'; |
| 81 _requestSerial++; | 90 _requestSerial++; |
| 82 var completer = new Completer(); | 91 var completer = new Completer(); |
| 83 _outstandingRequests[idString] = completer; | 92 _outstandingRequests[idString] = completer; |
| 84 window.parent.postMessage(JSON.encode(message), '*'); | 93 window.parent.postMessage(JSON.encode(message), '*'); |
| 85 return completer.future; | 94 return completer.future; |
| 86 } | 95 } |
| 87 } | 96 } |
| OLD | NEW |