| 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 /** | 5 /** |
| 6 * This contains a reader that accesses data using the HttpRequest | 6 * This contains a reader that accesses data using the HttpRequest |
| 7 * facility, and thus works only in the web browser. | 7 * facility, and thus works only in the web browser. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 library http_request_data_reader; | 10 library http_request_data_reader; |
| 11 | 11 |
| 12 import 'dart:async'; | 12 import 'dart:async'; |
| 13 import 'dart:html'; | 13 import 'dart:html'; |
| 14 import 'intl_helpers.dart'; | 14 import 'intl_helpers.dart'; |
| 15 | 15 |
| 16 class HTTPRequestDataReader implements LocaleDataReader { | 16 class HttpRequestDataReader implements LocaleDataReader { |
| 17 | 17 |
| 18 /** The base url from which we read the data. */ | 18 /** The base url from which we read the data. */ |
| 19 String url; | 19 String url; |
| 20 HTTPRequestDataReader(this.url); | 20 HttpRequestDataReader(this.url); |
| 21 | 21 |
| 22 Future read(String locale) { | 22 Future read(String locale) { |
| 23 // TODO(alanknight): Remove this once it's not necessary for Chrome. | 23 // TODO(alanknight): Remove this once it's not necessary for Chrome. |
| 24 // Without it, the tests will be flaky on Chrome. Issue 11834. | 24 // Without it, the tests will be flaky on Chrome. Issue 11834. |
| 25 var someNumber = new DateTime.now().millisecondsSinceEpoch; | 25 var someNumber = new DateTime.now().millisecondsSinceEpoch; |
| 26 var request = new HttpRequest(); | 26 var request = new HttpRequest(); |
| 27 request.timeout = 5000; | 27 request.timeout = 5000; |
| 28 return _getString('$url$locale.json?cacheBlocker=$someNumber', request) | 28 return _getString('$url$locale.json?cacheBlocker=$someNumber', request) |
| 29 .then((r) => r.responseText); | 29 .then((r) => r.responseText); |
| 30 } | 30 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 completer.completeError(e); | 44 completer.completeError(e); |
| 45 } | 45 } |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 xhr.onError.listen(completer.completeError); | 48 xhr.onError.listen(completer.completeError); |
| 49 xhr.send(); | 49 xhr.send(); |
| 50 | 50 |
| 51 return completer.future; | 51 return completer.future; |
| 52 } | 52 } |
| 53 } | 53 } |
| OLD | NEW |