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 2011/05/11 19:48:52 UTC

svn commit: r1101996 - in /shindig/trunk: config/container.js content/container/rpctest_container.html content/container/rpctest_gadget.xml content/container/rpctest_perf.js features/src/main/javascript/features/rpc/rpc.js

Author: johnh
Date: Wed May 11 17:48:52 2011
New Revision: 1101996

URL: http://svn.apache.org/viewvc?rev=1101996&view=rev
Log:
Make referrer-passing in gadgets.rpc configurable.


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

Modified: shindig/trunk/config/container.js
URL: http://svn.apache.org/viewvc/shindig/trunk/config/container.js?rev=1101996&r1=1101995&r2=1101996&view=diff
==============================================================================
--- shindig/trunk/config/container.js (original)
+++ shindig/trunk/config/container.js Wed May 11 17:48:52 2011
@@ -236,7 +236,8 @@
     "useLegacyProtocol" : false,
 
     // Path to the cross-domain enabling SWF for rpc's Flash transport.
-    "commSwf": "/xpc.swf"
+    "commSwf": "/xpc.swf",
+    "passReferrer": "c2p:query"
   },
   // Skin defaults
   "skins" : {

Modified: shindig/trunk/content/container/rpctest_container.html
URL: http://svn.apache.org/viewvc/shindig/trunk/content/container/rpctest_container.html?rev=1101996&r1=1101995&r2=1101996&view=diff
==============================================================================
--- shindig/trunk/content/container/rpctest_container.html (original)
+++ shindig/trunk/content/container/rpctest_container.html Wed May 11 17:48:52 2011
@@ -55,17 +55,13 @@
 
       // Useful per-page variables.
       var gadgeturl = gadgethost + '/container/rpctest_gadget.xml';
-      var cachebust = 'cachebust=' + Math.random();
-      var gadgetrenderingurl = gadgethost + '/gadgets/ifr?url=' + gadgeturl + '&libs=rpc&parent=' + window.location.protocol + '//' + window.location.host + '&debug=1&nocache=1&' + cachebust + (flash ? '&rpctx=flash' : '') + (rmr ? '&rpctx=rmr' : '');
       var gadgetrelay = gadgethost + '/container/rpc_relay.uncompressed.html';
-
-      // Include rpc.js. Append random cache-busting param to ensure caching doesn't occur.
-      document.write('<scr' + 'ipt language="JavaScript" type="text/javascript" src="' +
-                     '/gadgets/js/rpc.js?c=1&nocache=1&debug=1&' + cachebust + '"></scr' + 'ipt>');
-
-      // Include rpctest_perf.js JS test helper, also with cachebusting.
-      document.write('<scr' + 'ipt language="JavaScript" type="text/javascript" src="' +
-                     '/container/rpctest_perf.js?' + cachebust + '"></scr' + 'ipt>');
+      </script>
+      <script language="JavaScript" type="text/javascript" src="/gadgets/js/rpc.js?c=1&nocache=1&debug=1"></script>
+      <script>
+      var gadgetrenderingurl = gadgethost + '/gadgets/ifr?url=' + gadgeturl + '&libs=rpc&parent=' + window.location.protocol + '//' + window.location.host + '&debug=1&nocache=1&' + (flash ? '&rpctx=flash' : '') + (rmr ? '&rpctx=rmr' : '');
+      </script>
+      <script language="JavaScript" type="text/javascript" src="/container/rpctest_perf.js"></script>
     </script>
     <!-- need a script break to allow rpc.js to load before calling referenced methods -->
     <script>
@@ -156,7 +152,8 @@
       Messages: <span id="results_num_received"></span>, Bytes: <span id="results_bytes_received"></span> <span id="in_or_out"></span><br/>
       Time elapsed for test run: <span id="results_time_used"></span><br/>
       Messages/second: <span id="results_msgs_per_sec"></span><br/>
-      Bytes/second: <span id="results_bytes_per_sec"></span>
+      Bytes/second: <span id="results_bytes_per_sec"></span><br/>
+      Referrer: <span id="results_referrer"></span>
     </div>
     <hr/>
     <div>Callback<br/>

Modified: shindig/trunk/content/container/rpctest_gadget.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/content/container/rpctest_gadget.xml?rev=1101996&r1=1101995&r2=1101996&view=diff
==============================================================================
--- shindig/trunk/content/container/rpctest_gadget.xml (original)
+++ shindig/trunk/content/container/rpctest_gadget.xml Wed May 11 17:48:52 2011
@@ -27,7 +27,7 @@
       // Pre-onload message send.
       gadgets.rpc.call(null, 'initial_gadget_message', null, 'Hello there! Pre-onload message sent successfully.');
     
-      var cachebust = 'cachebust=' + Math.random();
+      var cachebust = 'cachebust=1';// + Math.random();
       document.write('<scr' + 'ipt language="JavaScript" type="text/javascript" src="/container/rpctest_perf.js?' + cachebust + '"></scr' + 'ipt>');
     </script>
     <script>
@@ -100,7 +100,8 @@
       Messages: <span id="results_num_received"></span>, Bytes: <span id="results_bytes_received"></span> <span id="in_or_out"></span><br/>
       Time elapsed for test run: <span id="results_time_used"></span><br/>
       Messages/second: <span id="results_msgs_per_sec"></span><br/>
-      Bytes/second: <span id="results_bytes_per_sec"></span>
+      Bytes/second: <span id="results_bytes_per_sec"></span><br/>
+      Referrer: <span id="results_referrer"></span>
     </div><hr/>
     <div>Callback<br/>
       <ul>

Modified: shindig/trunk/content/container/rpctest_perf.js
URL: http://svn.apache.org/viewvc/shindig/trunk/content/container/rpctest_perf.js?rev=1101996&r1=1101995&r2=1101996&view=diff
==============================================================================
--- shindig/trunk/content/container/rpctest_perf.js (original)
+++ shindig/trunk/content/container/rpctest_perf.js Wed May 11 17:48:52 2011
@@ -54,6 +54,8 @@ function completePerfStats() {
   document.getElementById("results_time_used").innerHTML = timeUsedMs + "ms";
   document.getElementById("results_msgs_per_sec").innerHTML = (perfStats.numResults / (timeUsedMs / 1000));
   document.getElementById("results_bytes_per_sec").innerHTML = (perfStats.bytesReceived / (timeUsedMs / 1000));
+  document.getElementById("results_referrer").innerHTML = (this['referer'] || "n/a") + " -- config: " +
+      (gadgets.config.get("rpc")["passReferrer"] || "<empty>");
   document.getElementById("test_running").style.display = "none";
   document.getElementById("results").style.display = "";
 };

Modified: shindig/trunk/features/src/main/javascript/features/rpc/rpc.js
URL: http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/rpc/rpc.js?rev=1101996&r1=1101995&r2=1101996&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/rpc/rpc.js (original)
+++ shindig/trunk/features/src/main/javascript/features/rpc/rpc.js Wed May 11 17:48:52 2011
@@ -122,7 +122,8 @@ if (!window['gadgets']['rpc']) { // make
     var params = {};
     var receiverTx = {};
     var earlyRpcQueue = {};
-    var passReferrer = false;
+    var passReferrerDirection = null;
+    var passReferrerContents = null;
 
     // isGadget =~ isChild for the purposes of rpc (used only in setup).
     var isChild = (window.top !== window.self);
@@ -328,7 +329,7 @@ if (!window['gadgets']['rpc']) { // make
         if (opt_sender) {
           var origin = getOrigin(opt_sender);
           rpc[RPC_KEY_ORIGIN] = opt_sender;
-          var referrer = rpc['r'] || document.referrer;
+          var referrer = rpc['r'];
           if (!referrer || getOrigin(referrer) != origin) {
             // Transports send along as much info as they can about the sender
             // of the message; 'origin' is the origin component alone, while
@@ -643,11 +644,18 @@ if (!window['gadgets']['rpc']) { // make
       setupFrame(targetId, token);
     }
 
+    function setReferrerConfig(cfg) {
+      var passReferrer = cfg['passReferrer'] || "";
+      var prParts = passReferrer.split(":", 2);
+      passReferrerDirection = prParts[0] || "none";
+      passReferrerContents = prParts[1] || "origin";
+    }
+
     function setupContainedContext(rpctoken, opt_parent) {
       function init(config) {
         var cfg = config ? config['rpc'] : {};
         var useLegacy = String(cfg['useLegacyProtocol']) === 'true';
-        passReferrer = String(cfg['passReferrer']) === 'true';
+        setReferrerConfig(cfg);
 
         // Parent-relative only.
         var parentRelayUrl = cfg['parentRelayUrl'] || '';
@@ -755,6 +763,24 @@ if (!window['gadgets']['rpc']) { // make
       }
     }
 
+    function getReferrer(targetId) {
+      if (passReferrerDirection === "bidir" ||
+          (passReferrerDirection === "c2p" && targetId === "..") ||
+          (passReferrerDirection === "p2c" && targetId !== "..")) {
+        var href = window.location.href;
+        var lopOff = "?";  // default = origin
+        if (passReferrerContents === "query") {
+          lopOff = "#";
+        } else if (passReferrerContents === "hash") {
+          return href;
+        }
+        var lastIx = href.lastIndexOf(lopOff);
+        lastIx = lastIx === -1 ? href.length : lastIx;
+        return href.substring(0, lastIx);
+      }
+      return null;
+    }
+
     return /** @scope gadgets.rpc */ {
       config: function(config) {
         if (typeof config.securityCallback === 'function') {
@@ -872,8 +898,9 @@ if (!window['gadgets']['rpc']) { // make
           'l': useLegacyProtocol[targetId]
         };
 
-        if (passReferrer) {
-          rpc['r'] = window.location.href;
+        var referrer = getReferrer(targetId);
+        if (referrer) {
+          rpc['r'] = referrer;
         }
 
         if (targetId !== '..' &&
@@ -1000,6 +1027,8 @@ if (!window['gadgets']['rpc']) { // make
         }
         if (isChild) {
           setupReceiver('..');
+        } else {
+          gadgets.config.register('rpc', null, function(config) { setReferrerConfig(config['rpc'] || {}); });
         }
       },