Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <!-- |
michael@0 | 3 | NOTE! The content of this file is duplicated in file_CrossSiteXHR_inner.jar |
michael@0 | 4 | and file_CrossSiteXHR_inner_data.sjs |
michael@0 | 5 | Please update those files if you update this one. |
michael@0 | 6 | --> |
michael@0 | 7 | |
michael@0 | 8 | <html> |
michael@0 | 9 | <head> |
michael@0 | 10 | <script> |
michael@0 | 11 | function trimString(stringValue) { |
michael@0 | 12 | return stringValue.replace(/^\s+|\s+$/g, ''); |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | window.addEventListener("message", function(e) { |
michael@0 | 16 | |
michael@0 | 17 | sendData = null; |
michael@0 | 18 | |
michael@0 | 19 | req = eval(e.data); |
michael@0 | 20 | var res = { |
michael@0 | 21 | didFail: false, |
michael@0 | 22 | events: [], |
michael@0 | 23 | progressEvents: 0, |
michael@0 | 24 | status: 0, |
michael@0 | 25 | responseText: "", |
michael@0 | 26 | statusText: "", |
michael@0 | 27 | responseXML: null, |
michael@0 | 28 | sendThrew: false |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | var xhr = new XMLHttpRequest(); |
michael@0 | 32 | for (type of ["load", "abort", "error", "loadstart", "loadend"]) { |
michael@0 | 33 | xhr.addEventListener(type, function(e) { |
michael@0 | 34 | res.events.push(e.type); |
michael@0 | 35 | }, false); |
michael@0 | 36 | } |
michael@0 | 37 | xhr.addEventListener("readystatechange", function(e) { |
michael@0 | 38 | res.events.push("rs" + xhr.readyState); |
michael@0 | 39 | }, false); |
michael@0 | 40 | xhr.addEventListener("progress", function(e) { |
michael@0 | 41 | res.progressEvents++; |
michael@0 | 42 | }, false); |
michael@0 | 43 | if (req.uploadProgress) { |
michael@0 | 44 | xhr.upload.addEventListener(req.uploadProgress, function(e) { |
michael@0 | 45 | res.progressEvents++; |
michael@0 | 46 | }, false); |
michael@0 | 47 | } |
michael@0 | 48 | xhr.onerror = function(e) { |
michael@0 | 49 | res.didFail = true; |
michael@0 | 50 | }; |
michael@0 | 51 | xhr.onloadend = function (event) { |
michael@0 | 52 | res.status = xhr.status; |
michael@0 | 53 | try { |
michael@0 | 54 | res.statusText = xhr.statusText; |
michael@0 | 55 | } catch (e) { |
michael@0 | 56 | delete(res.statusText); |
michael@0 | 57 | } |
michael@0 | 58 | res.responseXML = xhr.responseXML ? |
michael@0 | 59 | (new XMLSerializer()).serializeToString(xhr.responseXML) : |
michael@0 | 60 | null; |
michael@0 | 61 | res.responseText = xhr.responseText; |
michael@0 | 62 | |
michael@0 | 63 | res.responseHeaders = {}; |
michael@0 | 64 | for (responseHeader in req.responseHeaders) { |
michael@0 | 65 | res.responseHeaders[responseHeader] = |
michael@0 | 66 | xhr.getResponseHeader(responseHeader); |
michael@0 | 67 | } |
michael@0 | 68 | res.allResponseHeaders = {}; |
michael@0 | 69 | var splitHeaders = xhr.getAllResponseHeaders().split("\r\n"); |
michael@0 | 70 | for (var i = 0; i < splitHeaders.length; i++) { |
michael@0 | 71 | var headerValuePair = splitHeaders[i].split(":"); |
michael@0 | 72 | if(headerValuePair[1] != null) { |
michael@0 | 73 | var headerName = trimString(headerValuePair[0]); |
michael@0 | 74 | var headerValue = trimString(headerValuePair[1]); |
michael@0 | 75 | res.allResponseHeaders[headerName] = headerValue; |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | post(e, res); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | if (req.withCred) |
michael@0 | 82 | xhr.withCredentials = true; |
michael@0 | 83 | if (req.body) |
michael@0 | 84 | sendData = req.body; |
michael@0 | 85 | |
michael@0 | 86 | res.events.push("opening"); |
michael@0 | 87 | // Allow passign in falsy usernames/passwords so we can test them |
michael@0 | 88 | try { |
michael@0 | 89 | xhr.open(req.method, req.url, true, |
michael@0 | 90 | ("username" in req) ? req.username : "", |
michael@0 | 91 | ("password" in req) ? req.password : "aa"); |
michael@0 | 92 | } catch (ex) { |
michael@0 | 93 | res.didFail = true; |
michael@0 | 94 | post(e, res); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | for (header in req.headers) { |
michael@0 | 98 | xhr.setRequestHeader(header, req.headers[header]); |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | res.events.push("sending"); |
michael@0 | 102 | try { |
michael@0 | 103 | xhr.send(sendData); |
michael@0 | 104 | } catch (ex) { |
michael@0 | 105 | res.didFail = true; |
michael@0 | 106 | res.sendThrew = true; |
michael@0 | 107 | post(e, res); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | }, false); |
michael@0 | 111 | |
michael@0 | 112 | function post(e, res) { |
michael@0 | 113 | e.source.postMessage(res.toSource(), "http://mochi.test:8888"); |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | </script> |
michael@0 | 117 | </head> |
michael@0 | 118 | <body> |
michael@0 | 119 | Inner page |
michael@0 | 120 | </body> |
michael@0 | 121 | </html> |