Reviewers: felix8a, ihab.awad,

Description:
* upgrade the version of Caja
* switch from cajita/valija to ES53

This change does not support taming of features.

Please review this at http://codereview.appspot.com/4303043/

Affected files:
  M     features/src/main/javascript/features/caja-debug/feature.xml
  D     features/src/main/javascript/features/caja/caja.js
  M     features/src/main/javascript/features/caja/feature.xml
  M     features/src/main/javascript/features/caja/taming.js
M java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java M java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/CajaContentRewriterTest.java
  M     pom.xml


Index: java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/CajaContentRewriterTest.java
===================================================================
--- java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/CajaContentRewriterTest.java (revision 1004342) +++ java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/CajaContentRewriterTest.java (working copy)
@@ -120,11 +120,11 @@
+ "<div classes=\"g___\" id=\"cajoled-output\" style=\"position: relative;\">"
         + "<script type=\"text/javascript\">caja___.enable()</script>"
+ "<script type=\"text/javascript\">{___.loadModule({'instantiate':function(___,IMPORTS___){" - + "return ___.prepareModule({'instantiate':function(___,IMPORTS___){var\n$v=___.readImport(" - + "IMPORTS___,'$v',{'getOuters':{'()':{}},'initOuter':{'()':{}},'so':{'()':{}},'ro':{'()':{" - + "}}});var\nmoduleResult___,$dis;moduleResult___=___.NO_RESULT;$dis=$v.getOuters();" - + "$v.initOuter('onerror');try{{moduleResult___=$v.so('a',0)}}catch(ex___){" - + "___.getNewModuleHandler().handleUncaughtException(ex___,$v.ro('onerror'),'unknown','1')}" + + "return ___.prepareModule({'instantiate':function(___,IMPORTS___){var\n" + + "dis___=IMPORTS___;var moduleResult___;moduleResult___=___.NO_RESULT;"
+        + "try{{moduleResult___=IMPORTS___.w___('a',0)}}"
+ + "catch(ex___){___.getNewModuleHandler().handleUncaughtException(ex___," + + "IMPORTS___.onerror_v___?IMPORTS___.onerror:___.ri(IMPORTS___,'onerror'),'unknown','1')}"
         + "return moduleResult___}";

     List<String> messages = ImmutableList.of(
Index: java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java
===================================================================
--- java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java (revision 1004342) +++ java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java (working copy)
@@ -122,6 +122,7 @@
       MessageQueue mq = new SimpleMessageQueue();
       MessageContext context = new MessageContext();
       PluginMeta meta = new PluginMeta(fetcher, policy);
+      meta.setEnableES53(true);
       PluginCompiler compiler = makePluginCompiler(meta, mq);

       compiler.setMessageContext(context);
Index: pom.xml
===================================================================
--- pom.xml     (revision 1004342)
+++ pom.xml     (working copy)
@@ -1490,7 +1490,7 @@
      <dependency>
        <groupId>caja</groupId>
        <artifactId>caja</artifactId>
-       <version>r4291</version>
+       <version>r4391</version>
        <scope>compile</scope>
        <exclusions>
          <!-- force use of xml-apis until caja fixes their pom -->
Index: features/src/main/javascript/features/caja-debug/feature.xml
===================================================================
--- features/src/main/javascript/features/caja-debug/feature.xml (revision 1004342) +++ features/src/main/javascript/features/caja-debug/feature.xml (working copy)
@@ -22,6 +22,7 @@
   <name>caja-debug</name>
   <dependency>caja</dependency>
   <gadget>
-    <script src="res://com/google/caja/cajita-debugmode.js"/>
+    <!-- debugging unsupported in this version -->
+    <!-- <script src="res://com/google/caja/cajita-debugmode.js"/> -->
   </gadget>
 </feature>
Index: features/src/main/javascript/features/caja/caja.js
===================================================================
--- features/src/main/javascript/features/caja/caja.js  (revision 1004342)
+++ features/src/main/javascript/features/caja/caja.js  (working copy)
@@ -1,36 +0,0 @@
-/*
- * 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.
- */
-
-var valijaMaker = undefined;
-
-(function() {
-  var imports = ___.copy(___.sharedImports);
-  imports.loader = {
-    provide: ___.func(function(v) { valijaMaker = v; })
-  };
-  ___.grantRead(imports, 'loader');
-  ___.getNewModuleHandler().setImports(imports);
-  ___.getNewModuleHandler().handleUncaughtException = function(e) {
-    throw e;
-  };
-})();
Index: features/src/main/javascript/features/caja/feature.xml
===================================================================
--- features/src/main/javascript/features/caja/feature.xml (revision 1004342)
+++ features/src/main/javascript/features/caja/feature.xml      (working copy)
@@ -21,9 +21,7 @@
 <feature>
   <name>caja</name>
   <gadget>
-    <script src="res://com/google/caja/plugin/domita-minified.js"/>
-    <script src="caja.js"/>
-    <script src="res://com/google/caja/plugin/valija.out.js"/>
+    <script src="res://com/google/caja/plugin/domita-es53-minified.js"/>
     <script src="taming.js"/>
   </gadget>
 </feature>
Index: features/src/main/javascript/features/caja/taming.js
===================================================================
--- features/src/main/javascript/features/caja/taming.js        (revision 
1004342)
+++ features/src/main/javascript/features/caja/taming.js        (working copy)
@@ -62,7 +62,7 @@
     for (var i = 0; i < length; i++) {
       var schema = schemas[i];
       if (typeof schema[0][schema[1]] === 'function') {
-        ___.markInnocent(schema[0][schema[1]], schema[1]);
+        ___.markFunc(schema[0][schema[1]], schema[1]);
       } else {
gadgets.warn('Error taming function: ' + schema[0] + '.' + schema[1]);
       }
@@ -73,7 +73,7 @@
     for (var i = 0; i < length; i++) {
       var schema = schemas[i];
       if (typeof schema[0].prototype[schema[1]] == 'function') {
-        ___.grantInnocentMethod(schema[0].prototype, schema[1]);
+        ___.markTameAsXo4a(schema[0].prototype[schema[1]]);
       } else {
gadgets.warn('Error taming method: ' + schema[0] + '.' + schema[1]);
       }
@@ -81,7 +81,7 @@
   }

   function enable() {
-    var imports = ___.copy(___.sharedImports);
+    var imports = {};
     imports.outers = imports;

     var gadgetRoot = document.getElementById('cajoled-output');
@@ -89,18 +89,26 @@
     document.body.appendChild(gadgetRoot);

     imports.htmlEmitter___ = new HtmlEmitter(gadgetRoot);
+    imports.onerror = ___.markFunc(function(x){
+        gadgets.warn(x);
+        return true;
+    });
+    ___.setLogFunc(imports.onerror);
+
     attachDocumentStub('-g___', uriCallback, imports, gadgetRoot);

-    imports.$v = valijaMaker.CALL___(imports.outers);
+    imports.window = imports.window || {};
+    // Use these imports
+    for (i in imports) {
+      imports.window[i] = imports[i];
+    }
+    imports = imports.window;
+    imports.domitaTrace___ = 1;
+    imports.handleSet___ = void 0;

-    ___.getNewModuleHandler().setImports(imports);
-
-    fire(imports);
-
-    imports.outers.gadgets = ___.tame(window.gadgets);
-    imports.outers.opensocial = ___.tame(window.opensocial);
-    ___.grantRead(imports.outers, 'gadgets');
-    ___.grantRead(imports.outers, 'opensocial');
+    // TODO(jasvir): Support tamed features
+    // fire(imports);
+    ___.getNewModuleHandler().setImports(___.whitelistAll(imports));
   }
   return {
     enable: enable,
@@ -108,11 +116,4 @@
     whitelistFuncs: whitelistFuncs,
     whitelistMeths: whitelistMeths
   };
-})();
-
-// Expose alert and console.log to cajoled programs
-var tamings___ = tamings___ || [];
-tamings___.push(function(imports) {
-  imports.outers.alert = function(msg) { alert(msg); };
-  ___.grantFunc(imports.outers, 'alert');
-});
+})();
\ No newline at end of file


Reply via email to