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: [],
|
2010-11-30 10:18:15 -08:00
|
|
|
progressEvents: 0,
|
|
|
|
status: 0,
|
|
|
|
responseText: "",
|
|
|
|
statusText: "",
|
|
|
|
responseXML: null,
|
|
|
|
sendThrew: false
|
2008-09-30 17:50:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
2012-12-21 03:47:52 -08:00
|
|
|
for (type of ["load", "abort", "error", "loadstart", "loadend"]) {
|
2008-09-30 17:50:42 -07:00
|
|
|
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) {
|
2012-07-21 19:28:26 -07:00
|
|
|
xhr.upload.addEventListener(req.uploadProgress, function(e) {
|
|
|
|
res.progressEvents++;
|
|
|
|
}, false);
|
2008-09-30 17:51:53 -07:00
|
|
|
}
|
2011-03-28 13:18:55 -07:00
|
|
|
xhr.onerror = function(e) {
|
|
|
|
res.didFail = true;
|
|
|
|
};
|
|
|
|
xhr.onloadend = function (event) {
|
2008-09-30 17:50:42 -07:00
|
|
|
res.status = xhr.status;
|
2010-03-16 16:23:45 -07:00
|
|
|
try {
|
|
|
|
res.statusText = xhr.statusText;
|
|
|
|
} catch (e) {
|
2010-11-30 10:18:15 -08:00
|
|
|
delete(res.statusText);
|
2010-03-16 16:23:45 -07:00
|
|
|
}
|
2008-09-30 17:50:42 -07:00
|
|
|
res.responseXML = xhr.responseXML ?
|
|
|
|
(new XMLSerializer()).serializeToString(xhr.responseXML) :
|
|
|
|
null;
|
|
|
|
res.responseText = xhr.responseText;
|
2010-10-04 18:25:44 -07:00
|
|
|
|
|
|
|
res.responseHeaders = {};
|
|
|
|
for (responseHeader in req.responseHeaders) {
|
|
|
|
res.responseHeaders[responseHeader] =
|
|
|
|
xhr.getResponseHeader(responseHeader);
|
|
|
|
}
|
|
|
|
|
2008-09-30 17:50:42 -07:00
|
|
|
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");
|
2010-11-30 10:18:15 -08:00
|
|
|
// Allow passign in falsy usernames/passwords so we can test them
|
|
|
|
try {
|
|
|
|
xhr.open(req.method, req.url, true,
|
|
|
|
("username" in req) ? req.username : "",
|
|
|
|
("password" in req) ? req.password : "aa");
|
|
|
|
} catch (ex) {
|
|
|
|
res.didFail = true;
|
|
|
|
post(e, res);
|
|
|
|
}
|
2008-09-30 17:50:42 -07:00
|
|
|
|
|
|
|
for (header in req.headers) {
|
|
|
|
xhr.setRequestHeader(header, req.headers[header]);
|
|
|
|
}
|
|
|
|
|
|
|
|
res.events.push("sending");
|
2010-11-30 10:18:15 -08:00
|
|
|
try {
|
|
|
|
xhr.send(sendData);
|
|
|
|
} catch (ex) {
|
|
|
|
res.didFail = true;
|
|
|
|
res.sendThrew = true;
|
|
|
|
post(e, res);
|
|
|
|
}
|
2008-09-30 17:50:42 -07:00
|
|
|
|
|
|
|
}, 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>
|