caps/include/nsPrincipal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/caps/include/nsPrincipal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,172 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsPrincipal_h__
    1.10 +#define nsPrincipal_h__
    1.11 +
    1.12 +#include "nsAutoPtr.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsJSPrincipals.h"
    1.15 +#include "nsTArray.h"
    1.16 +#include "nsAutoPtr.h"
    1.17 +#include "nsIProtocolHandler.h"
    1.18 +#include "nsNetUtil.h"
    1.19 +#include "nsScriptSecurityManager.h"
    1.20 +
    1.21 +class nsIObjectInputStream;
    1.22 +class nsIObjectOutputStream;
    1.23 +
    1.24 +class nsBasePrincipal : public nsJSPrincipals
    1.25 +{
    1.26 +public:
    1.27 +  nsBasePrincipal();
    1.28 +
    1.29 +protected:
    1.30 +  virtual ~nsBasePrincipal();
    1.31 +
    1.32 +public:
    1.33 +  NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
    1.34 +  NS_IMETHOD_(MozExternalRefCountType) Release(void);
    1.35 +  NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp);
    1.36 +  NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp);
    1.37 +public:
    1.38 +
    1.39 +  static const char sInvalid[];
    1.40 +
    1.41 +protected:
    1.42 +
    1.43 +#ifdef DEBUG
    1.44 +  virtual void dumpImpl() = 0;
    1.45 +#endif
    1.46 +
    1.47 +  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
    1.48 +};
    1.49 +
    1.50 +class nsPrincipal : public nsBasePrincipal
    1.51 +{
    1.52 +public:
    1.53 +  NS_DECL_ISUPPORTS_INHERITED
    1.54 +  NS_DECL_NSISERIALIZABLE
    1.55 +  NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval);
    1.56 +  NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval);
    1.57 +  NS_IMETHOD GetHashValue(uint32_t* aHashValue);
    1.58 +  NS_IMETHOD GetURI(nsIURI** aURI);
    1.59 +  NS_IMETHOD GetDomain(nsIURI** aDomain);
    1.60 +  NS_IMETHOD SetDomain(nsIURI* aDomain);
    1.61 +  NS_IMETHOD GetOrigin(char** aOrigin);
    1.62 +  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval);
    1.63 +  NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval);
    1.64 +  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal);
    1.65 +  NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix);
    1.66 +  NS_IMETHOD GetAppStatus(uint16_t* aAppStatus);
    1.67 +  NS_IMETHOD GetAppId(uint32_t* aAppStatus);
    1.68 +  NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement);
    1.69 +  NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId);
    1.70 +  NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal);
    1.71 +  NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain);
    1.72 +#ifdef DEBUG
    1.73 +  virtual void dumpImpl();
    1.74 +#endif
    1.75 +
    1.76 +  nsPrincipal();
    1.77 +
    1.78 +  // Init() must be called before the principal is in a usable state.
    1.79 +  nsresult Init(nsIURI* aCodebase,
    1.80 +                uint32_t aAppId,
    1.81 +                bool aInMozBrowser);
    1.82 +
    1.83 +  virtual void GetScriptLocation(nsACString& aStr) MOZ_OVERRIDE;
    1.84 +  void SetURI(nsIURI* aURI);
    1.85 +
    1.86 +  static bool IsPrincipalInherited(nsIURI* aURI) {
    1.87 +    // return true if the loadee URI has
    1.88 +    // the URI_INHERITS_SECURITY_CONTEXT flag set.
    1.89 +    bool doesInheritSecurityContext;
    1.90 +    nsresult rv =
    1.91 +    NS_URIChainHasFlags(aURI,
    1.92 +                        nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
    1.93 +                        &doesInheritSecurityContext);
    1.94 +
    1.95 +    if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) {
    1.96 +      return true;
    1.97 +    }
    1.98 +
    1.99 +    return false;
   1.100 +  }
   1.101 +
   1.102 +
   1.103 +  /**
   1.104 +   * Computes the puny-encoded origin of aURI.
   1.105 +   */
   1.106 +  static nsresult GetOriginForURI(nsIURI* aURI, char **aOrigin);
   1.107 +
   1.108 +  nsCOMPtr<nsIURI> mDomain;
   1.109 +  nsCOMPtr<nsIURI> mCodebase;
   1.110 +  uint32_t mAppId;
   1.111 +  bool mInMozBrowser;
   1.112 +  // If mCodebaseImmutable is true, mCodebase is non-null and immutable
   1.113 +  bool mCodebaseImmutable;
   1.114 +  bool mDomainImmutable;
   1.115 +  bool mInitialized;
   1.116 +
   1.117 +protected:
   1.118 +  virtual ~nsPrincipal();
   1.119 +
   1.120 +  /**
   1.121 +   * Returns the app status of the principal based on mAppId and mInMozBrowser.
   1.122 +   */
   1.123 +  uint16_t GetAppStatus();
   1.124 +};
   1.125 +
   1.126 +class nsExpandedPrincipal : public nsIExpandedPrincipal, public nsBasePrincipal
   1.127 +{
   1.128 +public:
   1.129 +  nsExpandedPrincipal(nsTArray< nsCOMPtr<nsIPrincipal> > &aWhiteList);
   1.130 +
   1.131 +protected:
   1.132 +  virtual ~nsExpandedPrincipal();
   1.133 +
   1.134 +public:
   1.135 +  NS_DECL_ISUPPORTS_INHERITED
   1.136 +  NS_DECL_NSIEXPANDEDPRINCIPAL
   1.137 +  NS_DECL_NSISERIALIZABLE
   1.138 +  NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval);
   1.139 +  NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval);
   1.140 +  NS_IMETHOD GetHashValue(uint32_t* aHashValue);
   1.141 +  NS_IMETHOD GetURI(nsIURI** aURI);
   1.142 +  NS_IMETHOD GetDomain(nsIURI** aDomain);
   1.143 +  NS_IMETHOD SetDomain(nsIURI* aDomain);
   1.144 +  NS_IMETHOD GetOrigin(char** aOrigin);
   1.145 +  NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval);
   1.146 +  NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval);
   1.147 +  NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal);
   1.148 +  NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix);
   1.149 +  NS_IMETHOD GetAppStatus(uint16_t* aAppStatus);
   1.150 +  NS_IMETHOD GetAppId(uint32_t* aAppStatus);
   1.151 +  NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement);
   1.152 +  NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId);
   1.153 +  NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal);
   1.154 +  NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain);
   1.155 +#ifdef DEBUG
   1.156 +  virtual void dumpImpl();
   1.157 +#endif
   1.158 +  
   1.159 +  virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE;
   1.160 +
   1.161 +private:
   1.162 +  nsTArray< nsCOMPtr<nsIPrincipal> > mPrincipals;
   1.163 +};
   1.164 +
   1.165 +#define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1"
   1.166 +#define NS_PRINCIPAL_CID \
   1.167 +  { 0x09b7e598, 0x490d, 0x423f, \
   1.168 +    { 0xa8, 0xa6, 0x2e, 0x6c, 0x4e, 0xc8, 0x77, 0x50 }}
   1.169 +
   1.170 +#define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1"
   1.171 +#define NS_EXPANDEDPRINCIPAL_CID \
   1.172 +  { 0xb33a3807, 0xb76c, 0x44e5, \
   1.173 +    { 0xb9, 0x9d, 0x95, 0x7e, 0xe9, 0xba, 0x6e, 0x39 }}
   1.174 +
   1.175 +#endif // nsPrincipal_h__

mercurial