LCOV - code coverage report
Current view: directory - caps/include - nsPrincipal.h (source / functions) Found Hit Coverage
Test: app.info Lines: 4 0 0.0 %
Date: 2012-06-02 Functions: 2 0 0.0 %

       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
       4                 :  *
       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/
       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) 2003
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Christopher A. Aillon <christopher@aillon.com>
      24                 :  *   Giorgio Maone <g.maone@informaction.com>
      25                 :  *
      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.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #ifndef nsPrincipal_h__
      41                 : #define nsPrincipal_h__
      42                 : 
      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"
      50                 : 
      51                 : class nsIObjectInputStream;
      52                 : class nsIObjectOutputStream;
      53                 : 
      54                 : class nsPrincipal : public nsJSPrincipals
      55                 : {
      56                 : public:
      57                 :   nsPrincipal();
      58                 : 
      59                 : protected:
      60                 :   virtual ~nsPrincipal();
      61                 : 
      62                 : public:
      63                 :   // Our refcount is managed by nsJSPrincipals.  Use this macro to avoid
      64                 :   // an extra refcount member.
      65                 :   NS_DECL_ISUPPORTS_INHERITED
      66                 : public:
      67                 : 
      68                 :   NS_DECL_NSIPRINCIPAL
      69                 :   NS_DECL_NSISERIALIZABLE
      70                 : 
      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                 :                               bool aIsCert,
      86                 :                               bool aTrusted);
      87                 : 
      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);
      94                 : 
      95                 :   enum AnnotationValue { AnnotationEnabled=1, AnnotationDisabled };
      96                 : 
      97                 :   void SetURI(nsIURI *aURI);
      98                 :   nsresult SetCapability(const char *capability, void **annotation, 
      99                 :                          AnnotationValue value);
     100                 : 
     101                 :   static const char sInvalid[];
     102                 : 
     103                 :   virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE;
     104                 : 
     105                 : #ifdef DEBUG
     106                 :   virtual void dumpImpl() MOZ_OVERRIDE;
     107                 : #endif 
     108                 : 
     109                 : protected:
     110                 :   nsTArray< nsAutoPtr<nsHashtable> > mAnnotations;
     111                 :   nsHashtable* mCapabilities;
     112                 :   nsCString mPrefName;
     113                 :   static PRInt32 sCapabilitiesOrdinal;
     114                 : 
     115                 :   // XXXcaa This is a semi-hack.  The best solution here is to keep
     116                 :   // a reference to an interface here, except there is no interface
     117                 :   // that we can use yet.
     118                 :   struct Certificate
     119               0 :   {
     120               0 :     Certificate(const nsACString& aFingerprint, const nsACString& aSubjectName,
     121                 :                 const nsACString& aPrettyName, nsISupports* aCert)
     122                 :       : fingerprint(aFingerprint),
     123                 :         subjectName(aSubjectName),
     124                 :         prettyName(aPrettyName),
     125               0 :         cert(aCert)
     126                 :     {
     127               0 :     }
     128                 :     nsCString fingerprint;
     129                 :     nsCString subjectName;
     130                 :     nsCString prettyName;
     131                 :     nsCOMPtr<nsISupports> cert;
     132                 :   };
     133                 : 
     134                 :   nsresult SetCertificate(const nsACString& aFingerprint,
     135                 :                           const nsACString& aSubjectName,
     136                 :                           const nsACString& aPrettyName,
     137                 :                           nsISupports* aCert);
     138                 : 
     139                 :   // Checks whether this principal's certificate equals aOther's.
     140                 :   bool CertificateEquals(nsIPrincipal *aOther);
     141                 : 
     142                 :   // Keep this is a pointer, even though it may slightly increase the
     143                 :   // cost of keeping a certificate, this is a good tradeoff though since
     144                 :   // it is very rare that we actually have a certificate.
     145                 :   nsAutoPtr<Certificate> mCert;
     146                 : 
     147                 :   DomainPolicy* mSecurityPolicy;
     148                 : 
     149                 :   nsCOMPtr<nsIContentSecurityPolicy> mCSP;
     150                 :   nsCOMPtr<nsIURI> mCodebase;
     151                 :   nsCOMPtr<nsIURI> mDomain;
     152                 :   bool mTrusted;
     153                 :   bool mInitialized;
     154                 :   // If mCodebaseImmutable is true, mCodebase is non-null and immutable
     155                 :   bool mCodebaseImmutable;
     156                 :   bool mDomainImmutable;
     157                 : };
     158                 : 
     159                 : 
     160                 : #define NS_PRINCIPAL_CLASSNAME  "principal"
     161                 : #define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
     162                 : #define NS_PRINCIPAL_CID \
     163                 :   { 0x36102b6b, 0x7b62, 0x451a, \
     164                 :     { 0xa1, 0xc8, 0xa0, 0xd4, 0x56, 0xc9, 0x2d, 0xc5 }}
     165                 : 
     166                 : 
     167                 : #endif // nsPrincipal_h__

Generated by: LCOV version 1.7