commit 5d4fab6fa41d7848bb99a795cbadac09c92c5643
parent c3bc8e9113b711e1b653b8e41f690706b688ab7e
Author: Sandor Molnar <smolnar@mozilla.com>
Date: Wed, 7 Jan 2026 12:31:45 +0200
Revert "Bug 2003729 - Buffer reports by type separately r=smaug" for causing assertion failures
This reverts commit 8f2a3fac38ddb47db9216164a710c092b278720d.
Diffstat:
7 files changed, 28 insertions(+), 127 deletions(-)
diff --git a/dom/base/nsIGlobalObject.cpp b/dom/base/nsIGlobalObject.cpp
@@ -26,6 +26,9 @@
#include "nsGlobalWindowInner.h"
#include "nsThreadUtils.h"
+// Max number of Report objects
+constexpr auto MAX_REPORT_RECORDS = 100;
+
using mozilla::AutoSlowOperation;
using mozilla::CycleCollectedJSContext;
using mozilla::DOMEventTargetHelper;
@@ -134,7 +137,7 @@ void nsIGlobalObject::UnlinkObjectsInGlobal() {
}
}
- ClearReports();
+ mReportRecords.Clear();
mReportingObservers.Clear();
mCountQueuingStrategySizeFunction = nullptr;
mByteLengthQueuingStrategySizeFunction = nullptr;
@@ -151,7 +154,7 @@ void nsIGlobalObject::TraverseObjectsInGlobal(
}
nsIGlobalObject* tmp = this;
- NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportBuffer)
+ NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportRecords)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mReportingObservers)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCountQueuingStrategySizeFunction)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mByteLengthQueuingStrategySizeFunction)
@@ -386,7 +389,7 @@ void nsIGlobalObject::RegisterReportingObserver(ReportingObserver* aObserver,
return;
}
- for (const auto& report : mReportBuffer) {
+ for (Report* report : mReportRecords) {
aObserver->MaybeReport(report);
}
}
@@ -404,24 +407,12 @@ void nsIGlobalObject::BroadcastReport(Report* aReport) {
observer->MaybeReport(aReport);
}
- if (NS_WARN_IF(!mReportBuffer.AppendElement(aReport, mozilla::fallible))) {
+ if (NS_WARN_IF(!mReportRecords.AppendElement(aReport, mozilla::fallible))) {
return;
}
- uint32_t& count = mReportPerTypeCount.LookupOrInsert(aReport->Type());
- ++count;
-
- const uint32_t maxReportCount =
- mozilla::StaticPrefs::dom_reporting_delivering_maxReports();
- const nsString& reportType = aReport->Type();
-
- for (size_t i = 0u; count > maxReportCount && i < mReportBuffer.Length();) {
- if (mReportBuffer[i]->Type() == reportType) {
- mReportBuffer.RemoveElementAt(i);
- --count;
- } else {
- ++i;
- }
+ while (mReportRecords.Length() > MAX_REPORT_RECORDS) {
+ mReportRecords.RemoveElementAt(0);
}
}
@@ -437,7 +428,7 @@ void nsIGlobalObject::NotifyReportingObservers() {
}
void nsIGlobalObject::RemoveReportRecords() {
- ClearReports();
+ mReportRecords.Clear();
for (auto& observer : mReportingObservers) {
observer->ForgetReports();
@@ -527,8 +518,3 @@ void nsIGlobalObject::ReportToConsole(
nsContentUtils::ReportToConsole(aErrorFlags, aCategory, nullptr, aFile,
aMessageName.get(), aParams, aLocation);
}
-
-void nsIGlobalObject::ClearReports() {
- mReportBuffer.Clear();
- mReportPerTypeCount.Clear();
-}
diff --git a/dom/base/nsIGlobalObject.h b/dom/base/nsIGlobalObject.h
@@ -406,14 +406,9 @@ class nsIGlobalObject : public nsISupports {
size_t ShallowSizeOfExcludingThis(mozilla::MallocSizeOf aSizeOf) const;
private:
- void ClearReports();
-
- private:
// List of Report objects for ReportingObservers.
nsTArray<RefPtr<mozilla::dom::ReportingObserver>> mReportingObservers;
- // https://w3c.github.io/reporting/#windoworworkerglobalscope-report-buffer
- nsTArray<RefPtr<mozilla::dom::Report>> mReportBuffer;
- nsTHashMap<nsString, uint32_t> mReportPerTypeCount;
+ nsTArray<RefPtr<mozilla::dom::Report>> mReportRecords;
// https://streams.spec.whatwg.org/#count-queuing-strategy-size-function
RefPtr<mozilla::dom::Function> mCountQueuingStrategySizeFunction;
diff --git a/dom/reporting/Report.cpp b/dom/reporting/Report.cpp
@@ -39,8 +39,6 @@ JSObject* Report::WrapObject(JSContext* aCx,
return Report_Binding::Wrap(aCx, this, aGivenProto);
}
-const nsString& Report::Type() const { return mType; }
-
void Report::GetType(nsAString& aType) const { aType = mType; }
void Report::GetUrl(nsAString& aURL) const { aURL = mURL; }
diff --git a/dom/reporting/Report.h b/dom/reporting/Report.h
@@ -37,9 +37,8 @@ class Report final : public nsISupports, public nsWrapperCache {
nsIGlobalObject* GetParentObject() const { return mGlobal; }
- const nsString& Type() const;
-
void GetType(nsAString& aType) const;
+
void GetUrl(nsAString& aURL) const;
ReportBody* GetBody() const;
@@ -49,8 +48,8 @@ class Report final : public nsISupports, public nsWrapperCache {
nsCOMPtr<nsIGlobalObject> mGlobal;
- nsString mType;
- nsString mURL;
+ const nsString mType;
+ const nsString mURL;
RefPtr<ReportBody> mBody;
};
diff --git a/testing/web-platform/meta/reporting/reporting-api-honors-limits.https.sub.html.ini b/testing/web-platform/meta/reporting/reporting-api-honors-limits.https.sub.html.ini
@@ -0,0 +1,14 @@
+[reporting-api-honors-limits.https.sub.html]
+ expected: TIMEOUT
+
+ [CSP Report limits were honored]
+ expected: TIMEOUT
+ bug: 2003729
+
+ [Combined report limits were honored]
+ expected: NOTRUN
+ bug: 2003729
+
+ [Test Report limits were honored]
+ expected: NOTRUN
+ bug: 2003729
diff --git a/testing/web-platform/tests/reporting/reporting-api-orders-reports-buffered.https.html b/testing/web-platform/tests/reporting/reporting-api-orders-reports-buffered.https.html
@@ -1,84 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<head>
- <meta charset="utf-8">
- <title>
- Reporting API: buffered observer preserves ordering across report types
- </title>
- <script src="/resources/testharness.js"></script>
- <script src="/resources/testharnessreport.js"></script>
- <script src="/resources/testdriver.js"></script>
- <script src="/resources/testdriver-vendor.js"></script>
-</head>
-
-<body>
-<script>
-promise_test(async t => {
- assert_true("ReportingObserver" in self);
-
- function generateTest(i) {
- test_driver.generate_test_report(`Test report ${i}`);
- }
-
- function generateDeprecation(i) {
- let img = document.createElement("img");
-
- img.src = `/some/bunk/file${i}.png`;
- document.body.appendChild(img);
- }
-
- let nonBufferedReports = [];
- const observeTwoReports = async () => {
- let { promise, resolve } = Promise.withResolvers();
- let count = 0;
- let reportingObserver = new ReportingObserver(reports => {
- count += reports.length;
- nonBufferedReports.push(...reports);
- if (count >= 2) {
- resolve();
- }
- });
-
- reportingObserver.observe();
- return promise.finally(() => reportingObserver.disconnect());
- }
-
- // Generate interleaved reports
- for (let i = 0; i < 25; i++) {
- generateTest(i);
- generateDeprecation(i);
- await observeTwoReports();
- }
-
- const collected = [];
- const { promise: collectedAll, resolve } = Promise.withResolvers();
-
- const observer = new ReportingObserver(
- reports => {
- collected.push(...reports);
- if (collected.length == nonBufferedReports.length) {
- resolve();
- }
- },
- { buffered: true }
- );
-
- observer.observe();
-
- await collectedAll;
- observer.disconnect();
-
- assert_greater_than(
- collected.length,
- 0,
- "Some reports must be delivered"
- );
-
- // Verify relative ordering by type
- const observedTypes = collected.map(r => r.type);
-
- assert_array_equals(observedTypes, nonBufferedReports.map(r => r.type));
-}, "Buffered ReportingObserver preserves report generation order");
-</script>
-</body>
-</html>
diff --git a/testing/web-platform/tests/reporting/reporting-api-orders-reports-buffered.https.html.sub.headers b/testing/web-platform/tests/reporting/reporting-api-orders-reports-buffered.https.html.sub.headers
@@ -1,7 +0,0 @@
-Expires: Mon, 26 Jul 1997 05:00:00 GMT
-Cache-Control: no-store, no-cache, must-revalidate
-Cache-Control: post-check=0, pre-check=0, false
-Pragma: no-cache
-Set-Cookie: reporting-api-sends-reports-on-violation={{$id:uuid()}}; Path=/content-security-policy/reporting-api
-Reporting-Endpoints: csp-group="https://{{host}}:{{ports[https][0]}}/reporting/resources/report.py?op=put&reportID={{$id}}"
-Content-Security-Policy: script-src 'self' 'unsafe-inline'; img-src 'none'; report-to csp-group