Reviewers: jasvir, dev_shindig.apache.org,

Description:
This change introduces the feature caja-debug which is loaded by
CajaContentRewriter if debug mode is enabled.

Make CajaContentRewriter#cajaEnabled protected since subclasses may have
different requirements for enabling/disabling caja.

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

Affected files:
  features/src/main/javascript/features/caja-debug/feature.xml
  features/src/main/javascript/features/features.txt
java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java


Index: features/src/main/javascript/features/caja-debug/feature.xml
===================================================================
--- features/src/main/javascript/features/caja-debug/feature.xml (revision 995883) +++ features/src/main/javascript/features/caja-debug/feature.xml (working copy)
@@ -19,11 +19,8 @@
 The javascript referenced here should be found in the caja jar.
 -->
 <feature>
-  <name>caja</name>
+  <name>caja-debug</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="taming.js"/>
+    <script src="res://com/google/caja/cajita-debugmode.js"/>
   </gadget>
 </feature>
Index: features/src/main/javascript/features/features.txt
===================================================================
--- features/src/main/javascript/features/features.txt  (revision 995883)
+++ features/src/main/javascript/features/features.txt  (working copy)
@@ -22,6 +22,7 @@
 features/analytics/feature.xml
 features/auth-refresh/feature.xml
 features/caja/feature.xml
+features/caja-debug/feature.xml
 features/container/feature.xml
 features/content-rewrite/feature.xml
 features/core.config/feature.xml
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 995883) +++ java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/CajaContentRewriter.java (working copy)
@@ -27,6 +27,7 @@
 import com.google.caja.parser.html.Dom;
 import com.google.caja.parser.html.Namespaces;
 import com.google.caja.parser.js.CajoledModule;
+import com.google.caja.plugin.PipelineMaker;
 import com.google.caja.plugin.PluginCompiler;
 import com.google.caja.plugin.PluginMeta;
 import com.google.caja.plugin.UriFetcher;
@@ -124,17 +125,13 @@

       compiler.setMessageContext(context);

-      /**
-       * TODO(jasvir): This can provide support for debugging with
-       * cajita-debugmode.js but cajita-debugmode.js should be loaded
-       * iff url param debug=1
-       *
-       *      if (debug) {
-       *        compiler.setGoals(compiler.getGoals()
-       *            .without(PipelineMaker.ONE_CAJOLED_MODULE)
-       *            .with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG));
-       *      }
-       */
+      if (debug) {
+        // This will load cajita-debugmode.js
+        gadget.addFeature("caja-debug");
+        compiler.setGoals(compiler.getGoals()
+                .without(PipelineMaker.ONE_CAJOLED_MODULE)
+                .with(PipelineMaker.ONE_CAJOLED_MODULE_DEBUG));
+      }

       InputSource is = new InputSource(javaGadgetUri);
       boolean safe = false;
@@ -180,7 +177,7 @@
         if (cajoledCache != null && !debug) {
           cajoledCache.addElement(cacheKey, cajoledOutput);
         }
-        safe = true;
+
         cajoledData = cajoledOutput;
         createContainerFor(doc, cajoledData);
         mc.documentChanged();
@@ -203,7 +200,7 @@
     }
   }

-  private boolean cajaEnabled(Gadget gadget) {
+  protected boolean cajaEnabled(Gadget gadget) {
     return (gadget.getAllFeatures().contains("caja") ||
         "1".equals(gadget.getContext().getParameter("caja")));
   }


Reply via email to