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
;
51 bool mIncludeSubdomains
;
53 TimeStamp mCreationTime
;
54 nsTObserverArray
<Endpoint
> mEndpoints
;
58 nsTObserverArray
<Group
> mGroups
;
61 static UniquePtr
<Client
> ParseHeader(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
62 const nsACString
& aHeaderValue
);
64 static void GetEndpointForReport(
65 const nsAString
& aGroupName
,
66 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
,
67 nsACString
& aEndpointURI
);
69 static void GetEndpointForReport(const nsAString
& aGroupName
,
70 nsIPrincipal
* aPrincipal
,
71 nsACString
& aEndpointURI
);
73 static void RemoveEndpoint(const nsAString
& aGroupName
,
74 const nsACString
& aEndpointURL
,
75 const mozilla::ipc::PrincipalInfo
& aPrincipalInfo
);
77 // ChromeOnly-WebIDL methods
79 static bool HasReportingHeaderForOrigin(const nsACString
& aOrigin
);
85 static void Shutdown();
87 // Checks if a channel contains a Report-To header and parses its value.
88 void ReportingFromChannel(nsIHttpChannel
* aChannel
);
90 // This method checks if the protocol handler of the URI has the
91 // URI_IS_POTENTIALLY_TRUSTWORTHY flag.
92 bool IsSecureURI(nsIURI
* aURI
) const;
94 void RemoveOriginsFromHost(const nsAString
& aHost
);
96 void RemoveOriginsFromOriginAttributesPattern(
97 const OriginAttributesPattern
& aPattern
);
101 void RemoveOriginsForTTL();
103 void MaybeCreateCleanupTimer();
105 void MaybeCancelCleanupTimer();
107 static void LogToConsoleInvalidJSON(nsIHttpChannel
* aChannel
, nsIURI
* aURI
);
109 static void LogToConsoleDuplicateGroup(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
110 const nsAString
& aName
);
112 static void LogToConsoleInvalidNameItem(nsIHttpChannel
* aChannel
,
115 static void LogToConsoleIncompleteItem(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
116 const nsAString
& aName
);
118 static void LogToConsoleIncompleteEndpoint(nsIHttpChannel
* aChannel
,
120 const nsAString
& aName
);
122 static void LogToConsoleInvalidURLEndpoint(nsIHttpChannel
* aChannel
,
124 const nsAString
& aName
,
125 const nsAString
& aURL
);
127 static void LogToConsoleInternal(nsIHttpChannel
* aChannel
, nsIURI
* aURI
,
129 const nsTArray
<nsString
>& aParams
);
131 static void GetEndpointForReportInternal(const ReportingHeader::Group
& aGrup
,
132 nsACString
& aEndpointURI
);
134 nsClassHashtable
<nsCStringHashKey
, Client
> mOrigins
;
136 nsCOMPtr
<nsITimer
> mCleanupTimer
;
140 } // namespace mozilla
142 #endif // mozilla_dom_ReportingHeader_h