Backed out changeset ad0d9f62c29c (bug 206659) for B2G desktop mochitest orange.
[gecko.git] / caps / src / nsSystemPrincipal.cpp
blob3e270bd2d64eaacc916483ea6486b6042fb8c896
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_INTERFACE2_CI(nsSystemPrincipal,
26 nsIPrincipal,
27 nsISerializable)
28 NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal,
29 nsIPrincipal,
30 nsISerializable)
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));
38 return count;
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");
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::EqualsIgnoringDomain(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::SubsumesIgnoringDomain(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::GetSecurityPolicy(void** aSecurityPolicy)
158 *aSecurityPolicy = nullptr;
159 return NS_OK;
162 NS_IMETHODIMP
163 nsSystemPrincipal::SetSecurityPolicy(void* aSecurityPolicy)
165 return NS_OK;
168 NS_IMETHODIMP
169 nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix)
171 aJarPrefix.Truncate();
172 return NS_OK;
175 NS_IMETHODIMP
176 nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus)
178 *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
179 return NS_OK;
182 NS_IMETHODIMP
183 nsSystemPrincipal::GetAppId(uint32_t* aAppId)
185 *aAppId = nsIScriptSecurityManager::NO_APP_ID;
186 return NS_OK;
189 NS_IMETHODIMP
190 nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement)
192 *aIsInBrowserElement = false;
193 return NS_OK;
196 NS_IMETHODIMP
197 nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId)
199 *aUnknownAppId = false;
200 return NS_OK;
203 NS_IMETHODIMP
204 nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal)
206 *aIsNullPrincipal = false;
207 return NS_OK;
210 NS_IMETHODIMP
211 nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain)
213 // No base domain for chrome.
214 return NS_OK;
217 //////////////////////////////////////////
218 // Methods implementing nsISerializable //
219 //////////////////////////////////////////
221 NS_IMETHODIMP
222 nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
224 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
225 return NS_OK;
228 NS_IMETHODIMP
229 nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
231 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
232 return NS_OK;
235 /////////////////////////////////////////////
236 // Constructor, Destructor, initialization //
237 /////////////////////////////////////////////
239 nsSystemPrincipal::nsSystemPrincipal()
243 nsSystemPrincipal::~nsSystemPrincipal()