diff --git a/dom/bindings/GenerateCSS2PropertiesWebIDL.py b/dom/bindings/GenerateCSS2PropertiesWebIDL.py index 4be12b72cd1..e1e4a3a56e3 100644 --- a/dom/bindings/GenerateCSS2PropertiesWebIDL.py +++ b/dom/bindings/GenerateCSS2PropertiesWebIDL.py @@ -7,9 +7,18 @@ import string propList = eval(sys.stdin.read()) props = "" -for [prop, pref] in propList: +for [prop, id, flags, pref] in propList: extendedAttrs = ["Throws", "TreatNullAs=EmptyString"] - if pref is not "": + # To limit the overhead of Func= annotations, we only generate them when + # necessary, which is when the + # CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP flag is set. + # Otherwise, we try to get by with just a Pref= annotation or no annotation + # at all. + if "CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP" in flags: + extendedAttrs.append('Func="IsCSSPropertyExposedToJS"' % id) + # The following is an 'elif' because it is the responsibility of + # IsCSSPropertyExposedToJS to handle the pref if there is one. + elif pref is not "": extendedAttrs.append('Pref="%s"' % pref) if not prop.startswith("Moz"): prop = prop[0].lower() + prop[1:] diff --git a/dom/webidl/CSS2PropertiesProps.h b/dom/webidl/CSS2PropertiesProps.h index b799db07295..63d5f5eff87 100644 --- a/dom/webidl/CSS2PropertiesProps.h +++ b/dom/webidl/CSS2PropertiesProps.h @@ -5,13 +5,16 @@ [ -#define DO_PROP(method, pref) \ - [ #method, pref ], +#define PROP_STRINGIFY_INTERNAL(X) #X +#define PROP_STRINGIFY(X) PROP_STRINGIFY_INTERNAL(X) + +#define DO_PROP(method, id, flags, pref) \ + [ #method, #id, PROP_STRINGIFY(flags), pref ], #define CSS_PROP(name, id, method, flags, pref, parsevariant, kwtable, \ stylestruct, stylestructofset, animtype) \ - DO_PROP(method, pref) + DO_PROP(method, id, flags, pref) #define CSS_PROP_SHORTHAND(name, id, method, flags, pref) \ - DO_PROP(method, pref) + DO_PROP(method, id, flags, pref) #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) publicname_ #define CSS_PROP_LIST_EXCLUDE_INTERNAL @@ -23,12 +26,14 @@ #undef CSS_PROP #define CSS_PROP_ALIAS(name, id, method, pref) \ - DO_PROP(method, pref) + DO_PROP(method, id, 0, pref) #include "nsCSSPropAliasList.h" #undef CSS_PROP_ALIAS #undef DO_PROP +#undef PROP_STRINGIFY +#undef PROP_STRINGIFY_INTERNAL ] diff --git a/layout/style/nsDOMCSSDeclaration.cpp b/layout/style/nsDOMCSSDeclaration.cpp index de250c7819d..d438918473e 100644 --- a/layout/style/nsDOMCSSDeclaration.cpp +++ b/layout/style/nsDOMCSSDeclaration.cpp @@ -16,6 +16,8 @@ #include "nsCOMPtr.h" #include "mozAutoDocUpdate.h" #include "nsIURI.h" +#include "mozilla/dom/BindingUtils.h" +#include "nsContentUtils.h" using namespace mozilla; @@ -429,3 +431,24 @@ nsDOMCSSDeclaration::RemoveCustomProperty(const nsAString& aPropertyName) decl->RemoveVariableDeclaration(Substring(aPropertyName, VAR_PREFIX_LENGTH)); return SetCSSDeclaration(decl); } + +bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj) +{ + nsCSSProps::EnabledState enabledState = nsCSSProps::eEnabledForAllContent; + + // Optimization: we skip checking properties of the JSContext + // in the majority case where the property does not have the + // CSS_PROPERTY_ALWAYS_ENABLED_IN_PRIVILEGED_CONTENT flag. + bool isEnabledInChromeOrCertifiedApp + = nsCSSProps::PropHasFlags(aProperty, + CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP); + + if (isEnabledInChromeOrCertifiedApp) { + if (dom::IsInCertifiedApp(cx, obj) || + nsContentUtils::ThreadsafeIsCallerChrome()) + { + enabledState |= nsCSSProps::eEnabledInChromeOrCertifiedApp; + } + } + return nsCSSProps::IsEnabled(aProperty, enabledState); +} diff --git a/layout/style/nsDOMCSSDeclaration.h b/layout/style/nsDOMCSSDeclaration.h index 4ea076716a0..8cb35708aae 100644 --- a/layout/style/nsDOMCSSDeclaration.h +++ b/layout/style/nsDOMCSSDeclaration.h @@ -15,6 +15,8 @@ class nsIPrincipal; class nsIDocument; +struct JSContext; +class JSObject; namespace mozilla { namespace css { @@ -152,4 +154,12 @@ protected: } }; +bool IsCSSPropertyExposedToJS(nsCSSProperty aProperty, JSContext* cx, JSObject* obj); + +template +MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj) +{ + return IsCSSPropertyExposedToJS(Property, cx, obj); +} + #endif // nsDOMCSSDeclaration_h___