Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / caps / ExpandedPrincipal.h
blob0981f9df70e9c81b32d32d52fff1195b83536350
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 mozilla {
19 class JSONWriter;
20 } // namespace mozilla
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 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 {
72 public:
73 NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
76 protected:
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;
88 private:
89 const nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
90 nsMainThreadPtrHandle<nsIContentSecurityPolicy> mCSP
91 MOZ_GUARDED_BY(mozilla::sMainThreadCapability);
94 #define NS_EXPANDEDPRINCIPAL_CID \
95 { \
96 0xe8ee88b0, 0x5571, 0x4086, { \
97 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
98 } \
101 #endif // ExpandedPrincipal_h