Bug 1860954 clarify that gGraphs is not used for offline graphs r=pehrsons
[gecko.git] / caps / ContentPrincipal.h
blobd2f9d7ed83e0d3cf33564a499b91683bd6952432
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
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/Mutex.h"
16 #include "mozilla/extensions/WebExtensionPolicy.h"
18 namespace Json {
19 class Value;
22 namespace mozilla {
24 class ContentPrincipal final : public BasePrincipal {
25 public:
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 GetSiteOriginNoSuffix(nsACString& aSiteOrigin) override;
34 bool IsContentPrincipal() const override { return true; }
36 ContentPrincipal(nsIURI* aURI, const OriginAttributes& aOriginAttributes,
37 const nsACString& aOriginNoSuffix, nsIURI* aInitialDomain);
38 ContentPrincipal(ContentPrincipal* aOther,
39 const OriginAttributes& aOriginAttributes);
41 static PrincipalKind Kind() { return eContentPrincipal; }
43 virtual nsresult GetScriptLocation(nsACString& aStr) override;
45 nsresult GetSiteIdentifier(SiteIdentifier& aSite) override;
47 static nsresult GenerateOriginNoSuffixFromURI(nsIURI* aURI,
48 nsACString& aOrigin);
50 RefPtr<extensions::WebExtensionPolicyCore> AddonPolicyCore();
52 virtual nsresult PopulateJSONObject(Json::Value& aObject) override;
53 // Serializable keys are the valid enum fields the serialization supports
54 enum SerializableKeys : uint8_t {
55 eURI = 0,
56 eDomain,
57 eSuffix,
58 eMax = eSuffix
60 typedef mozilla::BasePrincipal::KeyValT<SerializableKeys> KeyVal;
62 static already_AddRefed<BasePrincipal> FromProperties(
63 nsTArray<ContentPrincipal::KeyVal>& aFields);
65 class Deserializer : public BasePrincipal::Deserializer {
66 public:
67 NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
70 protected:
71 virtual ~ContentPrincipal();
73 bool SubsumesInternal(nsIPrincipal* aOther,
74 DocumentDomainConsideration aConsideration) override;
75 bool MayLoadInternal(nsIURI* aURI) override;
77 private:
78 const nsCOMPtr<nsIURI> mURI;
79 mozilla::Mutex mMutex{"ContentPrincipal::mMutex"};
80 nsCOMPtr<nsIURI> mDomain MOZ_GUARDED_BY(mMutex);
81 Maybe<RefPtr<extensions::WebExtensionPolicyCore>> mAddon
82 MOZ_GUARDED_BY(mMutex);
85 } // namespace mozilla
87 #define NS_PRINCIPAL_CID \
88 { \
89 0x653e0e4d, 0x3ee4, 0x45fa, { \
90 0xb2, 0x72, 0x97, 0xc2, 0x0b, 0xc0, 0x1e, 0xb8 \
91 } \
94 #endif // mozilla_ContentPrincipal_h