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 mozilla_ContentPrincipal_h
7 #define mozilla_ContentPrincipal_h
10 #include "nsJSPrincipals.h"
12 #include "nsNetUtil.h"
13 #include "nsScriptSecurityManager.h"
14 #include "mozilla/BasePrincipal.h"
15 #include "mozilla/extensions/WebExtensionPolicy.h"
23 class ContentPrincipal final
: public BasePrincipal
{
25 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) override
;
26 uint32_t GetHashValue() override
;
27 NS_IMETHOD
GetURI(nsIURI
** aURI
) override
;
28 NS_IMETHOD
GetDomain(nsIURI
** aDomain
) override
;
29 NS_IMETHOD
SetDomain(nsIURI
* aDomain
) override
;
30 NS_IMETHOD
GetBaseDomain(nsACString
& aBaseDomain
) override
;
31 NS_IMETHOD
GetAddonId(nsAString
& aAddonId
) override
;
32 NS_IMETHOD
GetSiteOriginNoSuffix(nsACString
& aSiteOrigin
) override
;
33 bool IsContentPrincipal() const override
{ return true; }
35 ContentPrincipal(nsIURI
* aURI
, const OriginAttributes
& aOriginAttributes
,
36 const nsACString
& aOriginNoSuffix
);
37 ContentPrincipal(ContentPrincipal
* aOther
,
38 const OriginAttributes
& aOriginAttributes
);
40 static PrincipalKind
Kind() { return eContentPrincipal
; }
42 virtual nsresult
GetScriptLocation(nsACString
& aStr
) override
;
44 nsresult
GetSiteIdentifier(SiteIdentifier
& aSite
) override
;
46 static nsresult
GenerateOriginNoSuffixFromURI(nsIURI
* aURI
,
49 extensions::WebExtensionPolicy
* AddonPolicy();
51 virtual nsresult
PopulateJSONObject(Json::Value
& aObject
) override
;
52 // Serializable keys are the valid enum fields the serialization supports
53 enum SerializableKeys
: uint8_t {
59 typedef mozilla::BasePrincipal::KeyValT
<SerializableKeys
> KeyVal
;
61 static already_AddRefed
<BasePrincipal
> FromProperties(
62 nsTArray
<ContentPrincipal::KeyVal
>& aFields
);
64 class Deserializer
: public BasePrincipal::Deserializer
{
66 NS_IMETHOD
Read(nsIObjectInputStream
* aStream
) override
;
70 virtual ~ContentPrincipal();
72 bool SubsumesInternal(nsIPrincipal
* aOther
,
73 DocumentDomainConsideration aConsideration
) override
;
74 bool MayLoadInternal(nsIURI
* aURI
) override
;
77 const nsCOMPtr
<nsIURI
> mURI
;
78 nsCOMPtr
<nsIURI
> mDomain
;
79 Maybe
<RefPtr
<extensions::WebExtensionPolicyCore
>> mAddon
;
82 } // namespace mozilla
84 #define NS_PRINCIPAL_CID \
86 0x653e0e4d, 0x3ee4, 0x45fa, { \
87 0xb2, 0x72, 0x97, 0xc2, 0x0b, 0xc0, 0x1e, 0xb8 \
91 #endif // mozilla_ContentPrincipal_h