Bug 1446470: Add another pref to control the url-prefix hack. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 17 Mar 2018 00:00:36 +0100
changeset 768862 61fd7fc567ec59d427a64fd3c4211e755c8f6200
parent 768861 2e9f6bfd8c7f6fe570bb4b6708dd7af68e779120
push id102993
push userbmo:emilio@crisal.io
push dateFri, 16 Mar 2018 23:07:24 +0000
reviewersxidorn
bugs1446470
milestone61.0a1
Bug 1446470: Add another pref to control the url-prefix hack. r?xidorn MozReview-Commit-ID: D4qL0oO69Uh
dom/ipc/ContentPrefs.cpp
layout/reftests/bugs/1446470-2.html
layout/reftests/bugs/reftest.list
layout/style/StylePrefs.cpp
layout/style/StylePrefs.h
modules/libpref/init/all.js
servo/components/style/stylesheets/document_rule.rs
--- a/dom/ipc/ContentPrefs.cpp
+++ b/dom/ipc/ContentPrefs.cpp
@@ -162,16 +162,17 @@ const char* mozilla::dom::ContentPrefs::
   "layout.css.grid-template-subgrid-value.enabled",
   "layout.css.grid.enabled",
   "layout.css.image-orientation.enabled",
   "layout.css.individual-transform.enabled",
   "layout.css.initial-letter.enabled",
   "layout.css.isolation.enabled",
   "layout.css.mix-blend-mode.enabled",
   "layout.css.moz-document.content.enabled",
+  "layout.css.moz-document.url-prefix-hack.enabled",
   "layout.css.osx-font-smoothing.enabled",
   "layout.css.overflow-clip-box.enabled",
   "layout.css.overscroll-behavior.enabled",
   "layout.css.prefixes.animations",
   "layout.css.prefixes.border-image",
   "layout.css.prefixes.box-sizing",
   "layout.css.prefixes.device-pixel-ratio-webkit",
   "layout.css.prefixes.font-features",
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/1446470-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>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -2059,8 +2059,9 @@ test-pref(font.size.systemFontScale,200)
 == 1422393.html 1422393-ref.html
 == 1424177.html 1424177-ref.html
 == 1424680.html 1424680-ref.html
 == 1424798-1.html 1424798-ref.html
 fuzzy(74,2234) random-if(webrender) == 1425243-1.html 1425243-1-ref.html
 fuzzy-if(Android,66,574) fuzzy-if(d2d,89,777) fuzzy-if(!Android&&!d2d,1,31219) == 1425243-2.html 1425243-2-ref.html
 == 1432541.html 1432541-ref.html
 pref(layout.css.moz-document.content.enabled,false) fails-if(!stylo||styloVsGecko) == 1446470.html 1035091-ref.html
+pref(layout.css.moz-document.url-prefix-hack.enabled,false) fails-if(!stylo||styloVsGecko) == 1446470-2.html 1035091-ref.html
--- a/layout/style/StylePrefs.cpp
+++ b/layout/style/StylePrefs.cpp
@@ -15,16 +15,17 @@ 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::sMozDocumentEnabledInContent;
+bool StylePrefs::sMozDocumentURLPrefixHackEnabled;
 bool StylePrefs::sGridTemplateSubgridValueEnabled;
 bool StylePrefs::sFontVariationsEnabled;
 bool StylePrefs::sEmulateMozBoxWithFlex;
 
 /* static */ void
 StylePrefs::Init()
 {
   Preferences::AddBoolVarCache(&sFontDisplayEnabled,
@@ -42,16 +43,18 @@ StylePrefs::Init()
   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(&sMozDocumentEnabledInContent,
                                "layout.css.moz-document.content.enabled");
+  Preferences::AddBoolVarCache(&sMozDocumentURLPrefixHackEnabled,
+                               "layout.css.moz-document.url-prefix-hack.enabled");
   Preferences::AddBoolVarCache(&sGridTemplateSubgridValueEnabled,
                                "layout.css.grid-template-subgrid-value.enabled");
   Preferences::AddBoolVarCache(&sFontVariationsEnabled,
                                "layout.css.font-variations.enabled");
 
   // Only honor layout.css.emulate-moz-box-with-flex in prerelease builds.
   // (In release builds, sEmulateMozBoxWithFlex will be implicitly false.)
 #ifndef RELEASE_OR_BETA
--- a/layout/style/StylePrefs.h
+++ b/layout/style/StylePrefs.h
@@ -18,16 +18,17 @@ struct StylePrefs
   static bool sWebkitPrefixedAliasesEnabled;
   static bool sWebkitDevicePixelRatioEnabled;
   static bool sMozGradientsEnabled;
   static bool sControlCharVisibility;
   static bool sFramesTimingFunctionEnabled;
   static bool sUnprefixedFullscreenApiEnabled;
   static bool sVisitedLinksEnabled;
   static bool sMozDocumentEnabledInContent;
+  static bool sMozDocumentURLPrefixHackEnabled;
   static bool sGridTemplateSubgridValueEnabled;
   static bool sFontVariationsEnabled;
   static bool sEmulateMozBoxWithFlex;
 
   static void Init();
 };
 
 } // namespace mozilla
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -2953,16 +2953,20 @@ pref("layout.selection.caret_style", 0);
 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.
 pref("layout.css.moz-document.content.enabled",  false);
 
+// Pref to control whether @-moz-document url-prefix() is parsed in content
+// pages. Only effective when layout.css.moz-document.content.enabled is false.
+pref("layout.css.moz-document.url-prefix-hack.enabled", true);
+
 // 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/document_rule.rs
+++ b/servo/components/style/stylesheets/document_rule.rs
@@ -220,16 +220,20 @@ impl DocumentCondition {
         if context.stylesheet_origin != Origin::Author {
             return true;
         }
 
         if unsafe { structs::StylePrefs_sMozDocumentEnabledInContent } {
             return true;
         }
 
+        if !unsafe { structs::StylePrefs_sMozDocumentURLPrefixHackEnabled } {
+            return false;
+        }
+
         // Allow a single url-prefix() for compatibility.
         //
         // See bug 1446470 and dependencies.
         if self.0.len() != 1 {
             return false;
         }
 
         // NOTE(emilio): This technically allows url-prefix("") too, but...