[Pkg-javascript-commits] [sockjs-client] 112/434: Messages exchanged between main window and an iframe must be tagged with window_id - in order to identify a proper iframe.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 1e05664ec720b4b51a875ab3fc7fe1ee0b021f30
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Thu Sep 1 17:26:03 2011 +0100

    Messages exchanged between main window and an iframe must be tagged with window_id - in order to identify a proper iframe.
    
    Due to Opera bug, it's impossible to check where did the event (onmessage) came from - "event.source === iframe...window" fails.
    As a result, if there are more iframes open the communication gets completely messed up. To avoid that, we need to be able to identify a particular iframe from main window. The problem is how to share a handle with an iframe - it's on a foreign domain. For that we use an old hack - we push the handle as uri fragment (#hash). That way, the iframe.html document may still be cached and the iframe can be properly identified on both sides.
---
 lib/trans-iframe-within.js | 11 ++++++++---
 lib/trans-iframe.js        | 12 +++++++++---
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/lib/trans-iframe-within.js b/lib/trans-iframe-within.js
index 73dc92c..bf76afe 100644
--- a/lib/trans-iframe-within.js
+++ b/lib/trans-iframe-within.js
@@ -1,6 +1,8 @@
+var curr_window_id;
+
 var postMessage = function (type, data) {
     if(parent !== _window) {
-        parent.postMessage(type + (data || ''), '*');
+        parent.postMessage(curr_window_id + type + (data || ''), '*');
     } else {
         utils.log("Can't postMessage, no parent window.", type, data);
     }
@@ -22,10 +24,13 @@ FacadeJS.prototype._doCleanup = function () {
 
 SockJS.bootstrap_iframe = function() {
     var facade;
+    curr_window_id = _document.location.hash.slice(1);
     var onMessage = function(e) {
         if(e.source !== parent) return;
-        var type = e.data.slice(0, 1);
-        var data = e.data.slice(1);
+        var window_id = e.data.slice(0, 8);
+        var type = e.data.slice(8, 9);
+        var data = e.data.slice(9);
+        if (window_id !== curr_window_id) return;
         switch(type) {
         case 's':
             var p = JSON.parse(data);
diff --git a/lib/trans-iframe.js b/lib/trans-iframe.js
index ffeb7cf..4f7e306 100644
--- a/lib/trans-iframe.js
+++ b/lib/trans-iframe.js
@@ -18,6 +18,8 @@ IframeTransport.prototype.i_constructor = function(ri, trans_url, base_url) {
     if (that.ri._options.devel) {
         iframe_url += '?t=' + (+new Date);
     }
+    that.window_id = utils.random_string(8);
+    iframe_url += '#' + that.window_id;
 
     that.iframeObj = utils.createIframe(iframe_url, function(r) {
                                             that.ri._didClose(1006, "Unable to load an iframe (" + r + ")");
@@ -51,8 +53,12 @@ IframeTransport.prototype.doCleanup = function() {
 IframeTransport.prototype.onmessage = function(e) {
     var that = this;
     if (e.origin !== that.origin) return;
-    var type = e.data.slice(0, 1);
-    var data = e.data.slice(1);
+    var window_id = e.data.slice(0, 8);
+    var type = e.data.slice(8, 9);
+    var data = e.data.slice(9);
+
+    if (window_id !== that.window_id) return;
+
     switch(type) {
     case 's':
         that.iframeObj.loaded();
@@ -66,7 +72,7 @@ IframeTransport.prototype.onmessage = function(e) {
 
 IframeTransport.prototype.postMessage = function(type, data) {
     var that = this;
-    that.iframeObj.iframe.contentWindow.postMessage(type + (data || ''), that.origin);
+    that.iframeObj.iframe.contentWindow.postMessage(that.window_id + type + (data || ''), that.origin);
 };
 
 IframeTransport.prototype.doSend = function (message) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list