1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ReportingHeader_h
8 #define mozilla_dom_ReportingHeader_h
10 #include "mozilla/TimeStamp.h"
11 #include "nsClassHashtable.h"
12 #include "nsIObserver.h"
14 #include "nsTObserverArray.h"
22 class OriginAttributesPattern
;
30 class ReportingHeader final
: public nsIObserver
,
31 public nsITimerCallback
,
36 NS_DECL_NSITIMERCALLBACK
39 static void Initialize();
41 // Exposed structs for gtests
44 nsCOMPtr
<nsIURI
> mUrl
;
45 nsCString mEndpointName
;
53 bool mIncludeSubdomains
;
55 TimeStamp mCreationTime
;
56 nsTObserverArray
<Endpoint
> mEndpoints
;
60 nsTObserverArray
<Group
> mGroups
;
63 // Parses the Reporting-Endpoints of a given header according to the algorithm
64 // in https://www.w3.org/TR/reporting-1/#header
65 static UniquePtr
<Client
> ParseReportingEndpointsHeader(
66 const nsACString
& aHeaderValue
, nsIURI
* aURI
);
68 // [Deprecated] Parses the contents of a given header according to the
69 // algorithm in https://www.w3.org/TR/2018/WD-reporting-1-20180925/#header
70 static UniquePtr
<Client
> ParseReportToHeader(nsIHttpChannel
* aChannel
,
72 const nsACString
& aHeaderValue
);
74 static void GetEndpointForReport(
75 const nsAString
& aGroupName
,
76 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
,
77 nsACString
& aEndpointURI
);
79 static void GetEndpointForReport(const nsAString
& aGroupName
,
80 nsIPrincipal
* aPrincipal
,
81 nsACString
& aEndpointURI
);
83 static void RemoveEndpoint(const nsAString
& aGroupName
,
84 const nsACString
& aEndpointURL
,
85 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
);
87 // ChromeOnly-WebIDL methods
89 static bool HasReportingHeaderForOrigin(const nsACString
& aOrigin
);
95 static void Shutdown();
97 // Checks if a channel contains a Report-To header and parses its value.
98 void ReportingFromChannel(nsIHttpChannel
* aChannel
);
100 // This method checks if the protocol handler of the URI has the
101 // URI_IS_POTENTIALLY_TRUSTWORTHY flag.
102 static bool IsSecureURI(nsIURI
* aURI
);
104 void RemoveOriginsFromHost(const nsAString
& aHost
);
106 void RemoveOriginsFromOriginAttributesPattern(
107 const OriginAttributesPattern
& aPattern
);
109 void RemoveOrigins();
111 void RemoveOriginsForTTL();
113 void MaybeCreateCleanupTimer();
115 void MaybeCancelCleanupTimer();
117 static void LogToConsoleInvalidJSON(nsIHttpChannel
* aChannel
, nsIURI
* aURI
);
119 static void LogToConsoleDuplicateGroup(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
120 const nsAString
& aName
);
122 static void LogToConsoleInvalidNameItem(nsIHttpChannel
* aChannel
,
125 static void LogToConsoleIncompleteItem(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
126 const nsAString
& aName
);
128 static void LogToConsoleIncompleteEndpoint(nsIHttpChannel
* aChannel
,
130 const nsAString
& aName
);
132 static void LogToConsoleInvalidURLEndpoint(nsIHttpChannel
* aChannel
,
134 const nsAString
& aName
,
135 const nsAString
& aURL
);
137 static void LogToConsoleInternal(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
139 const nsTArray
<nsString
>& aParams
);
141 static void GetEndpointForReportInternal(const ReportingHeader::Group
& aGrup
,
142 nsACString
& aEndpointURI
);
144 nsClassHashtable
<nsCStringHashKey
, Client
> mOrigins
;
146 nsCOMPtr
<nsITimer
> mCleanupTimer
;
150 } // namespace mozilla
152 #endif // mozilla_dom_ReportingHeader_h