Bug 1771540 [wpt PR 34240] - FSA: EnforceRange on FileSystemReadWriteOptions.at,...
[gecko.git] / caps / ExpandedPrincipal.h
blob3df4aff5d5d10cd966a4d5ffb085000bfcdf8e9c
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 "nsTArray.h"
12 #include "nsNetUtil.h"
13 #include "mozilla/BasePrincipal.h"
15 class nsIContentSecurityPolicy;
17 namespace Json {
18 class Value;
21 class ExpandedPrincipal : public nsIExpandedPrincipal,
22 public mozilla::BasePrincipal {
23 public:
24 static already_AddRefed<ExpandedPrincipal> Create(
25 const nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
26 const mozilla::OriginAttributes& aAttrs);
28 static PrincipalKind Kind() { return eExpandedPrincipal; }
30 NS_DECL_NSIEXPANDEDPRINCIPAL
32 NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
33 return nsJSPrincipals::AddRef();
35 NS_IMETHOD_(MozExternalRefCountType) Release() override {
36 return nsJSPrincipals::Release();
38 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
39 uint32_t GetHashValue() override;
40 NS_IMETHOD GetURI(nsIURI** aURI) override;
41 NS_IMETHOD GetDomain(nsIURI** aDomain) override;
42 NS_IMETHOD SetDomain(nsIURI* aDomain) override;
43 NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
44 NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
45 NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
46 virtual bool AddonHasPermission(const nsAtom* aPerm) override;
47 virtual nsresult GetScriptLocation(nsACString& aStr) override;
49 bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
51 void SetCsp(nsIContentSecurityPolicy* aCSP);
53 // Returns the principal to inherit when this principal requests the given
54 // URL. See BasePrincipal::PrincipalToInherit.
55 nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
57 nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
59 virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
60 // Serializable keys are the valid enum fields the serialization supports
61 enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
62 typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
64 static already_AddRefed<BasePrincipal> FromProperties(
65 nsTArray<ExpandedPrincipal::KeyVal>& aFields);
67 class Deserializer : public BasePrincipal::Deserializer {
68 public:
69 NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
72 protected:
73 explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>&& aPrincipals,
74 const nsACString& aOriginNoSuffix,
75 const mozilla::OriginAttributes& aAttrs);
77 virtual ~ExpandedPrincipal();
79 bool SubsumesInternal(nsIPrincipal* aOther,
80 DocumentDomainConsideration aConsideration) override;
82 bool MayLoadInternal(nsIURI* aURI) override;
84 private:
85 const nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
86 nsCOMPtr<nsIContentSecurityPolicy> mCSP;
89 #define NS_EXPANDEDPRINCIPAL_CID \
90 { \
91 0xe8ee88b0, 0x5571, 0x4086, { \
92 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
93 } \
96 #endif // ExpandedPrincipal_h