Bug 393757 - Don't report CSS style errors for identifiers designated as vendor-specific by the CSS spec. This means we won't report errors for things like _width or for any of the -khtml-, -webkit-, -o-, -ms-, etc. properties, cutting down on error console spam a touch. r+sr+a=dbaron
authorjwalden@mit.edu
Wed, 03 Oct 2007 21:58:27 -0700
changeset 6640 b9f8097b46dd954aeb1adbfc852327d46f717f42
parent 6639 2dcc8178e7e4c5b25ff0a4834e278d24be7396b2
child 6641 8b5fca4d69d7c13a93922ed556d276cc06e79af2
push idunknown
push userunknown
push dateunknown
bugs393757
milestone1.9a9pre
Bug 393757 - Don't report CSS style errors for identifiers designated as vendor-specific by the CSS spec. This means we won't report errors for things like _width or for any of the -khtml-, -webkit-, -o-, -ms-, etc. properties, cutting down on error console spam a touch. r+sr+a=dbaron
layout/style/nsCSSParser.cpp
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -786,16 +786,29 @@ CSSParserImpl::Parse(nsIUnicharInputStre
   mUnsafeRulesEnabled = PR_FALSE;
 
   aResult = mSheet;
   NS_ADDREF(aResult);
 
   return NS_OK;
 }
 
+/**
+ * Determines whether the identifier contained in the given string is a
+ * vendor-specific identifier, as described in CSS 2.1 section 4.1.2.1.
+ */
+static PRBool
+NonMozillaVendorIdentifier(const nsAString& ident)
+{
+  return (ident.First() == PRUnichar('-') &&
+          !StringBeginsWith(ident, NS_LITERAL_STRING("-moz-"))) ||
+         ident.First() == PRUnichar('_');
+
+}
+
 NS_IMETHODIMP
 CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
                                    nsIURI*                  aDocURL,
                                    nsIURI*                  aBaseURL,
                                    nsIPrincipal*            aNodePrincipal,
                                    nsICSSStyleRule**        aResult)
 {
   NS_PRECONDITION(aNodePrincipal, "Must have principal here!");
@@ -1289,18 +1302,21 @@ PRBool CSSParserImpl::ParseAtRule(nsresu
     }
   }
   if (mToken.mIdent.LowerCaseEqualsLiteral("page")) {
     if (ParsePageRule(aErrorCode, aAppendFunc, aData)) {
       mSection = eCSSSection_General;
       return PR_TRUE;
     }
   }
-  REPORT_UNEXPECTED_TOKEN(PEUnknownAtRule);
-  OUTPUT_ERROR();
+
+  if (!NonMozillaVendorIdentifier(mToken.mIdent)) {
+    REPORT_UNEXPECTED_TOKEN(PEUnknownAtRule);
+    OUTPUT_ERROR();
+  }
 
   // Skip over unsupported at rule, don't advance section
   return SkipAtRule(aErrorCode);
 }
 
 PRBool CSSParserImpl::ParseCharsetRule(nsresult& aErrorCode, RuleAppendFunc aAppendFunc,
                                        void* aData)
 {
@@ -3293,25 +3309,28 @@ CSSParserImpl::ParseDeclaration(nsresult
       REPORT_UNEXPECTED(PEDeclSkipped);
       OUTPUT_ERROR();
     }
     // Not a declaration...
     UngetToken();
     return PR_FALSE;
   }
 
-  // Map property name to it's ID and then parse the property
+  // Map property name to its ID and then parse the property
   nsCSSProperty propID = nsCSSProps::LookupProperty(propertyName);
   if (eCSSProperty_UNKNOWN == propID) { // unknown property
-    const PRUnichar *params[] = {
-      propertyName.get()
-    };
-    REPORT_UNEXPECTED_P(PEUnknownProperty, params);
-    REPORT_UNEXPECTED(PEDeclDropped);
-    OUTPUT_ERROR();
+    if (!NonMozillaVendorIdentifier(propertyName)) {
+      const PRUnichar *params[] = {
+        propertyName.get()
+      };
+      REPORT_UNEXPECTED_P(PEUnknownProperty, params);
+      REPORT_UNEXPECTED(PEDeclDropped);
+      OUTPUT_ERROR();
+    }
+
     return PR_FALSE;
   }
   if (! ParseProperty(aErrorCode, propID)) {
     // XXX Much better to put stuff in the value parsers instead...
     const PRUnichar *params[] = {
       propertyName.get()
     };
     REPORT_UNEXPECTED_P(PEPropertyParsingError, params);