OLD | NEW |
---|---|
(Empty) | |
1 <link rel="import" href="/mojo/public/html/core.html" as="core" /> | |
2 <link rel="import" href="/mojo/public/html/unicode.html" as="unicode" /> | |
3 <link rel="import" href="/mojo/services/public/interfaces/network/network_servic e.mojom.html" as="net" /> | |
4 <link rel="import" href="/mojo/services/public/interfaces/network/url_loader.moj om.html" as="loader" /> | |
5 <link rel="import" href="shell.sky" as="shell" /> | |
6 <script> | |
7 function XMLHttpRequest() { | |
8 this.networkService_ = shell.connectToService( | |
9 "mojo://network_service/", net.NetworkService); | |
10 this.request_ = null; | |
11 this.loader_ = null; | |
12 this.responseText = null; | |
13 }; | |
14 | |
15 XMLHttpRequest.prototype.onload = function() { }; | |
16 XMLHttpRequest.prototype.onerror = function() { }; | |
esprehn
2014/10/29 19:39:46
onerror should take an argument "error"
| |
17 | |
18 XMLHttpRequest.prototype.open = function(method, url) { | |
19 this.request_ = new loader.URLRequest(); | |
20 this.request_.url = url; | |
21 this.request_.method = method; | |
22 this.request_.auto_follow_redirects = true; | |
23 }; | |
24 | |
25 XMLHttpRequest.prototype.send = function() { | |
26 // FIXME: Factor this into the JS bindings. | |
27 var pipe = new core.createMessagePipe(); | |
28 this.networkService_.createURLLoader(pipe.handle1); | |
29 this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader); | |
30 | |
31 var self = this; | |
32 this.loader_.start(this.request_).then(function(result) { | |
33 core.drainData(result.response.body).then(function(result) { | |
34 self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer) ); | |
35 self.onload(); | |
36 }).catch(function() { | |
37 self.onerror(); | |
esprehn
2014/10/29 19:39:46
function(e) and then onerror(e)
| |
38 }); | |
39 }).catch(function() { | |
40 self.onerror(); | |
esprehn
2014/10/29 19:39:46
you should pass the error here.
| |
41 }); | |
42 }; | |
43 | |
44 this.exports = XMLHttpRequest; | |
45 </script> | |
OLD | NEW |