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: {
init: function() {
var code;
var code, script;
code = function(e) {
var data, host, i, o, u;
var data, host;
data = e.data;
if (!data.changeContext) return;
delete data.changeContext;
host = location.hostname;
o = {};
for (i in data) {
u = data[i];
o[i] = u;
}
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') {
return parent.postMessage(o, '*');
return parent.postMessage(data, '*');
}
};
if (engine === 'gecko') {
return $.on(window, 'message', code);
} else {
return window.location = "javascript:window.addEventListener('message'," + code + ",false)";
script = $.el('script', {
textContent: "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) {
data.changeContext = true;

View File

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