From 7cf243add5e2ae37c0a6343cefcfebae7dab636a Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 6 Mar 2014 11:38:21 -0500 Subject: [PATCH] Bug 977757 - 3/3 - Expose CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP properties in JS bindings as needed - r=bz --- dom/bindings/GenerateCSS2PropertiesWebIDL.py | 13 +++++++++-- dom/webidl/CSS2PropertiesProps.h | 15 ++++++++----- layout/style/nsDOMCSSDeclaration.cpp | 23 ++++++++++++++++++++ layout/style/nsDOMCSSDeclaration.h | 10 +++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/dom/bindings/GenerateCSS2PropertiesWebIDL.py b/dom/bindings/GenerateCSS2PropertiesWebIDL.py index 4be12b72cd1b..e1e4a3a56e34 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 b799db07295e..63d5f5eff876 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 de250c7819d4..d438918473e8 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 4ea076716a0f..8cb35708aae8 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___