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

Revision 20014, 5.2 KB checked in by rbasch, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20013, 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
51
52NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal, nsIPrincipal, nsISerializable)
53NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal, nsIPrincipal, nsISerializable)
54
55NSBASEPRINCIPALS_ADDREF(nsSystemPrincipal)
56NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal)
57
58
59///////////////////////////////////////
60// Methods implementing nsIPrincipal //
61///////////////////////////////////////
62
63NS_IMETHODIMP
64nsSystemPrincipal::ToString(char **result)
65{
66    nsAutoString buf;
67    buf.Assign(NS_LITERAL_STRING("[System]"));
68
69    *result = ToNewCString(buf);
70    return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
71}
72
73NS_IMETHODIMP
74nsSystemPrincipal::ToUserVisibleString(char **result)
75{
76    return ToString(result);
77}
78
79NS_IMETHODIMP
80nsSystemPrincipal::GetPreferences(char** aPrefName, char** aID,
81                                  char** aGrantedList, char** aDeniedList)
82{
83    // The system principal should never be streamed out
84    return NS_ERROR_FAILURE;
85}
86
87NS_IMETHODIMP
88nsSystemPrincipal::Equals(nsIPrincipal *other, PRBool *result)
89{
90    *result = (other == this);
91    return NS_OK;
92}
93
94NS_IMETHODIMP
95nsSystemPrincipal::HashValue(PRUint32 *result)
96{
97    *result = NS_PTR_TO_INT32(this);
98    return NS_OK;
99}
100
101NS_IMETHODIMP
102nsSystemPrincipal::CanEnableCapability(const char *capability,
103                                       PRInt16 *result)
104{
105    // System principal can enable all capabilities.
106    *result = nsIPrincipal::ENABLE_GRANTED;
107    return NS_OK;
108}
109
110NS_IMETHODIMP
111nsSystemPrincipal::SetCanEnableCapability(const char *capability,
112                                          PRInt16 canEnable)
113{
114    return NS_ERROR_FAILURE;
115}
116
117
118NS_IMETHODIMP
119nsSystemPrincipal::IsCapabilityEnabled(const char *capability,
120                                       void *annotation,
121                                       PRBool *result)
122{
123    *result = PR_TRUE;
124    return NS_OK;
125}
126
127NS_IMETHODIMP
128nsSystemPrincipal::EnableCapability(const char *capability, void **annotation)
129{
130    return NS_OK;
131}
132
133NS_IMETHODIMP
134nsSystemPrincipal::RevertCapability(const char *capability, void **annotation)
135{
136    return NS_OK;
137}
138
139NS_IMETHODIMP
140nsSystemPrincipal::DisableCapability(const char *capability, void **annotation)
141{
142    // Can't disable the capabilities of the system principal.
143    // XXX might be handy to be able to do so!
144    return NS_ERROR_FAILURE;
145}
146
147//////////////////////////////////////////
148// Methods implementing nsISerializable //
149//////////////////////////////////////////
150
151NS_IMETHODIMP
152nsSystemPrincipal::Read(nsIObjectInputStream* aStream)
153{
154    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
155    return NS_OK;
156}
157
158NS_IMETHODIMP
159nsSystemPrincipal::Write(nsIObjectOutputStream* aStream)
160{
161    // no-op: CID is sufficient to identify the mSystemPrincipal singleton
162    return NS_OK;
163}
164
165/////////////////////////////////////////////
166// Constructor, Destructor, initialization //
167/////////////////////////////////////////////
168
169nsSystemPrincipal::nsSystemPrincipal()
170{
171}
172
173NS_IMETHODIMP
174nsSystemPrincipal::Init()
175{
176    char *codebase = nsCRT::strdup("[System Principal]");
177    if (!codebase)
178        return NS_ERROR_OUT_OF_MEMORY;
179    if (NS_FAILED(mJSPrincipals.Init(codebase)))
180        return NS_ERROR_FAILURE;
181    return NS_OK;
182}
183
184nsSystemPrincipal::~nsSystemPrincipal(void)
185{
186}
Note: See TracBrowser for help on using the repository browser.