Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / caps / src / nsSystemPrincipal.cpp
blob7673e85467c2fc75caeaca4bf2a1977c5cc927dd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1999-2000
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* The privileged system principal. */
40 #include "nscore.h"
41 #include "nsSystemPrincipal.h"
42 #include "nsIComponentManager.h"
43 #include "nsIServiceManager.h"
44 #include "nsIURL.h"
45 #include "nsCOMPtr.h"
46 #include "nsXPIDLString.h"
47 #include "nsReadableUtils.h"
48 #include "nsCRT.h"
49 #include "nsString.h"
50 #include "nsIClassInfoImpl.h"
53 NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal,
54 nsIPrincipal,
55 nsISerializable)
56 NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal,
57 nsIPrincipal,
58 nsISerializable)
60 NS_IMETHODIMP_(nsrefcnt)
61 nsSystemPrincipal::AddRef()
63 NS_PRECONDITION(PRInt32(mJSPrincipals.refcount) >= 0, "illegal refcnt");
64 nsrefcnt count = PR_AtomicIncrement((PRInt32 *)&mJSPrincipals.refcount);
65 NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
66 return count;
69 NS_IMETHODIMP_(nsrefcnt)
70 nsSystemPrincipal::Release()
72 NS_PRECONDITION(0 != mJSPrincipals.refcount, "dup release");
73 nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mJSPrincipals.refcount);
74 NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
75 if (count == 0) {
76 NS_DELETEXPCOM(this);
79 return count;
83 ///////////////////////////////////////
84 // Methods implementing nsIPrincipal //
85 ///////////////////////////////////////
87 NS_IMETHODIMP
88 nsSystemPrincipal::GetPreferences(char** aPrefName, char** aID,
89 char** aSubjectName,
90 char** aGrantedList, char** aDeniedList,
91 PRBool* aIsTrusted)
93 // The system principal should never be streamed out
94 *aPrefName = nsnull;
95 *aID = nsnull;
96 *aSubjectName = nsnull;
97 *aGrantedList = nsnull;
98 *aDeniedList = nsnull;
99 *aIsTrusted = PR_FALSE;
101 return NS_ERROR_FAILURE;
104 NS_IMETHODIMP
105 nsSystemPrincipal::Equals(nsIPrincipal *other, PRBool *result)
107 *result = (other == this);
108 return NS_OK;
111 NS_IMETHODIMP
112 nsSystemPrincipal::Subsumes(nsIPrincipal *other, PRBool *result)
114 *result = PR_TRUE;
115 return NS_OK;
118 NS_IMETHODIMP
119 nsSystemPrincipal::CheckMayLoad(nsIURI* uri, PRBool aReport)
121 return NS_OK;
124 NS_IMETHODIMP
125 nsSystemPrincipal::GetHashValue(PRUint32 *result)
127 *result = NS_PTR_TO_INT32(this);
128 return NS_OK;
131 NS_IMETHODIMP
132 nsSystemPrincipal::CanEnableCapability(const char *capability,
133 PRInt16 *result)
135 // System principal can enable all capabilities.
136 *result = nsIPrincipal::ENABLE_GRANTED;
137 return NS_OK;
140 NS_IMETHODIMP
141 nsSystemPrincipal::SetCanEnableCapability(const char *capability,
142 PRInt16 canEnable)
144 return NS_ERROR_FAILURE;
148 NS_IMETHODIMP
149 nsSystemPrincipal::IsCapabilityEnabled(const char *capability,
150 void *annotation,
151 PRBool *result)
153 *result = PR_TRUE;
154 return NS_OK;
157 NS_IMETHODIMP
158 nsSystemPrincipal::EnableCapability(const char *capability, void **annotation)
160 *annotation = nsnull;
161 return NS_OK;
164 NS_IMETHODIMP
165 nsSystemPrincipal::RevertCapability(const char *capability, void **annotation)
167 *annotation = nsnull;
168 return NS_OK;
171 NS_IMETHODIMP
172 nsSystemPrincipal::DisableCapability(const char *capability, void **annotation)
174 // Can't disable the capabilities of the system principal.
175 // XXX might be handy to be able to do so!
176 *annotation = nsnull;
177 return NS_ERROR_FAILURE;
180 NS_IMETHODIMP
181 nsSystemPrincipal::GetURI(nsIURI** aURI)
183 *aURI = nsnull;
184 return NS_OK;
187 NS_IMETHODIMP
188 nsSystemPrincipal::GetOrigin(char** aOrigin)
190 *aOrigin = ToNewCString(NS_LITERAL_CSTRING("[System]"));
191 return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
194 NS_IMETHODIMP
195 nsSystemPrincipal::GetFingerprint(nsACString& aID)
197 return NS_ERROR_NOT_AVAILABLE;
200 NS_IMETHODIMP
201 nsSystemPrincipal::GetPrettyName(nsACString& aName)
203 return NS_ERROR_NOT_AVAILABLE;
206 NS_IMETHODIMP
207 nsSystemPrincipal::GetSubjectName(nsACString& aName)
209 return NS_ERROR_NOT_AVAILABLE;
212 NS_IMETHODIMP
213 nsSystemPrincipal::GetCertificate(nsISupports** aCertificate)
215 *aCertificate = nsnull;
216 return NS_OK;
219 NS_IMETHODIMP
220 nsSystemPrincipal::GetHasCertificate(PRBool* aResult)
222 *aResult = PR_FALSE;
223 return NS_OK;
226 NS_IMETHODIMP
227 nsSystemPrincipal::GetDomain(nsIURI** aDomain)
229 *aDomain = nsnull;
230 return NS_OK;
233 NS_IMETHODIMP
234 nsSystemPrincipal::SetDomain(nsIURI* aDomain)
236 return NS_OK;
239 NS_IMETHODIMP
240 nsSystemPrincipal::GetSecurityPolicy(void** aSecurityPolicy)
242 *aSecurityPolicy = nsnull;
243 return NS_OK;
246 NS_IMETHODIMP
247 nsSystemPrincipal::SetSecurityPolicy(void* aSecurityPolicy)
249 return NS_OK;
252 NS_IMETHODIMP
253 nsSystemPrincipal::GetJSPrincipals(JSContext *cx, JSPrincipals **jsprin)
255 NS_PRECONDITION(mJSPrincipals.nsIPrincipalPtr, "mJSPrincipals is uninitialized!");
257 JSPRINCIPALS_HOLD(cx, &mJSPrincipals);
258 *jsprin = &mJSPrincipals;
259 return NS_OK;
263 //////////////////////////////////////////
264 // Methods implementing nsISerializable //
265 //////////////////////////////////////////
267 NS_IMETHODIMP
268 nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
270 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
271 return NS_OK;
274 NS_IMETHODIMP
275 nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
277 // no-op: CID is sufficient to identify the mSystemPrincipal singleton
278 return NS_OK;
281 /////////////////////////////////////////////
282 // Constructor, Destructor, initialization //
283 /////////////////////////////////////////////
285 nsSystemPrincipal::nsSystemPrincipal()
289 #define SYSTEM_PRINCIPAL_SPEC "[System Principal]"
291 nsresult
292 nsSystemPrincipal::Init()
294 // Use an nsCString so we only do the allocation once here and then
295 // share with nsJSPrincipals
296 nsCString str(SYSTEM_PRINCIPAL_SPEC);
297 if (!str.EqualsLiteral(SYSTEM_PRINCIPAL_SPEC)) {
298 NS_WARNING("Out of memory initializing system principal");
299 return NS_ERROR_OUT_OF_MEMORY;
302 return mJSPrincipals.Init(this, str);
305 nsSystemPrincipal::~nsSystemPrincipal(void)