Package com.google.caja.util

Examples of com.google.caja.util.Name


      CssPropertySignature rep = sig.getRepeatedSignature();
      inspectSig(rep);
    }

    private void inspectRef(CssPropertySignature.PropertyRefSignature sig) {
      Name propertyName = sig.getPropertyName();
      if (refsUsed.incr(propertyName.getCanonicalForm()) == 0) {
        CssSchema.CssPropertyInfo p = schema.getCssProperty(propertyName);
        if (p == null) {
          throw new SomethingWidgyHappenedError(
              "Unsatisfied reference " + propertyName);
        }
View Full Code Here


        inspectSig(child);
      }
    }

    private void inspectSymbol(CssPropertySignature.SymbolSignature sig) {
      Name symbolName = sig.getValue();
      CssSchema.SymbolInfo s = schema.getSymbol(symbolName);
      if (s != null) {
        inspectSig(s.sig);
      } else if (!inspectBuiltin(symbolName)) {
        throw new SomethingWidgyHappenedError(
View Full Code Here

      if (!")".equals(t)) {
        while (true) {
          if (!Character.isLetter(t.charAt(0))) {
            throw new IllegalArgumentException("Not attr name: " + t);
          }
          Name attrName = Name.css(t);
          t = toks.next();
          if (!"=".equals(t)) {
            throw new IllegalArgumentException("Not '=':" + t);
          }
          CssPropertySignature valueSig = parseSignatureAtom(toks);
View Full Code Here

    // Is it an empty declaration?  Effectively a noop, but the CSS2 spec
    // insists that a noop is a full-class declaration.
    CssTree.Property prop = d.getProperty();
    // Replace invalid but commonly used forms with a valid form, e.g.
    // replace font:12px with font-size:12px.
    Name moreSpecificName = specializeProperty(d);
    if (!moreSpecificName.equals(prop.getPropertyName())) {
      CssTree.Property specializedProp = new CssTree.Property(
          prop.getFilePosition(), moreSpecificName, prop.children());
      mq.addMessage(
          PluginMessageType.SPECIALIZING_CSS_PROPERTY, prop.getFilePosition(),
          prop.getPropertyName(), moreSpecificName);
View Full Code Here

        "<absolute-size> | <relative-size> | <length:0,> | <percentage:0,>");
    specialization("font", "font-family", "<loose-quotable-words>");
  }

  private Name specializeProperty(CssTree.PropertyDeclaration p) {
    Name propertyName = p.getProperty().getPropertyName();
    CssTree.Expr expr = p.getExpr();
    for (Specialization s : SPECIALIZATIONS.get(propertyName)) {
      SignatureResolver r = new SignatureResolver(expr, cssSchema);
      List<Candidate> matches = r.applySignature(
          Collections.singletonList(new Candidate(0, null, null)),
View Full Code Here

  private void combineLooseWords(CssTree.Expr e) {
    for (int i = 0, n = e.getNTerms(); i < n; ++i) {
      CssTree.Term t = e.getNthTerm(i);
      if (!isLooseWord(t)) { continue; }

      Name propertyPart = propertyPart(t);
      StringBuilder sb = new StringBuilder();
      sb.append(t.getExprAtom().getValue());

      // Compile a mutation that removes all the extraneous terms and that
      // replaces t with a string literal.
      MutableParseTreeNode.Mutation mut = e.createMutation();

      // Compute end, the term index after the last of the run of loose terms
      // for t's property part.
      int start = i;
      int end = i + 1;
      while (end < n) {
        CssTree.Operation op = e.getNthOperation(end - 1);
        CssTree.Term t2 = e.getNthTerm(end);
        if (!(CssTree.Operator.NONE == op.getOperator() && isLooseWord(t2)
              && propertyPart.equals(propertyPart(t2)))) {
          break;
        }
        mut.removeChild(op);
        mut.removeChild(t2);
        sb.append(' ').append(e.getNthTerm(end).getExprAtom().getValue());
View Full Code Here

            return false;
          } else if (stdColorMatcher != null
                     && CssPropertyPartType.IDENT == partType
                     && (propertyPart(term).getCanonicalForm()
                         .endsWith("::color"))) {
            Name colorName = Name.css(
                ((CssTree.IdentLiteral) term.getExprAtom()).getValue());
            if (!stdColorMatcher.matcher(colorName.getCanonicalForm() + " ")
                .matches()) {
              FilePosition pos = term.getExprAtom().getFilePosition();
              CssTree.HashLiteral replacement = colorHash(pos, colorName);
              MessageLevel lvl = MessageLevel.LINT;
              if (replacement == null) {
View Full Code Here

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

            String uriStr = content.getValue();
            try {
              URI baseUri = content.getFilePosition().source().getUri();
              URI relUri = new URI(uriStr);
              URI uri = baseUri.resolve(relUri);
              ExternalReference ref = new ExternalReference(
                  uri, baseUri, relUri, content.getFilePosition());
              Name propertyPart = propertyPart(node)// TODO
              if (uriPolicy != null) {
                String rewritten = UriPolicyNanny.apply(
                    uriPolicy,
                    ref, UriEffect.SAME_DOCUMENT, LoaderType.SANDBOXED,
                    Collections.singletonMap(
View Full Code Here

                  (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);
View Full Code Here

        pd = (CssTree.PropertyDeclaration) child;
      } else {
        pd = ((CssTree.UserAgentHack) child).getDeclaration();
      }
      CssTree.Property p = pd.getProperty();
      Name propName = p.getPropertyName();
      boolean allowedInLinkClass = propertyNames.contains(propName);
      if (!allowedInLinkClass && propName.getCanonicalForm().startsWith("_")) {
        allowedInLinkClass = propertyNames.contains(Name.css(
            propName.getCanonicalForm().substring(1)));
      }
      if (!allowedInLinkClass || mightContainUrl(pd.getExpr())) {
        mq.getMessages().add(new Message(
            PluginMessageType.DISALLOWED_CSS_PROPERTY_IN_SELECTOR,
            this.invalidNodeMessageLevel,
View Full Code Here

TOP

Related Classes of com.google.caja.util.Name

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.