Author: jasvir
Date: Tue Jan 26 17:30:34 2010
New Revision: 903332
URL: http://svn.apache.org/viewvc?rev=903332&view=rev
Log:
[http://codereview.appspot.com/186265/show] Flash Bridge Example for Caja
Patch from Mike Stay
* Adds an example of using a flash bridge to communicate between a flash and a
cajoled gadget.
Added:
incubator/shindig/trunk/javascript/samplecontainer/examples/FlashBridgeCajaExample.xml
Modified:
incubator/shindig/trunk/features/src/main/javascript/features/flash/taming.js
Modified:
incubator/shindig/trunk/features/src/main/javascript/features/flash/taming.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/src/main/javascript/features/flash/taming.js?rev=903332&r1=903331&r2=903332&view=diff
==============================================================================
---
incubator/shindig/trunk/features/src/main/javascript/features/flash/taming.js
(original)
+++
incubator/shindig/trunk/features/src/main/javascript/features/flash/taming.js
Tue Jan 26 17:30:34 2010
@@ -22,6 +22,8 @@
* Tame and expose core gadgets.flash.* API to cajoled gadgets
*/
var tamings___ = tamings___ || [];
+var bridge___;
+
tamings___.push(function(imports) {
___.tamesTo(gadgets.flash.embedFlash, (function () {
var cleanse = (function () {
@@ -32,7 +34,6 @@
var ifr = document.createElement("iframe");
ifr.width = 1; ifr.height = 1; ifr.border = 0;
document.body.appendChild(ifr);
- var A = ifr.contentWindow.Array;
var O = ifr.contentWindow.Object;
document.body.removeChild(ifr);
@@ -42,13 +43,12 @@
return obj;
}
if (t === 'object') {
- var o;
- if (obj instanceof Array) { o = new A; }
- else if (obj instanceof Object) { o = new O; }
+ var o = new O;
for (i in obj) {
if (/__$/.test(i)) { continue; }
o[i] = c(obj[i]);
}
+ if (obj.length !== undefined) { o.length = obj.length; }
return o;
}
return (void 0);
@@ -56,6 +56,43 @@
return c;
})();
+
+ var d = document.createElement('div');
+ d.appendChild(document.createTextNode("bridge"));
+ document.body.appendChild(d);
+
+ gadgets.flash.embedFlash(
+ "/gadgets/files/container/Bridge.swf",
+ d,
+ 10,
+ {
+ allowNetworking: "always",
+ allowScriptAccess: "all",
+ width: 0,
+ height: 0,
+ flashvars: "logging=true"
+ });
+ bridge___ = d.childNodes[0];
+ bridge___.channels = [];
+
+ callJS = function (functionName, argv) {
+ // This assumes that there's a single gadget in the frame.
+ var $v = ___.getNewModuleHandler().getImports().$v;
+ return $v.cf($v.ro(functionName), argv);
+ };
+
+ onFlashBridgeReady = function () {
+ var len = bridge___.channels.length;
+ for(var i = 0; i < len; ++i) {
+ bridge___.registerChannel(bridge___.channels[i]);
+ }
+ delete bridge___.channels;
+ var outers = ___.getNewModuleHandler().getImports().$v.getOuters();
+ if (outers.onFlashBridgeReady) {
+ callJS("onFlashBridgeReady", []);
+ }
+ };
+
return ___.frozenFunc(function tamedEmbedFlash(
swfUrl,
swfContainer,
@@ -122,40 +159,4 @@
});
});
})());
-
- var d = document.createElement('div');
- d.appendChild(document.createTextNode("bridge"));
- document.body.appendChild(d);
-
- gadgets.flash.embedFlash(
- "/gadgets/files/container/Bridge.swf",
- d,
- 10,
- {
- allowNetworking: "always",
- allowScriptAccess: "all",
- width: 0,
- height: 0,
- flashvars: "logging=true"
- });
- bridge___ = d.childNodes[0];
- bridge___.channels = [];
-
- callJS = function (functionName, argv) {
- // This assumes that there's a single gadget in the frame.
- var $v = ___.getNewModuleHandler().getImports().$v;
- return $v.cf($v.ro(functionName), [argv]);
- };
-
- onFlashBridgeReady = function () {
- var len = bridge___.channels.length;
- for(var i = 0; i < len; ++i) {
- bridge___.registerChannel(bridge___.channels[i]);
- }
- delete bridge___.channels;
- var outers = ___.getNewModuleHandler().getImports().$v.getOuters();
- if (outers.onFlashBridgeReady) {
- callJS("onFlashBridgeReady");
- }
- };
});
Added:
incubator/shindig/trunk/javascript/samplecontainer/examples/FlashBridgeCajaExample.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/examples/FlashBridgeCajaExample.xml?rev=903332&view=auto
==============================================================================
---
incubator/shindig/trunk/javascript/samplecontainer/examples/FlashBridgeCajaExample.xml
(added)
+++
incubator/shindig/trunk/javascript/samplecontainer/examples/FlashBridgeCajaExample.xml
Tue Jan 26 17:30:34 2010
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+ <ModulePrefs title="Flash Caja Demo"
+ height="200"
+ description="Demonstrates the use of caja to protect flash gadgets and
the flash bridge">
+ <Require feature="caja"></Require>
+ <Require feature="flash"></Require>
+ <Require feature="dynamic-height"></Require>
+ </ModulePrefs>
+ <Content type="html">
+ <![CDATA[
+ Caja does not allow <code>object</code> or <code>embed</code> tags
+ in HTML. However, Shindig provides a tamed JavaScript API for
+ embedding flash on a page. To embed a flash file, use
+ <code>Require feature="flash"</code> in your
+ ModulePrefs and <code>gadges.flash.embedFlash</code> in the body of
+ your gadget to embed flash.
+ <p>
+ This example illustrates the use of the flash bridge for enabling
+ communication between the sandboxed flash and the cajoled gadget.
+ <p>
+ The sources for this example are on the <a
href="http://code.google.com/p/google-caja/downloads/list">Caja downloads
page</a>:
+ <a href="http://google-caja.googlecode.com/files/Boxed.as">Boxed.as</a>,
+ <a href="http://google-caja.googlecode.com/files/Boxed.fla">Boxed.fla</a>
+ <div id="flashcontainer" style="width:200; height: 200">
+ You need Flash player 10 and JavaScript enabled to view this video.
+ </div>
+ <button id="btn" onclick='bridge.callSWF("mySWFMethod", [5,6,7]);'
disabled>mySWFMethod(5,6,7)</button>
+ <div id="result"></div>
+
+ <script>
+ var bridge;
+ function onFlashBridgeReady() {
+ bridge = gadgets.flash.embedFlash(
+ "http://caja.appspot.com/Boxed.swf",
+ "flashcontainer",
+ 10);
+ document.getElementById('btn').disabled = false;
+ gadgets.window.adjustHeight();
+ }
+
+ function myJSMethod(x, y, z) {
+ document.getElementById("result").innerHTML +=
"myJSMethod("+[x,y,z]+")<br>";
+ gadgets.window.adjustHeight();
+ }
+ gadgets.window.adjustHeight();
+ </script>
+ ]]>
+ </Content>
+</Module>