| 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 client-side XHR request for getting data from a URL, | 8 * A client-side XHR request for getting data from a URL, |
| 9 * formally known as XMLHttpRequest. | 9 * formally known as XMLHttpRequest. |
| 10 * | 10 * |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 xhr.send(); | 246 xhr.send(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 return completer.future; | 249 return completer.future; |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * Checks to see if the Progress event is supported on the current platform. | 253 * Checks to see if the Progress event is supported on the current platform. |
| 254 */ | 254 */ |
| 255 static bool get supportsProgressEvent { | 255 static bool get supportsProgressEvent { |
| 256 $if DART2JS | |
| 257 var xhr = new HttpRequest(); | 256 var xhr = new HttpRequest(); |
| 258 return JS('bool', '("onprogress" in #)', xhr); | 257 return JS('bool', '("onprogress" in #)', xhr); |
| 259 $else | |
| 260 return true; | |
| 261 $endif | |
| 262 } | 258 } |
| 263 | 259 |
| 264 /** | 260 /** |
| 265 * Checks to see if the current platform supports making cross origin | 261 * Checks to see if the current platform supports making cross origin |
| 266 * requests. | 262 * requests. |
| 267 * | 263 * |
| 268 * Note that even if cross origin requests are supported, they still may fail | 264 * Note that even if cross origin requests are supported, they still may fail |
| 269 * if the destination server does not support CORS requests. | 265 * if the destination server does not support CORS requests. |
| 270 */ | 266 */ |
| 271 static bool get supportsCrossOrigin { | 267 static bool get supportsCrossOrigin { |
| 272 $if DART2JS | |
| 273 var xhr = new HttpRequest(); | 268 var xhr = new HttpRequest(); |
| 274 return JS('bool', '("withCredentials" in #)', xhr); | 269 return JS('bool', '("withCredentials" in #)', xhr); |
| 275 $else | |
| 276 return true; | |
| 277 $endif | |
| 278 } | 270 } |
| 279 | 271 |
| 280 /** | 272 /** |
| 281 * Checks to see if the LoadEnd event is supported on the current platform. | 273 * Checks to see if the LoadEnd event is supported on the current platform. |
| 282 */ | 274 */ |
| 283 static bool get supportsLoadEndEvent { | 275 static bool get supportsLoadEndEvent { |
| 284 $if DART2JS | |
| 285 var xhr = new HttpRequest(); | 276 var xhr = new HttpRequest(); |
| 286 return JS('bool', '("onloadend" in #)', xhr); | 277 return JS('bool', '("onloadend" in #)', xhr); |
| 287 $else | |
| 288 return true; | |
| 289 $endif | |
| 290 } | 278 } |
| 291 | 279 |
| 292 /** | 280 /** |
| 293 * Checks to see if the overrideMimeType method is supported on the current | 281 * Checks to see if the overrideMimeType method is supported on the current |
| 294 * platform. | 282 * platform. |
| 295 */ | 283 */ |
| 296 static bool get supportsOverrideMimeType { | 284 static bool get supportsOverrideMimeType { |
| 297 $if DART2JS | |
| 298 var xhr = new HttpRequest(); | 285 var xhr = new HttpRequest(); |
| 299 return JS('bool', '("overrideMimeType" in #)', xhr); | 286 return JS('bool', '("overrideMimeType" in #)', xhr); |
| 300 $else | |
| 301 return true; | |
| 302 $endif | |
| 303 } | 287 } |
| 304 | 288 |
| 305 /** | 289 /** |
| 306 * Makes a cross-origin request to the specified URL. | 290 * Makes a cross-origin request to the specified URL. |
| 307 * | 291 * |
| 308 * This API provides a subset of [request] which works on IE9. If IE9 | 292 * This API provides a subset of [request] which works on IE9. If IE9 |
| 309 * cross-origin support is not required then [request] should be used instead. | 293 * cross-origin support is not required then [request] should be used instead. |
| 310 */ | 294 */ |
| 311 @Experimental() | 295 @Experimental() |
| 312 static Future<String> requestCrossOrigin(String url, | 296 static Future<String> requestCrossOrigin(String url, |
| 313 {String method, String sendData}) { | 297 {String method, String sendData}) { |
| 314 if (supportsCrossOrigin) { | 298 if (supportsCrossOrigin) { |
| 315 return request(url, method: method, sendData: sendData).then((xhr) { | 299 return request(url, method: method, sendData: sendData).then((xhr) { |
| 316 return xhr.responseText; | 300 return xhr.responseText; |
| 317 }); | 301 }); |
| 318 } | 302 } |
| 319 $if DART2JS | |
| 320 var completer = new Completer<String>(); | 303 var completer = new Completer<String>(); |
| 321 if (method == null) { | 304 if (method == null) { |
| 322 method = 'GET'; | 305 method = 'GET'; |
| 323 } | 306 } |
| 324 var xhr = JS('var', 'new XDomainRequest()'); | 307 var xhr = JS('var', 'new XDomainRequest()'); |
| 325 JS('', '#.open(#, #)', xhr, method, url); | 308 JS('', '#.open(#, #)', xhr, method, url); |
| 326 JS('', '#.onload = #', xhr, convertDartClosureToJS((e) { | 309 JS('', '#.onload = #', xhr, convertDartClosureToJS((e) { |
| 327 var response = JS('String', '#.responseText', xhr); | 310 var response = JS('String', '#.responseText', xhr); |
| 328 completer.complete(response); | 311 completer.complete(response); |
| 329 }, 1)); | 312 }, 1)); |
| 330 JS('', '#.onerror = #', xhr, convertDartClosureToJS((e) { | 313 JS('', '#.onerror = #', xhr, convertDartClosureToJS((e) { |
| 331 completer.completeError(e); | 314 completer.completeError(e); |
| 332 }, 1)); | 315 }, 1)); |
| 333 | 316 |
| 334 // IE9 RTM - XDomainRequest issued requests may abort if all event handlers | 317 // IE9 RTM - XDomainRequest issued requests may abort if all event handlers |
| 335 // not specified | 318 // not specified |
| 336 // http://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-
f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handl
ers-not-specified | 319 // http://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-
f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handl
ers-not-specified |
| 337 JS('', '#.onprogress = {}', xhr); | 320 JS('', '#.onprogress = {}', xhr); |
| 338 JS('', '#.ontimeout = {}', xhr); | 321 JS('', '#.ontimeout = {}', xhr); |
| 339 JS('', '#.timeout = Number.MAX_VALUE', xhr); | 322 JS('', '#.timeout = Number.MAX_VALUE', xhr); |
| 340 | 323 |
| 341 if (sendData != null) { | 324 if (sendData != null) { |
| 342 JS('', '#.send(#)', xhr, sendData); | 325 JS('', '#.send(#)', xhr, sendData); |
| 343 } else { | 326 } else { |
| 344 JS('', '#.send()', xhr); | 327 JS('', '#.send()', xhr); |
| 345 } | 328 } |
| 346 | 329 |
| 347 return completer.future; | 330 return completer.future; |
| 348 $endif | |
| 349 } | 331 } |
| 350 | 332 |
| 351 /** | 333 /** |
| 352 * Returns all response headers as a key-value map. | 334 * Returns all response headers as a key-value map. |
| 353 * | 335 * |
| 354 * Multiple values for the same header key can be combined into one, | 336 * Multiple values for the same header key can be combined into one, |
| 355 * separated by a comma and a space. | 337 * separated by a comma and a space. |
| 356 * | 338 * |
| 357 * See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method | 339 * See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method |
| 358 */ | 340 */ |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 * Calling `open` again on a currently active request is equivalent to | 376 * Calling `open` again on a currently active request is equivalent to |
| 395 * calling `abort`. | 377 * calling `abort`. |
| 396 * | 378 * |
| 397 * Note: Most simple HTTP requests can be accomplished using the [getString], | 379 * Note: Most simple HTTP requests can be accomplished using the [getString], |
| 398 * [request], [requestCrossOrigin], or [postFormData] methods. Use of this | 380 * [request], [requestCrossOrigin], or [postFormData] methods. Use of this |
| 399 * `open` method is intended only for more complex HTTP requests where | 381 * `open` method is intended only for more complex HTTP requests where |
| 400 * finer-grained control is needed. | 382 * finer-grained control is needed. |
| 401 */ | 383 */ |
| 402 @DomName('XMLHttpRequest.open') | 384 @DomName('XMLHttpRequest.open') |
| 403 @DocsEditable() | 385 @DocsEditable() |
| 404 $if JSINTEROP | |
| 405 void open(String method, String url, {bool async, String user, String password
}) { | |
| 406 if (async == null && user == null && password == null) { | |
| 407 _blink.BlinkXMLHttpRequest.instance.open_Callback_2_(this, method, url); | |
| 408 } else { | |
| 409 _blink.BlinkXMLHttpRequest.instance.open_Callback_5_(this, method, url, as
ync, user, password); | |
| 410 } | |
| 411 } | |
| 412 $else | |
| 413 void open(String method, String url, {bool async, String user, String password
}) native; | 386 void open(String method, String url, {bool async, String user, String password
}) native; |
| 414 $endif | |
| 415 | 387 |
| 416 $!MEMBERS | 388 $!MEMBERS |
| 417 } | 389 } |
| OLD | NEW |