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

Side by Side Diff: runtime/bin/vmservice/client/lib/service_html.dart

Issue 208243006: Allow built in Observatory to work on any port (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 10
11 import 'package:logging/logging.dart'; 11 import 'package:logging/logging.dart';
12 import 'package:observatory/service.dart'; 12 import 'package:observatory/service.dart';
13 13
14 // Export the service library. 14 // Export the service library.
15 export 'package:observatory/service.dart'; 15 export 'package:observatory/service.dart';
16 16
17 class HttpVM extends VM { 17 class HttpVM extends VM {
18 final String address; 18 String host;
19 19
20 HttpVM(this.address) : super(); 20 bool runningInJavaScript() => identical(1.0, 1);
21
22 HttpVM() : super() {
23 if (runningInJavaScript()) {
24 // When we are running as JavaScript use the same hostname:port
25 // that the Observatory is loaded from.
26 host = 'http://${window.location.host}/';
27 } else {
28 // Otherwise, assume we are running from the Dart Editor and
29 // want to connect on the defaul port.
turnidge 2014/03/21 19:48:45 defaul -> default
30 host = 'http://127.0.0.1:8181/';
31 }
32 }
21 33
22 Future<String> getString(String id) { 34 Future<String> getString(String id) {
23 Logger.root.info('Fetching $id from $address'); 35 Logger.root.info('Fetching $id from $host');
24 return HttpRequest.getString(address + id).catchError((error) { 36 return HttpRequest.getString(host + id).catchError((error) {
25 // If we get an error here, the network request has failed. 37 // If we get an error here, the network request has failed.
26 Logger.root.severe('HttpRequest.getString failed.'); 38 Logger.root.severe('HttpRequest.getString failed.');
27 return JSON.encode({ 39 return JSON.encode({
28 'type': 'Error', 40 'type': 'Error',
29 'id': '', 41 'id': '',
30 'kind': 'NetworkError', 42 'kind': 'NetworkError',
31 'message': 'Could not connect to service. Check that you started the' 43 'message': 'Could not connect to service. Check that you started the'
32 ' VM with the following flags:\n --enable-vm-service' 44 ' VM with the following flags:\n --enable-vm-service'
33 ' --pin-isolates' 45 ' --pin-isolates'
34 }); 46 });
(...skipping 29 matching lines...) Expand all
64 message['id'] = idString; 76 message['id'] = idString;
65 message['method'] = 'observatoryQuery'; 77 message['method'] = 'observatoryQuery';
66 message['query'] = '/$path'; 78 message['query'] = '/$path';
67 _requestSerial++; 79 _requestSerial++;
68 var completer = new Completer(); 80 var completer = new Completer();
69 _outstandingRequests[idString] = completer; 81 _outstandingRequests[idString] = completer;
70 window.parent.postMessage(JSON.encode(message), '*'); 82 window.parent.postMessage(JSON.encode(message), '*');
71 return completer.future; 83 return completer.future;
72 } 84 }
73 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698