blob: ef2a2700135f58307941c4b27134dc0173f2a35a [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/base/base.html">
<script>
'use strict';
tv.exportTo('tv.b', function() {
var THIS_DOC = document._currentScript.ownerDocument;
function getAsync(url) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
var isBinary = /[.]gz$/.test(url) || /[.]zip$/.test(url);
req.overrideMimeType('text/plain; charset=x-user-defined');
req.open('GET', url, true);
if (isBinary)
req.responseType = 'arraybuffer';
req.onreadystatechange = function(aEvt) {
if (req.readyState == 4) {
window.setTimeout(function() {
if (req.status == 200) {
resolve(isBinary ? req.response : req.responseText);
} else {
reject(new Error('XHR failed with status ' + req.status));
}
}, 0);
}
};
req.send(null);
});
}
return {
getAsync: getAsync
};
});
</script>