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

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

Issue 59283007: List scripts in library and display script source (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 14
15 ObservatoryApplication _application; 15 ObservatoryApplication _application;
16 ObservatoryApplication get application => _application; 16 ObservatoryApplication get application => _application;
17 17
18 @observable String currentHash = ''; 18 @observable String currentHash = '';
19 19 @observable Uri currentHashUri;
20 void init() { 20 void init() {
21 window.onHashChange.listen((event) { 21 window.onHashChange.listen((event) {
22 if (setDefaultHash()) { 22 if (setDefaultHash()) {
23 // We just triggered another onHashChange event. 23 // We just triggered another onHashChange event.
24 return; 24 return;
25 } 25 }
26 // Request the current anchor. 26 // Request the current anchor.
27 requestCurrentHash(); 27 requestCurrentHash();
28 }); 28 });
29 29
(...skipping 11 matching lines...) Expand all
41 return null; 41 return null;
42 } 42 }
43 return m.input.substring(m.start, m.end); 43 return m.input.substring(m.start, m.end);
44 } 44 }
45 45
46 /// Predicate, does the current URL have a current isolate ID in it? 46 /// Predicate, does the current URL have a current isolate ID in it?
47 bool get hasCurrentIsolate { 47 bool get hasCurrentIsolate {
48 return currentIsolateAnchorPrefix() != null; 48 return currentIsolateAnchorPrefix() != null;
49 } 49 }
50 50
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
51 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId] 60 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId]
52 /// if none is present in window.location. 61 /// if none is present in window.location.
53 int currentIsolateId() { 62 int currentIsolateId() {
54 String isolatePrefix = currentIsolateAnchorPrefix(); 63 String isolatePrefix = currentIsolateAnchorPrefix();
55 if (isolatePrefix == null) { 64 if (isolatePrefix == null) {
56 return InvalidIsolateId; 65 return InvalidIsolateId;
57 } 66 }
58 String id = isolatePrefix.split("/")[2]; 67 String id = isolatePrefix.split("/")[2];
59 return int.parse(id); 68 return int.parse(id);
60 } 69 }
61 70
62 /// If no anchor is set, set the default anchor and return true. 71 /// If no anchor is set, set the default anchor and return true.
63 /// Return false otherwise. 72 /// Return false otherwise.
64 bool setDefaultHash() { 73 bool setDefaultHash() {
65 currentHash = window.location.hash; 74 currentHash = window.location.hash;
66 if (currentHash == '' || currentHash == '#') { 75 if (currentHash == '' || currentHash == '#') {
67 window.location.hash = defaultHash; 76 window.location.hash = defaultHash;
68 return true; 77 return true;
69 } 78 }
70 return false; 79 return false;
71 } 80 }
72 81
73 /// Take the current request string from window.location and submit the 82 /// Take the current request string from window.location and submit the
74 /// request to the request manager. 83 /// request to the request manager.
75 void requestCurrentHash() { 84 void requestCurrentHash() {
76 currentHash = window.location.hash; 85 currentHash = window.location.hash;
77 // Chomp off the # 86 // Chomp off the #
78 String requestUrl = currentHash.substring(1); 87 String requestUrl = currentHash.substring(1);
88 currentHashUri = Uri.parse(requestUrl);
79 application.requestManager.get(requestUrl); 89 application.requestManager.get(requestUrl);
80 } 90 }
81 91
82 /// Create a request for [l] on the current isolate. 92 /// Create a request for [l] on the current isolate.
83 @observable 93 @observable
84 String currentIsolateRelativeLink(String l) { 94 String currentIsolateRelativeLink(String l) {
85 var isolateId = currentIsolateId(); 95 var isolateId = currentIsolateId();
86 if (isolateId == LocationManager.InvalidIsolateId) { 96 if (isolateId == LocationManager.InvalidIsolateId) {
87 return defaultHash; 97 return defaultHash;
88 } 98 }
(...skipping 13 matching lines...) Expand all
102 /// Create a request for [cid] on the current isolate. 112 /// Create a request for [cid] on the current isolate.
103 @observable 113 @observable
104 String currentIsolateClassLink(int cid) { 114 String currentIsolateClassLink(int cid) {
105 var isolateId = currentIsolateId(); 115 var isolateId = currentIsolateId();
106 if (isolateId == LocationManager.InvalidIsolateId) { 116 if (isolateId == LocationManager.InvalidIsolateId) {
107 return defaultHash; 117 return defaultHash;
108 } 118 }
109 return classLink(isolateId, cid); 119 return classLink(isolateId, cid);
110 } 120 }
111 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 }
131
112 /// Create a request for [l] on [isolateId]. 132 /// Create a request for [l] on [isolateId].
113 @observable 133 @observable
114 String relativeLink(int isolateId, String l) { 134 String relativeLink(int isolateId, String l) {
115 return '#/isolates/$isolateId/$l'; 135 return '#/isolates/$isolateId/$l';
116 } 136 }
117 137
118 /// Create a request for [objectId] on [isolateId]. 138 /// Create a request for [objectId] on [isolateId].
119 @observable 139 @observable
120 String objectLink(int isolateId, int objectId) { 140 String objectLink(int isolateId, int objectId) {
121 return '#/isolates/$isolateId/objects/$objectId'; 141 return '#/isolates/$isolateId/objects/$objectId';
122 } 142 }
123 143
124 /// Create a request for [cid] on [isolateId]. 144 /// Create a request for [cid] on [isolateId].
125 @observable 145 @observable
126 String classLink(int isolateId, int cid) { 146 String classLink(int isolateId, int cid) {
127 return '#/isolates/$isolateId/classes/$cid'; 147 return '#/isolates/$isolateId/classes/$cid';
128 } 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 }
129 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698