Bug 1377144 - Allow <style scoped> in about:reader documents. r=emilio draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 10 Jul 2017 15:59:20 +0800
changeset 606053 0d023b131dd7142f6da1e2b77630da241bed7f91
parent 606039 39f796c2d332f502369ad4750501867680878ae7
child 636661 08351b37a51b0cd12275646a43ade6b5fb3f0e0c
push id67589
push userbmo:cam@mcc.id.au
push dateMon, 10 Jul 2017 07:59:52 +0000
reviewersemilio
bugs1377144
milestone55.0
Bug 1377144 - Allow <style scoped> in about:reader documents. r=emilio MozReview-Commit-ID: B2nkVYZXUFw
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -13476,19 +13476,38 @@ nsDocument::IsThirdParty()
     return mIsThirdParty.value();
   }
 
   // Fall-through. Document is not a Third-Party Document.
   mIsThirdParty.emplace(false);
   return mIsThirdParty.value();
 }
 
+static bool
+IsAboutReader(nsIURI* aURI)
+{
+  if (!aURI) {
+    return false;
+  }
+
+  nsCString spec;
+  aURI->GetSpec(spec);
+
+  // Reader mode URLs look like about:reader?[...].
+  return StringBeginsWith(spec, NS_LITERAL_CSTRING("about:reader"));
+}
+
 bool
 nsIDocument::IsScopedStyleEnabled()
 {
   if (mIsScopedStyleEnabled == eScopedStyle_Unknown) {
+    // We allow <style scoped> in about:reader pages since on Android
+    // we use it to inject some in-page UI.  (We currently don't
+    // support styling about:reader pages in stylo anyway, so for
+    // now it's OK to enable it here.)
     mIsScopedStyleEnabled = nsContentUtils::IsChromeDoc(this) ||
+                            IsAboutReader(mDocumentURI) ||
                             nsContentUtils::IsScopedStylePrefEnabled()
                               ? eScopedStyle_Enabled
                               : eScopedStyle_Disabled;
   }
   return mIsScopedStyleEnabled == eScopedStyle_Enabled;
 }