Package com.google.caja.parser

Examples of com.google.caja.parser.Visitor


  public static List<String> rewrite(CssTree.StyleSheet styleSheet, final Uri source,
      final UriMaker uriMaker, final boolean extractImports, final GadgetContext gadgetContext) {
    final List<String> imports = Lists.newLinkedList();
    final List<CssTree.UriLiteral> skip = Lists.newLinkedList();

    styleSheet.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        if (chain.node instanceof CssTree.Import) {
          CssTree.Import importNode = (CssTree.Import) chain.node;
          CssTree.UriLiteral uriLiteral = importNode.getUri();
          skip.add(importNode.getUri());
View Full Code Here


   * @param importRewriter to rewrite links to sanitizing proxy
   * @param imageRewriter to rewrite links to the sanitizing proxy
   */
  public void sanitize(CssTree css, final Uri linkContext, final GadgetContext gadgetContext,
                       final ProxyUriManager importRewriter, final ProxyUriManager imageRewriter) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (ancestorChain.node instanceof CssTree.Property) {
          if (!schema.isPropertyAllowed(((CssTree.Property) ancestorChain.node).
              getPropertyName())) {
            // Remove offending property
View Full Code Here

  /**
   * Get all descendants of the passed node with the specified node type
   */
  public static <T extends CssTree> List<T> descendants(CssTree node, final Class<T> nodeType) {
    final List<T> descendants = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (nodeType.isAssignableFrom(ancestorChain.node.getClass())) {
          descendants.add(nodeType.cast(ancestorChain.node));
        }
        return true;
View Full Code Here

  /**
   * Get all descendants of the passed node with the specified node type
   */
  public static <T extends CssTree> List<T> descendants(CssTree node, final Class<T> nodeType) {
    final List<T> descendants = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (nodeType.isAssignableFrom(ancestorChain.node.getClass())) {
          descendants.add(nodeType.cast(ancestorChain.node));
        }
        return true;
View Full Code Here

   * @param importRewriter to rewrite links to sanitizing proxy
   * @param imageRewriter to rewrite links to the sanitizing proxy
   */
  public void sanitize(CssTree css, final Uri linkContext, final GadgetContext gadgetContext,
                       final ProxyUriManager importRewriter, final ProxyUriManager imageRewriter) {
    css.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (ancestorChain.node instanceof CssTree.Property) {
          if (!schema.isPropertyAllowed(((CssTree.Property) ancestorChain.node).
              getPropertyName())) {
            // Remove offending property
View Full Code Here

  /**
   * Get all descendants of the passed node with the specified node type
   */
  public static <T extends CssTree> List<T> descendants(CssTree node, final Class<T> nodeType) {
    final List<T> descendants = Lists.newArrayList();
    node.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> ancestorChain) {
        if (nodeType.isAssignableFrom(ancestorChain.node.getClass())) {
          descendants.add(nodeType.cast(ancestorChain.node));
        }
        return true;
View Full Code Here

  public static List<String> rewrite(CssTree.StyleSheet styleSheet, final Uri source,
      final UriMaker uriMaker, final boolean extractImports, final GadgetContext gadgetContext) {
    final List<String> imports = Lists.newLinkedList();
    final List<CssTree.UriLiteral> skip = Lists.newLinkedList();

    styleSheet.acceptPreOrder(new Visitor() {
      public boolean visit(AncestorChain<?> chain) {
        if (chain.node instanceof CssTree.Import) {
          CssTree.Import importNode = (CssTree.Import) chain.node;
          CssTree.UriLiteral uriLiteral = importNode.getUri();
          skip.add(importNode.getUri());
View Full Code Here

   * <p>We do this to ensure the most predictable possible browser behavior
   * around this sensitive and exploitable issue.
   */
  private void rewriteHistorySensitiveRulesets(
      final AncestorChain<? extends CssTree> t) {
    t.node.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          if (!(ancestors.node instanceof CssTree.RuleSet)) { return true; }
          Pair<CssTree.RuleSet, CssTree.RuleSet> rewritten =
              rewriteHistorySensitiveRuleset((CssTree.RuleSet) ancestors.node);
          if (rewritten != null) {
View Full Code Here

  }

  /** Get rid of rules like <code>p { }</code>. */
  private void removeEmptyDeclarationsAndSelectors(
      AncestorChain<? extends CssTree> t) {
    t.node.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode node = ancestors.node;
          if (node instanceof CssTree.EmptyDeclaration) {
            ParseTreeNode parent = ancestors.getParentNode();
            if (parent instanceof MutableParseTreeNode) {
View Full Code Here

          return true;
        }
      }, t.parent);
  }
  private void removeEmptyRuleSets(AncestorChain<? extends CssTree> t) {
    t.node.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode node = ancestors.node;
          if (!(node instanceof CssTree.RuleSet)) { return true; }
          CssTree.RuleSet rset = (CssTree.RuleSet) node;
          List<? extends CssTree> children = rset.children();
View Full Code Here

TOP

Related Classes of com.google.caja.parser.Visitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.