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

Unified Diff: sky/framework/xmlhttprequest.sky

Issue 690803002: Add a basic XMLHttpRequest implementation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Propagate error Created 6 years, 2 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 | « sky/framework/shell.sky ('k') | sky/tests/services/xhr.sky » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/xmlhttprequest.sky
diff --git a/sky/framework/xmlhttprequest.sky b/sky/framework/xmlhttprequest.sky
new file mode 100644
index 0000000000000000000000000000000000000000..6f23fac9f454db8becd3e413e3f37b2ab86396d3
--- /dev/null
+++ b/sky/framework/xmlhttprequest.sky
@@ -0,0 +1,45 @@
+<link rel="import" href="/mojo/public/html/core.html" as="core" />
+<link rel="import" href="/mojo/public/html/unicode.html" as="unicode" />
+<link rel="import" href="/mojo/services/public/interfaces/network/network_service.mojom.html" as="net" />
+<link rel="import" href="/mojo/services/public/interfaces/network/url_loader.mojom.html" as="loader" />
+<link rel="import" href="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;
+};
+
+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;
+};
+
+XMLHttpRequest.prototype.send = function() {
+ // 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);
+ });
+};
+
+this.exports = XMLHttpRequest;
+</script>
« no previous file with comments | « sky/framework/shell.sky ('k') | sky/tests/services/xhr.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698