Author: johnh
Date: Fri Jun  5 23:13:07 2009
New Revision: 782163

URL: http://svn.apache.org/viewvc?rev=782163&view=rev
Log:
In-gadget improvements to initialization of parentRelayUrl aka. 
gadgets.rpc.getRelayUrl('..')

* Only performed for a gadget (non-top-level page).
* Uses gadgets.util.getUrlParameters() to get parent param rather than 
implementing a second parser.
* Moved transport.setup('..', ...) into config init method rather than 
immediately-executed gadgets.rpc.init(). This ensures that any transport (or 
other code that runs before gadgets.config.init(...), which ultimately computes 
parentRelayUrl) has accurate access to the parent URL.
  - This fixes RMR-based browsers' container-to-gadget communication.

Tested w/ "correct" setAuthToken behavior (gadgets.rpc.setAuthToken('gadget', 
...) after gadget has been created on:
* FF2, FF3, Opera 9, Safari 3, Safari 4, Chrome 2 (OSX); Chrome 1, IE6, IE7, 
IE8 (Win)

Also, improved rpc test framework a bit:
* Gadget rendered w/ &libs=rpc to doubly ensure that new rpc code gets picked 
up in-gadget.
* Gadget spits out its parent relay URL for immediate display.


Modified:
    incubator/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js
    incubator/shindig/trunk/javascript/container/rpctest_container.html
    incubator/shindig/trunk/javascript/container/rpctest_gadget.xml

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=782163&r1=782162&r2=782163&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 Jun  5 23:13:07 2009
@@ -372,43 +372,43 @@
   }
 
   // gadgets.config might not be available, such as when serving container js.
-  if (gadgets.config) {
+  if (isGadget && gadgets.config) {
     /**
-     * Initializes RPC from the provided configuration.
+     * Initializes gadget to container RPC params from the provided 
configuration.
      */
     function init(config) {
+      var configRpc = config ? config.rpc : {};
+      var parentRelayUrl = configRpc.parentRelayUrl;
+
       // Allow for wild card parent relay files as long as it's from a
       // white listed domain. This is enforced by the rendering servlet.
-      if (config.rpc.parentRelayUrl.substring(0, 7) === 'http://' ||
-          config.rpc.parentRelayUrl.substring(0, 8) === 'https://' ||
-          config.rpc.parentRelayUrl.substring(0, 2) === '//') {
-        relayUrl['..'] = config.rpc.parentRelayUrl;
-      } else {
-        // It's a relative path, and we must append to the parent.
+      if (parentRelayUrl.substring(0, 7) !== 'http://' &&
+          parentRelayUrl.substring(0, 8) !== 'https://' &&
+          parentRelayUrl.substring(0, 2) !== '//') {
+        // Relative path: we append to the parent.
         // We're relying on the server validating the parent parameter in this
-        // case. Because of this, parent may only be passed in the query, not
-        // the fragment.
-        var params = document.location.search.substring(1).split("&");
-        var parentParam = "";
-        for (var i = 0, param; (param = params[i]); ++i) {
-          // Only the first parent can be validated.
-          if (param.indexOf("parent=") === 0) {
-            parentParam = decodeURIComponent(param.substring(7));
-            break;
-          }
-        }
-        if (parentParam !== "") {
+        // case. Because of this, parent may only be passed in the query, not 
fragment.
+        if (params.parent !== "") {
           // Otherwise, relayUrl['..'] will be null, signaling transport
           // code to ignore rpc calls since they cannot work without a
           // relay URL with host qualification.
-          relayUrl['..'] = parentParam + config.rpc.parentRelayUrl;
+          parentRelayUrl = getDomainRoot(params.parent) + parentRelayUrl;
         }
       }
-      var useLegacy = !!config.rpc.useLegacyProtocol;
+      relayUrl['..'] = parentRelayUrl;
+
+      var useLegacy = !!configRpc.useLegacyProtocol;
       useLegacyProtocol['..'] = useLegacy;
       if (useLegacy) {
         transport = gadgets.rpctx.Ifpc;
       }
+
+      // Here, we add a hook for the transport to actively set up
+      // gadget -> container communication. Running here ensures
+      // that relayUri info will be available.
+      if (transport.setup('..') === false) {
+        transport = fallbackTransport;
+      }
     }
 
     var requiredConfig = {
@@ -668,11 +668,6 @@
       if (transport.init(process, transportReady) === false) {
         transport = fallbackTransport;
       }
-      // Here, we add a hook for the transport to actively set up
-      // gadget -> container communication, if we're a gadget.
-      if (isGadget && transport.setup('..') === false) {
-        transport = fallbackTransport;
-      }
     },
 
     /** Exported constant, for use by transports only. */

Modified: incubator/shindig/trunk/javascript/container/rpctest_container.html
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/rpctest_container.html?rev=782163&r1=782162&r2=782163&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/rpctest_container.html 
(original)
+++ incubator/shindig/trunk/javascript/container/rpctest_container.html Fri Jun 
 5 23:13:07 2009
@@ -56,7 +56,7 @@
       // Useful per-page variables.
       var gadgeturl = gadgethost + 
'/gadgets/files/container/rpctest_gadget.xml';
       var cachebust = 'cachebust=' + Math.random();
-      var gadgetrenderingurl = gadgethost + '/gadgets/ifr?url=' + gadgeturl + 
'&parent=' + window.location.protocol + '//' + window.location.host + 
'&debug=1&' + cachebust;
+      var gadgetrenderingurl = gadgethost + '/gadgets/ifr?url=' + gadgeturl + 
'&libs=rpc&parent=' + window.location.protocol + '//' + window.location.host + 
'&debug=1&' + cachebust;
       var gadgetrelay = gadgethost + 
'/gadgets/files/container/rpc_relay.uncompressed.html';
 
       // Set up faux gadgets.config(...)

Modified: incubator/shindig/trunk/javascript/container/rpctest_gadget.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/rpctest_gadget.xml?rev=782163&r1=782162&r2=782163&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/rpctest_gadget.xml (original)
+++ incubator/shindig/trunk/javascript/container/rpctest_gadget.xml Fri Jun  5 
23:13:07 2009
@@ -35,6 +35,9 @@
       gadgets.util.registerOnLoadHandler(initPerfTest);
     </script>
     <div>gadgets.rpc Performance: "Gadget" page</div><hr/>
+    <script>
+      document.write("<div>"Parent relay: " + gadgets.rpc.getRelayUrl('..') + 
"</div><hr/>");
+    </script>
     <div>Test<br/>
       <ul>
         <li>Number of messages to send:


Reply via email to