Bug 1595199 - Make nsGfxScrollFrame propagate ReflowInput's mFlags.mIsBResizeForPerce...
[gecko.git] / caps / ExpandedPrincipal.h
blob98ff40437f4dd079ecf941a74b3eff201bbea9e2
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 nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList,
26 const mozilla::OriginAttributes& aAttrs);
28 static PrincipalKind Kind() { return eExpandedPrincipal; }
30 // For use from the XPCOM factory constructor only. Do not ever use this
31 // constructor by hand!
32 ExpandedPrincipal();
34 NS_DECL_NSIEXPANDEDPRINCIPAL
35 NS_DECL_NSISERIALIZABLE
37 NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
38 return nsJSPrincipals::AddRef();
40 NS_IMETHOD_(MozExternalRefCountType) Release() override {
41 return nsJSPrincipals::Release();
43 NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
44 uint32_t GetHashValue() override;
45 NS_IMETHOD GetURI(nsIURI** aURI) override;
46 NS_IMETHOD GetDomain(nsIURI** aDomain) override;
47 NS_IMETHOD SetDomain(nsIURI* aDomain) override;
48 NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
49 NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
50 virtual bool AddonHasPermission(const nsAtom* aPerm) override;
51 virtual nsresult GetScriptLocation(nsACString& aStr) override;
53 bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
55 void SetCsp(nsIContentSecurityPolicy* aCSP);
57 // Returns the principal to inherit when this principal requests the given
58 // URL. See BasePrincipal::PrincipalToInherit.
59 nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
61 nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
63 virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
64 // Serializable keys are the valid enum fields the serialization supports
65 enum SerializableKeys { eSpecs = 0, eSuffix, eMax = eSuffix };
66 // KeyVal is a lightweight storage that passes
67 // SerializableKeys and values after JSON parsing in the BasePrincipal to
68 // FromProperties
69 struct KeyVal {
70 bool valueWasSerialized;
71 nsCString value;
72 SerializableKeys key;
74 static already_AddRefed<BasePrincipal> FromProperties(
75 nsTArray<ExpandedPrincipal::KeyVal>& aFields);
77 protected:
78 explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList);
80 virtual ~ExpandedPrincipal();
82 bool SubsumesInternal(nsIPrincipal* aOther,
83 DocumentDomainConsideration aConsideration) override;
85 bool MayLoadInternal(nsIURI* aURI) override;
87 private:
88 nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
89 nsCOMPtr<nsIContentSecurityPolicy> mCSP;
92 #define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1"
93 #define NS_EXPANDEDPRINCIPAL_CID \
94 { \
95 0xe8ee88b0, 0x5571, 0x4086, { \
96 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
97 } \
100 #endif // ExpandedPrincipal_h