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

Side by Side Diff: sky/framework/xmlhttprequest.sky

Issue 690803002: Add a basic XMLHttpRequest implementation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: typo Created 6 years, 1 month 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
(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>
OLDNEW
« no previous file with comments | « sky/framework/shell.sky ('k') | sky/tests/services/xhr.sky » ('j') | sky/tests/services/xhr.sky » ('J')

Powered by Google App Engine
This is Rietveld 408576698