gecko-dev/content/base/test/file_CrossSiteXHR_inner.html

96 строки
2.1 KiB
HTML

<!DOCTYPE HTML>
<!--
NOTE! The content of this file is duplicated in file_CrossSiteXHR_inner.jar
and file_CrossSiteXHR_inner_data.sjs
Please update those files if you update this one.
-->
<html>
<head>
<script>
window.addEventListener("message", function(e) {
sendData = null;
req = eval(e.data);
var res = {
didFail: false,
events: [],
progressEvents: 0
};
var xhr = new XMLHttpRequest();
for each(type in ["load", "abort", "error", "loadstart"]) {
xhr.addEventListener(type, function(e) {
res.events.push(e.type);
}, false);
}
xhr.addEventListener("readystatechange", function(e) {
res.events.push("rs" + xhr.readyState);
}, false);
xhr.addEventListener("progress", function(e) {
res.progressEvents++;
}, false);
if (req.uploadProgress) {
if (req.uploadProgress == "uploadProgress") {
xhr.addEventListener("uploadProgress", function(e) {
res.progressEvents++;
}, false);
}
else {
xhr.upload.addEventListener(req.uploadProgress, function(e) {
res.progressEvents++;
}, false);
}
}
xhr.onload = function () {
res.status = xhr.status;
res.statusText = xhr.statusText;
res.responseXML = xhr.responseXML ?
(new XMLSerializer()).serializeToString(xhr.responseXML) :
null;
res.responseText = xhr.responseText;
post(e, res);
};
xhr.onerror = function () {
res.didFail = true;
res.status = xhr.status;
try {
res.statusText = xhr.statusText;
} catch (e) {
}
res.responseXML = xhr.responseXML ?
(new XMLSerializer()).serializeToString(xhr.responseXML) :
null;
res.responseText = xhr.responseText;
post(e, res);
}
if (req.withCred)
xhr.withCredentials = true;
if (req.body)
sendData = req.body;
res.events.push("opening");
xhr.open(req.method, req.url, true);
for (header in req.headers) {
xhr.setRequestHeader(header, req.headers[header]);
}
res.events.push("sending");
xhr.send(sendData);
}, false);
function post(e, res) {
e.source.postMessage(res.toSource(), "http://mochi.test:8888");
}
</script>
</head>
<body>
Inner page
</body>
</html>