Examples of CssTree


Examples of com.google.caja.parser.css.CssTree

    if (!(mediaTypes.isEmpty() || mediaTypes.contains(Name.css("all")))) {
      final List<CssTree.RuleSet> rules = Lists.newArrayList();
      stylesheet.acceptPreOrder(
          new Visitor() {
            public boolean visit(AncestorChain<?> ancestors) {
              CssTree node = (CssTree) ancestors.node;
              if (node instanceof CssTree.StyleSheet) { return true; }
              if (node instanceof CssTree.RuleSet) {
                rules.add((CssTree.RuleSet) node);
                ((MutableParseTreeNode) ancestors.parent.node)
                    .removeChild(node);
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

    CssTree.Combination c = (CssTree.Combination) children.get(1);
    if (c.getCombinator() == Combinator.SIBLING) { return 0; }
    CssTree.SimpleSelector ss = (CssTree.SimpleSelector) children.get(0);
    List<? extends CssTree> ssParts = ss.children();
    if (ssParts.isEmpty()) { return 0; }
    CssTree ssPart0 = ssParts.get(0);
    if (!(ssPart0 instanceof CssTree.IdentLiteral
          && "body".equals(ssPart0.getValue()))) {
      return 0;
    }
    return 2;
  }
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

    return false;
  }

  private void skipBlank(Candidate candidate) {
    // Skip over any blank operators
    CssTree child = expr.children().get(candidate.exprIdx);
    if (child instanceof CssTree.Operation
        && (CssTree.Operator.NONE
            == ((CssTree.Operation) child).getOperator())) {
      ++candidate.exprIdx;
    }
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

      CssTree.StyleSheet ss, Set<Name> mediaTypes) {
    MutableParseTreeNode.Mutation mut = ss.createMutation();
    int nonMedia = 0;
    int n = ss.children().size();
    for (int i = 0; i < n; ++i) {
      CssTree child = ss.children().get(i);
      if (child instanceof CssTree.Media) {
        CssTree.Media media = (CssTree.Media) child;
        // Take a chunk and of non @media blocks and put them in an @media block
        wrapInMediaBlock(ss.children().subList(nonMedia, i), mediaTypes, mut);
        nonMedia = i + 1;
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

          CssTree.SuffixedSelectorPart ssp
              = (CssTree.SuffixedSelectorPart) node;
          MutableParseTreeNode parent = ancestors.parent.cast(
              MutableParseTreeNode.class)
              .node;
          CssTree replacement;
          if (gadgetNameSuffix == null) {
            replacement = new SuffixedClassOrIdLiteral(
                ssp.getFilePosition(),
                ssp.typePrefix() + ssp.suffixedIdentifier(""));
          } else {
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

    ss.acceptPreOrder(new Visitor() {
          public boolean visit(AncestorChain<?> ancestors) {
            ParseTreeNode node = ancestors.node;
            if (node instanceof UnsafeUriLiteral) {
              UnsafeUriLiteral uul = (UnsafeUriLiteral) node;
              CssTree parent = (CssTree) ancestors.parent.node;
              assert(null != parent);
              AncestorChain<?> prop = ancestors;
              while (null != prop &&
                     !(prop.node instanceof CssTree.PropertyDeclaration)) {
                prop = prop.parent;
              }
              assert(null != prop);
              parent.replaceChild(
                  new JsExpressionUriLiteral(
                      uul.getFilePosition(),
                      (Expression) QuasiBuilder.substV(
                          "IMPORTS___./*@synthetic*/rewriteUriInCss___(@u, @p)",
                          "u", StringLiteral.valueOf(
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

   */
  private boolean vetLinkToHistorySensitiveSimpleSelector(
      CssTree.SimpleSelector selector) {
    if (selector.children().isEmpty()) { return false; }
    if (!containsLinkPseudoClass(selector)) { return false; }
    CssTree firstChild = selector.children().get(0);
    if (firstChild instanceof CssTree.WildcardElement) {
      // "*#foo:visited" --> "a#foo:visited"
      selector.replaceChild(
          new CssTree.IdentLiteral(
              firstChild.getFilePosition(), HTML_ANCHOR.toString()),
          firstChild);
      return true;
    } else if (firstChild instanceof CssTree.IdentLiteral) {
      // "a#foo:visited" is legal; "p#foo:visited" is not
      String value = ((CssTree.IdentLiteral) firstChild).getValue();
      if (!HTML_ANCHOR.equals(
              ElKey.forElement(Namespaces.HTML_DEFAULT, value))) {
        mq.addMessage(
            PluginMessageType.CSS_LINK_PSEUDO_SELECTOR_NOT_ALLOWED_ON_NONANCHOR,
            firstChild.getFilePosition());
      }
      return false;
    } else {
      // "#foo:visited" --> "a#foo:visited"
      selector.insertBefore(
          new CssTree.IdentLiteral(
              firstChild.getFilePosition(), HTML_ANCHOR.toString()),
          firstChild);
      return true;
    }
  }
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

  private boolean containsLinkPseudoClass(CssTree.SimpleSelector selector) {
    final boolean[] result = new boolean[1];
    selector.visitPreOrder(new ParseTreeNodeVisitor() {
      public boolean visit(ParseTreeNode node) {
        if (node instanceof CssTree.Pseudo) {
          CssTree firstChild = (CssTree) node.children().get(0);
          if (firstChild instanceof CssTree.IdentLiteral) {
            CssTree.IdentLiteral ident = (CssTree.IdentLiteral) firstChild;
            if (LINK_PSEUDO_CLASSES.contains(Name.css(ident.getValue()))) {
              result[0] = true;
              return false;
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

        // Use the start position of the base selector as the position of
        // the synthetic parts.
        FilePosition pos = FilePosition.endOf(
            baseSelector.getFilePosition());

        CssTree restrictClass = new CssTree.SuffixedSelectorPart(pos);

        if (baseIsDescendant) {
          CssTree.Combination op = new CssTree.Combination(
              pos, CssTree.Combinator.DESCENDANT);
          CssTree.SimpleSelector restrictSel = new CssTree.SimpleSelector(
View Full Code Here

Examples of com.google.caja.parser.css.CssTree

    t.node.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode node = ancestors.node;
          if (node instanceof CssTree.Pseudo) {
            boolean remove = false;
            CssTree child = ((CssTree.Pseudo) node).children().get(0);
            if (child instanceof CssTree.IdentLiteral) {
              Name pseudoName = Name.css(
                  ((CssTree.IdentLiteral) child).getValue());
              if (!ALLOWED_PSEUDO_CLASSES.contains(pseudoName)) {
                // Allow the visited pseudo selector but not with any styles
                // that can be fetched via getComputedStyle in DOMita's
                // COMPUTED_STYLE_WHITELIST.
                if (!(LINK_PSEUDO_CLASSES.contains(pseudoName)
                      && strippedPropertiesBannedInLinkClasses(
                          ancestors.parent.parent.cast(CssTree.Selector.class)
                          ))) {
                  mq.addMessage(PluginMessageType.UNSAFE_CSS_PSEUDO_SELECTOR,
                                invalidNodeMessageLevel, node.getFilePosition(),
                                node);
                  remove = true;
                }
              }
            } else {
              StringBuilder rendered = new StringBuilder();
              TokenConsumer tc = new CssPrettyPrinter(rendered);
              node.render(new RenderContext(tc));
              tc.noMoreTokens();
              mq.addMessage(PluginMessageType.UNSAFE_CSS_PSEUDO_SELECTOR,
                            invalidNodeMessageLevel, node.getFilePosition(),
                            MessagePart.Factory.valueOf(rendered.toString()));
              remove = true;
            }
            if (remove) {
              // Delete the containing selector, since otherwise we'd broaden
              // the rule.
              selectorFor(ancestors).getAttributes().set(
                  CssValidator.INVALID, Boolean.TRUE);
            }
          }
          return true;
        }
      }, t.parent);
    // 3) Remove any properties and attributes that didn't validate
    t.node.acceptPreOrder(new Visitor() {
        public boolean visit(AncestorChain<?> ancestors) {
          ParseTreeNode node = ancestors.node;
          if (node instanceof CssTree.Property) {
            if (node.getAttributes().is(CssValidator.INVALID)) {
              declarationFor(ancestors).getAttributes().set(
                  CssValidator.INVALID, Boolean.TRUE);
            }
          } else if (node instanceof CssTree.Attrib) {
            if (node.getAttributes().is(CssValidator.INVALID)) {
              simpleSelectorFor(ancestors).getAttributes().set(
                  CssValidator.INVALID, Boolean.TRUE);
            }
          } else if (node instanceof CssTree.Term
                     && (CssPropertyPartType.URI == propertyPartType(node))) {

            boolean remove = false;
            Message removeMsg = null;

            CssTree term = (CssTree.Term) node;
            CssTree.CssLiteral content =
                (CssTree.CssLiteral) term.children().get(0);

            if (content instanceof CssTree.Substitution) {
              return true// Handled by later pass.
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.