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
--- 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;
}