Bug 977757 - 2/3 - add nsCSSProps::eEnabledInChromeOrCertifiedApp bit, and use it for will-change - r=dbaron,bz
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 07 Mar 2014 12:14:25 -0500
changeset 190378 71014b91b6c65668f32d182d6990c314215b9704
parent 190377 aaabd2d390603d2dfa6054fbe390ae92857f1574
child 190379 a10d0ba50f64d6a4cf31490c473c29527254f80d
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)
reviewersdbaron, bz
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 - 2/3 - add nsCSSProps::eEnabledInChromeOrCertifiedApp bit, and use it for will-change - r=dbaron,bz
layout/style/nsCSSParser.cpp
layout/style/nsCSSPropList.h
layout/style/nsCSSProps.cpp
layout/style/nsCSSProps.h
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -40,16 +40,17 @@
 #include "nsContentUtils.h"
 #include "nsAutoPtr.h"
 #include "CSSCalc.h"
 #include "nsMediaFeatures.h"
 #include "nsLayoutUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsRuleData.h"
 #include "mozilla/CSSVariableValues.h"
+#include "mozilla/dom/URL.h"
 
 using namespace mozilla;
 
 typedef nsCSSProps::KTableValue KTableValue;
 
 const uint32_t
 nsCSSProps::kParserVariantTable[eCSSProperty_COUNT_no_shorthands] = {
 #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, \
@@ -250,16 +251,19 @@ public:
   nsCSSProperty LookupEnabledProperty(const nsAString& aProperty) {
     static_assert(nsCSSProps::eEnabledForAllContent == 0,
                   "nsCSSProps::eEnabledForAllContent should be zero for "
                   "this bitfield to work");
     nsCSSProps::EnabledState enabledState = nsCSSProps::eEnabledForAllContent;
     if (mUnsafeRulesEnabled) {
       enabledState |= nsCSSProps::eEnabledInUASheets;
     }
+    if (mIsChromeOrCertifiedApp) {
+      enabledState |= nsCSSProps::eEnabledInChromeOrCertifiedApp;
+    }
     return nsCSSProps::LookupProperty(aProperty, enabledState);
   }
 
 protected:
   class nsAutoParseCompoundProperty;
   friend class nsAutoParseCompoundProperty;
 
   class nsAutoFailingSupportsRule;
@@ -913,16 +917,22 @@ protected:
   bool mHashlessColorQuirk : 1;
 
   // True when the unitless length quirk applies.
   bool mUnitlessLengthQuirk : 1;
 
   // True if unsafe rules should be allowed
   bool mUnsafeRulesEnabled : 1;
 
+  // True if we are in parsing rules for Chrome or Certified App content,
+  // in which case CSS properties with the
+  // CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP
+  // flag should be allowed.
+  bool mIsChromeOrCertifiedApp : 1;
+
   // True if viewport units should be allowed.
   bool mViewportUnitsEnabled : 1;
 
   // True for parsing media lists for HTML attributes, where we have to
   // ignore CSS comments.
   bool mHTMLMediaMode : 1;
 
   // This flag is set when parsing a non-box shorthand; it's used to not apply
@@ -1007,16 +1017,17 @@ CSSParserImpl::CSSParserImpl()
     mChildLoader(nullptr),
     mSection(eCSSSection_Charset),
     mNameSpaceMap(nullptr),
     mHavePushBack(false),
     mNavQuirkMode(false),
     mHashlessColorQuirk(false),
     mUnitlessLengthQuirk(false),
     mUnsafeRulesEnabled(false),
+    mIsChromeOrCertifiedApp(false),
     mViewportUnitsEnabled(true),
     mHTMLMediaMode(false),
     mParsingCompoundProperty(false),
     mInSupportsCondition(false),
     mInFailingSupportsRule(false),
     mSuppressErrors(false),
     mNextFree(nullptr)
 {
@@ -1147,16 +1158,19 @@ CSSParserImpl::ParseSheet(const nsAStrin
       }
     }
   }
   else {
     mSection = eCSSSection_Charset; // sheet is empty, any rules are fair
   }
 
   mUnsafeRulesEnabled = aAllowUnsafeRules;
