Files
tubestation/toolkit/components/cookiebanners/nsCookieInjector.h
Paul Zuehlcke 1839ee5ae5 Bug 1783019 - Implement cookie banner handling components. r=timhuang,necko-reviewers,valentin
This patch adds the following components:
 - nsICookieBannerService: Main service singleton managing the rules and initiating other components.
   It's exposed via Services.cookieBanners and can be configured via the cookiebanners.* prefs.
   To enable it set "cookiebanners.service.mode" to 1 or 2 and restart the browser.
 - nsCookieInjector: Looks up rules and injects cookies for matching top level loads.
 - nsICookieBannerListService: Imports and updates the cookie banner rules.
 - nsICookieBannerRule: Rules for a given domain.
 - nsICookieRule: Part of nsICookieBannerRule. Holds cookie specific rules.

Depends on D153641

Differential Revision: https://phabricator.services.mozilla.com/D153642
2022-08-16 12:07:13 +00:00

48 lines
1.4 KiB
C++

/* 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_nsCookieInjector_h__
#define mozilla_nsCookieInjector_h__
#include "nsCOMPtr.h"
#include "nsICookieBannerRule.h"
#include "nsIHttpChannel.h"
#include "nsIObserver.h"
namespace mozilla {
class nsCookieInjector final : public nsIObserver {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static already_AddRefed<nsCookieInjector> GetSingleton();
[[nodiscard]] nsresult Init();
[[nodiscard]] nsresult Shutdown();
private:
nsCookieInjector() = default;
~nsCookieInjector() = default;
// Whether the component is enabled and ready to inject cookies.
bool mIsInitialized = false;
// Enables or disables the component when the relevant prefs change.
static void OnPrefChange(const char* aPref, void* aData);
// Called when the http observer topic is dispatched.
nsresult MaybeInjectCookies(nsIHttpChannel* aChannel, const char* aTopic);
// Inserts cookies via the cookie manager given a list of cookie injection
// rules.
nsresult InjectCookiesFromRules(const nsCString& aHostPort,
const nsTArray<RefPtr<nsICookieRule>>& aRules,
OriginAttributes& aOriginAttributes);
};
} // namespace mozilla
#endif