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

Unified Diff: runtime/bin/vmservice/client/observatory/packages/observatory/src/observatory/anchor.dart

Issue 24471002: Initial GUI for review (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/client/observatory/packages/observatory/src/observatory/anchor.dart
diff --git a/runtime/bin/vmservice/client/observatory/packages/observatory/src/observatory/anchor.dart b/runtime/bin/vmservice/client/observatory/packages/observatory/src/observatory/anchor.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8f1fee323e30cbdb5426f98ed69c8977c096ad46
--- /dev/null
+++ b/runtime/bin/vmservice/client/observatory/packages/observatory/src/observatory/anchor.dart
@@ -0,0 +1,111 @@
+part of observatory;
+
+class Anchor extends Object with ObservableMixin {
justinfagnani 2013/09/24 23:20:16 What does this class do? Is it an HTML <a> tag of
+ static const int InvalidIsolateId = 0;
+ static const String defaultAnchor = '#/isolates/';
+ static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+/");
+
+ ObservatoryApplication _application;
+ ObservatoryApplication get application => _application;
+
+ @observable String currentAnchor = '';
+
+ void init() {
+ window.onHashChange.listen((event) {
+ if (setDefaultAnchor()) {
+ // We just triggered another onHashChange event.
+ return;
+ }
+ // Request the current anchor.
+ requestCurrentAnchor();
+ });
+
+ if (!setDefaultAnchor()) {
+ // An anchor was already present, trigger a request.
+ requestCurrentAnchor();
+ }
+ }
+
+ String currentIsolateAnchorPrefix() {
+ Match m = currentIsolateMatcher.matchAsPrefix(currentAnchor);
+ if (m == null) {
+ return null;
+ }
+ return m.input.substring(m.start, m.end);
+ }
+
+ bool get hasCurrentIsolate {
+ return currentIsolateAnchorPrefix() != null;
+ }
+
+ int currentIsolateId() {
+ String isolatePrefix = currentIsolateAnchorPrefix();
+ if (isolatePrefix == null) {
+ return InvalidIsolateId;
+ }
+ String id = isolatePrefix.split("/")[2];
+ return int.parse(id);
+ }
+
+ bool setDefaultAnchor() {
+ currentAnchor = window.location.hash;
+ if (currentAnchor == '' || currentAnchor == '#') {
+ window.location.hash = defaultAnchor;
+ return true;
+ }
+ return false;
+ }
+
+ String linkToContainerObject(String container, int id) {
+ String link = currentIsolateAnchorPrefix();
+ if (link == null) {
+ return '';
+ }
+ link += '$container/';
+ link += id.toString();
+ return link;
+ }
+
+ void requestCurrentAnchor() {
+ currentAnchor = window.location.hash;
+ // Chomp off the #
+ String requestUrl = currentAnchor.substring(1);
+ application.requestManager.get(requestUrl);
+ }
+
+ String currentIsolateRelativeLink(String l) {
+ var isolateId = currentIsolateId();
+ if (isolateId == Anchor.InvalidIsolateId) {
+ return defaultAnchor;
+ }
+ return relativeLink(isolateId, l);
+ }
+
+ String currentIsolateObjectLink(int objectId) {
+ var isolateId = currentIsolateId();
+ if (isolateId == Anchor.InvalidIsolateId) {
+ return defaultAnchor;
+ }
+ return objectLink(isolateId, objectId);
+ }
+
+ String currentIsolateClassLink(int cid) {
+ var isolateId = currentIsolateId();
+ if (isolateId == Anchor.InvalidIsolateId) {
+ return defaultAnchor;
+ }
+ return classLink(isolateId, cid);
+ }
+
+ String relativeLink(int isolateId, String l) {
+ return '#/isolates/$isolateId/$l';
+ }
+
+ String objectLink(int isolateId, int objectId) {
+ return '#/isolates/$isolateId/objects/$objectId';
+ }
+
+ String classLink(int isolateId, int cid) {
+ return '#/isolates/$isolateId/classes/$cid';
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698