Bug 977757 - 3/3 - Expose CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP properties in JS bindings as needed - r=bz
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 07 Mar 2014 12:14:26 -0500
changeset 189717 45253e02bde3323313d6b67e6c782b0ff6569b3d
parent 189716 fd02f1217e4c5ddfa9b4a0cfd222dcfdad3c884d
child 189718 9c88a32cffb09451352e140cf778f4f7a2021d94
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs977757
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/webidl/CSS2PropertiesProps.h
layout/style/nsDOMCSSDeclaration.cpp
layout/style/nsDOMCSSDeclaration.h
--- a/dom/bindings/GenerateCSS2PropertiesWebIDL.py
+++ b/dom/bindings/GenerateCSS2PropertiesWebIDL.py
@@ -2,19 +2,28 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import sys
 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:]
     # Unfortunately, even some of the getters here are fallible
     # (e.g. on nsComputedDOMStyle).
     props += "  [%s] attribute DOMString %s;\n" % (", ".join(extendedAttrs),
                                                    prop)
 
--- a/dom/webidl/CSS2PropertiesProps.h
+++ b/dom/webidl/CSS2PropertiesProps.h
@@ -1,34 +1,39 @@
 /* A file meant as input to the preprocessor only */
 
 /* DO_PROP serves as an extra level of indirection to allow expansion
    of CSS_PROP_DOMPROP_PREFIXED */
 
 [
 
-#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
 
 #include "nsCSSPropList.h"
 
 #undef CSS_PROP_LIST_EXCLUDE_INTERNAL
 #undef CSS_PROP_PUBLIC_OR_PRIVATE
 #undef CSS_PROP_SHORTHAND
 #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
 
 ]
--- a/layout/style/nsDOMCSSDeclaration.cpp
+++ b/layout/style/nsDOMCSSDeclaration.cpp
@@ -11,16 +11,18 @@
 #include "nsCSSStyleSheet.h"
 #include "mozilla/css/Rule.h"
 #include "mozilla/css/Declaration.h"
 #include "mozilla/dom/CSS2PropertiesBinding.h"
 #include "nsCSSProps.h"
 #include "nsCOMPtr.h"
 #include "mozAutoDocUpdate.h"
 #include "nsIURI.h"
+#include "mozilla/dom/BindingUtils.h"
+#include "nsContentUtils.h"
 
 using namespace mozilla;
 
 nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
 {
 }
 
 /* virtual */ JSObject*
@@ -424,8 +426,29 @@ nsDOMCSSDeclaration::RemoveCustomPropert
   // between when we mutate the declaration and when we set the new
   // rule (see stack in bug 209575).
   mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
 
   decl = decl->EnsureMutable();
   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);
+}
--- a/layout/style/nsDOMCSSDeclaration.h
+++ b/layout/style/nsDOMCSSDeclaration.h
@@ -10,16 +10,18 @@
 
 #include "nsICSSDeclaration.h"
 
 #include "mozilla/Attributes.h"
 #include "nsCOMPtr.h"
 
 class nsIPrincipal;
 class nsIDocument;
+struct JSContext;
+class JSObject;
 
 namespace mozilla {
 namespace css {
 class Declaration;
 class Loader;
 class Rule;
 }
 }
@@ -147,9 +149,17 @@ protected:
 protected:
   virtual ~nsDOMCSSDeclaration();
   nsDOMCSSDeclaration()
   {
     SetIsDOMBinding();
   }
 };
 
+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___