Bug 1035091: Keep @-moz-document on late beta and later. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Wed, 29 Nov 2017 19:08:36 +0100
changeset 705234 f00f3d6a4f6c1e6949bebc1aaa4f6cab504dadc5
parent 705233 0771e14e3888ebc6b65ca4aa10f0e02e32a106d6
child 742310 3da58d6f3360d2b019ecff0cc99eba623ad6bba4
push id91415
push userbmo:emilio@crisal.io
push dateWed, 29 Nov 2017 18:12:42 +0000
reviewersxidorn
bugs1035091
milestone59.0a1
Bug 1035091: Keep @-moz-document on late beta and later. r?xidorn MozReview-Commit-ID: 2aJV0lQWrxi
layout/reftests/bugs/1035091-2.html
layout/reftests/bugs/1035091-ref.html
layout/reftests/bugs/1035091.html
layout/reftests/bugs/reftest.list
layout/style/StylePrefs.cpp
layout/style/StylePrefs.h
layout/style/nsCSSParser.cpp
modules/libpref/init/all.js
servo/components/style/stylesheets/rule_parser.rs
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1035091-2.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<style>
+div { color: green; }
+@-moz-document url-prefix() {
+  div { color: red; }
+}
+</style>
+<div>Should be green</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1035091-ref.html
@@ -0,0 +1,2 @@
+<!doctype html>
+<div style="color: green;">Should be green</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1035091.html
@@ -0,0 +1,7 @@
+<!doctype html>
+<style>
+@-moz-document url-prefix() {
+  div { color: green; }
+}
+</style>
+<div>Should be green</div>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -2044,8 +2044,10 @@ needs-focus != 1377447-1.html 1377447-2.
 == 1401992.html 1401992-ref.html
 == 1405878-1.xml 1405878-1-ref.xml
 == 1404057.html 1404057-ref.html
 != 1404057.html 1404057-noref.html
 == 1406183-1.html 1406183-1-ref.html
 == 1410028.html 1410028-ref.html
 test-pref(font.size.systemFontScale,200) == 1412743.html 1412743-ref.html
 == 1419820-1.html 1419820-1-ref.html
+pref(layout.css.moz-document-hidden-from-content,false) == 1035091.html 1035091-ref.html
+pref(layout.css.moz-document-hidden-from-content,true) == 1035091-2.html 1035091-ref.html
--- a/layout/style/StylePrefs.cpp
+++ b/layout/style/StylePrefs.cpp
@@ -14,16 +14,17 @@ bool StylePrefs::sFontDisplayEnabled;
 bool StylePrefs::sOpentypeSVGEnabled;
 bool StylePrefs::sWebkitPrefixedAliasesEnabled;
 bool StylePrefs::sWebkitDevicePixelRatioEnabled;
 bool StylePrefs::sMozGradientsEnabled;
 bool StylePrefs::sControlCharVisibility;
 bool StylePrefs::sFramesTimingFunctionEnabled;
 bool StylePrefs::sUnprefixedFullscreenApiEnabled;
 bool StylePrefs::sVisitedLinksEnabled;
+bool StylePrefs::sMozDocumentHiddenFromContent;
 
 /* static */ void
 StylePrefs::Init()
 {
   Preferences::AddBoolVarCache(&sFontDisplayEnabled,
                                "layout.css.font-display.enabled");
   Preferences::AddBoolVarCache(&sOpentypeSVGEnabled,
                                "gfx.font_rendering.opentype_svg.enabled");
@@ -36,11 +37,13 @@ StylePrefs::Init()
   Preferences::AddBoolVarCache(&sControlCharVisibility,
                                "layout.css.control-characters.visible");
   Preferences::AddBoolVarCache(&sFramesTimingFunctionEnabled,
                                "layout.css.frames-timing.enabled");
   Preferences::AddBoolVarCache(&sUnprefixedFullscreenApiEnabled,
                                "full-screen-api.unprefix.enabled");
   Preferences::AddBoolVarCache(&sVisitedLinksEnabled,
                                "layout.css.visited_links_enabled");
+  Preferences::AddBoolVarCache(&sMozDocumentHiddenFromContent,
+                               "layout.css.moz-document-hidden-from-content");
 }
 
 } // namespace mozilla
