Index: sky/examples/dart-mojo.sky |
diff --git a/sky/examples/dart-mojo.sky b/sky/examples/dart-mojo.sky |
deleted file mode 100644 |
index 056bc71ca92d0a476b911a630f4a1acd9c58b9b6..0000000000000000000000000000000000000000 |
--- a/sky/examples/dart-mojo.sky |
+++ /dev/null |
@@ -1,82 +0,0 @@ |
-#!mojo mojo:sky_viewer |
-<sky> |
-<import src="dart-library.sky" as="library" /> |
-<script> |
-import 'dart:async'; |
-import '/mojo/public/dart/application.dart'; |
-import 'dart:typed_data'; |
-import 'dart:sky.internals' as internals; |
-import 'mojo:bindings'; |
-import 'mojo:core'; |
- |
-import 'package:mojo/services/network/public/interfaces/network_service.mojom.dart'; |
-import 'package:mojo/services/network/public/interfaces/url_loader.mojom.dart'; |
-import 'package:mojo/public/interfaces/application/shell.mojom.dart' as shell_mojom; |
- |
-class WGet extends Application { |
- NetworkServiceProxy _networkService; |
- UrlLoaderProxy _urlLoaderProxy; |
- |
- WGet.fromHandle(MojoHandle handle) : super.fromHandle(handle); |
- WGet(MojoMessagePipeEndpoint endpoint) : super(endpoint); |
- |
- void initialize(List<String> args, String url) { |
- run(args); |
- } |
- |
- run(List<String> args) async { |
- if (args == null || args.length != 2) { |
- throw "Expected URL argument"; |
- } |
- |
- ByteData bodyData = await _getUrl(args[1]); |
- print("read ${bodyData.lengthInBytes} bytes"); |
- |
- _closeProxies(); |
- close(); |
- } |
- |
- Future<ByteData> _getUrl(String url) async { |
- _initProxiesIfNeeded(); |
- |
- var urlRequest = new UrlRequest() |
- ..url = url |
- ..autoFollowRedirects = true; |
- |
- var urlResponse = await _urlLoaderProxy.start(urlRequest); |
- print("url => ${urlResponse.response.url}"); |
- print("status_line => ${urlResponse.response.statusLine}"); |
- print("mime_type => ${urlResponse.response.mimeType}"); |
- |
- return DataPipeDrainer.drainHandle(urlResponse.response.body); |
- } |
- |
- void _initProxiesIfNeeded() { |
- if (_networkService == null) { |
- _networkService = new NetworkServiceProxy.unbound(); |
- connectToService("mojo:network_service", _networkService); |
- } |
- if (_urlLoaderProxy == null) { |
- _urlLoaderProxy = new UrlLoaderProxy.unbound(); |
- _networkService.createUrlLoader(_urlLoaderProxy); |
- } |
- } |
- |
- void _closeProxies() { |
- _urlLoaderProxy.close(); |
- _networkService.close(); |
- _urlLoaderProxy = null; |
- _networkService = null; |
- } |
-} |
- |
-main() { |
- var messagePipe = new MojoMessagePipe(); |
- var wget = new WGet(messagePipe.endpoints[1]); |
- wget.listen(); |
- var shellProxy = new shell_mojom.ShellProxy.fromHandle(new MojoHandle(internals.takeShellProxyHandle())); |
- wget.initializeFromShellProxy(shellProxy, ["mojo:wget", "http://www.google.com"], "mojo:wget"); |
-} |
- |
-</script> |
-</sky> |