Author: johnh
Date: Tue Dec 21 00:21:23 2010
New Revision: 1051332

URL: http://svn.apache.org/viewvc?rev=1051332&view=rev
Log:
Additional code implementing flash gadgets.rpc transport. This code actually 
depends, for proper function, on a slight refactoring in gadgets.rpc which will 
be committed separately. It's not in any live code paths at present, and builds 
fine, so I wanted to get this out for additional iteration.


Modified:
    shindig/trunk/content/xpc.swf
    shindig/trunk/features/src/main/flex/Main.as
    shindig/trunk/features/src/main/javascript/features/rpc/flash.transport.js

Modified: shindig/trunk/content/xpc.swf
URL: 
http://svn.apache.org/viewvc/shindig/trunk/content/xpc.swf?rev=1051332&r1=1051331&r2=1051332&view=diff
==============================================================================
Files shindig/trunk/content/xpc.swf (original) and 
shindig/trunk/content/xpc.swf Tue Dec 21 00:21:23 2010 differ

Modified: shindig/trunk/features/src/main/flex/Main.as
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/flex/Main.as?rev=1051332&r1=1051331&r2=1051332&view=diff
==============================================================================
--- shindig/trunk/features/src/main/flex/Main.as (original)
+++ shindig/trunk/features/src/main/flex/Main.as Tue Dec 21 00:21:23 2010
@@ -29,24 +29,24 @@ class Main {
     if (SINGLETON) return;
     SINGLETON = true;
     
-    var origin:String;
+    var my_origin:String;
     
     if (_level0.origin == undefined){
-      origin = "http://*";;
+      my_origin = "http://*";;
     } else {
-      origin = _level0.origin;
+      my_origin = _level0.origin;
     }
     
-    var domain:String = origin.substr(origin.indexOf("//") + 2, origin.length);
+    var domain:String = my_origin.substr(my_origin.indexOf("//") + 2, 
my_origin.length);
     
-    if (origin.substr(0,5)==="http:") {
+    if (my_origin.substr(0,5)==="http:") {
       security.allowInsecureDomain(domain);
     } else {
       security.allowDomain(domain);
     }
     
-    ExternalInterface.addCallback("setup", { }, function(this_channel:String, 
role:String) {
-      if (this_channel.indexOf(":") > -1) {
+    ExternalInterface.addCallback("setup", { }, 
function(channel_recv_id:String, role:String) {
+      if (channel_recv_id.indexOf(":") > -1) {
         return;
       }
 
@@ -61,17 +61,17 @@ class Main {
 
       var receiving_lc:LocalConnection = new LocalConnection();
       var sending_lc:LocalConnection = new LocalConnection();
-      receiving_lc.receiveMessage = function(to:String, from:String, 
channel:String, message:String) {
-        if ((to === "*" || to === origin) && channel === this_channel) {
-          ExternalInterface.call("gadgets.rpctx.flash._receiveMessage", 
channel, message, from, to);
+      receiving_lc.receiveMessage = function(to_origin:String, 
from_origin:String, target_id:String, message:String) {
+        if ((to_origin === "*" || to_origin === my_origin) && target_id === 
channel_recv_id) {
+          ExternalInterface.call("gadgets.rpctx.flash._receiveMessage", 
target_id, message, from_origin, to_origin);
         }
       }
 
-      ExternalInterface.addCallback("sendMessage_"+this_channel, { }, 
function(message:String, to:String) {
-        if (!to) to = "*";
-        sending_lc.send(this_channel + "_" + other_role, "receiveMessage", to, 
origin, this_channel, message);
+      ExternalInterface.addCallback("sendMessage_" + channel_recv_id, { }, 
function(message:String, to_origin:String) {
+        if (!to_origin) to_origin = "*";
+        sending_lc.send(channel_recv_id + "_" + other_role, "receiveMessage", 
to_origin, my_origin, channel_recv_id, message);
       } );
-      receiving_lc.connect(this_channel + "_" + role);
+      receiving_lc.connect(channel_recv_id + "_" + role);
     } );
     ExternalInterface.call("gadgets.rpctx.flash._ready");
   }

Modified: 
shindig/trunk/features/src/main/javascript/features/rpc/flash.transport.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/rpc/flash.transport.js?rev=1051332&r1=1051331&r2=1051332&view=diff
==============================================================================
--- shindig/trunk/features/src/main/javascript/features/rpc/flash.transport.js 
(original)
+++ shindig/trunk/features/src/main/javascript/features/rpc/flash.transport.js 
Tue Dec 21 00:21:23 2010
@@ -32,9 +32,12 @@ gadgets.rpctx = gadgets.rpctx || {};
 if (!gadgets.rpctx.flash) {  // make lib resilient to double-inclusion
 
   gadgets.rpctx.flash = function() {
+    // TODO: provide method to override this
+    // TODO: implement xpc swf servlet
     var swfUrl = "//flashrpctx.googleusercontent.com/xpc.swf";
     var process = null;
     var ready = null;
+    var secureReceivers = {};
     var relayHandle = null;
 
     var LOADER_TIMEOUT_MS = 100;
@@ -43,11 +46,13 @@ if (!gadgets.rpctx.flash) {  // make lib
     var setupHandle = null;
     var setupAttempts = 0;
 
-    function handshakePoller() {
+    var myLoc = window.location.href;
+
+    function relayLoader() {
       if (relayHandle === null && document.body) {
         relayHandle = document.createElement('embed');
         relayHandle.allowScriptAccess = true;
-        relayHandle.src = swfUrl + '?origin=' + window.location;
+        relayHandle.src = swfUrl + '?origin=' + myLoc;
         document.body.appendChild(relayHandle);
       }
       ++setupAttempts;
@@ -67,6 +72,7 @@ if (!gadgets.rpctx.flash) {  // make lib
     }
 
     return {
+      // "core" transport methods
       getCode: function() {
         return 'flash';
       },
@@ -81,7 +87,7 @@ if (!gadgets.rpctx.flash) {  // make lib
         return true;
       },
 
-      setup: function(receiverId, token) {
+      setup: function(receiverId, token, forceSecure) {
         // Perform all setup, including embedding of relay SWF (a one-time
         // per Window operation), in this method. We cannot assume 
document.body
         // exists however, since child-to-parent setup is often done in head.
@@ -89,6 +95,7 @@ if (!gadgets.rpctx.flash) {  // make lib
         // If body already exists then this enqueueing will immediately flush;
         // otherwise polling will occur until the SWF has completed loading, at
         // which point all connections will complete their handshake.
+        secureReceivers[receiverId] = !!forceSecure;
         var role = targetId === ".." ? "OUTER" : "INNER";
         pendingHandshakes.push({ id: targetId, role: role });
         if (relayHandle === null && setupHandle === null) {
@@ -99,15 +106,22 @@ if (!gadgets.rpctx.flash) {  // make lib
       },
 
       call: function(targetId, from, rpc) {
+        var targetOrigin = gadgets.rpc.getTargetOrigin(targetId);;
+        relayHandle["sendMessage_" + targetId](gadgets.json.stringify(rpc), 
targetOrigin);
         return true;
       },
 
       // Methods called by relay SWF. Should be considered private.
-      _receiveMessage: function(channel, message, from, to) {
+      _receiveMessage: function(targetId, message, fromOrigin, toOrigin) {
+        // TODO: validate targetId for sanity, and fromOrigin/toOrigin for 
domain verification.
+        window.setTimeout(function() { process(gadgets.json.parse(message)); 
}, 0);
       },
 
       _ready: function() {
         flushHandshakes();
+        if (setupHandle !== null) {
+          window.clearTimeout(setupHandle);
+        }
         setupHandle = null;
       }
     };


Reply via email to