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

Side by Side Diff: dart/runtime/bin/vmservice/client/lib/src/observatory/location_manager.dart

Issue 119673004: Version 1.1.0-dev.5.2 (Closed) Base URL: http://dart.googlecode.com/svn/trunk/
Patch Set: Created 6 years, 11 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of observatory; 5 part of observatory;
6 6
7 /// The LocationManager class observes and parses the hash ('#') portion of the 7 /// The LocationManager class observes and parses the hash ('#') portion of the
8 /// URL in window.location. The text after the '#' is used as the request 8 /// URL in window.location. The text after the '#' is used as the request
9 /// string for the VM service. 9 /// string for the VM service.
10 class LocationManager extends Observable { 10 class LocationManager extends Observable {
11 static const int InvalidIsolateId = 0; 11 static const int InvalidIsolateId = 0;
12 static const String defaultHash = '#/isolates/'; 12 static const String defaultHash = '#/isolates/';
13 static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+/"); 13 static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+");
14 static final RegExp currentIsolateProfileMatcher =
15 new RegExp(r'#/isolates/\d+/profile');
14 16
15 ObservatoryApplication _application; 17 ObservatoryApplication _application;
16 ObservatoryApplication get application => _application; 18 ObservatoryApplication get application => _application;
17 19
20 @observable bool profile = false;
18 @observable String currentHash = ''; 21 @observable String currentHash = '';
19 @observable Uri currentHashUri; 22 @observable Uri currentHashUri;
20 void init() { 23 void init() {
21 window.onHashChange.listen((event) { 24 window.onHashChange.listen((event) {
22 if (setDefaultHash()) { 25 if (setDefaultHash()) {
23 // We just triggered another onHashChange event. 26 // We just triggered another onHashChange event.
24 return; 27 return;
25 } 28 }
26 // Request the current anchor. 29 // Request the current anchor.
27 requestCurrentHash(); 30 requestCurrentHash();
(...skipping 13 matching lines...) Expand all
41 return null; 44 return null;
42 } 45 }
43 return m.input.substring(m.start, m.end); 46 return m.input.substring(m.start, m.end);
44 } 47 }
45 48
46 /// Predicate, does the current URL have a current isolate ID in it? 49 /// Predicate, does the current URL have a current isolate ID in it?
47 bool get hasCurrentIsolate { 50 bool get hasCurrentIsolate {
48 return currentIsolateAnchorPrefix() != null; 51 return currentIsolateAnchorPrefix() != null;
49 } 52 }
50 53
51 bool get isScriptLink {
52 String type = currentHashUri.queryParameters['type'];
53 return type == 'Script';
54 }
55
56 String get scriptName {
57 return Uri.decodeQueryComponent(currentHashUri.queryParameters['name']);
58 }
59
60 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId] 54 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId]
61 /// if none is present in window.location. 55 /// if none is present in window.location.
62 int currentIsolateId() { 56 String currentIsolateId() {
63 String isolatePrefix = currentIsolateAnchorPrefix(); 57 var prefix = currentIsolateAnchorPrefix();
64 if (isolatePrefix == null) { 58 if (prefix == null) {
65 return InvalidIsolateId; 59 return '';
66 } 60 }
67 String id = isolatePrefix.split("/")[2]; 61 // Chop off the '/#'.
68 return int.parse(id); 62 return prefix.substring(2);
69 } 63 }
70 64
71 /// If no anchor is set, set the default anchor and return true. 65 /// If no anchor is set, set the default anchor and return true.
72 /// Return false otherwise. 66 /// Return false otherwise.
73 bool setDefaultHash() { 67 bool setDefaultHash() {
74 currentHash = window.location.hash; 68 currentHash = window.location.hash;
75 if (currentHash == '' || currentHash == '#') { 69 if (currentHash == '' || currentHash == '#') {
76 window.location.hash = defaultHash; 70 window.location.hash = defaultHash;
77 return true; 71 return true;
78 } 72 }
79 return false; 73 return false;
80 } 74 }
81 75
82 /// Take the current request string from window.location and submit the 76 /// Take the current request string from window.location and submit the
83 /// request to the request manager. 77 /// request to the request manager.
84 void requestCurrentHash() { 78 void requestCurrentHash() {
85 currentHash = window.location.hash; 79 currentHash = window.location.hash;
86 // Chomp off the # 80 // Chomp off the #
87 String requestUrl = currentHash.substring(1); 81 String requestUrl = currentHash.substring(1);
88 currentHashUri = Uri.parse(requestUrl); 82 currentHashUri = Uri.parse(requestUrl);
89 application.requestManager.get(requestUrl); 83 if (currentIsolateProfileMatcher.hasMatch(currentHash)) {
84 // We do not automatically fetch profile data.
85 profile = true;
86 } else {
87 application.requestManager.get(requestUrl);
88 }
90 } 89 }
91 90
92 /// Create a request for [l] on the current isolate. 91 /// Create a request for [l] on the current isolate.
93 @observable 92 @observable
94 String currentIsolateRelativeLink(String l) { 93 String currentIsolateRelativeLink(String l) {
95 var isolateId = currentIsolateId(); 94 var isolateId = currentIsolateId();
96 if (isolateId == LocationManager.InvalidIsolateId) { 95 if (isolateId == LocationManager.InvalidIsolateId) {
97 return defaultHash; 96 return defaultHash;
98 } 97 }
99 return relativeLink(isolateId, l); 98 return relativeLink(isolateId, l);
100 } 99 }
101 100
102 /// Create a request for [objectId] on the current isolate. 101 /// Create a request for [scriptURL] on the current isolate.
103 @observable 102 @observable
104 String currentIsolateObjectLink(int objectId) { 103 String currentIsolateScriptLink(String scriptURL) {
105 var isolateId = currentIsolateId(); 104 var encoded = Uri.encodeComponent(scriptURL);
106 if (isolateId == LocationManager.InvalidIsolateId) { 105 return currentIsolateRelativeLink('scripts/$encoded');
107 return defaultHash;
108 }
109 return objectLink(isolateId, objectId);
110 }
111
112 /// Create a request for [cid] on the current isolate.
113 @observable
114 String currentIsolateClassLink(int cid) {
115 var isolateId = currentIsolateId();
116 if (isolateId == LocationManager.InvalidIsolateId) {
117 return defaultHash;
118 }
119 return classLink(isolateId, cid);
120 }
121
122 /// Create a request for the script [objectId] with script [name].
123 @observable
124 String currentIsolateScriptLink(int objectId, String name) {
125 var isolateId = currentIsolateId();
126 if (isolateId == LocationManager.InvalidIsolateId) {
127 return defaultHash;
128 }
129 return scriptLink(isolateId, objectId, name);
130 } 106 }
131 107
132 /// Create a request for [l] on [isolateId]. 108 /// Create a request for [l] on [isolateId].
133 @observable 109 @observable
134 String relativeLink(int isolateId, String l) { 110 String relativeLink(String isolateId, String l) {
135 return '#/isolates/$isolateId/$l'; 111 return '#/$isolateId/$l';
136 }
137
138 /// Create a request for [objectId] on [isolateId].
139 @observable
140 String objectLink(int isolateId, int objectId) {
141 return '#/isolates/$isolateId/objects/$objectId';
142 }
143
144 /// Create a request for [cid] on [isolateId].
145 @observable
146 String classLink(int isolateId, int cid) {
147 return '#/isolates/$isolateId/classes/$cid';
148 }
149
150 @observable
151 /// Create a request for the script [objectId] with script [url].
152 String scriptLink(int isolateId, int objectId, String name) {
153 String encodedName = Uri.encodeQueryComponent(name);
154 return '#/isolates/$isolateId/objects/$objectId'
155 '?type=Script&name=$encodedName';
156 } 112 }
157 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698