| OLD | NEW |
| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 return false; | 73 return false; |
| 71 } | 74 } |
| 72 | 75 |
| 73 /// Take the current request string from window.location and submit the | 76 /// Take the current request string from window.location and submit the |
| 74 /// request to the request manager. | 77 /// request to the request manager. |
| 75 void requestCurrentHash() { | 78 void requestCurrentHash() { |
| 76 currentHash = window.location.hash; | 79 currentHash = window.location.hash; |
| 77 // Chomp off the # | 80 // Chomp off the # |
| 78 String requestUrl = currentHash.substring(1); | 81 String requestUrl = currentHash.substring(1); |
| 79 currentHashUri = Uri.parse(requestUrl); | 82 currentHashUri = Uri.parse(requestUrl); |
| 80 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 } |
| 81 } | 89 } |
| 82 | 90 |
| 83 /// Create a request for [l] on the current isolate. | 91 /// Create a request for [l] on the current isolate. |
| 84 @observable | 92 @observable |
| 85 String currentIsolateRelativeLink(String l) { | 93 String currentIsolateRelativeLink(String l) { |
| 86 var isolateId = currentIsolateId(); | 94 var isolateId = currentIsolateId(); |
| 87 if (isolateId == LocationManager.InvalidIsolateId) { | 95 if (isolateId == LocationManager.InvalidIsolateId) { |
| 88 return defaultHash; | 96 return defaultHash; |
| 89 } | 97 } |
| 90 return relativeLink(isolateId, l); | 98 return relativeLink(isolateId, l); |
| 91 } | 99 } |
| 92 | 100 |
| 93 /// Create a request for [scriptURL] on the current isolate. | 101 /// Create a request for [scriptURL] on the current isolate. |
| 94 @observable | 102 @observable |
| 95 String currentIsolateScriptLink(String scriptURL) { | 103 String currentIsolateScriptLink(String scriptURL) { |
| 96 var encoded = Uri.encodeComponent(scriptURL); | 104 var encoded = Uri.encodeComponent(scriptURL); |
| 97 return currentIsolateRelativeLink('scripts/$encoded'); | 105 return currentIsolateRelativeLink('scripts/$encoded'); |
| 98 } | 106 } |
| 99 | 107 |
| 100 /// Create a request for [l] on [isolateId]. | 108 /// Create a request for [l] on [isolateId]. |
| 101 @observable | 109 @observable |
| 102 String relativeLink(String isolateId, String l) { | 110 String relativeLink(String isolateId, String l) { |
| 103 return '#/$isolateId/$l'; | 111 return '#/$isolateId/$l'; |
| 104 } | 112 } |
| 105 } | 113 } |
| OLD | NEW |