Bumping manifests a=b2g-bump
[gecko.git] / caps / nsSystemPrincipal.cpp
blob634128a67419b053886518bd7a505933302a5b0c
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. */
8 #include "nscore.h"
9 #include "nsSystemPrincipal.h"
10 #include "nsIComponentManager.h"
11 #include "nsIServiceManager.h"
12 #include "nsIURL.h"
13 #include "nsCOMPtr.h"
14 #include "nsXPIDLString.h"
15 #include "nsReadableUtils.h"
16 #include "nsCRT.h"
17 #include "nsString.h"
18 #include "nsIClassInfoImpl.h"
19 #include "nsIScriptSecurityManager.h"
20 #include "pratom.h"
22 NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr,
23 nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY,
24 NS_SYSTEMPRINCIPAL_CID)
25 NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal,
26 nsIPrincipal,
27 nsISerializable)
28 NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal,
29 nsIPrincipal,
30 nsISerializable)
32 NS_IMETHODIMP_(MozExternalRefCountType)
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));
38 return count;
41 NS_IMETHODIMP_(MozExternalRefCountType)
42 nsSystemPrincipal::Release()
44 NS_PRECONDITION(0 != refcount, "dup release");
45 nsrefcnt count = --refcount;
46 NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
47 if (count == 0) {
48 delete this;
51 return count;
54 static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]";
56 void
57 nsSystemPrincipal::GetScriptLocation(nsACString &aStr)
59 aStr.Assign(SYSTEM_PRINCIPAL_SPEC);
62 #ifdef DEBUG
63 void nsSystemPrincipal::dumpImpl()
65 fprintf(stderr, "nsSystemPrincipal (%p)\n", this);
67 #endif
70 ///////////////////////////////////////
71 // Methods implementing nsIPrincipal //
72 ///////////////////////////////////////
74 NS_IMETHODIMP
75 nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result)
77 *result = (other == this);
78 return NS_OK;
81 NS_IMETHODIMP
82 nsSystemPrincipal::EqualsConsideringDomain(nsIPrincipal *other, bool *result)
84 return Equals(other, result);
87 NS_IMETHODIMP
88 nsSystemPrincipal::Subsumes(nsIPrincipal *other, bool *result)
90 *result = true;
91 return NS_OK;
94 NS_IMETHODIMP
95 nsSystemPrincipal::SubsumesConsideringDomain(nsIPrincipal *other, bool *result)
97 *result = true;
98 return NS_OK;
101 NS_IMETHODIMP
102 nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal)
104 return NS_OK;
107 NS_IMETHODIMP
108 nsSystemPrincipal::GetHashValue(uint32_t *result)
110 *result = NS_PTR_TO_INT32(this);
111 return NS_OK;
114 NS_IMETHODIMP
115 nsSystemPrincipal::GetURI(nsIURI** aURI)
117 *aURI = nullptr;
118 return NS_OK;
121 NS_IMETHODIMP
122 nsSystemPrincipal::GetOrigin(char** aOrigin)
124 *aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC));
125 return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
128 NS_IMETHODIMP
129 nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
131 *aCsp = nullptr;
132 return NS_OK;
135 NS_IMETHODIMP
136 nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
138 // CSP on a null principal makes no sense
139 return NS_OK;
142 NS_IMETHODIMP
143 nsSystemPrincipal::GetDomain(nsIURI** aDomain)
145 *aDomain = nullptr;
146 return NS_OK;
149 NS_IMETHODIMP
150 nsSystemPrincipal::SetDomain(nsIURI* aDomain)
152 return NS_OK;
155 NS_IMETHODIMP
156 nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix)
158 aJarPrefix.Truncate();
159 return NS_OK;
162 NS_IMETHODIMP
163 nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus)
165 *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
166 return NS_OK;
169 NS_IMETHODIMP
170 nsSystemPrincipal::GetAppId(uint32_t* aAppId)
172 *aAppId = nsIScriptSecurityManager::NO_APP_ID;
173 return NS_OK;
176 NS_IMETHODIMP
177 nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
179 *aIsInBrowserElement = false;
180 return NS_OK;
183 NS_IMETHODIMP
184 nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId)
186 *aUnknownAppId = false;
187 return NS_OK;
190 NS_IMETHODIMP
191 nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
193 *aIsNullPrincipal = false;
194 return NS_OK;
197 NS_IMETHODIMP
198 nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
200 // No base domain for chrome.
201 return NS_OK;
204 //////////////////////////////////////////
205 // Methods implementing nsISerializable //
206 //////////////////////////////////////////
208 NS_IMETHODIMP
209 nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
211 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
212 return NS_OK;
215 NS_IMETHODIMP
216 nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
218 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
219 return NS_OK;
222 /////////////////////////////////////////////
223 // Constructor, Destructor, initialization //
224 /////////////////////////////////////////////
226 nsSystemPrincipal::nsSystemPrincipal()
230 nsSystemPrincipal::~nsSystemPrincipal()