OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <title>cross-site iframe factory</title> |
| 4 <style> |
| 5 body {font-family: Sans-Serif; |
| 6 text-align: center;} |
| 7 h1 {color:black} |
| 8 h2 {color:black} |
| 9 iframe {border-radius: 7px; |
| 10 border-style: solid; |
| 11 vertical-align: top; |
| 12 margin: 2px; |
| 13 } |
| 14 </style> |
| 15 </head> |
| 16 <body> |
| 17 <!-- This only works if the CrossSiteRedirector is running on the embedded test |
| 18 server, and the host_resolver is set up to handle b.com. --> |
| 19 <script src="cross_site_iframe_factory_parser.js"></script> |
| 20 <script type="text/javascript"> |
| 21 |
| 22 function murmurhash3_32_gc(key, seed) { |
| 23 var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i; |
| 24 |
| 25 remainder = key.length & 3; // key.length % 4 |
| 26 bytes = key.length - remainder; |
| 27 h1 = seed; |
| 28 c1 = 0xcc9e2d51; |
| 29 c2 = 0x1b873593; |
| 30 i = 0; |
| 31 |
| 32 while (i < bytes) { |
| 33 k1 = |
| 34 ((key.charCodeAt(i) & 0xff)) | |
| 35 ((key.charCodeAt(++i) & 0xff) << 8) | |
| 36 ((key.charCodeAt(++i) & 0xff) << 16) | |
| 37 ((key.charCodeAt(++i) & 0xff) << 24); |
| 38 ++i; |
| 39 |
| 40 k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xff
ffffff; |
| 41 k1 = (k1 << 15) | (k1 >>> 17); |
| 42 k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xff
ffffff; |
| 43 |
| 44 h1 ^= k1; |
| 45 h1 = (h1 << 13) | (h1 >>> 19); |
| 46 h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xfff
fffff; |
| 47 h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16)
); |
| 48 } |
| 49 |
| 50 k1 = 0; |
| 51 |
| 52 switch (remainder) { |
| 53 case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16; |
| 54 case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8; |
| 55 case 1: k1 ^= (key.charCodeAt(i) & 0xff); |
| 56 |
| 57 k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffff
ffff; |
| 58 k1 = (k1 << 15) | (k1 >>> 17); |
| 59 k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffff
ffff; |
| 60 h1 ^= k1; |
| 61 } |
| 62 |
| 63 h1 ^= key.length; |
| 64 |
| 65 h1 ^= h1 >>> 16; |
| 66 h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) <<
16)) & 0xffffffff; |
| 67 h1 ^= h1 >>> 13; |
| 68 h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) <
< 16))) & 0xffffffff; |
| 69 h1 ^= h1 >>> 16; |
| 70 |
| 71 return h1 >>> 0; |
| 72 } |
| 73 |
| 74 function pastel_color(input_str, gamma) { |
| 75 // Picked by trial and erro so that [a.com ... h.com] are well distributed |
| 76 // in colorspace. |
| 77 var seeded_value = input_str + "14"; |
| 78 var hash = murmurhash3_32_gc(seeded_value, 0); |
| 79 var x1 = ((hash >> 00) & 0x3FF) / 0x3FF; |
| 80 var x2 = ((hash >> 10) & 0x3FF) / 0x3FF; |
| 81 var x3 = ((hash >> 20) & 0x3FF) / 0x3FF; |
| 82 |
| 83 // Apply gamma for lighter/darker tones. |
| 84 x1 = Math.pow(x1, gamma); |
| 85 x2 = Math.pow(x2, gamma); |
| 86 x3 = Math.pow(x3, gamma); |
| 87 |
| 88 // Average the color with the base. This produces pastel-like tones. |
| 89 var alpha = 0.5; |
| 90 var r = Math.round(255 * (alpha * x1 + (1 - alpha))); |
| 91 var g = Math.round(255 * (alpha * x2 + (1 - alpha))); |
| 92 var b = Math.round(255 * (alpha * x3 + (1 - alpha))); |
| 93 |
| 94 return "rgb(" + r + ", " + g + ", " + b + ")"; |
| 95 } |
| 96 |
| 97 function backgroundColor(input_str) { |
| 98 return pastel_color(input_str, .5); |
| 99 } |
| 100 function borderColor(input_str) { |
| 101 return pastel_color(input_str, 2); |
| 102 } |
| 103 |
| 104 if (!window.location.protocol.startsWith('http')) { |
| 105 var me = document.createElement('h1'); |
| 106 document.body.appendChild(me); |
| 107 } |
| 108 |
| 109 function canonicalizeSite(site_string) { |
| 110 if (site_string.indexOf('.') == -1) |
| 111 return site_string + ".com"; |
| 112 return site_string; |
| 113 } |
| 114 |
| 115 var query_string = unescape(window.location.search.substring(1)); |
| 116 var command = query_parser.parse(query_string); |
| 117 |
| 118 var me = document.createElement('h2'); |
| 119 var document_site = canonicalizeSite(command.site); |
| 120 me.innerText = document_site; |
| 121 document.body.appendChild(me); |
| 122 document.body.style.backgroundColor = backgroundColor(document_site); |
| 123 |
| 124 for (var i = 0; i < command.frames.length; i++) { |
| 125 var go_cross_site = window.location.protocol.startsWith('http'); |
| 126 var host = canonicalizeSite(command.frames[i].site); |
| 127 var url = ""; |
| 128 url += window.location.protocol + "//"; // scheme (preserved) |
| 129 url += go_cross_site ? host : window.location.host; // host |
| 130 if (window.location.port) |
| 131 url += ":" + window.location.port; // port (preserved) |
| 132 url += "/" + window.location.pathname; // path (preserved) |
| 133 url += "?" + escape(command.frames[i].args); // query |
| 134 |
| 135 var iframe = document.createElement('iframe'); |
| 136 iframe.src = url; |
| 137 iframe.style.borderColor = borderColor(host); |
| 138 iframe.scrolling = "no"; |
| 139 iframe.width = iframe.height = command.frames[i].args.length*25 + 50; |
| 140 document.body.appendChild(iframe); |
| 141 } |
| 142 </script> |
| 143 </body></html> |
OLD | NEW |