Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: mojo/apps/js/main.js

Issue 628763002: Mojo JS bindings: simplify mojo.connectToService() usage - Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed template indentation Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This trivial app just loads "cnn.com" using the Mojo Network and URLLoader 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. It's intended to 6 // services and then prints a brief summary of the response. It's intended to
7 // be run using the mojo_js content handler and assumes that this source file 7 // be run using the mojo_js content handler and assumes that this source file
8 // is specified as a URL. For example: 8 // is specified as a URL. For example:
9 // 9 //
10 // (cd YOUR_DIR/mojo/apps/js; python -m SimpleHTTPServer ) & 10 // (cd YOUR_DIR/mojo/apps/js; python -m SimpleHTTPServer ) &
11 // mojo_shell --content-handlers=application/javascript,mojo://mojo_js \ 11 // mojo_shell --content-handlers=application/javascript,mojo://mojo_js \
12 // http://localhost:8000/test.js 12 // http://localhost:8000/test.js
13 13
14 define("test", [ 14 define("test", [
15 "mojo/public/js/bindings/core", 15 "mojo/public/js/bindings/core",
16 "mojo/public/js/bindings/connection", 16 "mojo/public/js/bindings/connection",
17 "mojo/public/js/bindings/support", 17 "mojo/public/js/bindings/support",
18 "mojo/services/public/interfaces/network/network_service.mojom", 18 "mojo/services/public/interfaces/network/network_service.mojom",
19 "mojo/services/public/interfaces/network/url_loader.mojom", 19 "mojo/services/public/interfaces/network/url_loader.mojom",
20 "mojo", 20 "mojo",
21 "console" 21 "console"
22 ], function(core, connection, support, net, loader, mojo, console) { 22 ], function(core, connection, support, net, loader, mojo, console) {
23 23
24 var netServiceHandle = mojo.connectToService( 24 var netServiceHandle = mojo.connectToService(
25 "mojo:mojo_network_service", "mojo::NetworkService"); 25 "mojo:mojo_network_service", net.NetworkService.name);
26 var netConnection = new connection.Connection( 26 var netConnection = new connection.Connection(
27 netServiceHandle, net.NetworkServiceStub, net.NetworkServiceProxy); 27 netServiceHandle,
28 net.NetworkService.stubClass,
29 net.NetworkService.proxyClass);
28 30
29 var urlLoaderPipe = new core.createMessagePipe(); 31 var urlLoaderPipe = core.createMessagePipe();
30 netConnection.remote.createURLLoader(urlLoaderPipe.handle1); 32 netConnection.remote.createURLLoader(urlLoaderPipe.handle1);
31 var urlLoaderConnection = new connection.Connection( 33 var urlLoaderConnection = new connection.Connection(
32 urlLoaderPipe.handle0, loader.URLLoaderStub, loader.URLLoaderProxy); 34 urlLoaderPipe.handle0,
35 loader.URLLoader.stubClass,
36 loader.URLLoader.proxyClass);
33 37
34 var urlRequest = new loader.URLRequest(); 38 var urlRequest = new loader.URLRequest({
35 urlRequest.url = "http://www.cnn.com"; 39 url: "http://www.cnn.com",
36 urlRequest.method = "GET"; 40 method: "GET",
37 urlRequest.auto_follow_redirects = true; 41 auto_follow_redirects: true
42 });
38 43
39 var urlRequestPromise = urlLoaderConnection.remote.start(urlRequest); 44 var urlRequestPromise = urlLoaderConnection.remote.start(urlRequest);
40 urlRequestPromise.then(function(result) { 45 urlRequestPromise.then(function(result) {
41 for(var key in result.response) 46 for(var key in result.response)
42 console.log(key + " => " + result.response[key]); 47 console.log(key + " => " + result.response[key]);
43 var drainDataPromise = core.drainData(result.response.body); 48 var drainDataPromise = core.drainData(result.response.body);
44 drainDataPromise.then(function(result) { 49 drainDataPromise.then(function(result) {
45 console.log("read " + result.buffer.byteLength + " bytes"); 50 console.log("read " + result.buffer.byteLength + " bytes");
46 }).then(function() { 51 }).then(function() {
47 mojo.quit(); 52 mojo.quit();
48 }); 53 });
49 }); 54 });
50 }); 55 });
OLDNEW
« no previous file with comments | « mojo/apps/js/bindings/sample_service_unittests.js ('k') | mojo/apps/js/test/js_to_cpp_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698