no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / reporting / ReportingHeader.h
blobd0db5f612b3e4ccfccfc7c573dfba4c1c615927a
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"
13 #include "nsITimer.h"
14 #include "nsTObserverArray.h"
16 class nsIHttpChannel;
17 class nsIPrincipal;
18 class nsIURI;
20 namespace mozilla {
22 class OriginAttributesPattern;
24 namespace ipc {
25 class PrincipalInfo;
28 namespace dom {
30 class ReportingHeader final : public nsIObserver,
31 public nsITimerCallback,
32 public nsINamed {
33 public:
34 NS_DECL_ISUPPORTS
35 NS_DECL_NSIOBSERVER
36 NS_DECL_NSITIMERCALLBACK
37 NS_DECL_NSINAMED
39 static void Initialize();
41 // Exposed structs for gtests
43 struct Endpoint {
44 nsCOMPtr<nsIURI> mUrl;
45 uint32_t mPriority;
46 uint32_t mWeight;
49 struct Group {
50 nsString mName;
51 bool mIncludeSubdomains;
52 int32_t mTTL;
53 TimeStamp mCreationTime;
54 nsTObserverArray<Endpoint> mEndpoints;
57 struct Client {
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);
81 private:
82 ReportingHeader();
83 ~ReportingHeader();
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);
99 void RemoveOrigins();
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,
113 nsIURI* aURI);
115 static void LogToConsoleIncompleteItem(nsIHttpChannel* aChannel, nsIURI* aURI,
116 const nsAString& aName);
118 static void LogToConsoleIncompleteEndpoint(nsIHttpChannel* aChannel,
119 nsIURI* aURI,
120 const nsAString& aName);
122 static void LogToConsoleInvalidURLEndpoint(nsIHttpChannel* aChannel,
123 nsIURI* aURI,
124 const nsAString& aName,
125 const nsAString& aURL);
127 static void LogToConsoleInternal(nsIHttpChannel* aChannel, nsIURI* aURI,
128 const char* aMsg,
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;
139 } // namespace dom
140 } // namespace mozilla
142 #endif // mozilla_dom_ReportingHeader_h