Source code

Revision control

Other Tools

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/. */
5
6
#ifndef ExpandedPrincipal_h
7
#define ExpandedPrincipal_h
8
9
#include "nsCOMPtr.h"
10
#include "nsJSPrincipals.h"
11
#include "nsTArray.h"
12
#include "nsNetUtil.h"
13
#include "mozilla/BasePrincipal.h"
14
15
class nsIContentSecurityPolicy;
16
17
namespace Json {
18
class Value;
19
}
20
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);
27
28
static PrincipalKind Kind() { return eExpandedPrincipal; }
29
30
// For use from the XPCOM factory constructor only. Do not ever use this
31
// constructor by hand!
32
ExpandedPrincipal();
33
34
NS_DECL_NSIEXPANDEDPRINCIPAL
35
NS_DECL_NSISERIALIZABLE
36
37
NS_IMETHOD_(MozExternalRefCountType) AddRef() override {
38
return nsJSPrincipals::AddRef();
39
};
40
NS_IMETHOD_(MozExternalRefCountType) Release() override {
41
return nsJSPrincipals::Release();
42
};
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;
52
53
bool AddonAllowsLoad(nsIURI* aURI, bool aExplicit = false);
54
55
void SetCsp(nsIContentSecurityPolicy* aCSP);
56
57
// Returns the principal to inherit when this principal requests the given
58
// URL. See BasePrincipal::PrincipalToInherit.
59
nsIPrincipal* PrincipalToInherit(nsIURI* aRequestedURI = nullptr);
60
61
nsresult GetSiteIdentifier(mozilla::SiteIdentifier& aSite) override;
62
63
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
64
// Serializable keys are the valid enum fields the serialization supports
65
enum SerializableKeys : uint8_t { eSpecs = 0, eSuffix, eMax = eSuffix };
66
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
67
68
static already_AddRefed<BasePrincipal> FromProperties(
69
nsTArray<ExpandedPrincipal::KeyVal>& aFields);
70
71
protected:
72
explicit ExpandedPrincipal(nsTArray<nsCOMPtr<nsIPrincipal>>& aAllowList);
73
74
virtual ~ExpandedPrincipal();
75
76
bool SubsumesInternal(nsIPrincipal* aOther,
77
DocumentDomainConsideration aConsideration) override;
78
79
bool MayLoadInternal(nsIURI* aURI) override;
80
81
private:
82
nsTArray<nsCOMPtr<nsIPrincipal>> mPrincipals;
83
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
84
};
85
86
#define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1"
87
#define NS_EXPANDEDPRINCIPAL_CID \
88
{ \
89
0xe8ee88b0, 0x5571, 0x4086, { \
90
0xa4, 0x5b, 0x39, 0xa7, 0x16, 0x90, 0x6b, 0xdb \
91
} \
92
}
93
94
#endif // ExpandedPrincipal_h