| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A utility for retrieving data from a URL. | 8 * A utility for retrieving data from a URL. |
| 9 * | 9 * |
| 10 * HttpRequest can be used to obtain data from http, ftp, and file | 10 * HttpRequest can be used to obtain data from http, ftp, and file |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 */ | 214 */ |
| 215 static bool get supportsOverrideMimeType { | 215 static bool get supportsOverrideMimeType { |
| 216 $if DART2JS | 216 $if DART2JS |
| 217 var xhr = new HttpRequest(); | 217 var xhr = new HttpRequest(); |
| 218 return JS('bool', '("overrideMimeType" in #)', xhr); | 218 return JS('bool', '("overrideMimeType" in #)', xhr); |
| 219 $else | 219 $else |
| 220 return true; | 220 return true; |
| 221 $endif | 221 $endif |
| 222 } | 222 } |
| 223 | 223 |
| 224 /** |
| 225 * Makes a cross-origin request to the specified URL. |
| 226 * |
| 227 * This API provides a subset of [request] which works on IE9. If IE9 |
| 228 * cross-origin support is not required then [request] should be used instead. |
| 229 */ |
| 230 @Experimental() |
| 231 static Future<String> requestCrossOrigin(String url, |
| 232 {String method, String sendData}) { |
| 233 if (supportsCrossOrigin) { |
| 234 return request(url, method: method, sendData: sendData).then((xhr) { |
| 235 return xhr.responseText; |
| 236 }); |
| 237 } |
| 238 $if DART2JS |
| 239 var completer = new Completer<String>(); |
| 240 if (method == null) { |
| 241 method = 'GET'; |
| 242 } |
| 243 var xhr = JS('var', 'new XDomainRequest()'); |
| 244 JS('', '#.open(#, #)', xhr, method, url); |
| 245 JS('', '#.onload = #', xhr, convertDartClosureToJS((e) { |
| 246 var response = JS('String', '#.responseText', xhr); |
| 247 completer.complete(response); |
| 248 }, 1)); |
| 249 JS('', '#.onerror = #', xhr, convertDartClosureToJS((e) { |
| 250 completer.completeError(e); |
| 251 }, 1)); |
| 252 |
| 253 if (sendData != null) { |
| 254 JS('', '#.send(#)', xhr, sendData); |
| 255 } else { |
| 256 JS('', '#.send()', xhr); |
| 257 } |
| 258 |
| 259 return completer.future; |
| 260 $endif |
| 261 } |
| 262 |
| 224 $!MEMBERS | 263 $!MEMBERS |
| 225 } | 264 } |
| OLD | NEW |