2008-09-30 17:50:42 -07:00
|
|
|
<!DOCTYPE HTML>
|
2009-01-21 14:50:28 -08:00
|
|
|
<!--
|
|
|
|
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.
|
|
|
|
-->
|
|
|
|
|
2008-09-30 17:50:42 -07:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<script>
|
2009-01-21 14:50:28 -08:00
|
|
|
window.addEventListener("message", function(e) {
|
2008-09-30 17:50:42 -07:00
|
|
|
|
|
|
|
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);
|
2008-09-30 17:51:53 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2008-09-30 17:50:42 -07:00
|
|
|
xhr.onload = function () {
|
|
|
|
res.status = xhr.status;
|
2010-03-16 16:23:45 -07:00
|
|
|
res.statusText = xhr.statusText;
|
2008-09-30 17:50:42 -07:00
|
|
|
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;
|
2010-03-16 16:23:45 -07:00
|
|
|
try {
|
|
|
|
res.statusText = xhr.statusText;
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2008-09-30 17:50:42 -07:00
|
|
|
res.responseXML = xhr.responseXML ?
|
|
|
|
(new XMLSerializer()).serializeToString(xhr.responseXML) :
|
|
|
|
null;
|
|
|
|
res.responseText = xhr.responseText;
|
|
|
|
post(e, res);
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:52:52 -07:00
|
|
|
if (req.withCred)
|
|
|
|
xhr.withCredentials = true;
|
2009-01-13 22:53:43 -08:00
|
|
|
if (req.body)
|
|
|
|
sendData = req.body;
|
2008-09-30 17:52:52 -07:00
|
|
|
|
2008-09-30 17:50:42 -07:00
|
|
|
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) {
|
2010-03-12 13:53:36 -08:00
|
|
|
e.source.postMessage(res.toSource(), "http://mochi.test:8888");
|
2008-09-30 17:50:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
Inner page
|
|
|
|
</body>
|
2010-03-12 13:53:36 -08:00
|
|
|
</html>
|