diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index ff407ccfabd7..3c0862bc5538 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -19,6 +19,7 @@ #include "mozilla/TimeStamp.h" #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/IdleDeadline.h" +#include "mozilla/dom/ReportingHeader.h" #include "mozilla/dom/UnionTypes.h" #include "mozilla/dom/WindowBinding.h" // For IdleRequestCallback/Options #include "IOActivityMonitor.h" @@ -726,5 +727,16 @@ constexpr auto kSkipSelfHosted = JS::SavedFrameSelfHosted::Exclude; BrowsingContext::GetRootBrowsingContexts(aBrowsingContexts); } +/* static */ bool ChromeUtils::HasReportingHeaderForOrigin( + GlobalObject& global, const nsAString& aOrigin, ErrorResult& aRv) { + if (!XRE_IsParentProcess()) { + aRv.Throw(NS_ERROR_FAILURE); + return false; + } + + return ReportingHeader::HasReportingHeaderForOrigin( + NS_ConvertUTF16toUTF8(aOrigin)); +} + } // namespace dom } // namespace mozilla diff --git a/dom/base/ChromeUtils.h b/dom/base/ChromeUtils.h index 8308f6af4a1e..16525b3a4e5d 100644 --- a/dom/base/ChromeUtils.h +++ b/dom/base/ChromeUtils.h @@ -165,6 +165,10 @@ class ChromeUtils { static void GetRootBrowsingContexts( GlobalObject& aGlobal, nsTArray>& aBrowsingContexts); + + static bool HasReportingHeaderForOrigin(GlobalObject& global, + const nsAString& aOrigin, + ErrorResult& aRv); }; } // namespace dom diff --git a/dom/chrome-webidl/ChromeUtils.webidl b/dom/chrome-webidl/ChromeUtils.webidl index b555d7feb366..20b67c6f3b92 100644 --- a/dom/chrome-webidl/ChromeUtils.webidl +++ b/dom/chrome-webidl/ChromeUtils.webidl @@ -364,6 +364,9 @@ partial namespace ChromeUtils { */ [ChromeOnly] sequence getRootBrowsingContexts(); + + [ChromeOnly, Throws] + boolean hasReportingHeaderForOrigin(DOMString aOrigin); }; /** diff --git a/dom/reporting/ReportingHeader.cpp b/dom/reporting/ReportingHeader.cpp index d9eaa019e32e..5a082c1b86a0 100644 --- a/dom/reporting/ReportingHeader.cpp +++ b/dom/reporting/ReportingHeader.cpp @@ -653,6 +653,15 @@ void ReportingHeader::RemoveOriginsFromOriginAttributesPattern( void ReportingHeader::RemoveOrigins() { mOrigins.Clear(); } +/* static */ bool ReportingHeader::HasReportingHeaderForOrigin( + const nsACString& aOrigin) { + if (!gReporting) { + return false; + } + + return gReporting->mOrigins.Contains(aOrigin); +} + NS_INTERFACE_MAP_BEGIN(ReportingHeader) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver) NS_INTERFACE_MAP_ENTRY(nsIObserver) diff --git a/dom/reporting/ReportingHeader.h b/dom/reporting/ReportingHeader.h index dd3817d46f94..31ebb3e59533 100644 --- a/dom/reporting/ReportingHeader.h +++ b/dom/reporting/ReportingHeader.h @@ -65,6 +65,10 @@ class ReportingHeader final : public nsIObserver { const nsACString& aEndpointURL, const mozilla::ipc::PrincipalInfo& aPrincipalInfo); + // ChromeOnly-WebIDL methods + + static bool HasReportingHeaderForOrigin(const nsACString& aOrigin); + private: ReportingHeader(); ~ReportingHeader();