Examples of CssTree


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

   */
  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

    t.node.visitPreOrder(new ParseTreeNodeVisitor() {
        public boolean visit(ParseTreeNode node) {
          if (node instanceof CssTree.SuffixedSelectorPart) { return false; }
          if (!(node instanceof CssTree.SimpleSelector)) { return true; }
          CssTree.SimpleSelector ss = (CssTree.SimpleSelector) node;
          CssTree name = (CssTree) ss.children().get(0);
          if (name instanceof CssTree.IdentLiteral) {
            CssTree.IdentLiteral lit = (CssTree.IdentLiteral) name;

            ElKey key = ElKey.forHtmlElement(lit.getValue());
                // TODO(kpreid): handle namespaces
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 (!selectorMatchesClass(baseSelector, "vdoc-container___")) {
          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

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

  private void translateUrls(AncestorChain<? extends CssTree> t) {
      t.node.visitPreOrder(new ParseTreeNodeVisitor() {
          public boolean visit(ParseTreeNode node) {
            if (node instanceof CssTree.Term
                && CssPropertyPartType.URI == propertyPartType(node)) {
              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.
              }

              Name propertyPart = propertyPart(node);
              String uriStr = content.getValue();
              try {
                URI baseUri = content.getFilePosition().source().getUri();
                URI relUri = new URI(uriStr);
                URI uri = baseUri.resolve(relUri);
                // Rewrite the URI.
                // TODO(mikesamuel): for content: and other URI types, use
                // mime-type of text/*.
                ExternalReference ref = new ExternalReference(
                    uri, baseUri, relUri, content.getFilePosition());
                CssTree.UriLiteral replacement;
                if (uriPolicy != null) {
                  String rewrittenUri = UriPolicyNanny.apply(
                      uriPolicy,
                      ref, UriEffect.SAME_DOCUMENT, LoaderType.SANDBOXED,
                      Collections.singletonMap(
                          UriPolicyHintKey.CSS_PROP.key, propertyPart));
                  replacement = new SafeUriLiteral(
                          content.getFilePosition(), URI.create(rewrittenUri));
                } else {
                  replacement = new UnsafeUriLiteral(
                          content.getFilePosition(), uri);
                }
                replacement.getAttributes().putAll(content.getAttributes());
                term.replaceChild(replacement, content);
              } catch (URISyntaxException ex) {
                // Should've been checked in removeUnsafeConstructs.
                throw new SomethingWidgyHappenedError(ex);
              }
            }
View Full Code Here

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

    return SAFE_SELECTOR_PART.matcher(s).matches();
  }

  private static boolean selectorMatchesClass(
      CssTree.SimpleSelector t, String className) {
    CssTree first = t.children().get(0);
    return first instanceof CssTree.ClassLiteral
        && className.equals(((CssTree.ClassLiteral) first).getIdentifier());
  }
View Full Code Here

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
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.