| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class XMLHttpRequestEventsImplementation extends EventsImplementation | |
| 6 implements XMLHttpRequestEvents { | |
| 7 XMLHttpRequestEventsImplementation._wrap(_ptr) : super._wrap(_ptr); | |
| 8 | |
| 9 EventListenerList get abort() => _get('abort'); | |
| 10 EventListenerList get error() => _get('error'); | |
| 11 EventListenerList get load() => _get('load'); | |
| 12 EventListenerList get loadStart() => _get('loadstart'); | |
| 13 EventListenerList get progress() => _get('progress'); | |
| 14 EventListenerList get readyStateChange() => _get('readystatechange'); | |
| 15 } | |
| 16 | |
| 17 class XMLHttpRequestWrappingImplementation extends EventTargetWrappingImplementa
tion implements XMLHttpRequest { | |
| 18 XMLHttpRequestWrappingImplementation._wrap( | |
| 19 dom.XMLHttpRequest ptr) : super._wrap(ptr); | |
| 20 | |
| 21 factory XMLHttpRequestWrappingImplementation() { | |
| 22 return new XMLHttpRequestWrappingImplementation._wrap( | |
| 23 new dom.XMLHttpRequest()); | |
| 24 } | |
| 25 | |
| 26 factory XMLHttpRequestWrappingImplementation.get(String url, | |
| 27 onSuccess(XMLHttpRequest request)) { | |
| 28 final request = new XMLHttpRequest(); | |
| 29 request.open('GET', url, true); | |
| 30 | |
| 31 // TODO(terry): Validate after client login added if necessary to forward | |
| 32 // cookies to server. | |
| 33 request.withCredentials = true; | |
| 34 | |
| 35 // Status 0 is for local XHR request. | |
| 36 request.on.readyStateChange.add((e) { | |
| 37 if (request.readyState == XMLHttpRequest.DONE && | |
| 38 (request.status == 200 || request.status == 0)) { | |
| 39 onSuccess(request); | |
| 40 } | |
| 41 }); | |
| 42 | |
| 43 request.send(); | |
| 44 | |
| 45 return request; | |
| 46 } | |
| 47 | |
| 48 int get readyState() => _ptr.readyState; | |
| 49 | |
| 50 String get responseText() => _ptr.responseText; | |
| 51 | |
| 52 String get responseType() => _ptr.responseType; | |
| 53 | |
| 54 void set responseType(String value) { _ptr.responseType = value; } | |
| 55 | |
| 56 XMLDocument get responseXML() => LevelDom.wrapDocument(_ptr.responseXML); | |
| 57 | |
| 58 int get status() => _ptr.status; | |
| 59 | |
| 60 String get statusText() => _ptr.statusText; | |
| 61 | |
| 62 XMLHttpRequestUpload get upload() => LevelDom.wrapXMLHttpRequestUpload(_ptr.up
load); | |
| 63 | |
| 64 bool get withCredentials() => _ptr.withCredentials; | |
| 65 | |
| 66 void set withCredentials(bool value) { _ptr.withCredentials = value; } | |
| 67 | |
| 68 void abort() { | |
| 69 _ptr.abort(); | |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 String getAllResponseHeaders() { | |
| 74 return _ptr.getAllResponseHeaders(); | |
| 75 } | |
| 76 | |
| 77 String getResponseHeader(String header) { | |
| 78 return _ptr.getResponseHeader(header); | |
| 79 } | |
| 80 | |
| 81 void open(String method, String url, bool async, [String user = null, String p
assword = null]) { | |
| 82 if (user === null) { | |
| 83 if (password === null) { | |
| 84 _ptr.open(method, url, async); | |
| 85 return; | |
| 86 } | |
| 87 } else { | |
| 88 if (password === null) { | |
| 89 _ptr.open(method, url, async, user); | |
| 90 return; | |
| 91 } else { | |
| 92 _ptr.open(method, url, async, user, password); | |
| 93 return; | |
| 94 } | |
| 95 } | |
| 96 throw "Incorrect number or type of arguments"; | |
| 97 } | |
| 98 | |
| 99 void overrideMimeType(String mime) { | |
| 100 _ptr.overrideMimeType(mime); | |
| 101 } | |
| 102 | |
| 103 void send([var data = null]) { | |
| 104 if (data === null) { | |
| 105 _ptr.send(); | |
| 106 return; | |
| 107 } else { | |
| 108 if (data is Document) { | |
| 109 _ptr.send(LevelDom.unwrapMaybePrimitive(data)); | |
| 110 return; | |
| 111 } else { | |
| 112 if (data is String) { | |
| 113 _ptr.send(LevelDom.unwrapMaybePrimitive(data)); | |
| 114 return; | |
| 115 } | |
| 116 } | |
| 117 } | |
| 118 throw "Incorrect number or type of arguments"; | |
| 119 } | |
| 120 | |
| 121 void setRequestHeader(String header, String value) { | |
| 122 _ptr.setRequestHeader(header, value); | |
| 123 } | |
| 124 | |
| 125 XMLHttpRequestEvents get on() { | |
| 126 if (_on === null) { | |
| 127 _on = new XMLHttpRequestEventsImplementation._wrap(_ptr); | |
| 128 } | |
| 129 return _on; | |
| 130 } | |
| 131 } | |
| OLD | NEW |