2017-02-22 12:01:43 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
#ifndef ExpandedPrincipal_h
|
|
|
|
#define ExpandedPrincipal_h
|
2017-02-22 12:01:43 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsJSPrincipals.h"
|
2022-12-02 03:53:50 +03:00
|
|
|
#include "nsProxyRelease.h"
|
2017-02-22 12:01:43 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "mozilla/BasePrincipal.h"
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
class nsIContentSecurityPolicy;
|
|
|
|
|
2024-01-26 18:39:38 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class JSONWriter;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
class ExpandedPrincipal : public nsIExpandedPrincipal,
|
|
|
|
public mozilla::BasePrincipal {
|
2017-02-25 01:02:24 +03:00
|
|
|
public:
|
2017-03-22 13:38:17 +03:00
|
|
|
static already_AddRefed<ExpandedPrincipal> Create(
|
2021-11-26 18:51:13 +03:00
|
|
|
const nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
|
2017-02-25 01:02:24 +03:00
|
|
|
const mozilla::OriginAttributes& aAttrs);
|
|
|
|
|
2017-04-16 23:32:42 +03:00
|
|
|
static PrincipalKind Kind() { return eExpandedPrincipal; }
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_DECL_NSIEXPANDEDPRINCIPAL
|
2017-03-22 13:38:17 +03:00
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
|
|
|
|
return nsJSPrincipals::AddRef();
|
|
|
|
};
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release() override {
|
|
|
|
return nsJSPrincipals::Release();
|
|
|
|
};
|
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
|
2018-11-20 04:17:52 +03:00
|
|
|
uint32_t GetHashValue() override;
|
2017-02-22 12:01:43 +03:00
|
|
|
NS_IMETHOD GetURI(nsIURI** aURI) override;
|
|
|
|
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
|
|
|
|
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
|
|
|
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
2016-11-06 08:38:17 +03:00
|
|
|
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
|
2020-05-13 19:50:19 +03:00
|
|
|
NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual bool AddonHasPermission(const nsAtom* aPerm) override;
|
2017-02-22 12:01:43 +03:00
|
|
|
virtual nsresult GetScriptLocation(nsACString& aStr) override;
|
|
|
|
|
2018-04-04 17:54:26 +03:00
|
|
|
bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
void SetCsp(nsIContentSecurityPolicy* aCSP);
|
|
|
|
|
2017-11-03 05:56:27 +03:00
|
|
|
// Returns the principal to inherit when this principal requests the given
|
|
|
|
// URL. See BasePrincipal::PrincipalToInherit.
|
2017-11-23 01:20:26 +03:00
|
|
|
nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
|
2017-11-03 05:56:27 +03:00
|
|
|
|
2018-09-11 12:01:14 +03:00
|
|
|
nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
|
|
|
|
|
2024-01-26 18:39:38 +03:00
|
|
|
virtual nsresult WriteJSONInnerProperties(
|
|
|
|
mozilla::JSONWriter& aWriter) override;
|
|
|
|
|
2019-06-03 15:37:12 +03:00
|
|
|
// Serializable keys are the valid enum fields the serialization supports
|
2019-12-04 01:20:03 +03:00
|
|
|
enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
|
2019-06-03 15:37:12 +03:00
|
|
|
|
2024-01-26 18:39:39 +03:00
|
|
|
static constexpr char SpecsKey = '0';
|
|
|
|
static_assert(eSpecs == 0);
|
|
|
|
static constexpr char SuffixKey = '1';
|
|
|
|
static_assert(eSuffix == 1);
|
2023-02-14 13:17:16 +03:00
|
|
|
|
2021-05-17 23:50:09 +03:00
|
|
|
class Deserializer : public BasePrincipal::Deserializer {
|
|
|
|
public:
|
|
|
|
NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
|
|
|
|
};
|
|
|
|
|
2017-02-22 12:01:43 +03:00
|
|
|
protected:
|
2021-05-17 23:50:09 +03:00
|
|
|
explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals,
|
|
|
|
const nsACString& aOriginNoSuffix,
|
|
|
|
const mozilla::OriginAttributes& aAttrs);
|
2017-03-29 09:21:03 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
virtual ~ExpandedPrincipal();
|
|
|
|
|
|
|
|
bool SubsumesInternal(nsIPrincipal* aOther,
|
|
|
|
DocumentDomainConsideration aConsideration) override;
|
2017-02-22 12:01:43 +03:00
|
|
|
|
|
|
|
bool MayLoadInternal(nsIURI* aURI) override;
|
|
|
|
|
|
|
|
private:
|
2021-05-17 23:50:09 +03:00
|
|
|
const nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
|
2022-12-02 03:53:50 +03:00
|
|
|
nsMainThreadPtrHandle<nsIContentSecurityPolicy> mCSP
|
|
|
|
MOZ_GUARDED_BY(mozilla::sMainThreadCapability);
|
2017-02-22 12:01:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_EXPANDEDPRINCIPAL_CID \
|
2018-11-30 13:46:48 +03:00
|
|
|
{ \
|
2017-02-22 12:01:43 +03:00
|
|
|
0xe8ee88b0, 0x5571, 0x4086, { \
|
|
|
|
0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
|
|
|
|
} \
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-22 13:38:17 +03:00
|
|
|
#endif // ExpandedPrincipal_h
|