Merge tracemonkey into mozilla-central. (a=blockers)
[mozilla-central.git] / caps / include / nsPrincipal.h
blob155460b32e8bd908da6549d01a855a92940a84b4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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) 2003
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Christopher A. Aillon <christopher@aillon.com>
24 * Giorgio Maone <g.maone@informaction.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsPrincipal_h__
41 #define nsPrincipal_h__
43 #include "nsAutoPtr.h"
44 #include "nsCOMPtr.h"
45 #include "nsVoidArray.h"
46 #include "nsHashtable.h"
47 #include "nsJSPrincipals.h"
48 #include "nsTArray.h"
49 #include "nsAutoPtr.h"
51 class nsIObjectInputStream;
52 class nsIObjectOutputStream;
54 class nsPrincipal : public nsIPrincipal
56 public:
57 nsPrincipal();
59 protected:
60 virtual ~nsPrincipal();
62 public:
63 // Our refcount is managed by mJSPrincipals. Use this macro to avoid
64 // an extra refcount member.
65 NS_DECL_ISUPPORTS_INHERITED
66 public:
68 NS_DECL_NSIPRINCIPAL
69 NS_DECL_NSISERIALIZABLE
71 // Either Init() or InitFromPersistent() must be called before
72 // the principal is in a usable state.
73 nsresult Init(const nsACString& aCertFingerprint,
74 const nsACString& aSubjectName,
75 const nsACString& aPrettyName,
76 nsISupports* aCert,
77 nsIURI *aCodebase);
78 nsresult InitFromPersistent(const char* aPrefName,
79 const nsCString& aFingerprint,
80 const nsCString& aSubjectName,
81 const nsACString& aPrettyName,
82 const char* aGrantedList,
83 const char* aDeniedList,
84 nsISupports* aCert,
85 PRBool aIsCert,
86 PRBool aTrusted);
88 // Call this to ensure that this principal has a subject name, a pretty name,
89 // and a cert pointer. This method will throw if there is already a
90 // different subject name or if this principal has no certificate.
91 nsresult EnsureCertData(const nsACString& aSubjectName,
92 const nsACString& aPrettyName,
93 nsISupports* aCert);
95 enum AnnotationValue { AnnotationEnabled=1, AnnotationDisabled };
97 void SetURI(nsIURI *aURI);
98 nsresult SetCapability(const char *capability, void **annotation,
99 AnnotationValue value);
101 static const char sInvalid[];
103 protected:
104 nsJSPrincipals mJSPrincipals;
105 nsTArray< nsAutoPtr<nsHashtable> > mAnnotations;
106 nsHashtable* mCapabilities;
107 nsCString mPrefName;
108 static PRInt32 sCapabilitiesOrdinal;
110 // XXXcaa This is a semi-hack. The best solution here is to keep
111 // a reference to an interface here, except there is no interface
112 // that we can use yet.
113 struct Certificate
115 Certificate(const nsACString& aFingerprint, const nsACString& aSubjectName,
116 const nsACString& aPrettyName, nsISupports* aCert)
117 : fingerprint(aFingerprint),
118 subjectName(aSubjectName),
119 prettyName(aPrettyName),
120 cert(aCert)
123 nsCString fingerprint;
124 nsCString subjectName;
125 nsCString prettyName;
126 nsCOMPtr<nsISupports> cert;
129 nsresult SetCertificate(const nsACString& aFingerprint,
130 const nsACString& aSubjectName,
131 const nsACString& aPrettyName,
132 nsISupports* aCert);
134 // Keep this is a pointer, even though it may slightly increase the
135 // cost of keeping a certificate, this is a good tradeoff though since
136 // it is very rare that we actually have a certificate.
137 nsAutoPtr<Certificate> mCert;
139 DomainPolicy* mSecurityPolicy;
141 nsCOMPtr<nsIContentSecurityPolicy> mCSP;
142 nsCOMPtr<nsIURI> mCodebase;
143 nsCOMPtr<nsIURI> mDomain;
144 PRPackedBool mTrusted;
145 PRPackedBool mInitialized;
146 // If mCodebaseImmutable is true, mCodebase is non-null and immutable
147 PRPackedBool mCodebaseImmutable;
148 PRPackedBool mDomainImmutable;
152 #define NS_PRINCIPAL_CLASSNAME "principal"
153 #define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
154 #define NS_PRINCIPAL_CID \
155 { 0x36102b6b, 0x7b62, 0x451a, \
156 { 0xa1, 0xc8, 0xa0, 0xd4, 0x56, 0xc9, 0x2d, 0xc5 }}
159 #endif // nsPrincipal_h__