mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Previously we were using string concatenation to build up the directory listing. Now we fetch some JSON from the server and use data binding to inflate a directory listing. This exmaple doesn't work yet because we're missing support for template@repeat, but hopefully we'll get that soon. Also, added support for setRequestHeader to XMLHttpRequest. R=rafaelw@chromium.org Review URL: https://codereview.chromium.org/688413005
58 lines
1.8 KiB
Plaintext
58 lines
1.8 KiB
Plaintext
<import src="/mojo/public/sky/core.sky" as="core" />
|
|
<import src="/mojo/public/sky/unicode.sky" as="unicode" />
|
|
<import src="/mojo/services/public/interfaces/network/network_service.mojom.sky" as="net" />
|
|
<import src="/mojo/services/public/interfaces/network/url_loader.mojom.sky" as="loader" />
|
|
<import src="shell.sky" as="shell" />
|
|
<script>
|
|
function XMLHttpRequest() {
|
|
this.networkService_ = shell.connectToService(
|
|
"mojo://network_service/", net.NetworkService);
|
|
this.request_ = null;
|
|
this.loader_ = null;
|
|
this.responseText = null;
|
|
this.headers_ = new Map();
|
|
};
|
|
|
|
XMLHttpRequest.prototype.onload = function() { };
|
|
XMLHttpRequest.prototype.onerror = function(error) { };
|
|
|
|
XMLHttpRequest.prototype.open = function(method, url) {
|
|
this.request_ = new loader.URLRequest();
|
|
this.request_.url = url;
|
|
this.request_.method = method;
|
|
this.request_.auto_follow_redirects = true;
|
|
this.headers_.clear();
|
|
};
|
|
|
|
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
|
|
this.headers_.set(header, value);
|
|
};
|
|
|
|
XMLHttpRequest.prototype.send = function() {
|
|
var requestHeaders = [];
|
|
this.headers_.forEach(function(value, key) {
|
|
requestHeaders.push(key + ': ' + value);
|
|
});
|
|
this.request_.headers = requestHeaders;
|
|
|
|
// FIXME: Factor this into the JS bindings.
|
|
var pipe = new core.createMessagePipe();
|
|
this.networkService_.createURLLoader(pipe.handle1);
|
|
this.loader_ = shell.wrapHandle(pipe.handle0, loader.URLLoader);
|
|
|
|
var self = this;
|
|
this.loader_.start(this.request_).then(function(result) {
|
|
core.drainData(result.response.body).then(function(result) {
|
|
self.responseText = unicode.decodeUtf8String(new Uint8Array(result.buffer));
|
|
self.onload();
|
|
}).catch(function(error) {
|
|
self.onerror(error);
|
|
});
|
|
}).catch(function(error) {
|
|
self.onerror(error);
|
|
});
|
|
};
|
|
|
|
module.exports = XMLHttpRequest;
|
|
</script>
|