Bug 1420026 - Part 3: Report canvas color parsing errors to the console. r?TYLin draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 04 Dec 2017 12:53:57 +0800
changeset 707334 f0a2493efcf6033b90b116dd844c1805e1513b5f
parent 707333 17388783ac4f08b7a1ba34b0f36ed4fd4ea3e1dd
child 742916 2e394dcb72c065c8097e227c6ae2ace2bf483d9b
push id92088
push userbmo:cam@mcc.id.au
push dateTue, 05 Dec 2017 05:26:04 +0000
reviewersTYLin
bugs1420026
milestone59.0a1
Bug 1420026 - Part 3: Report canvas color parsing errors to the console. r?TYLin MozReview-Commit-ID: BcWat5wfGJJ
dom/canvas/CanvasRenderingContext2D.cpp
layout/style/ServoBindingList.h
layout/style/ServoCSSParser.cpp
layout/style/ServoCSSParser.h
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1158,44 +1158,43 @@ CanvasRenderingContext2D::WrapObject(JSC
 {
   return CanvasRenderingContext2DBinding::Wrap(aCx, this, aGivenProto);
 }
 
 bool
 CanvasRenderingContext2D::ParseColor(const nsAString& aString,
                                      nscolor* aColor)
 {
-  nsIDocument* document = mCanvasElement
-                          ? mCanvasElement->OwnerDoc()
-                          : nullptr;
+  nsIDocument* document = mCanvasElement ? mCanvasElement->OwnerDoc() : nullptr;
+  css::Loader* loader = document ? document->CSSLoader() : nullptr;
 
   if (document->IsStyledByServo()) {
     nsCOMPtr<nsIPresShell> presShell = GetPresShell();
     ServoStyleSet* set = presShell ? presShell->StyleSet()->AsServo() : nullptr;
 
     // First, try computing the color without handling currentcolor.
     bool wasCurrentColor = false;
     if (!ServoCSSParser::ComputeColor(set, NS_RGB(0, 0, 0), aString, aColor,
-                                      &wasCurrentColor)) {
+                                      &wasCurrentColor, loader)) {
       return false;
     }
 
     if (wasCurrentColor) {
       // Otherwise, get the value of the color property, flushing style
       // if necessary.
       RefPtr<nsStyleContext> canvasStyle =
         nsComputedDOMStyle::GetStyleContext(mCanvasElement, nullptr, presShell);
       *aColor = canvasStyle->StyleColor()->mColor;
     }
     return true;
   }
 
   // Pass the CSS Loader object to the parser, to allow parser error
   // reports to include the outer window ID.
-  nsCSSParser parser(document ? document->CSSLoader() : nullptr);
+  nsCSSParser parser(loader);
   nsCSSValue value;
   if (!parser.ParseColorString(aString, nullptr, 0, value)) {
     return false;
   }
 
   if (value.IsNumericColorUnit()) {
     // if we already have a color we can just use it directly
     *aColor = value.GetColorValue();
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -740,17 +740,18 @@ SERVO_BINDING_FUNC(Servo_CloneArcStringD
 
 // CSS parsing utility functions.
 SERVO_BINDING_FUNC(Servo_IsValidCSSColor, bool, const nsAString* value);
 SERVO_BINDING_FUNC(Servo_ComputeColor, bool,
                    RawServoStyleSetBorrowedOrNull set,
                    nscolor current_color,
                    const nsAString* value,
                    nscolor* result_color,
-                   bool* was_current_color);
+                   bool* was_current_color,
+                   mozilla::css::Loader* loader)
 SERVO_BINDING_FUNC(Servo_ParseIntersectionObserverRootMargin, bool,
                    const nsAString* value,
                    nsCSSRect* result);
 // Returning false means the parsed transform contains relative lengths or
 // percentage value, so we cannot compute the matrix. In this case, we keep
 // |result| and |contains_3d_transform| as-is.
 SERVO_BINDING_FUNC(Servo_ParseTransformIntoMatrix, bool,
                    const nsAString* value,
--- a/layout/style/ServoCSSParser.cpp
+++ b/layout/style/ServoCSSParser.cpp
@@ -16,21 +16,22 @@ ServoCSSParser::IsValidCSSColor(const ns
   return Servo_IsValidCSSColor(&aValue);
 }
 
 /* static */ bool
 ServoCSSParser::ComputeColor(ServoStyleSet* aStyleSet,
                              nscolor aCurrentColor,
                              const nsAString& aValue,
                              nscolor* aResultColor,
-                             bool* aWasCurrentColor)
+                             bool* aWasCurrentColor,
+                             css::Loader* aLoader)
 {
   return Servo_ComputeColor(aStyleSet ? aStyleSet->RawSet() : nullptr,
                             aCurrentColor, &aValue, aResultColor,
-                            aWasCurrentColor);
+                            aWasCurrentColor, aLoader);
 }
 
 /* static */ bool
 ServoCSSParser::ParseIntersectionObserverRootMargin(const nsAString& aValue,
                                                     nsCSSRect* aResult)
 {
   return Servo_ParseIntersectionObserverRootMargin(&aValue, aResult);
 }
--- a/layout/style/ServoCSSParser.h
+++ b/layout/style/ServoCSSParser.h
@@ -7,16 +7,22 @@
 /* CSS parsing utility functions */
 
 #ifndef mozilla_ServoCSSParser_h
 #define mozilla_ServoCSSParser_h
 
 #include "mozilla/ServoBindings.h"
 
 namespace mozilla {
+namespace css {
+class Loader;
+} // namespace css
+} // namespace mozilla
+
+namespace mozilla {
 
 class ServoCSSParser
 {
 public:
   /**
    * Returns whether the specified string can be parsed as a valid CSS
    * <color> value.
    *
@@ -29,23 +35,27 @@ public:
    *
    * @param aStyleSet The style set whose nsPresContext will be used to
    *   compute system colors and other special color values.
    * @param aCurrentColor The color value that currentcolor should compute to.
    * @param aValue The CSS <color> value.
    * @param aResultColor The resulting computed color value.
    * @param aWasCurrentColor Whether aValue was currentcolor. Can be nullptr
    *   if the caller doesn't care.
+   * @param aLoader The CSS loader for document we're parsing a color for,
+   *   so that parse errors can be reported to the console. If nullptr, errors
+   *   won't be reported to the console.
    * @return Whether aValue was successfully parsed and aResultColor was set.
    */
   static bool ComputeColor(ServoStyleSet* aStyleSet,
                            nscolor aCurrentColor,
                            const nsAString& aValue,
                            nscolor* aResultColor,
-                           bool* aWasCurrentColor = nullptr);
+                           bool* aWasCurrentColor = nullptr,
+                           css::Loader* aLoader = nullptr);
 
   /**
    * Parses a IntersectionObserver's initialization dictionary's rootMargin
    * property.
    *
    * @param aValue The rootMargin value.
    * @param aResult The nsCSSRect object to write the result into.
    * @return Whether the value was successfully parsed.