OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 #!mojo mojo:sky_viewer |
2 // Use of this source code is governed by a BSD-style license that can be | 2 <sky> |
3 // found in the LICENSE file. | 3 <import src="dart-library.sky" as="library" /> |
4 | 4 <script> |
5 // Run with, e.g.: | |
6 // mojo_shell "mojo:dart_wget http://www.google.com" | |
7 | |
8 import 'dart:async'; | 5 import 'dart:async'; |
9 import 'dart:mojo_application'; | 6 import '/mojo/public/dart/application.dart'; |
10 import 'dart:mojo_bindings'; | 7 import 'dart:mojo_bindings'; |
11 import 'dart:mojo_core'; | 8 import 'dart:mojo_core'; |
12 import 'dart:typed_data'; | 9 import 'dart:typed_data'; |
| 10 import 'dart:sky.internals' as internals; |
13 | 11 |
14 import 'package:mojo/services/network/public/interfaces/network_service.mojom.da
rt'; | 12 import 'package:mojo/services/network/public/interfaces/network_service.mojom.da
rt'; |
15 import 'package:mojo/services/network/public/interfaces/url_loader.mojom.dart'; | 13 import 'package:mojo/services/network/public/interfaces/url_loader.mojom.dart'; |
| 14 import 'package:mojo/public/interfaces/application/shell.mojom.dart' as shell_mo
jom; |
16 | 15 |
17 class WGet extends Application { | 16 class WGet extends Application { |
18 NetworkServiceProxy _networkService; | 17 NetworkServiceProxy _networkService; |
19 UrlLoaderProxy _urlLoaderProxy; | 18 UrlLoaderProxy _urlLoaderProxy; |
20 | 19 |
21 WGet.fromHandle(MojoHandle handle) : super.fromHandle(handle); | 20 WGet.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
| 21 WGet(MojoMessagePipeEndpoint endpoint) : super(endpoint); |
22 | 22 |
23 void initialize(List<String> args, String url) { | 23 void initialize(List<String> args) { |
24 run(args); | 24 run(args); |
25 } | 25 } |
26 | 26 |
27 run(List<String> args) async { | 27 run(List<String> args) async { |
28 if (args == null || args.length != 2) { | 28 if (args == null || args.length != 2) { |
29 throw "Expected URL argument"; | 29 throw "Expected URL argument"; |
30 } | 30 } |
31 | 31 |
32 ByteData bodyData = await _getUrl(args[1]); | 32 ByteData bodyData = await _getUrl(args[1]); |
33 print("read ${bodyData.lengthInBytes} bytes"); | 33 print("read ${bodyData.lengthInBytes} bytes"); |
(...skipping 29 matching lines...) Expand all Loading... |
63 } | 63 } |
64 | 64 |
65 void _closeProxies() { | 65 void _closeProxies() { |
66 _urlLoaderProxy.close(); | 66 _urlLoaderProxy.close(); |
67 _networkService.close(); | 67 _networkService.close(); |
68 _urlLoaderProxy = null; | 68 _urlLoaderProxy = null; |
69 _networkService = null; | 69 _networkService = null; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 main(List args) { | 73 main() { |
74 MojoHandle appHandle = new MojoHandle(args[0]); | 74 var messagePipe = new MojoMessagePipe(); |
75 var wget = new WGet.fromHandle(appHandle); | 75 var wget = new WGet(messagePipe.endpoints[1]); |
76 wget.listen(); | 76 wget.listen(); |
| 77 var shellProxy = new shell_mojom.ShellProxy.fromHandle(new MojoHandle(internal
s.passShellProxyHandle())); |
| 78 wget.initializeFromShellProxy(shellProxy, ["mojo:wget", "http://www.google.com
"]); |
77 } | 79 } |
| 80 |
| 81 </script> |
| 82 </sky> |
OLD | NEW |