commit 41e840251edfd305b71014c4082566e21aeaf8b6
parent aad24563c3bbf81d2e90b03c568a2da03a6f0491
Author: Denis <dpalmeiro@mozilla.com>
Date: Wed, 8 Oct 2025 15:11:07 +0000
Bug 1987912: Move the dispatch of the pageload event to the PageloadEvent.cpp instead of ContentParent. r=bas
Moving the dispatch keeps the pageload event data, and specifically the domain, within the class so it cannot be modified or read.
Differential Revision: https://phabricator.services.mozilla.com/D264580
Diffstat:
4 files changed, 55 insertions(+), 51 deletions(-)
diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp
@@ -431,9 +431,6 @@ uint32_t ContentParent::sMaxContentProcesses = 0;
/* static */
LogModule* ContentParent::GetLog() { return gProcessLog; }
-/* static */
-uint32_t ContentParent::sPageLoadEventCounter = 0;
-
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
#define NS_IPC_IOSERVICE_SET_CONNECTIVITY_TOPIC "ipc:network:set-connectivity"
@@ -6335,39 +6332,14 @@ mozilla::ipc::IPCResult ContentParent::RecvRecordPageLoadEvent(
aAndroidAppLinkLaunchTypeIdentifier);
#endif
- // If the etld information exists, then we need to send it using a special
+ // If the domain information exists, then we need to send it using a special
// page load event ping that is sent via ohttp and stripped of any information
// that can be used to fingerprint the client. Otherwise, use the regular
// pageload event ping.
if (aPageloadEventData.HasDomain()) {
- // If the event is a page_load_domain event, then immediately send it.
- mozilla::glean::perf::PageLoadDomainExtra extra =
- aPageloadEventData.ToPageLoadDomainExtra();
- mozilla::glean::perf::page_load_domain.Record(mozilla::Some(extra));
-
- // The etld events must be sent by themselves for privacy preserving
- // reasons.
- NS_SUCCEEDED(NS_DispatchToMainThreadQueue(
- NS_NewRunnableFunction(
- "PageloadBaseDomainPingIdleTask",
- [] {
- mozilla::glean_pings::PageloadBaseDomain.Submit("pageload"_ns);
- }),
- EventQueuePriority::Idle));
+ aPageloadEventData.SendAsPageLoadDomainEvent();
} else {
- mozilla::glean::perf::PageLoadExtra extra =
- aPageloadEventData.ToPageLoadExtra();
- mozilla::glean::perf::page_load.Record(mozilla::Some(extra));
-
- // Send the PageLoadPing after every 10 page loads, or on startup.
- if (++sPageLoadEventCounter >= 10) {
- NS_SUCCEEDED(NS_DispatchToMainThreadQueue(
- NS_NewRunnableFunction(
- "PageLoadPingIdleTask",
- [] { mozilla::glean_pings::Pageload.Submit("threshold"_ns); }),
- EventQueuePriority::Idle));
- sPageLoadEventCounter = 0;
- }
+ aPageloadEventData.SendAsPageLoadEvent();
}
return IPC_OK();
}
diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h
@@ -1644,7 +1644,6 @@ class ContentParent final : public PContentParent,
RefPtr<IdleTaskRunner> mMaybeBeginShutdownRunner;
static uint32_t sMaxContentProcesses;
- static uint32_t sPageLoadEventCounter;
bool mIsSignaledImpendingShutdown = false;
bool mIsNotifiedShutdownSuccess = false;
diff --git a/tools/performance/PageloadEvent.cpp b/tools/performance/PageloadEvent.cpp
@@ -10,12 +10,14 @@
#include "mozilla/RandomNum.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/glean/DomMetrics.h"
+#include "mozilla/glean/GleanPings.h"
#include "nsIChannel.h"
#include "nsIEffectiveTLDService.h"
#include "nsITransportSecurityInfo.h"
#include "nsIURI.h"
#include "nsIX509Cert.h"
+#include "nsThreadUtils.h"
#include "ScopedNSSTypes.h"
#include "cert.h"
@@ -23,6 +25,9 @@
namespace mozilla::performance::pageload_event {
+/* static */
+uint32_t PageloadEventData::sPageLoadEventCounter = 0;
+
// We don't want to record an event for every page load, so instead we
// randomly sample the events based on the channel.
//
@@ -253,13 +258,24 @@ bool PageloadEventData::MaybeSetPublicRegistrableDomain(nsCOMPtr<nsIURI> aURI,
return true;
}
-mozilla::glean::perf::PageLoadExtra PageloadEventData::ToPageLoadExtra() const {
- mozilla::glean::perf::PageLoadExtra out;
+void PageloadEventData::SendAsPageLoadEvent() {
+ mozilla::glean::perf::PageLoadExtra extra;
-#define COPY_METRIC(name, type) out.name = this->name;
+#define COPY_METRIC(name, type) extra.name = this->name;
FOR_EACH_PAGELOAD_METRIC(COPY_METRIC)
#undef COPY_METRIC
- return out;
+
+ mozilla::glean::perf::page_load.Record(mozilla::Some(extra));
+
+ // Send the PageLoadPing after every 10 page loads, or on startup.
+ if (++sPageLoadEventCounter >= 10) {
+ NS_SUCCEEDED(NS_DispatchToMainThreadQueue(
+ NS_NewRunnableFunction(
+ "PageLoadPingIdleTask",
+ [] { mozilla::glean_pings::Pageload.Submit("threshold"_ns); }),
+ EventQueuePriority::Idle));
+ sPageLoadEventCounter = 0;
+ }
}
static mozilla::Maybe<uint32_t> AddMultiplicativeNoise(
@@ -281,19 +297,31 @@ static mozilla::Maybe<uint32_t> AddMultiplicativeNoise(
return mozilla::Some(output);
}
-mozilla::glean::perf::PageLoadDomainExtra
-PageloadEventData::ToPageLoadDomainExtra() const {
- mozilla::glean::perf::PageLoadDomainExtra out;
- out.domain = this->mDomain;
- out.httpVer = this->httpVer;
- out.sameOriginNav = this->sameOriginNav;
- out.documentFeatures = this->documentFeatures;
- out.loadType = this->loadType;
+void PageloadEventData::SendAsPageLoadDomainEvent() {
+ MOZ_ASSERT(HasDomain());
- // Add some noise to any numerical metrics.
- out.lcpTime = AddMultiplicativeNoise(this->lcpTime);
+ mozilla::glean::perf::PageLoadDomainExtra extra;
+ extra.domain = this->mDomain;
+ extra.httpVer = this->httpVer;
+ extra.sameOriginNav = this->sameOriginNav;
+ extra.documentFeatures = this->documentFeatures;
+ extra.loadType = this->loadType;
- return out;
+ // Add some noise to any numerical metrics.
+ extra.lcpTime = AddMultiplicativeNoise(this->lcpTime);
+
+ // If the event is a page_load_domain event, then immediately send it.
+ mozilla::glean::perf::page_load_domain.Record(mozilla::Some(extra));
+
+ // The etld events must be sent by themselves for privacy preserving
+ // reasons.
+ NS_SUCCEEDED(NS_DispatchToMainThreadQueue(
+ NS_NewRunnableFunction("PageloadBaseDomainPingIdleTask",
+ [] {
+ mozilla::glean_pings::PageloadBaseDomain.Submit(
+ "pageload"_ns);
+ }),
+ EventQueuePriority::Idle));
}
} // namespace mozilla::performance::pageload_event
diff --git a/tools/performance/PageloadEvent.h b/tools/performance/PageloadEvent.h
@@ -89,22 +89,27 @@ class PageloadEventData {
// Define ETLD separately since we want a special setter for it.
mozilla::Maybe<nsCString> mDomain;
+ // Number of page loads after which a normal pageload ping is sent.
+ static uint32_t sPageLoadEventCounter;
+
public:
// Define a setter for every member.
FOR_EACH_PAGELOAD_METRIC(DEFINE_SETTER)
bool MaybeSetPublicRegistrableDomain(nsCOMPtr<nsIURI> aURI,
nsIChannel* aChannel);
- bool HasDomain() { return mDomain.isSome() && !mDomain.value().IsEmpty(); }
+ bool HasDomain() const {
+ return mDomain.isSome() && !mDomain.value().IsEmpty();
+ }
- bool HasLoadTime() { return loadTime.isSome(); }
+ bool HasLoadTime() const { return loadTime.isSome(); }
// Define setters for the individual bit features.
void SetUserFeature(UserFeature aFeature);
void SetDocumentFeature(DocumentFeature aFeature);
- mozilla::glean::perf::PageLoadExtra ToPageLoadExtra() const;
- mozilla::glean::perf::PageLoadDomainExtra ToPageLoadDomainExtra() const;
+ void SendAsPageLoadEvent();
+ void SendAsPageLoadDomainEvent();
};
#undef DEFINE_METRIC
#undef DEFINE_SETTER