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 | |
---|
52 | NS_IMPL_QUERY_INTERFACE2_CI(nsSystemPrincipal, nsIPrincipal, nsISerializable) |
---|
53 | NS_IMPL_CI_INTERFACE_GETTER2(nsSystemPrincipal, nsIPrincipal, nsISerializable) |
---|
54 | |
---|
55 | NSBASEPRINCIPALS_ADDREF(nsSystemPrincipal) |
---|
56 | NSBASEPRINCIPALS_RELEASE(nsSystemPrincipal) |
---|
57 | |
---|
58 | |
---|
59 | /////////////////////////////////////// |
---|
60 | // Methods implementing nsIPrincipal // |
---|
61 | /////////////////////////////////////// |
---|
62 | |
---|
63 | NS_IMETHODIMP |
---|
64 | nsSystemPrincipal::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 | |
---|
73 | NS_IMETHODIMP |
---|
74 | nsSystemPrincipal::ToUserVisibleString(char **result) |
---|
75 | { |
---|
76 | return ToString(result); |
---|
77 | } |
---|
78 | |
---|
79 | NS_IMETHODIMP |
---|
80 | nsSystemPrincipal::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 | |
---|
87 | NS_IMETHODIMP |
---|
88 | nsSystemPrincipal::Equals(nsIPrincipal *other, PRBool *result) |
---|
89 | { |
---|
90 | *result = (other == this); |
---|
91 | return NS_OK; |
---|
92 | } |
---|
93 | |
---|
94 | NS_IMETHODIMP |
---|
95 | nsSystemPrincipal::HashValue(PRUint32 *result) |
---|
96 | { |
---|
97 | *result = NS_PTR_TO_INT32(this); |
---|
98 | return NS_OK; |
---|
99 | } |
---|
100 | |
---|
101 | NS_IMETHODIMP |
---|
102 | nsSystemPrincipal::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 | |
---|
110 | NS_IMETHODIMP |
---|
111 | nsSystemPrincipal::SetCanEnableCapability(const char *capability, |
---|
112 | PRInt16 canEnable) |
---|
113 | { |
---|
114 | return NS_ERROR_FAILURE; |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | NS_IMETHODIMP |
---|
119 | nsSystemPrincipal::IsCapabilityEnabled(const char *capability, |
---|
120 | void *annotation, |
---|
121 | PRBool *result) |
---|
122 | { |
---|
123 | *result = PR_TRUE; |
---|
124 | return NS_OK; |
---|
125 | } |
---|
126 | |
---|
127 | NS_IMETHODIMP |
---|
128 | nsSystemPrincipal::EnableCapability(const char *capability, void **annotation) |
---|
129 | { |
---|
130 | return NS_OK; |
---|
131 | } |
---|
132 | |
---|
133 | NS_IMETHODIMP |
---|
134 | nsSystemPrincipal::RevertCapability(const char *capability, void **annotation) |
---|
135 | { |
---|
136 | return NS_OK; |
---|
137 | } |
---|
138 | |
---|
139 | NS_IMETHODIMP |
---|
140 | nsSystemPrincipal::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 | |
---|
151 | NS_IMETHODIMP |
---|
152 | nsSystemPrincipal::Read(nsIObjectInputStream* aStream) |
---|
153 | { |
---|
154 | // no-op: CID is sufficient to identify the mSystemPrincipal singleton |
---|
155 | return NS_OK; |
---|
156 | } |
---|
157 | |
---|
158 | NS_IMETHODIMP |
---|
159 | nsSystemPrincipal::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 | |
---|
169 | nsSystemPrincipal::nsSystemPrincipal() |
---|
170 | { |
---|
171 | } |
---|
172 | |
---|
173 | NS_IMETHODIMP |
---|
174 | nsSystemPrincipal::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 | |
---|
184 | nsSystemPrincipal::~nsSystemPrincipal(void) |
---|
185 | { |
---|
186 | } |
---|