Bug 1855780 - Generate INVALID_ENUM in ProvokingVertex for bad `mode`. r=gfx-reviewer...
[gecko.git] / caps / ExpandedPrincipal.h
blob748a0c41385d2ae081ec432fecaa12689805d921
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
9 #include "nsCOMPtr.h"
10 #include "nsJSPrincipals.h"
11 #include "nsProxyRelease.h"
12 #include "nsTArray.h"
13 #include "nsNetUtil.h"
14 #include "mozilla/BasePrincipal.h"
16 class nsIContentSecurityPolicy;
18 namespace Json {
19 class Value;
22 class ExpandedPrincipal : public nsIExpandedPrincipal,
23 public mozilla::BasePrincipal {
24 public:
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 PopulateJSONObject(Json::Value& aObject) override;
61 // Serializable keys are the valid enum fields the serialization supports
62 enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
63 typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
65 // This is the legacy serializer for expanded principals. See note for
66 // `IsLegacyFormat` in BasePrincipal.cpp.
67 static already_AddRefed<BasePrincipal> FromProperties(
68 nsTArray<ExpandedPrincipal::KeyVal>& aFields);
70 // This is the new serializer for expanded principals. See note for
71 // `IsLegacyFormat` in BasePrincipal.cpp.
72 static already_AddRefed<BasePrincipal> FromProperties(
73 const Json::Value& aJSON);
75 class Deserializer : public BasePrincipal::Deserializer {
76 public:
77 NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
80 protected:
81 explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals,
82 const nsACString& aOriginNoSuffix,
83 const mozilla::OriginAttributes& aAttrs);
85 virtual ~ExpandedPrincipal();
87 bool SubsumesInternal(nsIPrincipal* aOther,
88 DocumentDomainConsideration aConsideration) override;
90 bool MayLoadInternal(nsIURI* aURI) override;
92 private:
93 const nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
94 nsMainThreadPtrHandle<nsIContentSecurityPolicy> mCSP
95 MOZ_GUARDED_BY(mozilla::sMainThreadCapability);
98 #define NS_EXPANDEDPRINCIPAL_CID \
99 { \
100 0xe8ee88b0, 0x5571, 0x4086, { \
101 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
105 #endif // ExpandedPrincipal_h