1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef ExpandedPrincipal_h
7 #define ExpandedPrincipal_h
10 #include "nsJSPrincipals.h"
11 #include "nsProxyRelease.h"
13 #include "nsNetUtil.h"
14 #include "mozilla/BasePrincipal.h"
16 class nsIContentSecurityPolicy
;
20 } // namespace mozilla
22 class ExpandedPrincipal
: public nsIExpandedPrincipal
,
23 public mozilla::BasePrincipal
{
25 static already_AddRefed
<ExpandedPrincipal
> Create(
26 const nsTArray
<nsCOMPtr
<nsIPrincipal
>>& aAllowList
,
27 const mozilla::OriginAttributes
& aAttrs
);
29 static PrincipalKind
Kind() { return eExpandedPrincipal
; }
31 NS_DECL_NSIEXPANDEDPRINCIPAL
33 NS_IMETHOD_(MozExternalRefCountType
) AddRef() override
{
34 return nsJSPrincipals::AddRef();
36 NS_IMETHOD_(MozExternalRefCountType
) Release() override
{
37 return nsJSPrincipals::Release();
39 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) override
;
40 uint32_t GetHashValue() override
;
41 NS_IMETHOD
GetURI(nsIURI
** aURI
) override
;
42 NS_IMETHOD
GetDomain(nsIURI
** aDomain
) override
;
43 NS_IMETHOD
SetDomain(nsIURI
* aDomain
) override
;
44 NS_IMETHOD
GetBaseDomain(nsACString
& aBaseDomain
) override
;
45 NS_IMETHOD
GetAddonId(nsAString
& aAddonId
) override
;
46 NS_IMETHOD
IsThirdPartyURI(nsIURI
* uri
, bool* aRes
) override
;
47 virtual bool AddonHasPermission(const nsAtom
* aPerm
) override
;
48 virtual nsresult
GetScriptLocation(nsACString
& aStr
) override
;
50 bool AddonAllowsLoad(nsIURI
* aURI
, bool aExplicit
= false);
52 void SetCsp(nsIContentSecurityPolicy
* aCSP
);
54 // Returns the principal to inherit when this principal requests the given
55 // URL. See BasePrincipal::PrincipalToInherit.
56 nsIPrincipal
* PrincipalToInherit(nsIURI
* aRequestedURI
= nullptr);
58 nsresult
GetSiteIdentifier(mozilla::SiteIdentifier
& aSite
) override
;
60 virtual nsresult
WriteJSONInnerProperties(
61 mozilla::JSONWriter
& aWriter
) override
;
63 // Serializable keys are the valid enum fields the serialization supports
64 enum SerializableKeys
: uint8_t { eSpecs
= 0, eSuffix
, eMax
= eSuffix
};
66 static constexpr char SpecsKey
= '0';
67 static_assert(eSpecs
== 0);
68 static constexpr char SuffixKey
= '1';
69 static_assert(eSuffix
== 1);
71 class Deserializer
: public BasePrincipal::Deserializer
{
73 NS_IMETHOD
Read(nsIObjectInputStream
* aStream
) override
;
77 explicit ExpandedPrincipal(nsTArray
<nsCOMPtr
<nsIPrincipal
>>&& aPrincipals
,
78 const nsACString
& aOriginNoSuffix
,
79 const mozilla::OriginAttributes
& aAttrs
);
81 virtual ~ExpandedPrincipal();
83 bool SubsumesInternal(nsIPrincipal
* aOther
,
84 DocumentDomainConsideration aConsideration
) override
;
86 bool MayLoadInternal(nsIURI
* aURI
) override
;
89 const nsTArray
<nsCOMPtr
<nsIPrincipal
>> mPrincipals
;
90 nsMainThreadPtrHandle
<nsIContentSecurityPolicy
> mCSP
91 MOZ_GUARDED_BY(mozilla::sMainThreadCapability
);
94 #define NS_EXPANDEDPRINCIPAL_CID \
96 0xe8ee88b0, 0x5571, 0x4086, { \
97 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
101 #endif // ExpandedPrincipal_h