You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2009/12/04 01:49:32 UTC

svn commit: r887018 - in /incubator/shindig/trunk/features/src/main/javascript/features/rpc: rmr.transport.js rpc.js wpm.transport.js

Author: johnh
Date: Fri Dec  4 00:49:31 2009
New Revision: 887018

URL: http://svn.apache.org/viewvc?rev=887018&view=rev
Log:
Make rpc.js searches of window.frames (or window.parent) more robust.


Modified:
    incubator/shindig/trunk/features/src/main/javascript/features/rpc/rmr.transport.js
    incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js
    incubator/shindig/trunk/features/src/main/javascript/features/rpc/wpm.transport.js

Modified: incubator/shindig/trunk/features/src/main/javascript/features/rpc/rmr.transport.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/rpc/rmr.transport.js?rev=887018&r1=887017&r2=887018&view=diff
==============================================================================
--- incubator/shindig/trunk/features/src/main/javascript/features/rpc/rmr.transport.js (original)
+++ incubator/shindig/trunk/features/src/main/javascript/features/rpc/rmr.transport.js Fri Dec  4 00:49:31 2009
@@ -195,12 +195,13 @@
     rmr_channels[frameId].searchCounter++;
 
     try {
+      var targetWin = gadgets.rpc._getTargetWin(frameId);
       if (frameId === '..') {
         // We are a gadget.
-        channelWindow = window.parent.frames['rmrtransport-' + gadgets.rpc.RPC_ID];
+        channelWindow = targetWin.frames['rmrtransport-' + gadgets.rpc.RPC_ID];
       } else {
         // We are a container.
-        channelWindow = window.frames[frameId].frames['rmrtransport-..'];
+        channelWindow = targetWin.frames['rmrtransport-..'];
       }
     } catch (e) {
       // Just in case; may happen when relay is set to about:blank or unset.

Modified: incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js?rev=887018&r1=887017&r2=887018&view=diff
==============================================================================
--- incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js (original)
+++ incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js Fri Dec  4 00:49:31 2009
@@ -295,6 +295,30 @@
     return protocol + "://" + host + portStr;
   }
 
+  function getTargetWin(id) {
+    if (typeof id === "undefined" ||
+        id === "..") {
+      return window.parent;
+    }
+
+    // Cast to a String to avoid an index lookup.
+    id = String(id);
+    
+    // Try window.frames first
+    var target = window.frames[id];
+    if (target) {
+      return target;
+    }
+    
+    // Fall back to getElementById()
+    target = document.getElementById(id);
+    if (target && target.contentWindow) {
+      return target.contentWindow;
+    }
+
+    return null;
+  }
+
   // Pick the most efficient RPC relay mechanism.
   var transport = getTransport();
 
@@ -369,12 +393,7 @@
         return false;
       }
 
-      var targetEl = null;
-      if (target === '..') {
-        targetEl = window.parent;
-      } else {
-        targetEl = window.frames[target];
-      }
+      var targetEl = getTargetWin(target);
       try {
         // If this succeeds, then same-domain policy applied
         sameDomain[target] = targetEl.gadgets.rpc.receiveSameDomain;
@@ -800,6 +819,9 @@
       }
     },
 
+    /** Returns the window keyed by the ID. null/".." for parent, else child */
+    _getTargetWin: getTargetWin,
+
     /** Exported constant, for use by transports only. */
     ACK: ACK,
 

Modified: incubator/shindig/trunk/features/src/main/javascript/features/rpc/wpm.transport.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/rpc/wpm.transport.js?rev=887018&r1=887017&r2=887018&view=diff
==============================================================================
--- incubator/shindig/trunk/features/src/main/javascript/features/rpc/wpm.transport.js (original)
+++ incubator/shindig/trunk/features/src/main/javascript/features/rpc/wpm.transport.js Fri Dec  4 00:49:31 2009
@@ -81,7 +81,7 @@
     },
 
     call: function(targetId, from, rpc) {
-      var targetWin = targetId === '..' ? window.parent : window.frames[targetId];
+      var targetWin = gadgets.rpc._getTargetWin(targetId);
       // targetOrigin = canonicalized relay URL
       var origRelay = gadgets.rpc.getRelayUrl(targetId) ||
                       gadgets.util.getUrlParameters()["parent"];