| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This trivial app just loads "cnn.com" using the Mojo Network and URLLoader | |
| 6 // services and then prints a brief summary of the response. | |
| 7 // | |
| 8 // To run it this file must be specified as a URL. For | |
| 9 // example: | |
| 10 // (cd YOUR_DIR/mojo/apps/js; python -m SimpleHTTPServer ) & | |
| 11 // mojo_shell \ | |
| 12 // --content-handlers=application/javascript,mojo:js_content_handler \ | |
| 13 // http://localhost:8000/test.js | |
| 14 | |
| 15 define("test", [ | |
| 16 "mojo/apps/js/mojo", | |
| 17 "mojo/public/js/core", | |
| 18 "mojo/public/js/connection", | |
| 19 "mojo/public/js/support", | |
| 20 "mojo/services/public/interfaces/network/network_service.mojom", | |
| 21 "mojo/services/public/interfaces/network/url_loader.mojom", | |
| 22 "console" | |
| 23 ], function(mojo, core, connection, support, net, loader, console) { | |
| 24 | |
| 25 var networkService = mojo.shell().connectToService( | |
| 26 "mojo:network_service", net.NetworkService); | |
| 27 | |
| 28 var urlLoaderPipe = core.createMessagePipe(); | |
| 29 networkService.createURLLoader(urlLoaderPipe.handle1); | |
| 30 var urlLoaderConnection = new connection.Connection( | |
| 31 urlLoaderPipe.handle0, | |
| 32 function(){}, | |
| 33 loader.URLLoader.proxyClass); | |
| 34 | |
| 35 var urlRequest = new loader.URLRequest({ | |
| 36 url: "http://www.cnn.com", | |
| 37 method: "GET", | |
| 38 auto_follow_redirects: true | |
| 39 }); | |
| 40 | |
| 41 var urlRequestPromise = urlLoaderConnection.remote.start(urlRequest); | |
| 42 urlRequestPromise.then(function(result) { | |
| 43 for(var key in result.response) | |
| 44 console.log(key + " => " + result.response[key]); | |
| 45 var drainDataPromise = core.drainData(result.response.body); | |
| 46 drainDataPromise.then(function(result) { | |
| 47 console.log("read " + result.buffer.byteLength + " bytes"); | |
| 48 }).then(function() { | |
| 49 mojo.quit(); | |
| 50 }); | |
| 51 }); | |
| 52 }); | |
| OLD | NEW |