Line data Source code
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 ContentPrincipal_h
7 : #define ContentPrincipal_h
8 :
9 : #include "nsCOMPtr.h"
10 : #include "nsJSPrincipals.h"
11 : #include "nsTArray.h"
12 : #include "nsIContentSecurityPolicy.h"
13 : #include "nsIProtocolHandler.h"
14 : #include "nsNetUtil.h"
15 : #include "nsScriptSecurityManager.h"
16 : #include "mozilla/BasePrincipal.h"
17 :
18 : class ContentPrincipal final : public mozilla::BasePrincipal
19 : {
20 : public:
21 : NS_DECL_NSISERIALIZABLE
22 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
23 : NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
24 : NS_IMETHOD GetURI(nsIURI** aURI) override;
25 : NS_IMETHOD GetDomain(nsIURI** aDomain) override;
26 : NS_IMETHOD SetDomain(nsIURI* aDomain) override;
27 : NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
28 : NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
29 3 : bool IsCodebasePrincipal() const override { return true; }
30 :
31 : ContentPrincipal();
32 :
33 : // Init() must be called before the principal is in a usable state.
34 : nsresult Init(nsIURI* aCodebase,
35 : const mozilla::OriginAttributes& aOriginAttributes,
36 : const nsACString& aOriginNoSuffix);
37 :
38 : virtual nsresult GetScriptLocation(nsACString& aStr) override;
39 :
40 : /**
41 : * Called at startup to setup static data, e.g. about:config pref-observers.
42 : */
43 : static void InitializeStatics();
44 :
45 : static nsresult
46 : GenerateOriginNoSuffixFromURI(nsIURI* aURI, nsACString& aOrigin);
47 :
48 : nsCOMPtr<nsIURI> mDomain;
49 : nsCOMPtr<nsIURI> mCodebase;
50 : // If mCodebaseImmutable is true, mCodebase is non-null and immutable
51 : bool mCodebaseImmutable;
52 : bool mDomainImmutable;
53 :
54 : protected:
55 : virtual ~ContentPrincipal();
56 :
57 : bool SubsumesInternal(nsIPrincipal* aOther,
58 : DocumentDomainConsideration aConsideration) override;
59 : bool MayLoadInternal(nsIURI* aURI) override;
60 :
61 : private:
62 : mozilla::Maybe<nsString> mAddonIdCache;
63 : };
64 :
65 : #define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
66 : #define NS_PRINCIPAL_CID \
67 : { 0x653e0e4d, 0x3ee4, 0x45fa, \
68 : { 0xb2, 0x72, 0x97, 0xc2, 0x0b, 0xc0, 0x1e, 0xb8 } }
69 :
70 : #endif // ContentPrincipal_h
|