| 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:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 | 9 |
| 10 import 'observatory_element.dart'; | 10 import 'observatory_element.dart'; |
| 11 import 'package:observatory/app.dart'; | |
| 12 import 'package:observatory/elements.dart'; | 11 import 'package:observatory/elements.dart'; |
| 13 import 'package:observatory/service_html.dart'; | 12 import 'package:observatory/service_html.dart'; |
| 14 import 'package:polymer/polymer.dart'; | 13 import 'package:polymer/polymer.dart'; |
| 15 | 14 |
| 16 void _connectToVM(ObservatoryApplication app, WebSocketVMTarget target) { | |
| 17 app.vm = new WebSocketVM(target); | |
| 18 } | |
| 19 | |
| 20 @CustomTag('vm-connect-target') | |
| 21 class VMConnectTargetElement extends ObservatoryElement { | |
| 22 @published WebSocketVMTarget target; | |
| 23 | |
| 24 VMConnectTargetElement.created() : super.created(); | |
| 25 | |
| 26 bool get isCurrentTarget { | |
| 27 if (app.vm == null) { | |
| 28 return false; | |
| 29 } | |
| 30 return (app.vm as WebSocketVM).target == target; | |
| 31 } | |
| 32 | |
| 33 void connectToVm(MouseEvent event, var detail, Element node) { | |
| 34 if (event.button > 0 || event.metaKey || event.ctrlKey || | |
| 35 event.shiftKey || event.altKey) { | |
| 36 // Not a left-click or a left-click with a modifier key: | |
| 37 // Let browser handle. | |
| 38 return; | |
| 39 } | |
| 40 event.preventDefault(); | |
| 41 WebSocketVM currentVM = app.vm; | |
| 42 if ((currentVM == null) || | |
| 43 currentVM.isDisconnected || | |
| 44 (currentVM.target != target)) { | |
| 45 _connectToVM(app, target); | |
| 46 } | |
| 47 var href = node.attributes['href']; | |
| 48 app.locationManager.go(href); | |
| 49 } | |
| 50 | |
| 51 void deleteVm(MouseEvent event, var detail, Element node) { | |
| 52 app.targets.remove(target); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 @CustomTag('vm-connect') | 15 @CustomTag('vm-connect') |
| 57 class VMConnectElement extends ObservatoryElement { | 16 class VMConnectElement extends ObservatoryElement { |
| 58 @published String standaloneVmAddress = ''; | 17 @published String standaloneVmAddress = ''; |
| 59 | 18 |
| 60 VMConnectElement.created() : super.created() { | 19 VMConnectElement.created() : super.created() { |
| 61 } | 20 } |
| 62 | 21 |
| 63 void _connect(WebSocketVMTarget target) { | 22 void _connect(WebSocketVMTarget target) { |
| 64 _connectToVM(app, target); | 23 app.vm = new WebSocketVM(target); |
| 65 app.locationManager.goForwardingParameters('/vm'); | 24 app.locationManager.goForwardingParameters('/vm'); |
| 66 } | 25 } |
| 67 | 26 |
| 68 @override | 27 @override |
| 69 void attached() { | 28 void attached() { |
| 70 super.attached(); | 29 super.attached(); |
| 71 var fileInput = shadowRoot.querySelector('#crashDumpFile'); | 30 var fileInput = shadowRoot.querySelector('#crashDumpFile'); |
| 72 fileInput.onChange.listen(_onCrashDumpFileChange); | 31 fileInput.onChange.listen(_onCrashDumpFileChange); |
| 73 } | 32 } |
| 74 | 33 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 96 _onCrashDumpFileChange(e) { | 55 _onCrashDumpFileChange(e) { |
| 97 var fileInput = shadowRoot.querySelector('#crashDumpFile'); | 56 var fileInput = shadowRoot.querySelector('#crashDumpFile'); |
| 98 var reader = new FileReader(); | 57 var reader = new FileReader(); |
| 99 reader.readAsText(fileInput.files[0]); | 58 reader.readAsText(fileInput.files[0]); |
| 100 reader.onLoad.listen((_) { | 59 reader.onLoad.listen((_) { |
| 101 var crashDump = JSON.decode(reader.result); | 60 var crashDump = JSON.decode(reader.result); |
| 102 app.loadCrashDump(crashDump); | 61 app.loadCrashDump(crashDump); |
| 103 }); | 62 }); |
| 104 } | 63 } |
| 105 } | 64 } |
| OLD | NEW |