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 mozilla_ContentPrincipal_h
7
#define mozilla_ContentPrincipal_h
8
9
#include "nsCOMPtr.h"
10
#include "nsJSPrincipals.h"
11
#include "nsTArray.h"
12
#include "nsNetUtil.h"
13
#include "nsScriptSecurityManager.h"
14
#include "mozilla/BasePrincipal.h"
15
#include "mozilla/extensions/WebExtensionPolicy.h"
16
17
namespace Json {
18
class Value;
19
}
20
21
namespace mozilla {
22
23
class ContentPrincipal final : public BasePrincipal {
24
public:
25
NS_DECL_NSISERIALIZABLE
26
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
27
uint32_t GetHashValue() override;
28
NS_IMETHOD GetURI(nsIURI** aURI) override;
29
NS_IMETHOD GetDomain(nsIURI** aDomain) override;
30
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
31
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
32
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
33
NS_IMETHOD GetSiteOrigin(nsACString& aSiteOrigin) override;
34
bool IsContentPrincipal() const override { return true; }
35
36
ContentPrincipal();
37
38
static PrincipalKind Kind() { return eContentPrincipal; }
39
40
// Init() must be called before the principal is in a usable state.
41
nsresult Init(nsIURI* aURI, const OriginAttributes& aOriginAttributes,
42
const nsACString& aOriginNoSuffix);
43
nsresult Init(ContentPrincipal* aOther,
44
const OriginAttributes& aOriginAttributes);
45
46
virtual nsresult GetScriptLocation(nsACString& aStr) override;
47
48
nsresult GetSiteIdentifier(SiteIdentifier& aSite) override;
49
50
static nsresult GenerateOriginNoSuffixFromURI(nsIURI* aURI,
51
nsACString& aOrigin);
52
53
extensions::WebExtensionPolicy* AddonPolicy();
54
55
nsCOMPtr<nsIURI> mDomain;
56
nsCOMPtr<nsIURI> mURI;
57
58
virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
59
// Serializable keys are the valid enum fields the serialization supports
60
enum SerializableKeys : uint8_t {
61
eURI = 0,
62
eDomain,
63
eSuffix,
64
eMax = eSuffix
65
};
66
typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
67
68
static already_AddRefed<BasePrincipal> FromProperties(
69
nsTArray<ContentPrincipal::KeyVal>& aFields);
70
71
protected:
72
virtual ~ContentPrincipal();
73
74
bool SubsumesInternal(nsIPrincipal* aOther,
75
DocumentDomainConsideration aConsideration) override;
76
bool MayLoadInternal(nsIURI* aURI) override;
77
78
private:
79
Maybe<WeakPtr<extensions::WebExtensionPolicy>> mAddon;
80
};
81
82
} // namespace mozilla
83
84
#define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
85
#define NS_PRINCIPAL_CID \
86
{ \
87
0x653e0e4d, 0x3ee4, 0x45fa, { \
88
0xb2, 0x72, 0x97, 0xc2, 0x0b, 0xc0, 0x1e, 0xb8 \
89
} \
90
}
91
92
#endif // mozilla_ContentPrincipal_h