| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of app; | |
| 6 | |
| 7 /// A [Page] controls the user interface of Observatory. At any given time | |
| 8 /// one page will be the current page. Pages are registered at startup. | |
| 9 /// When the user navigates within the application, each page is asked if it | |
| 10 /// can handle the current location, the first page to say yes, wins. | |
| 11 abstract class Page extends Observable { | |
| 12 final ObservatoryApplication app; | |
| 13 | |
| 14 @observable ObservatoryElement element; | |
| 15 @observable ObservableMap args; | |
| 16 | |
| 17 Page(this.app); | |
| 18 | |
| 19 /// Called when the page is installed, this callback must initialize | |
| 20 /// [element]. | |
| 21 void onInstall(); | |
| 22 | |
| 23 /// Called when the page is uninstalled, this callback must clear | |
| 24 /// [element]. | |
| 25 void onUninstall() { | |
| 26 element = null; | |
| 27 } | |
| 28 | |
| 29 /// Called when the page should update its state based on [url]. | |
| 30 /// NOTE: Only called when the page is installed. | |
| 31 void visit(String url, Map argsMap) { | |
| 32 args = toObservable(argsMap); | |
| 33 _visit(url); | |
| 34 } | |
| 35 | |
| 36 // Overridden by subclasses. | |
| 37 void _visit(String url); | |
| 38 | |
| 39 /// Called to test whether this page can visit [url]. | |
| 40 bool canVisit(String url); | |
| 41 } | |
| 42 | |
| 43 /// A general service object viewer. | |
| 44 class ServiceObjectPage extends Page { | |
| 45 ServiceObjectPage(app) : super(app); | |
| 46 | |
| 47 void onInstall() { | |
| 48 if (element == null) { | |
| 49 /// Lazily create page. | |
| 50 element = new Element.tag('service-view'); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void _visit(String url) { | |
| 55 assert(element != null); | |
| 56 assert(canVisit(url)); | |
| 57 if (url == '') { | |
| 58 // Nothing requested. | |
| 59 return; | |
| 60 } | |
| 61 /// Request url from VM and display it. | |
| 62 app.vm.get(url).then((obj) { | |
| 63 ServiceObjectViewElement serviceElement = element; | |
| 64 serviceElement.object = obj; | |
| 65 }).catchError((e) { | |
| 66 Logger.root.severe('ServiceObjectPage visit error: $e'); | |
| 67 }); | |
| 68 } | |
| 69 | |
| 70 /// Catch all. | |
| 71 bool canVisit(String url) => true; | |
| 72 } | |
| 73 | |
| 74 /// Class tree page. | |
| 75 class ClassTreePage extends Page { | |
| 76 static const _urlPrefix = 'class-tree/'; | |
| 77 | |
| 78 ClassTreePage(app) : super(app); | |
| 79 | |
| 80 void onInstall() { | |
| 81 if (element == null) { | |
| 82 element = new Element.tag('class-tree'); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 void _visit(String url) { | |
| 87 assert(element != null); | |
| 88 assert(canVisit(url)); | |
| 89 // ClassTree urls are 'class-tree/isolate-id', chop off prefix, leaving | |
| 90 // isolate url. | |
| 91 url = url.substring(_urlPrefix.length); | |
| 92 /// Request the isolate url. | |
| 93 app.vm.get(url).then((i) { | |
| 94 if (element != null) { | |
| 95 /// Update the page. | |
| 96 ClassTreeElement page = element; | |
| 97 page.isolate = i; | |
| 98 } | |
| 99 }).catchError((e) { | |
| 100 Logger.root.severe('ClassTreePage visit error: $e'); | |
| 101 }); | |
| 102 } | |
| 103 | |
| 104 /// Catch all. | |
| 105 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 106 } | |
| 107 | |
| 108 class ErrorViewPage extends Page { | |
| 109 ErrorViewPage(app) : super(app); | |
| 110 | |
| 111 void onInstall() { | |
| 112 if (element == null) { | |
| 113 /// Lazily create page. | |
| 114 element = new Element.tag('service-view'); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 void _visit(String url) { | |
| 119 assert(element != null); | |
| 120 assert(canVisit(url)); | |
| 121 (element as ServiceObjectViewElement).object = app.lastErrorOrException; | |
| 122 } | |
| 123 | |
| 124 bool canVisit(String url) => url.startsWith('error/'); | |
| 125 } | |
| 126 | |
| 127 class VMConnectPage extends Page { | |
| 128 VMConnectPage(app) : super(app); | |
| 129 | |
| 130 void onInstall() { | |
| 131 if (element == null) { | |
| 132 element = new Element.tag('vm-connect'); | |
| 133 } | |
| 134 assert(element != null); | |
| 135 } | |
| 136 | |
| 137 void _visit(String url) { | |
| 138 assert(element != null); | |
| 139 assert(canVisit(url)); | |
| 140 } | |
| 141 | |
| 142 bool canVisit(String url) => url.startsWith('vm-connect/'); | |
| 143 } | |
| OLD | NEW |