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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 _uri = Uri.parse(url); | 72 _uri = Uri.parse(url); |
73 } | 73 } |
74 | 74 |
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 _app._visit(_uri, internalArguments); | 82 runZoned(() => _app._visit(_uri, internalArguments), |
| 83 onError: (e, st) { |
| 84 if (e is IsolateNotFound) { |
| 85 var newPath = _app.vm == null ? '/vm-connect' : '/isolate-reconnect'; |
| 86 var parameters = {}; |
| 87 parameters.addAll(_uri.queryParameters); |
| 88 parameters['originalPath'] = _uri.path; |
| 89 parameters['originalIsolateId'] = parameters['isolateId']; |
| 90 var generatedUri = new Uri(path: newPath, queryParameters: parameters); |
| 91 go(makeLink(generatedUri.toString()), true); |
| 92 return; |
| 93 } |
| 94 throw e; |
| 95 }); |
83 } | 96 } |
84 | 97 |
85 /// Navigate to [url]. | 98 /// Navigate to [url]. |
86 void go(String url, [bool addToBrowserHistory = true]) { | 99 void go(String url, [bool addToBrowserHistory = true]) { |
87 if ((url != makeLink('/vm-connect/')) && _app.vm == null) { | 100 if ((url != makeLink('/vm-connect')) && _app.vm == null) { |
88 if (!window.confirm('Connection with VM has been lost. ' | 101 if (!window.confirm('Connection with VM has been lost. ' |
89 'Proceeding will lose current page.')) { | 102 'Proceeding will lose current page.')) { |
90 return; | 103 return; |
91 } | 104 } |
92 url = makeLink('/vm-connect/'); | 105 url = makeLink('/vm-connect/'); |
93 } | 106 } |
94 if (addToBrowserHistory) { | 107 if (addToBrowserHistory) { |
95 _addToBrowserHistory(url); | 108 _addToBrowserHistory(url); |
96 } | 109 } |
97 _updateApplicationLocation(url); | 110 _updateApplicationLocation(url); |
98 _visit(); | 111 _visit(); |
99 } | 112 } |
100 | 113 |
101 /// Starting with the current uri path and queryParameters, update | 114 /// Starting with the current uri path and queryParameters, update |
102 /// queryParameters present in [updateParameters], then generate a new uri | 115 /// queryParameters present in [updateParameters], then generate a new uri |
103 /// and navigate to that. | 116 /// and navigate to that. |
104 goParameter(Map updatedParameters, [bool addToBrowserHistory = true]) { | 117 goReplacingParameters(Map updatedParameters, [bool addToBrowserHistory = true]
) { |
| 118 go(makeLinkReplacingParameter(updatedParameters), addToBrowserHistory); |
| 119 } |
| 120 |
| 121 makeLinkReplacingParameters(Map updatedParameters) { |
105 var parameters = new Map.from(_uri.queryParameters); | 122 var parameters = new Map.from(_uri.queryParameters); |
106 updatedParameters.forEach((k, v) { | 123 updatedParameters.forEach((k, v) { |
107 parameters[k] = v; | 124 parameters[k] = v; |
108 }); | 125 }); |
109 // Ensure path starts with a slash. | 126 // Ensure path starts with a slash. |
110 var path = uri.path.startsWith('/') ? uri.path : '/${uri.path}'; | 127 var path = uri.path.startsWith('/') ? uri.path : '/${uri.path}'; |
111 var generatedUri = new Uri(path: path, queryParameters: parameters); | 128 var generatedUri = new Uri(path: path, queryParameters: parameters); |
112 go(makeLink(generatedUri.toString()), addToBrowserHistory); | 129 return makeLink(generatedUri.toString()); |
| 130 } |
| 131 |
| 132 goForwardingParameters(String newPath, [bool addToBrowserHistory = true]) { |
| 133 go(makeLinkForwardingParameters(newPath), addToBrowserHistory); |
| 134 } |
| 135 |
| 136 makeLinkForwardingParameters(String newPath) { |
| 137 var parameters = _uri.queryParameters; |
| 138 var generatedUri = new Uri(path: newPath, queryParameters: parameters); |
| 139 return makeLink(generatedUri.toString()); |
113 } | 140 } |
114 | 141 |
115 /// Utility event handler when clicking on application url link. | 142 /// Utility event handler when clicking on application url link. |
116 void onGoto(MouseEvent event) { | 143 void onGoto(MouseEvent event) { |
117 if ((event.button > 0) || | 144 if ((event.button > 0) || |
118 event.metaKey || | 145 event.metaKey || |
119 event.ctrlKey || | 146 event.ctrlKey || |
120 event.shiftKey || | 147 event.shiftKey || |
121 event.altKey) { | 148 event.altKey) { |
122 // Mouse event is not a left-click OR | 149 // Mouse event is not a left-click OR |
123 // mouse event is a left-click with a modifier key: | 150 // mouse event is a left-click with a modifier key: |
124 // let browser handle. | 151 // let browser handle. |
125 return; | 152 return; |
126 } | 153 } |
127 event.preventDefault(); | 154 event.preventDefault(); |
128 var target = event.target; | 155 var target = event.target; |
129 go(target.attributes['href']); | 156 go(target.attributes['href']); |
130 } | 157 } |
131 } | 158 } |
OLD | NEW |