Bug 977757 - 3/3 - Expose CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP properties in JS bindings as needed - r=bz

This commit is contained in:
Benoit Jacob 2014-03-07 12:14:26 -05:00
parent 91655cdf5c
commit 9b658d0e51
4 changed files with 54 additions and 7 deletions

View File

@ -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<eCSSProperty_%s>"' % 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:]

View File

@ -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
]

View File

@ -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);
}

View File

@ -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 <nsCSSProperty Property>
MOZ_ALWAYS_INLINE bool IsCSSPropertyExposedToJS(JSContext* cx, JSObject* obj)
{
return IsCSSPropertyExposedToJS(Property, cx, obj);
}
#endif // nsDOMCSSDeclaration_h___