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/. */
6 /* The privileged system principal. */
9 #include "nsSystemPrincipal.h"
10 #include "nsIComponentManager.h"
11 #include "nsIServiceManager.h"
14 #include "nsXPIDLString.h"
15 #include "nsReadableUtils.h"
18 #include "nsIClassInfoImpl.h"
19 #include "nsIScriptSecurityManager.h"
22 NS_IMPL_CLASSINFO(nsSystemPrincipal
, nullptr,
23 nsIClassInfo::SINGLETON
| nsIClassInfo::MAIN_THREAD_ONLY
,
24 NS_SYSTEMPRINCIPAL_CID
)
25 NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal
,
28 NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal
,
32 NS_IMETHODIMP_(nsrefcnt
)
33 nsSystemPrincipal::AddRef()
35 NS_PRECONDITION(int32_t(refcount
) >= 0, "illegal refcnt");
36 nsrefcnt count
= ++refcount
;
37 NS_LOG_ADDREF(this, count
, "nsSystemPrincipal", sizeof(*this));
41 NS_IMETHODIMP_(nsrefcnt
)
42 nsSystemPrincipal::Release()
44 NS_PRECONDITION(0 != refcount
, "dup release");
45 nsrefcnt count
= --refcount
;
46 NS_LOG_RELEASE(this, count
, "nsSystemPrincipal");
54 static const char SYSTEM_PRINCIPAL_SPEC
[] = "[System Principal]";
57 nsSystemPrincipal::GetScriptLocation(nsACString
&aStr
)
59 aStr
.Assign(SYSTEM_PRINCIPAL_SPEC
);
63 void nsSystemPrincipal::dumpImpl()
65 fprintf(stderr
, "nsSystemPrincipal (%p)\n", this);
70 ///////////////////////////////////////
71 // Methods implementing nsIPrincipal //
72 ///////////////////////////////////////
75 nsSystemPrincipal::Equals(nsIPrincipal
*other
, bool *result
)
77 *result
= (other
== this);
82 nsSystemPrincipal::EqualsIgnoringDomain(nsIPrincipal
*other
, bool *result
)
84 return Equals(other
, result
);
88 nsSystemPrincipal::Subsumes(nsIPrincipal
*other
, bool *result
)
95 nsSystemPrincipal::SubsumesIgnoringDomain(nsIPrincipal
*other
, bool *result
)
102 nsSystemPrincipal::CheckMayLoad(nsIURI
* uri
, bool aReport
, bool aAllowIfInheritsPrincipal
)
108 nsSystemPrincipal::GetHashValue(uint32_t *result
)
110 *result
= NS_PTR_TO_INT32(this);
115 nsSystemPrincipal::GetURI(nsIURI
** aURI
)
122 nsSystemPrincipal::GetOrigin(char** aOrigin
)
124 *aOrigin
= ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC
));
125 return *aOrigin
? NS_OK
: NS_ERROR_OUT_OF_MEMORY
;
129 nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy
** aCsp
)
136 nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy
* aCsp
)
138 // CSP on a null principal makes no sense
143 nsSystemPrincipal::GetDomain(nsIURI
** aDomain
)
150 nsSystemPrincipal::SetDomain(nsIURI
* aDomain
)
156 nsSystemPrincipal::GetSecurityPolicy(void** aSecurityPolicy
)
158 *aSecurityPolicy
= nullptr;
163 nsSystemPrincipal::SetSecurityPolicy(void* aSecurityPolicy
)
169 nsSystemPrincipal::GetJarPrefix(nsACString
& aJarPrefix
)
171 aJarPrefix
.Truncate();
176 nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus
)
178 *aAppStatus
= nsIPrincipal::APP_STATUS_NOT_INSTALLED
;
183 nsSystemPrincipal::GetAppId(uint32_t* aAppId
)
185 *aAppId
= nsIScriptSecurityManager::NO_APP_ID
;
190 nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement
)
192 *aIsInBrowserElement
= false;
197 nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId
)
199 *aUnknownAppId
= false;
204 nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal
)
206 *aIsNullPrincipal
= false;
211 nsSystemPrincipal::GetBaseDomain(nsACString
& aBaseDomain
)
213 // No base domain for chrome.
217 //////////////////////////////////////////
218 // Methods implementing nsISerializable //
219 //////////////////////////////////////////
222 nsSystemPrincipal::Read(nsIObjectInputStream
* aStream
)
224 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
229 nsSystemPrincipal::Write(nsIObjectOutputStream
* aStream
)
231 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
235 /////////////////////////////////////////////
236 // Constructor, Destructor, initialization //
237 /////////////////////////////////////////////
239 nsSystemPrincipal::nsSystemPrincipal()
243 nsSystemPrincipal::~nsSystemPrincipal()