Bug 1693315 - Insert "Page Source" before "Extensions for Developers" in the DevTools...
[gecko.git] / caps / ExpandedPrincipal.h
blob70173f41033d797f9a1fc08415f2ca1b1e586d92
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 NS_IMETHOD IsThirdPartyURI(nsIURI* uri, bool* aRes) override;
51 virtual bool AddonHasPermission(const nsAtom* aPerm) override;
52 virtual nsresult GetScriptLocation(nsACString& aStr) override;
54 bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
56 void SetCsp(nsIContentSecurityPolicy* aCSP);
58 // Returns the principal to inherit when this principal requests the given
59 // URL. See BasePrincipal::PrincipalToInherit.
60 nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
62 nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
64 virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
65 // Serializable keys are the valid enum fields the serialization supports
66 enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
67 typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
69 static already_AddRefed<BasePrincipal> FromProperties(
70 nsTArray<ExpandedPrincipal::KeyVal>& aFields);
72 protected:
73 explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList);
75 virtual ~ExpandedPrincipal();
77 bool SubsumesInternal(nsIPrincipal* aOther,
78 DocumentDomainConsideration aConsideration) override;
80 bool MayLoadInternal(nsIURI* aURI) override;
82 private:
83 nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
84 nsCOMPtr<nsIContentSecurityPolicy> mCSP;
87 #define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1"
88 #define NS_EXPANDEDPRINCIPAL_CID \
89 { \
90 0xe8ee88b0, 0x5571, 0x4086, { \
91 0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
92 } \
95 #endif // ExpandedPrincipal_h