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 "SystemPrincipal.h"
10 #include "nsIComponentManager.h"
11 #include "nsIServiceManager.h"
14 #include "nsReadableUtils.h"
17 #include "nsIClassInfoImpl.h"
18 #include "nsIScriptSecurityManager.h"
21 NS_IMPL_CLASSINFO(SystemPrincipal
, nullptr,
22 nsIClassInfo::SINGLETON
| nsIClassInfo::MAIN_THREAD_ONLY
,
23 NS_SYSTEMPRINCIPAL_CID
)
24 NS_IMPL_QUERY_INTERFACE_CI(SystemPrincipal
,
27 NS_IMPL_CI_INTERFACE_GETTER(SystemPrincipal
,
31 #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
33 already_AddRefed
<SystemPrincipal
>
34 SystemPrincipal::Create()
36 RefPtr
<SystemPrincipal
> sp
= new SystemPrincipal();
37 sp
->FinishInit(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC
),
43 SystemPrincipal::GetScriptLocation(nsACString
&aStr
)
45 aStr
.AssignLiteral(SYSTEM_PRINCIPAL_SPEC
);
49 ///////////////////////////////////////
50 // Methods implementing nsIPrincipal //
51 ///////////////////////////////////////
54 SystemPrincipal::GetHashValue(uint32_t *result
)
56 *result
= NS_PTR_TO_INT32(this);
61 SystemPrincipal::GetURI(nsIURI
** aURI
)
68 SystemPrincipal::GetCsp(nsIContentSecurityPolicy
** aCsp
)
75 SystemPrincipal::SetCsp(nsIContentSecurityPolicy
* aCsp
)
77 // Never destroy an existing CSP on the principal.
78 // This method should only be called in rare cases.
80 return NS_ERROR_FAILURE
;
84 SystemPrincipal::EnsureCSP(nsIDOMDocument
* aDocument
,
85 nsIContentSecurityPolicy
** aCSP
)
87 // CSP on a system principal makes no sense
88 return NS_ERROR_FAILURE
;
92 SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy
** aPreloadCSP
)
94 *aPreloadCSP
= nullptr;
99 SystemPrincipal::EnsurePreloadCSP(nsIDOMDocument
* aDocument
,
100 nsIContentSecurityPolicy
** aPreloadCSP
)
102 // CSP on a system principal makes no sense
107 SystemPrincipal::GetDomain(nsIURI
** aDomain
)
114 SystemPrincipal::SetDomain(nsIURI
* aDomain
)
120 SystemPrincipal::GetBaseDomain(nsACString
& aBaseDomain
)
122 // No base domain for chrome.
127 SystemPrincipal::GetAddonId(nsAString
& aAddonId
)
133 //////////////////////////////////////////
134 // Methods implementing nsISerializable //
135 //////////////////////////////////////////
138 SystemPrincipal::Read(nsIObjectInputStream
* aStream
)
140 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
145 SystemPrincipal::Write(nsIObjectOutputStream
* aStream
)
147 // no-op: CID is sufficient to identify the mSystemPrincipal singleton