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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/app/pane.dart

Issue 335463008: Allow Observatory to run as a hosted web service (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// A [Pane] controls the user interface of Observatory. At any given time 7 /// A [Pane] controls the user interface of Observatory. At any given time
8 /// one pane will be the current pane. Panes are registered at startup. 8 /// one pane will be the current pane. Panes are registered at startup.
9 /// When the user navigates within the application, each pane is asked if it 9 /// When the user navigates within the application, each pane is asked if it
10 /// can handle the current location, the first pane to say yes, wins. 10 /// can handle the current location, the first pane to say yes, wins.
11 abstract class Pane extends Observable { 11 abstract class Pane extends Observable {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 assert(element != null); 48 assert(element != null);
49 assert(canVisit(url)); 49 assert(canVisit(url));
50 if (url == '') { 50 if (url == '') {
51 // Nothing requested. 51 // Nothing requested.
52 return; 52 return;
53 } 53 }
54 /// Request url from VM and display it. 54 /// Request url from VM and display it.
55 app.vm.get(url).then((obj) { 55 app.vm.get(url).then((obj) {
56 ServiceObjectViewElement pane = element; 56 ServiceObjectViewElement pane = element;
57 pane.object = obj; 57 pane.object = obj;
58 }).catchError((e) {
59 Logger.root.severe('ServiceObjectPane visit error: $e');
58 }); 60 });
59 } 61 }
60 62
61 /// Catch all. 63 /// Catch all.
62 bool canVisit(String url) => true; 64 bool canVisit(String url) => true;
63 } 65 }
64 66
65 /// Class tree pane. 67 /// Class tree pane.
66 class ClassTreePane extends Pane { 68 class ClassTreePane extends Pane {
67 static const _urlPrefix = 'class-tree/'; 69 static const _urlPrefix = 'class-tree/';
(...skipping 12 matching lines...) Expand all
80 // ClassTree urls are 'class-tree/isolate-id', chop off prefix, leaving 82 // ClassTree urls are 'class-tree/isolate-id', chop off prefix, leaving
81 // isolate url. 83 // isolate url.
82 url = url.substring(_urlPrefix.length); 84 url = url.substring(_urlPrefix.length);
83 /// Request the isolate url. 85 /// Request the isolate url.
84 app.vm.get(url).then((i) { 86 app.vm.get(url).then((i) {
85 if (element != null) { 87 if (element != null) {
86 /// Update the pane. 88 /// Update the pane.
87 ClassTreeElement pane = element; 89 ClassTreeElement pane = element;
88 pane.isolate = i; 90 pane.isolate = i;
89 } 91 }
92 }).catchError((e) {
93 Logger.root.severe('ClassTreePane visit error: $e');
90 }); 94 });
91 } 95 }
92 96
93 /// Catch all. 97 /// Catch all.
94 bool canVisit(String url) => url.startsWith(_urlPrefix); 98 bool canVisit(String url) => url.startsWith(_urlPrefix);
95 } 99 }
96 100
97 class ErrorViewPane extends Pane { 101 class ErrorViewPane extends Pane {
98 ErrorViewPane(app) : super(app); 102 ErrorViewPane(app) : super(app);
99 103
100 void onInstall() { 104 void onInstall() {
101 if (element == null) { 105 if (element == null) {
102 /// Lazily create pane. 106 /// Lazily create pane.
103 element = new Element.tag('service-view'); 107 element = new Element.tag('service-view');
104 } 108 }
105 } 109 }
106 110
107 void visit(String url) { 111 void visit(String url) {
108 assert(element != null); 112 assert(element != null);
109 assert(canVisit(url)); 113 assert(canVisit(url));
110 (element as ServiceObjectViewElement).object = app.lastErrorOrException; 114 (element as ServiceObjectViewElement).object = app.lastErrorOrException;
111 } 115 }
112 116
113 bool canVisit(String url) => url.startsWith('error/'); 117 bool canVisit(String url) => url.startsWith('error/');
114 } 118 }
115 119
116 /// The observatory application. Instances of this are created and owned 120 class VMConnectPane extends Pane {
117 /// by the observatory_application custom element. 121 VMConnectPane(app) : super(app);
118 class ObservatoryApplication extends Observable {
119 final _paneRegistry = new List<Pane>();
120 ServiceObjectPane _serviceObjectPane;
121 Pane _currentPane;
122 @observable final LocationManager locationManager;
123 @observable final VM vm;
124 @observable Isolate isolate;
125 @reflectable final ObservatoryApplicationElement rootElement;
126 122
127 @reflectable ServiceObject lastErrorOrException; 123 void onInstall() {
128 124 if (element == null) {
129 void _initOnce() { 125 element = new Element.tag('vm-connect');
130 _registerPanes(); 126 }
131 vm.errors.stream.listen(_onError); 127 assert(element != null);
132 vm.exceptions.stream.listen(_onException);
133 location = locationManager;
134 locationManager._init(this);
135 } 128 }
136 129
137 void _registerPanes() { 130 void visit(String url) {
138 if (_serviceObjectPane != null) { 131 assert(element != null);
139 // Already done. 132 assert(canVisit(url));
140 return;
141 }
142 // Register ClassTreePane.
143 _paneRegistry.add(new ClassTreePane(this));
144 _paneRegistry.add(new ErrorViewPane(this));
145 // Note that ServiceObjectPane must be the last entry in the list as it is
146 // the catch all.
147 _serviceObjectPane = new ServiceObjectPane(this);
148 _paneRegistry.add(_serviceObjectPane);
149 } 133 }
150 134
151 void _onError(ServiceError error) { 135 bool canVisit(String url) => url.startsWith('vm-connect/');
152 lastErrorOrException = error;
153 _visit('error/', null);
154 }
155
156 void _onException(ServiceException exception) {
157 lastErrorOrException = exception;
158 _visit('error/', null);
159 }
160
161 void _visit(String url, String args) {
162 // TODO(johnmccutchan): Pass [args] to pane.
163 for (var i = 0; i < _paneRegistry.length; i++) {
164 var pane = _paneRegistry[i];
165 if (pane.canVisit(url)) {
166 _installPane(pane);
167 pane.visit(url);
168 return;
169 }
170 }
171 throw new FallThroughError();
172 }
173
174 /// Set the Observatory application pane.
175 void _installPane(Pane pane) {
176 assert(pane != null);
177 print('Installing $pane');
178 if (_currentPane == pane) {
179 // Already isntalled.
180 return;
181 }
182 if (_currentPane != null) {
183 _currentPane.onUninstall();
184 }
185 pane.onInstall();
186 // Clear children.
187 rootElement.children.clear();
188 // Add new pane.
189 rootElement.children.add(pane.element);
190 // Remember pane.
191 _currentPane = pane;
192 }
193
194 ObservatoryApplication.devtools(this.rootElement) :
195 locationManager = new HashLocationManager(),
196 vm = new DartiumVM() {
197 _initOnce();
198 }
199
200 ObservatoryApplication(this.rootElement) :
201 locationManager = new HashLocationManager(),
202 vm = new HttpVM() {
203 _initOnce();
204 }
205 } 136 }
206
207 LocationManager location;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698