source: trunk/third/mozilla/caps/src/nsSystemPrincipal.cpp @ 22152

Revision 22152, 8.1 KB checked in by rbasch, 19 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r22151, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
9 *
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.
14 *
15 * The Original Code is mozilla.org code.
16 *
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.
21 *
22 * Contributor(s):
23 *
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the NPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the NPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39/* The privileged system principal. */
40
41#include "nscore.h"
42#include "nsSystemPrincipal.h"
43#include "nsIComponentManager.h"
44#include "nsIServiceManager.h"
45#include "nsIURL.h"
46#include "nsCOMPtr.h"
47#include "nsXPIDLString.h"
48#include "nsReadableUtils.h"
49#include "nsCRT.h"
50#include "nsString.h"
51
52
53NS_INTERFACE_MAP_BEGIN(nsSystemPrincipal)
54    NS_INTERFACE_MAP_ENTRY(nsIPrincipal)
55    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISerializable, nsIPrincipal)
56    NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrincipal)
57    NS_INTERFACE_MAP_ENTRY(nsISubsumingPrincipal)
58    NS_INTERFACE_MAP_ENTRY(nsIPrincipalObsolete)
59    NS_IMPL_QUERY_CLASSINFO(nsSystemPrincipal)
60NS_INTERFACE_MAP_END
61
62NS_IMPL_CI_INTERFACE_GETTER3(nsSystemPrincipal,
63                             nsISubsumingPrincipal,
64                             nsIPrincipal,
65                             nsISerializable)
66
67NS_IMETHODIMP_(nsrefcnt)
68nsSystemPrincipal::AddRef()
69{
70  NS_PRECONDITION(PRInt32(mJSPrincipals.refcount) >= 0, "illegal refcnt");
71  nsrefcnt count = PR_AtomicIncrement((PRInt32 *)&mJSPrincipals.refcount);
72  NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this));
73  return count;
74}
75
76NS_IMETHODIMP_(nsrefcnt)
77nsSystemPrincipal::Release()
78{
79  NS_PRECONDITION(0 != mJSPrincipals.refcount, "dup release");
80  nsrefcnt count = PR_AtomicDecrement((PRInt32 *)&mJSPrincipals.refcount);
81  NS_LOG_RELEASE(this, count, "nsSystemPrincipal");
82  if (count == 0) {
83    NS_DELETEXPCOM(this);
84  }
85
86  return count;
87}
88
89
90///////////////////////////////////////
91// Methods implementing nsIPrincipal //
92///////////////////////////////////////
93
94NS_IMETHODIMP
95nsSystemPrincipal::GetPreferences(char** aPrefName, char** aID,
96                                  char** aGrantedList, char** aDeniedList)
97{
98    // The system principal should never be streamed out
99    *aPrefName = nsnull;
100    *aID = nsnull;
101    *aGrantedList = nsnull;
102    *aDeniedList = nsnull;
103
104    return NS_ERROR_FAILURE;
105}
106
107NS_IMETHODIMP
108nsSystemPrincipal::Equals(nsIPrincipal *other, PRBool *result)
109{
110    *result = (other == this);
111    return NS_OK;
112}
113
114NS_IMETHODIMP
115nsSystemPrincipal::Subsumes(nsIPrincipal *other, PRBool *result)
116{
117    *result = PR_TRUE;
118    return NS_OK;
119}
120
121NS_IMETHODIMP
122nsSystemPrincipal::GetHashValue(PRUint32 *result)
123{
124    *result = NS_PTR_TO_INT32(this);
125    return NS_OK;
126}
127
128NS_IMETHODIMP
129nsSystemPrincipal::CanEnableCapability(const char *capability,
130                                       PRInt16 *result)
131{
132    // System principal can enable all capabilities.
133    *result = nsIPrincipal::ENABLE_GRANTED;
134    return NS_OK;
135}
136
137NS_IMETHODIMP
138nsSystemPrincipal::SetCanEnableCapability(const char *capability,
139                                          PRInt16 canEnable)
140{
141    return NS_ERROR_FAILURE;
142}
143
144
145NS_IMETHODIMP
146nsSystemPrincipal::IsCapabilityEnabled(const char *capability,
147                                       void *annotation,
148                                       PRBool *result)
149{
150    *result = PR_TRUE;
151    return NS_OK;
152}
153
154NS_IMETHODIMP
155nsSystemPrincipal::EnableCapability(const char *capability, void **annotation)
156{
157    *annotation = nsnull;
158    return NS_OK;
159}
160
161NS_IMETHODIMP
162nsSystemPrincipal::RevertCapability(const char *capability, void **annotation)
163{
164    *annotation = nsnull;
165    return NS_OK;
166}
167
168NS_IMETHODIMP
169nsSystemPrincipal::DisableCapability(const char *capability, void **annotation)
170{
171    // Can't disable the capabilities of the system principal.
172    // XXX might be handy to be able to do so!
173    *annotation = nsnull;
174    return NS_ERROR_FAILURE;
175}
176
177NS_IMETHODIMP
178nsSystemPrincipal::GetURI(nsIURI** aURI)
179{
180    *aURI = nsnull;
181    return NS_OK;
182}
183
184NS_IMETHODIMP
185nsSystemPrincipal::GetOrigin(char** aOrigin)
186{
187    *aOrigin = ToNewCString(NS_LITERAL_CSTRING("[System]"));
188    return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
189}
190
191NS_IMETHODIMP
192nsSystemPrincipal::GetCertificateID(char** aID)
193{
194    *aID = nsnull;
195    return NS_OK;
196}
197
198NS_IMETHODIMP
199nsSystemPrincipal::GetCommonName(char** aName)
200{
201    *aName = nsnull;
202    return NS_OK;
203}
204
205NS_IMETHODIMP
206nsSystemPrincipal::SetCommonName(const char* aName)
207{
208    return NS_OK;
209}
210
211NS_IMETHODIMP
212nsSystemPrincipal::GetHasCertificate(PRBool* aResult)
213{
214    *aResult = PR_FALSE;
215    return NS_OK;
216}
217
218NS_IMETHODIMP
219nsSystemPrincipal::GetDomain(nsIURI** aDomain)
220{
221    *aDomain = nsnull;
222    return NS_OK;
223}
224
225NS_IMETHODIMP
226nsSystemPrincipal::SetDomain(nsIURI* aDomain)
227{
228  return NS_OK;
229}
230
231NS_IMETHODIMP
232nsSystemPrincipal::GetSecurityPolicy(void** aSecurityPolicy)
233{
234    *aSecurityPolicy = nsnull;
235    return NS_OK;
236}
237
238NS_IMETHODIMP
239nsSystemPrincipal::SetSecurityPolicy(void* aSecurityPolicy)
240{
241    return NS_OK;
242}
243
244NS_IMETHODIMP
245nsSystemPrincipal::GetJSPrincipals(JSContext *cx, JSPrincipals **jsprin)
246{
247    NS_PRECONDITION(mJSPrincipals.nsIPrincipalPtr, "mJSPrincipals is uninitalized!");
248
249    JSPRINCIPALS_HOLD(nsnull, &mJSPrincipals);
250    *jsprin = &mJSPrincipals;
251    return NS_OK;
252}
253
254///////////////////////////////////////////////
255// Methods implementing nsIPrincipalObsolete //
256///////////////////////////////////////////////
257
258NS_IMETHODIMP
259nsSystemPrincipal::ToString(char **aResult)
260{
261    return nsSystemPrincipal::GetOrigin(aResult);
262}
263
264NS_IMETHODIMP
265nsSystemPrincipal::ToUserVisibleString(char **aResult)
266{
267    return nsSystemPrincipal::GetOrigin(aResult);
268}
269
270NS_IMETHODIMP
271nsSystemPrincipal::Equals(nsIPrincipalObsolete *aOther, PRBool *aResult)
272{
273    *aResult = (aOther == this);
274    return NS_OK;
275}
276
277NS_IMETHODIMP
278nsSystemPrincipal::HashValue(PRUint32 *aResult)
279{
280    *aResult = NS_PTR_TO_INT32(this);
281    return NS_OK;
282}
283
284NS_IMETHODIMP
285nsSystemPrincipal::GetJSPrincipals(JSPrincipals **aResult)
286{
287    *aResult = &mJSPrincipals;
288    JSPRINCIPALS_HOLD(nsnull, *aResult);
289    return NS_OK;
290}
291
292//////////////////////////////////////////
293// Methods implementing nsISerializable //
294//////////////////////////////////////////
295
296NS_IMETHODIMP
297nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
298{
299    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
300    return NS_OK;
301}
302
303NS_IMETHODIMP
304nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
305{
306    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
307    return NS_OK;
308}
309
310/////////////////////////////////////////////
311// Constructor, Destructor, initialization //
312/////////////////////////////////////////////
313
314nsSystemPrincipal::nsSystemPrincipal()
315{
316}
317
318nsresult
319nsSystemPrincipal::Init()
320{
321    return mJSPrincipals.Init(this, "[System Principal]");
322}
323
324nsSystemPrincipal::~nsSystemPrincipal(void)
325{
326}
Note: See TracBrowser for help on using the repository browser.