diff --git a/dom/smil/nsSMILCSSValueType.cpp b/dom/smil/nsSMILCSSValueType.cpp index 85fe72085eac..8e8a916caf04 100644 --- a/dom/smil/nsSMILCSSValueType.cpp +++ b/dom/smil/nsSMILCSSValueType.cpp @@ -417,6 +417,34 @@ nsSMILCSSValueType::ValueFromString(nsCSSPropertyID aPropID, } } +// static +nsSMILValue +nsSMILCSSValueType::ValueFromAnimationValue(nsCSSPropertyID aPropID, + Element* aTargetElement, + const StyleAnimationValue& aValue) +{ + nsSMILValue result; + + nsIDocument* doc = aTargetElement->GetUncomposedDoc(); + // We'd like to avoid serializing |aValue| if possible, and since the + // string passed to CSPAllowsInlineStyle is only used for reporting violations + // and an intermediate CSS value is not likely to be particularly useful + // in that case, we just use a generic placeholder string instead. + static const nsLiteralString kPlaceholderText = + NS_LITERAL_STRING("[SVG animation of CSS]"); + if (doc && !nsStyleUtil::CSPAllowsInlineStyle(nullptr, + doc->NodePrincipal(), + doc->GetDocumentURI(), + 0, kPlaceholderText, nullptr)) { + return result; + } + + sSingleton.Init(result); + result.mU.mPtr = new ValueWrapper(aPropID, aValue); + + return result; +} + // static bool nsSMILCSSValueType::ValueToString(const nsSMILValue& aValue, diff --git a/dom/smil/nsSMILCSSValueType.h b/dom/smil/nsSMILCSSValueType.h index 0c71605f0576..f244639010b3 100644 --- a/dom/smil/nsSMILCSSValueType.h +++ b/dom/smil/nsSMILCSSValueType.h @@ -16,6 +16,7 @@ class nsAString; namespace mozilla { +class StyleAnimationValue; namespace dom { class Element; } // namespace dom @@ -28,6 +29,7 @@ class nsSMILCSSValueType : public nsISMILType { public: typedef mozilla::dom::Element Element; + typedef mozilla::StyleAnimationValue StyleAnimationValue; // Singleton for nsSMILValue objects to hold onto. static nsSMILCSSValueType sSingleton; @@ -84,6 +86,21 @@ public: nsSMILValue& aValue, bool* aIsContextSensitive); + /** + * Creates an nsSMILValue to wrap the given animation value. + * + * @param aPropID The property that |aValue| corresponds to. + * @param aTargetElement The target element to which the animation value + * applies. + * @param aValue The animation value to use. + * @return A new nsSMILValue. On failure, returns an + * nsSMILValue with the null type (i.e. rv.IsNull() + * returns true). + */ + static nsSMILValue ValueFromAnimationValue(nsCSSPropertyID aPropID, + Element* aTargetElement, + const StyleAnimationValue& aValue); + /** * Creates a string representation of the given nsSMILValue. *