Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/NullPrincipal.h
Line
Count
Source (jump to first uncovered line)
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
/**
7
 * This is the principal that has no rights and can't be accessed by
8
 * anything other than itself and chrome; null principals are not
9
 * same-origin with anything but themselves.
10
 */
11
12
#ifndef mozilla_NullPrincipal_h
13
#define mozilla_NullPrincipal_h
14
15
#include "nsIPrincipal.h"
16
#include "nsJSPrincipals.h"
17
#include "nsIScriptSecurityManager.h"
18
#include "nsCOMPtr.h"
19
#include "nsIContentSecurityPolicy.h"
20
21
#include "mozilla/BasePrincipal.h"
22
23
class nsIDocShell;
24
class nsIURI;
25
26
#define NS_NULLPRINCIPAL_CID \
27
{ 0xbd066e5f, 0x146f, 0x4472, \
28
  { 0x83, 0x31, 0x7b, 0xfd, 0x05, 0xb1, 0xed, 0x90 } }
29
#define NS_NULLPRINCIPAL_CONTRACTID "@mozilla.org/nullprincipal;1"
30
31
6
#define NS_NULLPRINCIPAL_SCHEME "moz-nullprincipal"
32
33
namespace mozilla {
34
35
class NullPrincipal final : public BasePrincipal
36
{
37
public:
38
  // This should only be used by deserialization, and the factory constructor.
39
  // Other consumers should use the Create and CreateWithInheritedAttributes
40
  // methods.
41
  NullPrincipal()
42
    : BasePrincipal(eNullPrincipal)
43
9
  {
44
9
  }
45
46
0
  static PrincipalKind Kind() { return eNullPrincipal; }
47
48
  NS_DECL_NSISERIALIZABLE
49
50
  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override;
51
  NS_IMETHOD GetHashValue(uint32_t* aHashValue) override;
52
  NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
53
  NS_IMETHOD GetURI(nsIURI** aURI) override;
54
  NS_IMETHOD GetDomain(nsIURI** aDomain) override;
55
  NS_IMETHOD SetDomain(nsIURI* aDomain) override;
56
  NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
57
  NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
58
59
  static already_AddRefed<NullPrincipal> CreateWithInheritedAttributes(nsIPrincipal* aInheritFrom);
60
61
  // Create NullPrincipal with origin attributes from docshell.
62
  // If aIsFirstParty is true, and the pref 'privacy.firstparty.isolate' is also
63
  // enabled, the mFirstPartyDomain value of the origin attributes will be set
64
  // to an unique value.
65
  static already_AddRefed<NullPrincipal>
66
  CreateWithInheritedAttributes(nsIDocShell* aDocShell, bool aIsFirstParty = false);
67
68
  static already_AddRefed<NullPrincipal>
69
  Create(const OriginAttributes& aOriginAttributes,
70
         nsIURI* aURI = nullptr);
71
72
  static already_AddRefed<NullPrincipal>
73
  CreateWithoutOriginAttributes();
74
75
  nsresult Init(const OriginAttributes& aOriginAttributes = OriginAttributes(),
76
                nsIURI* aURI = nullptr);
77
78
  virtual nsresult GetScriptLocation(nsACString &aStr) override;
79
80
3
  nsresult GetSiteIdentifier(SiteIdentifier& aSite) override {
81
3
    aSite.Init(this);
82
3
    return NS_OK;
83
3
  }
84
85
 protected:
86
0
  virtual ~NullPrincipal() = default;
87
88
  bool SubsumesInternal(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration) override
89
0
  {
90
0
    return aOther == this;
91
0
  }
92
93
  bool MayLoadInternal(nsIURI* aURI) override;
94
95
  nsCOMPtr<nsIURI> mURI;
96
97
private:
98
  // If aIsFirstParty is true, this NullPrincipal will be initialized base on
99
  // the aOriginAttributes with FirstPartyDomain set to an unique value, and this
100
  // value is generated from mURI.path, with ".mozilla" appending at the end.
101
  nsresult Init(const OriginAttributes& aOriginAttributes, bool aIsFirstParty);
102
};
103
104
} // mozilla namespace
105
106
#endif // mozilla_NullPrincipal_h