Author: etnu
Date: Mon Dec 8 13:32:27 2008
New Revision: 724493
URL: http://svn.apache.org/viewvc?rev=724493&view=rev
Log:
Applied patch to upgrade caja integration from Jasvir Nagra in SHINDIG-654.
Added:
incubator/shindig/trunk/features/caja/caja.js
incubator/shindig/trunk/java/server/src/test/resources/endtoend/cajaTest.xml
incubator/shindig/trunk/javascript/samplecontainer/examples/SocialCajaWorld.xml
Modified:
incubator/shindig/trunk/features/caja/feature.xml
incubator/shindig/trunk/features/opensocial-current/feature.xml
incubator/shindig/trunk/features/opensocial-reference/container.js
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
Added: incubator/shindig/trunk/features/caja/caja.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/caja/caja.js?rev=724493&view=auto
==============================================================================
--- incubator/shindig/trunk/features/caja/caja.js (added)
+++ incubator/shindig/trunk/features/caja/caja.js Mon Dec 8 13:32:27 2008
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+/**
+ * @fileoverview Caja is a whitelisting javascript sanitizing
+ * rewriter. This file sets up the container and allows a gadget to
+ * access console logging functions.
+ */
+
+var valijaMaker = undefined;
+
+(function(){
+ var imports = ___.copy(___.sharedImports);
+ imports.loader = {
+ provide: ___.func(function(v) { valijaMaker = v; })
+ };
+ ___.grantRead(imports, 'loader');
+ ___.grantCall(imports.loader, 'provide');
+ ___.getNewModuleHandler().setImports(imports);
+ ___.getNewModuleHandler().handleUncaughtException = function(e) {
+ throw e;
+ };
+ })();
+
+(function () {
+ ___.sharedImports.console = {};
+ for (var k in { log: 0, warn: 0, info: 0, error: 0, trace: 0,
+ group: 0, groupEnd: 0, time: 0, timeEnd: 0, dir: 0,
+ assert: 0, dirxml: 0, profile: 0, profileEnd: 0 }) {
+ ___.sharedImports.console[k] = (function (k, f) {
+ return ___.func(function () { f.apply(console, arguments); });
+ })(k, console[k]);
+ }
+})();
Modified: incubator/shindig/trunk/features/caja/feature.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/caja/feature.xml?rev=724493&r1=724492&r2=724493&view=diff
==============================================================================
--- incubator/shindig/trunk/features/caja/feature.xml (original)
+++ incubator/shindig/trunk/features/caja/feature.xml Mon Dec 8 13:32:27 2008
@@ -22,5 +22,7 @@
<name>caja</name>
<gadget>
<script src="res://com/google/caja/plugin/domita-minified.js"></script>
+ <script src="caja.js"></script>
+ <script src="res://com/google/caja/plugin/valija.co.js"></script>
</gadget>
</feature>
Modified: incubator/shindig/trunk/features/opensocial-current/feature.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/feature.xml?rev=724493&r1=724492&r2=724493&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/feature.xml (original)
+++ incubator/shindig/trunk/features/opensocial-current/feature.xml Mon Dec 8
13:32:27 2008
@@ -55,10 +55,6 @@
}
opensocial.Container.setContainer(new ShindigContainer());
-
- if (configParams.enableCaja) {
- opensocial.Container.get().enableCaja();
- }
});
</script>
</gadget>
Modified: incubator/shindig/trunk/features/opensocial-reference/container.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-reference/container.js?rev=724493&r1=724492&r2=724493&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-reference/container.js
(original)
+++ incubator/shindig/trunk/features/opensocial-reference/container.js Mon Dec
8 13:32:27 2008
@@ -550,7 +550,7 @@
var imports = ___.copy(___.sharedImports);
imports.outers = imports;
imports.console = console;
- imports.$v = ___.asSimpleFunc(valijaMaker)(imports);
+ imports.$v = ___.asFunc(valijaMaker)(imports);
___.getNewModuleHandler().setImports(imports);
@@ -1075,20 +1075,20 @@
var type = m[1], name = m[2];
switch (type) {
case 'c':
- ___.allowRead(obj, name);
+ ___.grantRead(obj, name);
whitelist(schema[k], obj[name]);
break;
case 'm':
- ___.allowCall(obj.prototype, name);
+ ___.grantCall(obj.prototype, name);
break;
case 'f':
- ___.allowRead(obj.prototype, name);
+ ___.grantRead(obj.prototype, name);
break;
case 's':
if ('function' === typeof obj[name]) {
- ___.allowCall(obj, name);
+ ___.grantCall(obj, name);
} else {
- ___.allowRead(obj, name);
+ ___.grantRead(obj, name);
}
break;
}
Modified:
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java?rev=724493&r1=724492&r2=724493&view=diff
==============================================================================
---
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java
(original)
+++
incubator/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java
Mon Dec 8 13:32:27 2008
@@ -99,11 +99,17 @@
throwCajolingException(e, mq);
return RewriterResults.notCacheable();
}
- content.setContent(output.toString());
+ content.setContent(tameCajaClientApi() + output.toString());
}
return null;
}
+ private String tameCajaClientApi() {
+ return "<script>" +
+ "opensocial.Container.get().enableCaja();" +
+ "</script>";
+ }
+
private void throwCajolingException(Exception cause, MessageQueue mq) {
StringBuilder errbuilder = new StringBuilder();
MessageContext mc = new MessageContext();
Modified:
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java?rev=724493&r1=724492&r2=724493&view=diff
==============================================================================
---
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
(original)
+++
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
Mon Dec 8 13:32:27 2008
@@ -52,6 +52,7 @@
"fetchPersonTest.xml",
"fetchPeopleTest.xml",
"errorTest.xml",
+ "cajaTest.xml",
"testframework.js"
};
Added:
incubator/shindig/trunk/java/server/src/test/resources/endtoend/cajaTest.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/cajaTest.xml?rev=724493&view=auto
==============================================================================
---
incubator/shindig/trunk/java/server/src/test/resources/endtoend/cajaTest.xml
(added)
+++
incubator/shindig/trunk/java/server/src/test/resources/endtoend/cajaTest.xml
Mon Dec 8 13:32:27 2008
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<Module>
+ <ModulePrefs title="EndToEndTest">
+ <Require feature="caja" />
+ <Require feature="opensocial-0.8" />
+ </ModulePrefs>
+ <Content type="html">
+ <![CDATA[
+ <script type="text/javascript" src="/testframework.js"></script>
+ <script type="text/javascript">
+ var tests = {
+ simpleTest: function() {
+ assertTrue("Basic cajoling failing", true);
+ finished();
+ },
+
+ domitaTest: function() {
+ var elDiv = document.createElement('div');
+ elDiv.setAttribute('id', 'elDiv');
+ elDiv.innerHTML = "hello world";
+ document.appendChild(elDiv);
+ assertEquals(document.getElementById('elDiv').innerHTML, "hello
world");
+ finished();
+ }
+ };
+ </script>
+ ]]>
+ </Content>
+</Module>
Added:
incubator/shindig/trunk/javascript/samplecontainer/examples/SocialCajaWorld.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/samplecontainer/examples/SocialCajaWorld.xml?rev=724493&view=auto
==============================================================================
---
incubator/shindig/trunk/javascript/samplecontainer/examples/SocialCajaWorld.xml
(added)
+++
incubator/shindig/trunk/javascript/samplecontainer/examples/SocialCajaWorld.xml
Mon Dec 8 13:32:27 2008
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Module>
+ <ModulePrefs title="Social Hello World">
+ <Require feature="opensocial-0.8"></Require>
+ <Require feature="caja"></Require>
+ <Require feature="dynamic-height"></Require>
+ </ModulePrefs>
+ <Content type="html">
+ <![CDATA[
+ <style type="text/css">
+ #helloworlds {
+ margin: 20px;
+ font-family: arial, sans-serif;
+ width: 310px;
+ }
+
+ div.person img {
+ margin-bottom: 10px;
+ }
+
+ div.bubble {
+ background-image:
url(/gadgets/files/samplecontainer/examples/bubble.gif);
+ background-repeat: no-repeat;
+ width: 202px;
+ height: 66px;
+ padding: 12px 0px 0px 12px;
+ font-weight: bold;
+ font-size: 18px;
+ float: right;
+ }
+
+ .c0 { color: #008000; }
+ .c1 { color: #FF8A00; }
+ .c2 { color: #7777CC; }
+ .c3 { color: #008000; }
+ .c4 { color: #CC0000; }
+ .c5 { color: #73A6FF; }
+
+ div.name {
+ width: 150px;
+ text-align: right;
+ font-weight: normal;
+ font-size: 12px;
+ color: #999;
+ position:relative;
+ top: 10px;
+ right: -35px;
+ }
+ </style>
+
+ <script type="text/javascript">
+ var hellos = new Array('Hello World', 'Hallo Welt', 'Ciao a tutti', 'Hola
mundo',
+ 'Появление
на свет',
'こんにちは世界',
'你好世界', '여러분,
안녕하세요');
+ var numberOfStyles = 6;
+ var viewerCount;
+
+ var allPeople, viewerFriendData;
+ function render(data) {
+ var viewer = data.get('viewer').getData();
+ allPeople = data.get('viewerFriends').getData().asArray() || new
Array();
+ if (viewer) {
+ allPeople.push(viewer);
+ }
+
+ var viewerData = data.get('viewerData').getData() || {};
+ viewerCount = getCount(viewerData[viewer.getId()]);
+
+ viewerFriendData = data.get('viewerFriendData').getData() || {};
+ viewerFriendData[viewer.getId()] = viewerData[viewer.getId()];
+
+ var html = '';
+ for (var i = 0; i < allPeople.length; i++) {
+ var count = getCount(viewerFriendData[allPeople[i].getId()]);
+ if (count == 0) {
+ //continue;
+ }
+
+ html += '<div class="person">';
+ html += '<div class="bubble c' + count % numberOfStyles + '">' +
hellos[count % hellos.length];
+ html += '<div class="name">' + allPeople[i].getDisplayName() + ' (' +
count + ') ' +
allPeople[i].getField(opensocial.Person.Field.GENDER).getDisplayValue();
+ html += '</div></div>';
+
+ if (allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL)
+ &&
allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL).indexOf('null') ==
-1) {
+ html += '<img src="' +
allPeople[i].getField(opensocial.Person.Field.THUMBNAIL_URL) + '"/>';
+ } else {
+ html += '<img
src="/gadgets/files/samplecontainer/examples/nophoto.gif"/>';
+ }
+ html += '<br style="clear:both"></div>';
+ }
+ document.getElementById('helloworlds').innerHTML = html;
+
+ gadgets.window.adjustHeight();
+ }
+
+ function getCount(data) {
+ return data && data['count'] ? Number(data['count']) : 0;
+ }
+
+ function sayHelloWorld() {
+ viewerCount++;
+ var req = opensocial.newDataRequest();
+ req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'count',
viewerCount), 'updateData');
+ req.send(initData);
+ }
+
+
+ var opts = {};
+ opts[opensocial.DataRequest.PeopleRequestFields.FIRST] = 0;
+ opts[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
+ opts[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
+ [opensocial.Person.Field.AGE,
+ opensocial.Person.Field.NAME,
+ opensocial.Person.Field.GENDER,
+ opensocial.Person.Field.PROFILE_URL,
+ opensocial.Person.Field.THUMBNAIL_URL,
+ opensocial.Person.Field.STATUS];
+ opts[opensocial.DataRequest.PeopleRequestFields.SORT_ORDER] =
opensocial.DataRequest.SortOrder.NAME;
+
+
+
+ function initData() {
+ var req = opensocial.newDataRequest();
+ req.add(req.newFetchPersonRequest('VIEWER', opts), 'viewer');
+ req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS', opts),
'viewerFriends');
+ req.add(req.newFetchPersonAppDataRequest('VIEWER', 'count'),
'viewerData');
+ req.add(req.newFetchPersonAppDataRequest('VIEWER_FRIENDS', 'count'),
'viewerFriendData');
+ req.send(render);
+ }
+
+ gadgets.util.registerOnLoadHandler(initData);
+ </script>
+
+ <div style="margin-bottom: 1em">
+ <input type="button" value="Say hello" onclick="sayHelloWorld(); return
false;"/>
+ </div>
+ <div id="helloworlds" style="margin: 4px">
+ </div>
+ ]]>
+ </Content>
+</Module>