--- a/layout/style/StylePrefs.h
+++ b/layout/style/StylePrefs.h
@@ -17,15 +17,16 @@ struct StylePrefs
   static bool sOpentypeSVGEnabled;
   static bool sWebkitPrefixedAliasesEnabled;
   static bool sWebkitDevicePixelRatioEnabled;
   static bool sMozGradientsEnabled;
   static bool sControlCharVisibility;
   static bool sFramesTimingFunctionEnabled;
   static bool sUnprefixedFullscreenApiEnabled;
   static bool sVisitedLinksEnabled;
+  static bool sMozDocumentHiddenFromContent;
 
   static void Init();
 };
 
 } // namespace mozilla
 
 #endif // mozilla_StylePrefs_h
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -3766,17 +3766,18 @@ CSSParserImpl::ParseMediaRule(RuleAppend
 }
 
 // Parse a @-moz-document rule.  This is like an @media rule, but instead
 // of a medium it has a nonempty list of items where each item is either
 // url(), url-prefix(), or domain().
 bool
 CSSParserImpl::ParseMozDocumentRule(RuleAppendFunc aAppendFunc, void* aData)
 {
-  if (mParsingMode == css::eAuthorSheetFeatures) {
+  if (mParsingMode == css::eAuthorSheetFeatures &&
+      StylePrefs::sMozDocumentHiddenFromContent) {
     return false;
   }
 
   css::DocumentRule::URL *urls = nullptr;
   css::DocumentRule::URL **next = &urls;
 
   uint32_t linenum, colnum;
   if (!GetNextTokenLocation(true, &linenum, &colnum)) {
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2830,16 +2830,23 @@ pref("layout.word_select.stop_at_punctua
 pref("layout.selection.caret_style", 0);
 
 // pref to report CSS errors to the error console
 pref("layout.css.report_errors", true);
 
 // Should the :visited selector ever match (otherwise :link matches instead)?
 pref("layout.css.visited_links_enabled", true);
 
+// Pref to control whether @-moz-document rules are enabled in content pages.
+#ifdef EARLY_BETA_OR_EARLIER
+pref("layout.css.moz-document-hidden-from-content",  true);
+#else
+pref("layout.css.moz-document-hidden-from-content",  false);
+#endif
+
 // Override DPI. A value of -1 means use the maximum of 96 and the system DPI.
 // A value of 0 means use the system DPI. A positive value is used as the DPI.
 // This sets the physical size of a device pixel and thus controls the
 // interpretation of physical units such as "pt".
 pref("layout.css.dpi", -1);
 
 // Set the number of device pixels per CSS pixel. A value <= 0 means choose
 // automatically based on user settings for the platform (e.g., "UI scale factor"
--- a/servo/components/style/stylesheets/rule_parser.rs
+++ b/servo/components/style/stylesheets/rule_parser.rs
@@ -419,19 +419,31 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> 
             "page" => {
                 if cfg!(feature = "gecko") {
                     Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Page(location)))
                 } else {
                     Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
                 }
             },
             "-moz-document" => {
-                // Don't allow @moz-document rules in author sheets.
-                if !cfg!(feature = "gecko") || self.stylesheet_origin == Origin::Author {
-                    return Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
+                if !cfg!(feature = "gecko") {
+                    return Err(input.new_custom_error(
+                        StyleParseErrorKind::UnsupportedAtRule(name.clone())
+                    ))
+                }
+
+                #[cfg(feature = "gecko")]
+                {
+                    if self.stylesheet_origin == Origin::Author &&
+                        unsafe { structs::StylePrefs_sMozDocumentHiddenFromContent }
+                    {
+                        return Err(input.new_custom_error(
+                            StyleParseErrorKind::UnsupportedAtRule(name.clone())
+                        ))
+                    }
                 }
 
                 let cond = DocumentCondition::parse(self.context, input)?;
                 Ok(AtRuleType::WithBlock(AtRuleBlockPrelude::Document(cond, location)))
             },
             _ => Err(input.new_custom_error(StyleParseErrorKind::UnsupportedAtRule(name.clone())))
         }
     }