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

Unified Diff: mojo/apps/js/main.js

Issue 577733002: Mojo JS bindings: draining a DataPipe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More size_t Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/apps/js/js_app.cc ('k') | mojo/bindings/js/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/apps/js/main.js
diff --git a/mojo/apps/js/main.js b/mojo/apps/js/main.js
index 8915f2e329229c8c6a11aafbed79b2145313f1d9..c8eaac5a5e655f58443b680568d9574132c9ef2d 100644
--- a/mojo/apps/js/main.js
+++ b/mojo/apps/js/main.js
@@ -14,50 +14,37 @@
define("test", [
"mojo/public/js/bindings/core",
"mojo/public/js/bindings/connection",
+ "mojo/public/js/bindings/support",
"mojo/services/public/interfaces/network/network_service.mojom",
"mojo/services/public/interfaces/network/url_loader.mojom",
"mojo",
"console"
-], function(core, connection, network, loader, mojo, console) {
+], function(core, connection, support, net, loader, mojo, console) {
- function NetworkServiceImpl(remote) { }
- NetworkServiceImpl.prototype =
- Object.create(network.NetworkServiceStub.prototype);
-
- function URLLoaderImpl(remote) { }
- URLLoaderImpl.prototype =
- Object.create(loader.URLLoaderStub.prototype);
-
- var networkServiceHandle = mojo.connectToService(
+ var netServiceHandle = mojo.connectToService(
"mojo:mojo_network_service", "mojo::NetworkService");
- var networkConnection = new connection.Connection(
- networkServiceHandle, NetworkServiceImpl, network.NetworkServiceProxy);
+ var netConnection = new connection.Connection(
+ netServiceHandle, net.NetworkServiceStub, net.NetworkServiceProxy);
var urlLoaderPipe = new core.createMessagePipe();
- networkConnection.remote.createURLLoader(urlLoaderPipe.handle1);
+ netConnection.remote.createURLLoader(urlLoaderPipe.handle1);
var urlLoaderConnection = new connection.Connection(
- urlLoaderPipe.handle0, URLLoaderImpl, loader.URLLoaderProxy);
+ urlLoaderPipe.handle0, loader.URLLoaderStub, loader.URLLoaderProxy);
var urlRequest = new loader.URLRequest();
urlRequest.url = "http://www.cnn.com";
urlRequest.method = "GET";
urlRequest.auto_follow_redirects = true;
+
var urlRequestPromise = urlLoaderConnection.remote.start(urlRequest);
- urlRequestPromise.then(
- function(result) {
- var body = core.readData(result.response.body,
- core.READ_DATA_FLAG_ALL_OR_NONE);
- if (body.result == core.RESULT_OK)
- console.log("body.buffer.byteLength=" + body.buffer.byteLength);
- else
- console.log("core.readData() failed err=" + body.result);
- for(var key in result.response)
- console.log(key + " => " + result.response[key]);
- mojo.quit();
- },
- function(error) {
- console.log("FAIL " + error.toString());
+ urlRequestPromise.then(function(result) {
+ for(var key in result.response)
+ console.log(key + " => " + result.response[key]);
+ var drainDataPromise = core.drainData(result.response.body);
+ drainDataPromise.then(function(result) {
+ console.log("read " + result.buffer.byteLength + " bytes");
+ }).then(function() {
mojo.quit();
});
-
+ });
});
« no previous file with comments | « mojo/apps/js/js_app.cc ('k') | mojo/bindings/js/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698