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

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

Issue 688413005: Convert the directory listing to run on top of the platform (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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
1 <link rel="import" href="/mojo/public/sky/core.sky" as="core" /> 1 <link rel="import" href="/mojo/public/sky/core.sky" as="core" />
2 <link rel="import" href="/mojo/public/sky/unicode.sky" as="unicode" /> 2 <link rel="import" href="/mojo/public/sky/unicode.sky" as="unicode" />
3 <link rel="import" href="/mojo/services/public/interfaces/network/network_servic e.mojom.sky" as="net" /> 3 <link rel="import" href="/mojo/services/public/interfaces/network/network_servic e.mojom.sky" as="net" />
4 <link rel="import" href="/mojo/services/public/interfaces/network/url_loader.moj om.sky" as="loader" /> 4 <link rel="import" href="/mojo/services/public/interfaces/network/url_loader.moj om.sky" as="loader" />
5 <link rel="import" href="shell.sky" as="shell" /> 5 <link rel="import" href="shell.sky" as="shell" />
6 <script> 6 <script>
7 function XMLHttpRequest() { 7 function XMLHttpRequest() {
8 this.networkService_ = shell.connectToService( 8 this.networkService_ = shell.connectToService(
9 "mojo://network_service/", net.NetworkService); 9 "mojo://network_service/", net.NetworkService);
10 this.request_ = null; 10 this.request_ = null;
11 this.loader_ = null; 11 this.loader_ = null;
12 this.responseText = null; 12 this.responseText = null;
13 this.headers_ = new Map();
13 }; 14 };
14 15
15 XMLHttpRequest.prototype.onload = function() { }; 16 XMLHttpRequest.prototype.onload = function() { };
16 XMLHttpRequest.prototype.onerror = function(error) { }; 17 XMLHttpRequest.prototype.onerror = function(error) { };
17 18
18 XMLHttpRequest.prototype.open = function(method, url) { 19 XMLHttpRequest.prototype.open = function(method, url) {
19 this.request_ = new loader.URLRequest(); 20 this.request_ = new loader.URLRequest();
20 this.request_.url = url; 21 this.request_.url = url;
21 this.request_.method = method; 22 this.request_.method = method;
22 this.request_.auto_follow_redirects = true; 23 this.request_.auto_follow_redirects = true;
24 this.headers_.clear();
25 };
26
27 XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
28 this.headers_.set(header, value);
23 }; 29 };
24 30
25 XMLHttpRequest.prototype.send = function() { 31 XMLHttpRequest.prototype.send = function() {
32 var requestHeaders = [];
33 this.headers_.forEach(function(value, key) {
34 requestHeaders.push(key + ': ' + value);
35 });
36 this.request_.headers = requestHeaders;
37
26 // FIXME: Factor this into the JS bindings. 38 // FIXME: Factor this into the JS bindings.
27 var pipe = new core.createMessagePipe(); 39 var pipe = new core.createMessagePipe();
28 this.networkService_.createURLLoader(pipe.handle1); 40 this.networkService_.createURLLoader(pipe.handle1);
29 this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader); 41 this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader);
30 42
31 var self = this; 43 var self = this;
32 this.loader_.start(this.request_).then(function(result) { 44 this.loader_.start(this.request_).then(function(result) {
33 core.drainData(result.response.body).then(function(result) { 45 core.drainData(result.response.body).then(function(result) {
34 self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer) ); 46 self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer) );
35 self.onload(); 47 self.onload();
36 }).catch(function(error) { 48 }).catch(function(error) {
37 self.onerror(error); 49 self.onerror(error);
38 }); 50 });
39 }).catch(function(error) { 51 }).catch(function(error) {
40 self.onerror(error); 52 self.onerror(error);
41 }); 53 });
42 }; 54 };
43 55
44 module.exports = XMLHttpRequest; 56 module.exports = XMLHttpRequest;
45 </script> 57 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698