Bug 1634602 - Exempt about:black from color scheme preference in RFP mode. r=emilio, a=jcristau
authorTom Ritter <tom@mozilla.com>
Tue, 02 Jun 2020 20:42:31 +0000
changeset 596956 307b75879bcaade2b454b512d721d82acd4a8478
parent 596955 6bef5b17397610b6bc22813c0997094a881b830d
child 596957 d6fc47eb7f3bce9812eed407f06dffeb7156d793
push id13215
push userjcristau@mozilla.com
push dateThu, 04 Jun 2020 13:33:19 +0000
treeherdermozilla-beta@d6fc47eb7f3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio, jcristau
bugs1634602
milestone78.0
Bug 1634602 - Exempt about:black from color scheme preference in RFP mode. r=emilio, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D77833
dom/base/Document.cpp
dom/base/Document.h
layout/base/PresShell.cpp
--- a/dom/base/Document.cpp
+++ b/dom/base/Document.cpp
@@ -16315,18 +16315,19 @@ void Document::RemoveToplevelLoadingDocu
           mozilla::ipc::IdleSchedulerChild::GetMainThreadIdleScheduler();
       if (idleScheduler) {
         idleScheduler->SendPrioritizedOperationDone();
       }
     }
   }
 }
 
-StylePrefersColorScheme Document::PrefersColorScheme() const {
-  if (nsContentUtils::ShouldResistFingerprinting(this)) {
+StylePrefersColorScheme Document::PrefersColorScheme(
+    Document::IgnoreRFP aIgnoreRFP /* = IgnoreRFP::No */) const {
+  if (aIgnoreRFP == IgnoreRFP::No && nsContentUtils::ShouldResistFingerprinting(this)) {
     return StylePrefersColorScheme::Light;
   }
 
   if (nsPresContext* pc = GetPresContext()) {
     if (auto devtoolsOverride = pc->GetOverridePrefersColorScheme()) {
       return *devtoolsOverride;
     }
 
--- a/dom/base/Document.h
+++ b/dom/base/Document.h
@@ -3863,17 +3863,18 @@ class Document : public nsINode,
     mDelayFrameLoaderInitialization = aDelayFrameLoaderInitialization;
   }
 
   void SetPrototypeDocument(nsXULPrototypeDocument* aPrototype);
 
   nsIPermissionDelegateHandler* PermDelegateHandler();
 
   // CSS prefers-color-scheme media feature for this document.
-  StylePrefersColorScheme PrefersColorScheme() const;
+  enum class IgnoreRFP { No, Yes };
+  StylePrefersColorScheme PrefersColorScheme(IgnoreRFP aIgnoreRFP = IgnoreRFP::No) const;
 
   // Returns true if we use overlay scrollbars on the system wide or on the
   // given document.
   static bool UseOverlayScrollbars(const Document* aDocument);
 
   static bool HasRecentlyStartedForegroundLoads();
 
   static bool AutomaticStorageAccessCanBeGranted(nsIPrincipal* aPrincipal);
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -5156,17 +5156,17 @@ nscolor PresShell::GetDefaultBackgroundC
   }
 
   // Use a dark background for top-level about:blank that is inaccessible to
   // content JS.
   Document* doc = GetDocument();
   BrowsingContext* bc = doc->GetBrowsingContext();
   if (bc && bc->IsTop() && !bc->HasOpener() && doc->GetDocumentURI() &&
       NS_IsAboutBlank(doc->GetDocumentURI()) &&
-      doc->PrefersColorScheme() == StylePrefersColorScheme::Dark) {
+      doc->PrefersColorScheme(Document::IgnoreRFP::Yes) == StylePrefersColorScheme::Dark) {
     // Use --in-content-page-background for prefers-color-scheme: dark.
     return NS_RGB(0x2A, 0x2A, 0x2E);
   }
 
   return backgroundColor;
 }
 
 void PresShell::UpdateCanvasBackground() {