| Index: sdk/lib/html/dart2js/html_dart2js.dart
|
| diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
|
| index d63f67b263970b2a3a0f4e7e51efe6a7664d18cb..c57a862b4e071e7a12b735452e72afdcd656a249 100644
|
| --- a/sdk/lib/html/dart2js/html_dart2js.dart
|
| +++ b/sdk/lib/html/dart2js/html_dart2js.dart
|
| @@ -12623,25 +12623,35 @@ class HtmlOptionsCollection extends HtmlCollection native "*HTMLOptionsCollectio
|
| */
|
| @DomName('XMLHttpRequest')
|
| class HttpRequest extends EventTarget native "*XMLHttpRequest" {
|
| +
|
| /**
|
| - * Creates a URL get request for the specified `url`.
|
| + * Creates a URL get request for the specified [url].
|
| + *
|
| + * The server response must be a `text/` mime type for this request to
|
| + * succeed.
|
| *
|
| - * After completing the request, the object will call the user-provided
|
| - * [onComplete] callback.
|
| + * This is similar to [request] but specialized for HTTP GET requests which
|
| + * return text content.
|
| + *
|
| + * See also:
|
| + *
|
| + * * [request]
|
| */
|
| - factory HttpRequest.get(String url, onComplete(HttpRequest request)) =>
|
| - _HttpRequestUtils.get(url, onComplete, false);
|
| + static Future<String> getString(String url,
|
| + {bool withCredentials, void onProgress(ProgressEvent e)}) {
|
| + return request(url, withCredentials: withCredentials,
|
| + onProgress: onProgress).then((xhr) => xhr.responseText);
|
| + }
|
|
|
| - // 80 char issue for comments in lists: dartbug.com/7588.
|
| /**
|
| - * Creates a URL GET request for the specified `url` with
|
| - * credentials such a cookie (already) set in the header or
|
| - * [authorization headers](http://tools.ietf.org/html/rfc1945#section-10.2).
|
| + * Creates a URL request for the specified [url].
|
| + *
|
| + * By default this will do an HTTP GET request, this can be overridden with
|
| + * [method].
|
| *
|
| - * After completing the request, the object will call the user-provided
|
| - * [onComplete] callback.
|
| + * The Future is completed when the response is available.
|
| *
|
| - * A few other details to keep in mind when using credentials:
|
| + * Details to keep in mind when using credentials:
|
| *
|
| * * Using credentials is only useful for cross-origin requests.
|
| * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildcard (*).
|
| @@ -12650,9 +12660,50 @@ class HttpRequest extends EventTarget native "*XMLHttpRequest" {
|
| *
|
| * See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access_authentication).
|
| */
|
| - factory HttpRequest.getWithCredentials(String url,
|
| - onComplete(HttpRequest request)) =>
|
| - _HttpRequestUtils.get(url, onComplete, true);
|
| + static Future<HttpRequest> request(String url,
|
| + {String method, bool withCredentials, String responseType, sendData,
|
| + void onProgress(ProgressEvent e)}) {
|
| + var completer = new Completer<String>();
|
| +
|
| + var xhr = new HttpRequest();
|
| + if (method == null) {
|
| + method = 'GET';
|
| + }
|
| + xhr.open(method, url, true);
|
| +
|
| + if (withCredentials != null) {
|
| + xhr.withCredentials = withCredentials;
|
| + }
|
| +
|
| + if (responseType != null) {
|
| + xhr.responseType = responseType;
|
| + }
|
| +
|
| + if (onProgress != null) {
|
| + xhr.onProgress.listen(onProgress);
|
| + }
|
| +
|
| + xhr.onLoad.listen((e) {
|
| + if (xhr.status >= 200 && xhr.status < 300 ||
|
| + xhr.status == 304 ) {
|
| + completer.complete(xhr);
|
| + } else {
|
| + completer.completeError(e);
|
| + }
|
| + });
|
| +
|
| + xhr.onError.listen((e) {
|
| + completer.completeError(e);
|
| + });
|
| +
|
| + if (sendData != null) {
|
| + xhr.send(sendData);
|
| + } else {
|
| + xhr.send();
|
| + }
|
| +
|
| + return completer.future;
|
| + }
|
|
|
|
|
| @DomName('XMLHttpRequest.abort')
|
|
|