+  mIsChromeOrCertifiedApp =
+    dom::IsChromeURI(aSheetURI) ||
+    aSheetPrincipal->GetAppStatus() == nsIPrincipal::APP_STATUS_CERTIFIED;
 
   nsCSSToken* tk = &mToken;
   for (;;) {
     // Get next non-whitespace token
     if (!GetToken(true)) {
       OUTPUT_ERROR();
       break;
     }
@@ -1170,16 +1184,17 @@ CSSParserImpl::ParseSheet(const nsAStrin
     UngetToken();
     if (ParseRuleSet(AppendRuleToSheet, this)) {
       mSection = eCSSSection_General;
     }
   }
   ReleaseScanner();
 
   mUnsafeRulesEnabled = false;
+  mIsChromeOrCertifiedApp = false;
 
   // XXX check for low level errors
   return NS_OK;
 }
 
 /**
  * Determines whether the identifier contained in the given string is a
  * vendor-specific identifier, as described in CSS 2.1 section 4.1.2.1.
--- a/layout/style/nsCSSPropList.h
+++ b/layout/style/nsCSSPropList.h
@@ -3902,17 +3902,18 @@ CSS_PROP_SVGRESET(
     offsetof(nsStyleSVGReset, mVectorEffect),
     eStyleAnimType_EnumU8)
 
 CSS_PROP_DISPLAY(
     will-change,
     will_change,
     WillChange,
     CSS_PROPERTY_PARSE_FUNCTION |
-        CSS_PROPERTY_VALUE_LIST_USES_COMMAS,
+        CSS_PROPERTY_VALUE_LIST_USES_COMMAS |
+        CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP,
     "layout.css.will-change.enabled",
     0,
     nullptr,
     CSS_PROP_NO_OFFSET,
     eStyleAnimType_None)
 
 // The shorthands below are essentially aliases, but they require different
 // parsing rules, and are therefore implemented as shorthands.
--- a/layout/style/nsCSSProps.cpp
+++ b/layout/style/nsCSSProps.cpp
@@ -390,17 +390,17 @@ nsCSSProps::LookupProperty(const nsACStr
   if (MOZ_LIKELY(res < eCSSProperty_COUNT)) {
     if (res != eCSSProperty_UNKNOWN && !IsEnabled(res, aEnabled)) {
       res = eCSSProperty_UNKNOWN;
     }
     return res;
   }
   MOZ_ASSERT(eCSSAliasCount != 0,
              "'res' must be an alias at this point so we better have some!");
-  // We intentionally don't support eEnabledInUASheets
+  // We intentionally don't support eEnabledInUASheets or eEnabledInChromeOrCertifiedApp
   // for aliases yet because it's unlikely there will be a need for it.
   if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) {
     res = gAliases[res - eCSSProperty_COUNT];
     NS_ABORT_IF_FALSE(0 <= res && res < eCSSProperty_COUNT,
                       "aliases must not point to other aliases");
     if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) {
       return res;
     }
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -196,16 +196,24 @@ static_assert((CSS_PROPERTY_PARSE_PROPER
 
 // This property is always enabled in UA sheets.  This is meant to be used
 // together with a pref that enables the property for non-UA sheets.
 // Note that if such a property has an alias, then any use of that alias
 // in an UA sheet will still be ignored unless the pref is enabled.
 // In other words, this bit has no effect on the use of aliases.
 #define CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS  (1<<22)
 
+// This property is always enabled in chrome and in certified apps. This is
+// meant to be used together with a pref that enables the property for
+// non-privileged content. Note that if such a property has an alias, then any
+// use of that alias in privileged content will still be ignored unless the
+// pref is enabled. In other words, this bit has no effect on the use of
+// aliases.
+#define CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP (1<<23)
+
 /**
  * Types of animatable values.
  */
 enum nsStyleAnimType {
   // requires a custom implementation in
   // nsStyleAnimation::ExtractComputedValue
   eStyleAnimType_Custom,
 
@@ -259,16 +267,18 @@ public:
   static void ReleaseTable(void);
 
   enum EnabledState {
     // The default EnabledState: only enable what's enabled for all content,
     // given the current values of preferences.
     eEnabledForAllContent = 0,
     // Enable a property in UA sheets.
     eEnabledInUASheets    = 0x01,
+    // Enable a property in privileged content, i.e. chrome or Certified Apps
+    eEnabledInChromeOrCertifiedApp = 0x02,
     // Special value to unconditionally enable a property. This implies all the
     // bits above, but is strictly more than just their OR-ed union.
     // This just skips any test so a property will be enabled even if it would
     // have been disabled with all the bits above set.
     eIgnoreEnabledState   = 0xff
   };
 
   // Looks up the property with name aProperty and returns its corresponding
@@ -462,16 +472,21 @@ public:
     if (aEnabled == eIgnoreEnabledState) {
       return true;
     }
     if ((aEnabled & eEnabledInUASheets) &&
         PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_UA_SHEETS))
     {
       return true;
     }
+    if ((aEnabled & eEnabledInChromeOrCertifiedApp) &&
+        PropHasFlags(aProperty, CSS_PROPERTY_ALWAYS_ENABLED_IN_CHROME_OR_CERTIFIED_APP))
+    {
+      return true;
+    }
     return false;
   }
 
 public:
 
 #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_)                    \
   for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_);   \
        *iter_ != eCSSProperty_UNKNOWN; ++iter_) \