Bug 1450017 - Part VIII, Exclude chrome UA style images from use counters r=heycam
authorTimothy Guan-tin Chien <timdream@gmail.com>
Wed, 25 Apr 2018 13:34:44 -0700
changeset 415874 7d7480f8fd9e4b89be3d409ef13da4633b840714
parent 415873 30abf100e11761be2162e1b0a7b42993d9d3b5ae
child 415875 94d0e43dad115ca9c7295278415ffa11abfb00a1
push id33911
push usercsabou@mozilla.com
push dateFri, 27 Apr 2018 10:01:39 +0000
treeherdermozilla-central@822936017145 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1450017
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1450017 - Part VIII, Exclude chrome UA style images from use counters r=heycam 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
@@ -12013,21 +12013,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) {
@@ -12104,27 +12129,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;
 }