2018-12-01 23:26:08 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ReportingHeader_h
|
|
|
|
#define mozilla_dom_ReportingHeader_h
|
|
|
|
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsIObserver.h"
|
2018-12-01 23:26:10 +03:00
|
|
|
#include "nsITimer.h"
|
2018-12-01 23:26:09 +03:00
|
|
|
#include "nsTObserverArray.h"
|
2018-12-01 23:26:08 +03:00
|
|
|
|
|
|
|
class nsIHttpChannel;
|
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIURI;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2018-12-01 23:26:09 +03:00
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
class OriginAttributesPattern;
|
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2018-12-01 23:26:08 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2018-12-01 23:26:10 +03:00
|
|
|
class ReportingHeader final : public nsIObserver, public nsITimerCallback {
|
2018-12-01 23:26:08 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2018-12-01 23:26:10 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2018-12-01 23:26:08 +03:00
|
|
|
|
|
|
|
static void Initialize();
|
|
|
|
|
|
|
|
// Exposed structs for gtests
|
|
|
|
|
|
|
|
struct Endpoint {
|
|
|
|
nsCOMPtr<nsIURI> mUrl;
|
|
|
|
uint32_t mPriority;
|
|
|
|
uint32_t mWeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Group {
|
|
|
|
nsString mName;
|
|
|
|
bool mIncludeSubdomains;
|
|
|
|
int32_t mTTL;
|
|
|
|
TimeStamp mCreationTime;
|
2018-12-01 23:26:09 +03:00
|
|
|
nsTObserverArray<Endpoint> mEndpoints;
|
2018-12-01 23:26:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Client {
|
2018-12-01 23:26:09 +03:00
|
|
|
nsTObserverArray<Group> mGroups;
|
2018-12-01 23:26:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static UniquePtr<Client> ParseHeader(nsIHttpChannel* aChannel, nsIURI* aURI,
|
|
|
|
const nsACString& aHeaderValue);
|
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
static void GetEndpointForReport(
|
|
|
|
const nsAString& aGroupName,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
|
|
|
nsACString& aEndpointURI);
|
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
static void RemoveEndpoint(const nsAString& aGroupName,
|
|
|
|
const nsACString& aEndpointURL,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
|
|
|
|
2018-12-01 23:26:10 +03:00
|
|
|
// ChromeOnly-WebIDL methods
|
|
|
|
|
|
|
|
static bool HasReportingHeaderForOrigin(const nsACString& aOrigin);
|
|
|
|
|
2018-12-01 23:26:08 +03:00
|
|
|
private:
|
|
|
|
ReportingHeader();
|
|
|
|
~ReportingHeader();
|
|
|
|
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
// Checks if a channel contains a Report-To header and parses its value.
|
|
|
|
void ReportingFromChannel(nsIHttpChannel* aChannel);
|
|
|
|
|
|
|
|
// This method checks if the protocol handler of the URI has the
|
|
|
|
// URI_IS_POTENTIALLY_TRUSTWORTHY flag.
|
|
|
|
bool IsSecureURI(nsIURI* aURI) const;
|
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
void RemoveOriginsFromHost(const nsAString& aHost);
|
|
|
|
|
|
|
|
void RemoveOriginsFromOriginAttributesPattern(
|
|
|
|
const OriginAttributesPattern& aPattern);
|
|
|
|
|
|
|
|
void RemoveOrigins();
|
|
|
|
|
2018-12-01 23:26:10 +03:00
|
|
|
void RemoveOriginsForTTL();
|
|
|
|
|
|
|
|
void MaybeCreateCleanupTimer();
|
|
|
|
|
|
|
|
void MaybeCancelCleanupTimer();
|
|
|
|
|
2018-12-01 23:26:08 +03:00
|
|
|
static void LogToConsoleInvalidJSON(nsIHttpChannel* aChannel, nsIURI* aURI);
|
|
|
|
|
|
|
|
static void LogToConsoleDuplicateGroup(nsIHttpChannel* aChannel, nsIURI* aURI,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
|
|
|
static void LogToConsoleInvalidNameItem(nsIHttpChannel* aChannel,
|
|
|
|
nsIURI* aURI);
|
|
|
|
|
|
|
|
static void LogToConsoleIncompleteItem(nsIHttpChannel* aChannel, nsIURI* aURI,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
|
|
|
static void LogToConsoleIncompleteEndpoint(nsIHttpChannel* aChannel,
|
|
|
|
nsIURI* aURI,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
|
|
|
static void LogToConsoleInvalidURLEndpoint(nsIHttpChannel* aChannel,
|
|
|
|
nsIURI* aURI,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aURL);
|
|
|
|
|
|
|
|
static void LogToConsoleInternal(nsIHttpChannel* aChannel, nsIURI* aURI,
|
|
|
|
const char* aMsg,
|
|
|
|
const nsTArray<nsString>& aParams);
|
|
|
|
|
2018-12-01 23:26:09 +03:00
|
|
|
static void GetEndpointForReportInternal(const ReportingHeader::Group& aGrup,
|
|
|
|
nsACString& aEndpointURI);
|
|
|
|
|
2018-12-01 23:26:08 +03:00
|
|
|
nsClassHashtable<nsCStringHashKey, Client> mOrigins;
|
2018-12-01 23:26:10 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimer> mCleanupTimer;
|
2018-12-01 23:26:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ReportingHeader_h
|