OLD | NEW |
1 // Copyright (c) 2014, 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 library vm_connect_element; | 5 library vm_connect_element; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'package:observatory/models.dart' as M; | 10 import 'package:observatory/models.dart' as M; |
11 import 'package:observatory/src/elements/helpers/tag.dart'; | 11 import 'package:observatory/src/elements/helpers/tag.dart'; |
12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 12 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
13 import 'package:observatory/src/elements/nav/bar.dart'; | 13 import 'package:observatory/src/elements/nav/bar.dart'; |
14 import 'package:observatory/src/elements/nav/notify.dart'; | 14 import 'package:observatory/src/elements/nav/notify.dart'; |
15 import 'package:observatory/src/elements/nav/top_menu.dart'; | 15 import 'package:observatory/src/elements/nav/top_menu.dart'; |
16 import 'package:observatory/src/elements/view_footer.dart'; | 16 import 'package:observatory/src/elements/view_footer.dart'; |
17 import 'package:observatory/src/elements/vm_connect_target.dart'; | 17 import 'package:observatory/src/elements/vm_connect_target.dart'; |
18 | 18 |
| 19 typedef void CrashDumpLoadCallback(Map dump); |
| 20 |
19 class VMConnectElement extends HtmlElement implements Renderable { | 21 class VMConnectElement extends HtmlElement implements Renderable { |
20 static const tag = const Tag<VMConnectElement>('vm-connect', | 22 static const tag = const Tag<VMConnectElement>('vm-connect', |
21 dependencies: const [NavBarElement.tag, | 23 dependencies: const [NavBarElement.tag, |
22 NavTopMenuElement.tag, | 24 NavTopMenuElement.tag, |
23 NavNotifyElement.tag, | 25 NavNotifyElement.tag, |
24 ViewFooterElement.tag, | 26 ViewFooterElement.tag, |
25 VMConnectTargetElement.tag]); | 27 VMConnectTargetElement.tag]); |
26 | 28 |
27 RenderingScheduler _r; | 29 RenderingScheduler _r; |
28 | 30 |
29 Stream<RenderedEvent<VMConnectElement>> get onRendered => _r.onRendered; | 31 Stream<RenderedEvent<VMConnectElement>> get onRendered => _r.onRendered; |
30 | 32 |
31 M.CrashDumpRepository _dump; | 33 CrashDumpLoadCallback _loadDump; |
32 M.NotificationRepository _notifications; | 34 M.NotificationRepository _notifications; |
33 M.TargetRepository _targets; | 35 M.TargetRepository _targets; |
34 StreamSubscription _targetsSubscription; | 36 StreamSubscription _targetsSubscription; |
35 | 37 |
36 String _address; | 38 String _address; |
37 | 39 |
38 factory VMConnectElement(M.TargetRepository targets, | 40 factory VMConnectElement(M.TargetRepository targets, |
39 M.CrashDumpRepository dump, | 41 CrashDumpLoadCallback loadDump, |
40 M.NotificationRepository notifications, | 42 M.NotificationRepository notifications, |
41 {String address: '', RenderingQueue queue}) { | 43 {String address: '', RenderingQueue queue}) { |
42 assert(address != null); | 44 assert(address != null); |
43 assert(dump != null); | 45 assert(loadDump != null); |
44 assert(notifications != null); | 46 assert(notifications != null); |
45 assert(targets != null); | 47 assert(targets != null); |
46 VMConnectElement e = document.createElement(tag.name); | 48 VMConnectElement e = document.createElement(tag.name); |
47 e._r = new RenderingScheduler(e, queue: queue); | 49 e._r = new RenderingScheduler(e, queue: queue); |
48 e._address = address; | 50 e._address = address; |
49 e._dump = dump; | 51 e._loadDump = loadDump; |
50 e._notifications = notifications; | 52 e._notifications = notifications; |
51 e._targets = targets; | 53 e._targets = targets; |
52 return e; | 54 return e; |
53 } | 55 } |
54 | 56 |
55 VMConnectElement.created() : super.created(); | 57 VMConnectElement.created() : super.created(); |
56 | 58 |
57 @override | 59 @override |
58 void attached() { | 60 void attached() { |
59 super.attached(); _r.enable(); | 61 super.attached(); |
60 _targetsSubscription = _targets.onChange.listen((_) => _r.dirty()); | 62 _targetsSubscription = _targets.onChange.listen((_) => _r.dirty()); |
| 63 _r.enable(); |
61 } | 64 } |
62 | 65 |
63 @override | 66 @override |
64 void detached() { | 67 void detached() { |
65 super.detached(); children = []; _r.disable(notify: true); | 68 super.detached(); |
66 _targetsSubscription.cancel(); _targetsSubscription = null; | 69 children = []; |
| 70 _r.disable(notify: true); |
| 71 _targetsSubscription.cancel(); |
67 } | 72 } |
68 | 73 |
69 void render() { | 74 void render() { |
70 final host = window.location.hostname; | 75 final host = window.location.hostname; |
71 final port = window.location.port; | 76 final port = window.location.port; |
72 children = [ | 77 children = [ |
73 new NavBarElement(queue: _r.queue) | 78 new NavBarElement(queue: _r.queue) |
74 ..children = [ | 79 ..children = [ |
75 new NavTopMenuElement(last: true, queue: _r.queue), | 80 new NavTopMenuElement(last: true, queue: _r.queue), |
76 new NavNotifyElement(_notifications, queue: _r.queue) | 81 new NavNotifyElement(_notifications, queue: _r.queue) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 156 } |
152 | 157 |
153 FileUploadInputElement _createCrushDumpLoader() { | 158 FileUploadInputElement _createCrushDumpLoader() { |
154 FileUploadInputElement e = new FileUploadInputElement() | 159 FileUploadInputElement e = new FileUploadInputElement() |
155 ..id = 'crashDumpFile'; | 160 ..id = 'crashDumpFile'; |
156 e.onChange.listen((_) { | 161 e.onChange.listen((_) { |
157 var reader = new FileReader(); | 162 var reader = new FileReader(); |
158 reader.readAsText(e.files[0]); | 163 reader.readAsText(e.files[0]); |
159 reader.onLoad.listen((_) { | 164 reader.onLoad.listen((_) { |
160 var crashDump = JSON.decode(reader.result); | 165 var crashDump = JSON.decode(reader.result); |
161 _dump.load(crashDump); | 166 _loadDump(crashDump); |
162 }); | 167 }); |
163 }); | 168 }); |
164 return e; | 169 return e; |
165 } | 170 } |
166 void _create() { | 171 void _create() { |
167 if (_address == null || _address.isEmpty) return; | 172 if (_address == null || _address.isEmpty) return; |
168 _targets.add(_normalizeStandaloneAddress(_address)); | 173 _targets.add(_normalizeStandaloneAddress(_address)); |
169 } | 174 } |
170 void _connect(TargetEvent e) => _targets.setCurrent(e.target); | 175 void _connect(TargetEvent e) => _targets.setCurrent(e.target); |
171 void _delete(TargetEvent e) => _targets.delete(e.target); | 176 void _delete(TargetEvent e) => _targets.delete(e.target); |
172 | 177 |
173 static String _normalizeStandaloneAddress(String networkAddress) { | 178 static String _normalizeStandaloneAddress(String networkAddress) { |
174 if (networkAddress.startsWith('ws://')) { | 179 if (networkAddress.startsWith('ws://')) { |
175 return networkAddress; | 180 return networkAddress; |
176 } | 181 } |
177 return 'ws://${networkAddress}/ws'; | 182 return 'ws://${networkAddress}/ws'; |
178 } | 183 } |
179 } | 184 } |
OLD | NEW |