Finally fix object cloning through interwindow messaging.

This commit is contained in:
Nicolas Stepien 2012-01-24 15:48:40 +01:00
parent c3cd11afd8
commit df14650cc6
2 changed files with 27 additions and 23 deletions

View File

@ -1638,29 +1638,31 @@
}, },
message: { message: {
init: function() { init: function() {
var code; var code, script;
code = function(e) { code = function(e) {
var data, host, i, o, u; var data, host;
data = e.data; data = e.data;
if (!data.changeContext) return; if (!data.changeContext) return;
delete data.changeContext; delete data.changeContext;
host = location.hostname; host = location.hostname;
o = {};
for (i in data) {
u = data[i];
o[i] = u;
}
if (host === 'boards.4chan.org') { if (host === 'boards.4chan.org') {
return document.getElementById('iframe').contentWindow.postMessage(o, '*'); return document.getElementById('iframe').contentWindow.postMessage(data, '*');
} else if (host === 'sys.4chan.org') { } else if (host === 'sys.4chan.org') {
return parent.postMessage(o, '*'); return parent.postMessage(data, '*');
} }
}; };
if (engine === 'gecko') { script = $.el('script', {
return $.on(window, 'message', code); textContent: "window.addEventListener('message'," + code + ",false)"
} else { });
return window.location = "javascript:window.addEventListener('message'," + code + ",false)"; if (d.documentElement) {
$.add(d.documentElement, script);
$.rm(script);
return;
} }
return $.ready(function() {
$.add(d.head, script);
return $.rm(script);
});
}, },
send: function(data) { send: function(data) {
data.changeContext = true; data.changeContext = true;

View File

@ -1262,18 +1262,20 @@ qr =
return unless data.changeContext return unless data.changeContext
delete data.changeContext delete data.changeContext
host = location.hostname host = location.hostname
o = {}
for i, u of data
o[i] = u
if host is 'boards.4chan.org' if host is 'boards.4chan.org'
document.getElementById('iframe').contentWindow.postMessage o, '*' document.getElementById('iframe').contentWindow.postMessage data, '*'
else if host is 'sys.4chan.org' else if host is 'sys.4chan.org'
parent.postMessage o, '*' parent.postMessage data, '*'
# do not wait for 4chan to load script = $.el 'script', textContent: "window.addEventListener('message',#{code},false)"
if engine is 'gecko' # Chrome can access the documentElement on document-start
$.on window, 'message', code if d.documentElement
else $.add d.documentElement, script
window.location = "javascript:window.addEventListener('message',#{code},false)" $.rm script
return
# other browsers will have to wait
$.ready ->
$.add d.head, script
$.rm script
send: (data) -> send: (data) ->
data.changeContext = true data.changeContext = true
data.qr = true data.qr = true