Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsPrincipal_h__ |
michael@0 | 7 | #define nsPrincipal_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "nsAutoPtr.h" |
michael@0 | 10 | #include "nsCOMPtr.h" |
michael@0 | 11 | #include "nsJSPrincipals.h" |
michael@0 | 12 | #include "nsTArray.h" |
michael@0 | 13 | #include "nsAutoPtr.h" |
michael@0 | 14 | #include "nsIProtocolHandler.h" |
michael@0 | 15 | #include "nsNetUtil.h" |
michael@0 | 16 | #include "nsScriptSecurityManager.h" |
michael@0 | 17 | |
michael@0 | 18 | class nsIObjectInputStream; |
michael@0 | 19 | class nsIObjectOutputStream; |
michael@0 | 20 | |
michael@0 | 21 | class nsBasePrincipal : public nsJSPrincipals |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | nsBasePrincipal(); |
michael@0 | 25 | |
michael@0 | 26 | protected: |
michael@0 | 27 | virtual ~nsBasePrincipal(); |
michael@0 | 28 | |
michael@0 | 29 | public: |
michael@0 | 30 | NS_IMETHOD_(MozExternalRefCountType) AddRef(void); |
michael@0 | 31 | NS_IMETHOD_(MozExternalRefCountType) Release(void); |
michael@0 | 32 | NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp); |
michael@0 | 33 | NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp); |
michael@0 | 34 | public: |
michael@0 | 35 | |
michael@0 | 36 | static const char sInvalid[]; |
michael@0 | 37 | |
michael@0 | 38 | protected: |
michael@0 | 39 | |
michael@0 | 40 | #ifdef DEBUG |
michael@0 | 41 | virtual void dumpImpl() = 0; |
michael@0 | 42 | #endif |
michael@0 | 43 | |
michael@0 | 44 | nsCOMPtr<nsIContentSecurityPolicy> mCSP; |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | class nsPrincipal : public nsBasePrincipal |
michael@0 | 48 | { |
michael@0 | 49 | public: |
michael@0 | 50 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 51 | NS_DECL_NSISERIALIZABLE |
michael@0 | 52 | NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval); |
michael@0 | 53 | NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval); |
michael@0 | 54 | NS_IMETHOD GetHashValue(uint32_t* aHashValue); |
michael@0 | 55 | NS_IMETHOD GetURI(nsIURI** aURI); |
michael@0 | 56 | NS_IMETHOD GetDomain(nsIURI** aDomain); |
michael@0 | 57 | NS_IMETHOD SetDomain(nsIURI* aDomain); |
michael@0 | 58 | NS_IMETHOD GetOrigin(char** aOrigin); |
michael@0 | 59 | NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval); |
michael@0 | 60 | NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval); |
michael@0 | 61 | NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal); |
michael@0 | 62 | NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix); |
michael@0 | 63 | NS_IMETHOD GetAppStatus(uint16_t* aAppStatus); |
michael@0 | 64 | NS_IMETHOD GetAppId(uint32_t* aAppStatus); |
michael@0 | 65 | NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement); |
michael@0 | 66 | NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId); |
michael@0 | 67 | NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal); |
michael@0 | 68 | NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain); |
michael@0 | 69 | #ifdef DEBUG |
michael@0 | 70 | virtual void dumpImpl(); |
michael@0 | 71 | #endif |
michael@0 | 72 | |
michael@0 | 73 | nsPrincipal(); |
michael@0 | 74 | |
michael@0 | 75 | // Init() must be called before the principal is in a usable state. |
michael@0 | 76 | nsresult Init(nsIURI* aCodebase, |
michael@0 | 77 | uint32_t aAppId, |
michael@0 | 78 | bool aInMozBrowser); |
michael@0 | 79 | |
michael@0 | 80 | virtual void GetScriptLocation(nsACString& aStr) MOZ_OVERRIDE; |
michael@0 | 81 | void SetURI(nsIURI* aURI); |
michael@0 | 82 | |
michael@0 | 83 | static bool IsPrincipalInherited(nsIURI* aURI) { |
michael@0 | 84 | // return true if the loadee URI has |
michael@0 | 85 | // the URI_INHERITS_SECURITY_CONTEXT flag set. |
michael@0 | 86 | bool doesInheritSecurityContext; |
michael@0 | 87 | nsresult rv = |
michael@0 | 88 | NS_URIChainHasFlags(aURI, |
michael@0 | 89 | nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT, |
michael@0 | 90 | &doesInheritSecurityContext); |
michael@0 | 91 | |
michael@0 | 92 | if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) { |
michael@0 | 93 | return true; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | return false; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | /** |
michael@0 | 101 | * Computes the puny-encoded origin of aURI. |
michael@0 | 102 | */ |
michael@0 | 103 | static nsresult GetOriginForURI(nsIURI* aURI, char **aOrigin); |
michael@0 | 104 | |
michael@0 | 105 | nsCOMPtr<nsIURI> mDomain; |
michael@0 | 106 | nsCOMPtr<nsIURI> mCodebase; |
michael@0 | 107 | uint32_t mAppId; |
michael@0 | 108 | bool mInMozBrowser; |
michael@0 | 109 | // If mCodebaseImmutable is true, mCodebase is non-null and immutable |
michael@0 | 110 | bool mCodebaseImmutable; |
michael@0 | 111 | bool mDomainImmutable; |
michael@0 | 112 | bool mInitialized; |
michael@0 | 113 | |
michael@0 | 114 | protected: |
michael@0 | 115 | virtual ~nsPrincipal(); |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Returns the app status of the principal based on mAppId and mInMozBrowser. |
michael@0 | 119 | */ |
michael@0 | 120 | uint16_t GetAppStatus(); |
michael@0 | 121 | }; |
michael@0 | 122 | |
michael@0 | 123 | class nsExpandedPrincipal : public nsIExpandedPrincipal, public nsBasePrincipal |
michael@0 | 124 | { |
michael@0 | 125 | public: |
michael@0 | 126 | nsExpandedPrincipal(nsTArray< nsCOMPtr<nsIPrincipal> > &aWhiteList); |
michael@0 | 127 | |
michael@0 | 128 | protected: |
michael@0 | 129 | virtual ~nsExpandedPrincipal(); |
michael@0 | 130 | |
michael@0 | 131 | public: |
michael@0 | 132 | NS_DECL_ISUPPORTS_INHERITED |
michael@0 | 133 | NS_DECL_NSIEXPANDEDPRINCIPAL |
michael@0 | 134 | NS_DECL_NSISERIALIZABLE |
michael@0 | 135 | NS_IMETHOD Equals(nsIPrincipal* other, bool* _retval); |
michael@0 | 136 | NS_IMETHOD EqualsConsideringDomain(nsIPrincipal* other, bool* _retval); |
michael@0 | 137 | NS_IMETHOD GetHashValue(uint32_t* aHashValue); |
michael@0 | 138 | NS_IMETHOD GetURI(nsIURI** aURI); |
michael@0 | 139 | NS_IMETHOD GetDomain(nsIURI** aDomain); |
michael@0 | 140 | NS_IMETHOD SetDomain(nsIURI* aDomain); |
michael@0 | 141 | NS_IMETHOD GetOrigin(char** aOrigin); |
michael@0 | 142 | NS_IMETHOD Subsumes(nsIPrincipal* other, bool* _retval); |
michael@0 | 143 | NS_IMETHOD SubsumesConsideringDomain(nsIPrincipal* other, bool* _retval); |
michael@0 | 144 | NS_IMETHOD CheckMayLoad(nsIURI* uri, bool report, bool allowIfInheritsPrincipal); |
michael@0 | 145 | NS_IMETHOD GetJarPrefix(nsACString& aJarPrefix); |
michael@0 | 146 | NS_IMETHOD GetAppStatus(uint16_t* aAppStatus); |
michael@0 | 147 | NS_IMETHOD GetAppId(uint32_t* aAppStatus); |
michael@0 | 148 | NS_IMETHOD GetIsInBrowserElement(bool* aIsInBrowserElement); |
michael@0 | 149 | NS_IMETHOD GetUnknownAppId(bool* aUnknownAppId); |
michael@0 | 150 | NS_IMETHOD GetIsNullPrincipal(bool* aIsNullPrincipal); |
michael@0 | 151 | NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain); |
michael@0 | 152 | #ifdef DEBUG |
michael@0 | 153 | virtual void dumpImpl(); |
michael@0 | 154 | #endif |
michael@0 | 155 | |
michael@0 | 156 | virtual void GetScriptLocation(nsACString &aStr) MOZ_OVERRIDE; |
michael@0 | 157 | |
michael@0 | 158 | private: |
michael@0 | 159 | nsTArray< nsCOMPtr<nsIPrincipal> > mPrincipals; |
michael@0 | 160 | }; |
michael@0 | 161 | |
michael@0 | 162 | #define NS_PRINCIPAL_CONTRACTID "@mozilla.org/principal;1" |
michael@0 | 163 | #define NS_PRINCIPAL_CID \ |
michael@0 | 164 | { 0x09b7e598, 0x490d, 0x423f, \ |
michael@0 | 165 | { 0xa8, 0xa6, 0x2e, 0x6c, 0x4e, 0xc8, 0x77, 0x50 }} |
michael@0 | 166 | |
michael@0 | 167 | #define NS_EXPANDEDPRINCIPAL_CONTRACTID "@mozilla.org/expandedprincipal;1" |
michael@0 | 168 | #define NS_EXPANDEDPRINCIPAL_CID \ |
michael@0 | 169 | { 0xb33a3807, 0xb76c, 0x44e5, \ |
michael@0 | 170 | { 0xb9, 0x9d, 0x95, 0x7e, 0xe9, 0xba, 0x6e, 0x39 }} |
michael@0 | 171 | |
michael@0 | 172 | #endif // nsPrincipal_h__ |