/src/mozilla-central/caps/SystemPrincipal.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | | /* The privileged system principal. */ |
7 | | |
8 | | #include "nscore.h" |
9 | | #include "SystemPrincipal.h" |
10 | | #include "nsIComponentManager.h" |
11 | | #include "nsIServiceManager.h" |
12 | | #include "nsIURL.h" |
13 | | #include "nsCOMPtr.h" |
14 | | #include "nsReadableUtils.h" |
15 | | #include "nsCRT.h" |
16 | | #include "nsString.h" |
17 | | #include "nsIClassInfoImpl.h" |
18 | | #include "nsIScriptSecurityManager.h" |
19 | | #include "pratom.h" |
20 | | |
21 | | using namespace mozilla; |
22 | | |
23 | | NS_IMPL_CLASSINFO(SystemPrincipal, nullptr, |
24 | | nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY, |
25 | | NS_SYSTEMPRINCIPAL_CID) |
26 | | NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal, |
27 | | nsIPrincipal, |
28 | | nsISerializable) |
29 | | NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal, |
30 | | nsIPrincipal, |
31 | | nsISerializable) |
32 | | |
33 | 0 | #define SYSTEM_PRINCIPAL_SPEC "[System Principal]" |
34 | | |
35 | | already_AddRefed<SystemPrincipal> |
36 | | SystemPrincipal::Create() |
37 | 3 | { |
38 | 3 | RefPtr<SystemPrincipal> sp = new SystemPrincipal(); |
39 | 3 | sp->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC), |
40 | 3 | OriginAttributes()); |
41 | 3 | return sp.forget(); |
42 | 3 | } |
43 | | |
44 | | nsresult |
45 | | SystemPrincipal::GetScriptLocation(nsACString &aStr) |
46 | 0 | { |
47 | 0 | aStr.AssignLiteral(SYSTEM_PRINCIPAL_SPEC); |
48 | 0 | return NS_OK; |
49 | 0 | } |
50 | | |
51 | | /////////////////////////////////////// |
52 | | // Methods implementing nsIPrincipal // |
53 | | /////////////////////////////////////// |
54 | | |
55 | | NS_IMETHODIMP |
56 | | SystemPrincipal::GetHashValue(uint32_t *result) |
57 | 0 | { |
58 | 0 | *result = NS_PTR_TO_INT32(this); |
59 | 0 | return NS_OK; |
60 | 0 | } |
61 | | |
62 | | NS_IMETHODIMP |
63 | | SystemPrincipal::GetURI(nsIURI** aURI) |
64 | 0 | { |
65 | 0 | *aURI = nullptr; |
66 | 0 | return NS_OK; |
67 | 0 | } |
68 | | |
69 | | NS_IMETHODIMP |
70 | | SystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp) |
71 | 5 | { |
72 | 5 | *aCsp = nullptr; |
73 | 5 | return NS_OK; |
74 | 5 | } |
75 | | |
76 | | NS_IMETHODIMP |
77 | | SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp) |
78 | 0 | { |
79 | 0 | // Never destroy an existing CSP on the principal. |
80 | 0 | // This method should only be called in rare cases. |
81 | 0 |
|
82 | 0 | return NS_ERROR_FAILURE; |
83 | 0 | } |
84 | | |
85 | | NS_IMETHODIMP |
86 | | SystemPrincipal::EnsureCSP(nsIDocument* aDocument, |
87 | | nsIContentSecurityPolicy** aCSP) |
88 | 0 | { |
89 | 0 | // CSP on a system principal makes no sense |
90 | 0 | return NS_ERROR_FAILURE; |
91 | 0 | } |
92 | | |
93 | | NS_IMETHODIMP |
94 | | SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP) |
95 | 0 | { |
96 | 0 | *aPreloadCSP = nullptr; |
97 | 0 | return NS_OK; |
98 | 0 | } |
99 | | |
100 | | NS_IMETHODIMP |
101 | | SystemPrincipal::EnsurePreloadCSP(nsIDocument* aDocument, |
102 | | nsIContentSecurityPolicy** aPreloadCSP) |
103 | 0 | { |
104 | 0 | // CSP on a system principal makes no sense |
105 | 0 | return NS_OK; |
106 | 0 | } |
107 | | |
108 | | NS_IMETHODIMP |
109 | | SystemPrincipal::GetDomain(nsIURI** aDomain) |
110 | 0 | { |
111 | 0 | *aDomain = nullptr; |
112 | 0 | return NS_OK; |
113 | 0 | } |
114 | | |
115 | | NS_IMETHODIMP |
116 | | SystemPrincipal::SetDomain(nsIURI* aDomain) |
117 | 0 | { |
118 | 0 | return NS_OK; |
119 | 0 | } |
120 | | |
121 | | NS_IMETHODIMP |
122 | | SystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) |
123 | 0 | { |
124 | 0 | // No base domain for chrome. |
125 | 0 | return NS_OK; |
126 | 0 | } |
127 | | |
128 | | NS_IMETHODIMP |
129 | | SystemPrincipal::GetAddonId(nsAString& aAddonId) |
130 | 0 | { |
131 | 0 | aAddonId.Truncate(); |
132 | 0 | return NS_OK; |
133 | 0 | }; |
134 | | |
135 | | ////////////////////////////////////////// |
136 | | // Methods implementing nsISerializable // |
137 | | ////////////////////////////////////////// |
138 | | |
139 | | NS_IMETHODIMP |
140 | | SystemPrincipal::Read(nsIObjectInputStream* aStream) |
141 | 0 | { |
142 | 0 | // no-op: CID is sufficient to identify the mSystemPrincipal singleton |
143 | 0 | return NS_OK; |
144 | 0 | } |
145 | | |
146 | | NS_IMETHODIMP |
147 | | SystemPrincipal::Write(nsIObjectOutputStream* aStream) |
148 | 0 | { |
149 | 0 | // no-op: CID is sufficient to identify the mSystemPrincipal singleton |
150 | 0 | return NS_OK; |
151 | 0 | } |