| 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 app; | 5 part of app; |
| 6 | 6 |
| 7 class LocationManager extends Observable { | 7 class LocationManager extends Observable { |
| 8 final _defaultPath = '/vm'; | 8 final _defaultPath = '/vm'; |
| 9 | 9 |
| 10 final ObservatoryApplication _app; | 10 final ObservatoryApplication _app; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 /// Add [url] to the browser history. | 75 /// Add [url] to the browser history. |
| 76 _addToBrowserHistory(String url) { | 76 _addToBrowserHistory(String url) { |
| 77 window.history.pushState(url, document.title, url); | 77 window.history.pushState(url, document.title, url); |
| 78 } | 78 } |
| 79 | 79 |
| 80 /// Notify the current page that something has changed. | 80 /// Notify the current page that something has changed. |
| 81 _visit() { | 81 _visit() { |
| 82 runZoned(() => _app._visit(_uri, internalArguments), | 82 runZoned(() => _app._visit(_uri, internalArguments), |
| 83 onError: (e, st) { | 83 onError: (e, st) { |
| 84 if (e is IsolateNotFound) { | 84 if (e is IsolateNotFound) { |
| 85 var newPath = _app.vm == null ? '/vm-connect' : '/isolate-reconnect'; | 85 var newPath = ((_app.vm == null || _app.vm.isDisconnected) |
| 86 ? '/vm-connect' : '/isolate-reconnect'); |
| 86 var parameters = {}; | 87 var parameters = {}; |
| 87 parameters.addAll(_uri.queryParameters); | 88 parameters.addAll(_uri.queryParameters); |
| 88 parameters['originalPath'] = _uri.path; | 89 parameters['originalPath'] = _uri.path; |
| 89 parameters['originalIsolateId'] = parameters['isolateId']; | 90 parameters['originalIsolateId'] = parameters['isolateId']; |
| 90 var generatedUri = new Uri(path: newPath, queryParameters: parameters); | 91 var generatedUri = new Uri(path: newPath, queryParameters: parameters); |
| 91 go(makeLink(generatedUri.toString()), true); | 92 go(makeLink(generatedUri.toString()), true); |
| 92 return; | 93 return; |
| 93 } | 94 } |
| 94 throw e; | 95 // Surface any uncaught exceptions. |
| 96 _app.handleException(e, st); |
| 95 }); | 97 }); |
| 96 } | 98 } |
| 97 | 99 |
| 98 /// Navigate to [url]. | 100 /// Navigate to [url]. |
| 99 void go(String url, [bool addToBrowserHistory = true]) { | 101 void go(String url, [bool addToBrowserHistory = true]) { |
| 100 if ((url != makeLink('/vm-connect')) && _app.vm == null) { | 102 if ((url != makeLink('/vm-connect')) && |
| 103 (_app.vm == null || _app.vm.isDisconnected)) { |
| 101 if (!window.confirm('Connection with VM has been lost. ' | 104 if (!window.confirm('Connection with VM has been lost. ' |
| 102 'Proceeding will lose current page.')) { | 105 'Proceeding will lose current page.')) { |
| 103 return; | 106 return; |
| 104 } | 107 } |
| 105 url = makeLink('/vm-connect/'); | 108 url = makeLink('/vm-connect'); |
| 106 } | 109 } |
| 110 |
| 111 if (url == makeLink('/vm-connect')) { |
| 112 // When we go to the vm-connect page, drop all notifications. |
| 113 _app.notifications.clear(); |
| 114 } |
| 115 |
| 107 if (addToBrowserHistory) { | 116 if (addToBrowserHistory) { |
| 108 _addToBrowserHistory(url); | 117 _addToBrowserHistory(url); |
| 109 } | 118 } |
| 110 _updateApplicationLocation(url); | 119 _updateApplicationLocation(url); |
| 111 _visit(); | 120 _visit(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 /// Starting with the current uri path and queryParameters, update | 123 /// Starting with the current uri path and queryParameters, update |
| 115 /// queryParameters present in [updateParameters], then generate a new uri | 124 /// queryParameters present in [updateParameters], then generate a new uri |
| 116 /// and navigate to that. | 125 /// and navigate to that. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // let browser handle. | 160 // let browser handle. |
| 152 return; | 161 return; |
| 153 } | 162 } |
| 154 event.preventDefault(); | 163 event.preventDefault(); |
| 155 // 'currentTarget' is the dom element that would process the event. | 164 // 'currentTarget' is the dom element that would process the event. |
| 156 // If we use 'target' we might get an <em> element or somesuch. | 165 // If we use 'target' we might get an <em> element or somesuch. |
| 157 var target = event.currentTarget; | 166 var target = event.currentTarget; |
| 158 go(target.attributes['href']); | 167 go(target.attributes['href']); |
| 159 } | 168 } |
| 160 } | 169 } |
| OLD | NEW |