Bug 1450017 - Part VIII, Exclude chrome UA style images from use counters draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 25 Apr 2018 13:34:44 -0700
changeset 788582 a6278b2d3e25ea63c017fe82a5031beb9fd2d442
parent 788006 7f330534d24a59b378b0d095c4f6b2662a9bb420
child 788583 e81d5893cd5488c2bb823fe1e3029a2b2110777f
push id108015
push usertimdream@gmail.com
push dateThu, 26 Apr 2018 16:31:28 +0000
bugs1450017
milestone61.0a1
Bug 1450017 - Part VIII, Exclude chrome UA style images from use counters Given that resizer.svg will be loaded in non-chrome documents, we will need to exclude it from the use counter. MozReview-Commit-ID: 4ZzidKJUfBW
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12009,21 +12009,46 @@ nsIDocument::GetTopLevelContentDocument(
 
     nsIDocument* candidate = parent->GetParentDocument();
     parent = static_cast<nsDocument*>(candidate);
   } while (parent);
 
   return parent;
 }
 
+static bool
+MightBeChromeScheme(nsIURI* aURI)
+{
+  MOZ_ASSERT(aURI);
+  bool isChrome = true;
+  aURI->SchemeIs("chrome", &isChrome);
+  return isChrome;
+}
+
+static bool
+MightBeAboutOrChromeScheme(nsIURI* aURI)
+{
+  MOZ_ASSERT(aURI);
+  bool isAbout = true;
+  aURI->SchemeIs("about", &isAbout);
+  return isAbout || MightBeChromeScheme(aURI);
+}
+
 void
 nsIDocument::PropagateUseCounters(nsIDocument* aParentDocument)
 {
   MOZ_ASSERT(this != aParentDocument);
 
+  // Don't count chrome resources, even in the web content.
+  nsCOMPtr<nsIURI> uri;
+  NodePrincipal()->GetURI(getter_AddRefs(uri));
+  if (!uri || MightBeChromeScheme(uri)) {
+    return;
+  }
+
   // What really matters here is that our use counters get propagated as
   // high up in the content document hierarchy as possible.  So,
   // starting with aParentDocument, we need to find the toplevel content
   // document, and propagate our use counters into its
   // mChildDocumentUseCounters.
   nsIDocument* contentParent = aParentDocument->GetTopLevelContentDocument();
 
   if (!contentParent) {
@@ -12100,27 +12125,16 @@ nsIDocument::InlineScriptAllowedByCSP()
                                        0,             // aLineNumber
                                        &allowsInlineScript);
     NS_ENSURE_SUCCESS(rv, true);
   }
   return allowsInlineScript;
 }
 
 static bool
-MightBeAboutOrChromeScheme(nsIURI* aURI)
-{
-  MOZ_ASSERT(aURI);
-  bool isAbout = true;
-  bool isChrome = true;
-  aURI->SchemeIs("about", &isAbout);
-  aURI->SchemeIs("chrome", &isChrome);
-  return isAbout || isChrome;
-}
-
-static bool
 ReportExternalResourceUseCounters(nsIDocument* aDocument, void* aData)
 {
   const auto reportKind
     = nsDocument::UseCounterReportKind::eIncludeExternalResources;
   static_cast<nsDocument*>(aDocument)->ReportUseCounters(reportKind);
   return true;
 }