1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/caps/src/nsSystemPrincipal.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,232 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 +/* The privileged system principal. */ 1.10 + 1.11 +#include "nscore.h" 1.12 +#include "nsSystemPrincipal.h" 1.13 +#include "nsIComponentManager.h" 1.14 +#include "nsIServiceManager.h" 1.15 +#include "nsIURL.h" 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsXPIDLString.h" 1.18 +#include "nsReadableUtils.h" 1.19 +#include "nsCRT.h" 1.20 +#include "nsString.h" 1.21 +#include "nsIClassInfoImpl.h" 1.22 +#include "nsIScriptSecurityManager.h" 1.23 +#include "pratom.h" 1.24 + 1.25 +NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr, 1.26 + nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY, 1.27 + NS_SYSTEMPRINCIPAL_CID) 1.28 +NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal, 1.29 + nsIPrincipal, 1.30 + nsISerializable) 1.31 +NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal, 1.32 + nsIPrincipal, 1.33 + nsISerializable) 1.34 + 1.35 +NS_IMETHODIMP_(MozExternalRefCountType) 1.36 +nsSystemPrincipal::AddRef() 1.37 +{ 1.38 + NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt"); 1.39 + nsrefcnt count = ++refcount; 1.40 + NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this)); 1.41 + return count; 1.42 +} 1.43 + 1.44 +NS_IMETHODIMP_(MozExternalRefCountType) 1.45 +nsSystemPrincipal::Release() 1.46 +{ 1.47 + NS_PRECONDITION(0 != refcount, "dup release"); 1.48 + nsrefcnt count = --refcount; 1.49 + NS_LOG_RELEASE(this, count, "nsSystemPrincipal"); 1.50 + if (count == 0) { 1.51 + delete this; 1.52 + } 1.53 + 1.54 + return count; 1.55 +} 1.56 + 1.57 +static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]"; 1.58 + 1.59 +void 1.60 +nsSystemPrincipal::GetScriptLocation(nsACString &aStr) 1.61 +{ 1.62 + aStr.Assign(SYSTEM_PRINCIPAL_SPEC); 1.63 +} 1.64 + 1.65 +#ifdef DEBUG 1.66 +void nsSystemPrincipal::dumpImpl() 1.67 +{ 1.68 + fprintf(stderr, "nsSystemPrincipal (%p)\n", this); 1.69 +} 1.70 +#endif 1.71 + 1.72 + 1.73 +/////////////////////////////////////// 1.74 +// Methods implementing nsIPrincipal // 1.75 +/////////////////////////////////////// 1.76 + 1.77 +NS_IMETHODIMP 1.78 +nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result) 1.79 +{ 1.80 + *result = (other == this); 1.81 + return NS_OK; 1.82 +} 1.83 + 1.84 +NS_IMETHODIMP 1.85 +nsSystemPrincipal::EqualsConsideringDomain(nsIPrincipal *other, bool *result) 1.86 +{ 1.87 + return Equals(other, result); 1.88 +} 1.89 + 1.90 +NS_IMETHODIMP 1.91 +nsSystemPrincipal::Subsumes(nsIPrincipal *other, bool *result) 1.92 +{ 1.93 + *result = true; 1.94 + return NS_OK; 1.95 +} 1.96 + 1.97 +NS_IMETHODIMP 1.98 +nsSystemPrincipal::SubsumesConsideringDomain(nsIPrincipal *other, bool *result) 1.99 +{ 1.100 + *result = true; 1.101 + return NS_OK; 1.102 +} 1.103 + 1.104 +NS_IMETHODIMP 1.105 +nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal) 1.106 +{ 1.107 + return NS_OK; 1.108 +} 1.109 + 1.110 +NS_IMETHODIMP 1.111 +nsSystemPrincipal::GetHashValue(uint32_t *result) 1.112 +{ 1.113 + *result = NS_PTR_TO_INT32(this); 1.114 + return NS_OK; 1.115 +} 1.116 + 1.117 +NS_IMETHODIMP 1.118 +nsSystemPrincipal::GetURI(nsIURI** aURI) 1.119 +{ 1.120 + *aURI = nullptr; 1.121 + return NS_OK; 1.122 +} 1.123 + 1.124 +NS_IMETHODIMP 1.125 +nsSystemPrincipal::GetOrigin(char** aOrigin) 1.126 +{ 1.127 + *aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC)); 1.128 + return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY; 1.129 +} 1.130 + 1.131 +NS_IMETHODIMP 1.132 +nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp) 1.133 +{ 1.134 + *aCsp = nullptr; 1.135 + return NS_OK; 1.136 +} 1.137 + 1.138 +NS_IMETHODIMP 1.139 +nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp) 1.140 +{ 1.141 + // CSP on a null principal makes no sense 1.142 + return NS_OK; 1.143 +} 1.144 + 1.145 +NS_IMETHODIMP 1.146 +nsSystemPrincipal::GetDomain(nsIURI** aDomain) 1.147 +{ 1.148 + *aDomain = nullptr; 1.149 + return NS_OK; 1.150 +} 1.151 + 1.152 +NS_IMETHODIMP 1.153 +nsSystemPrincipal::SetDomain(nsIURI* aDomain) 1.154 +{ 1.155 + return NS_OK; 1.156 +} 1.157 + 1.158 +NS_IMETHODIMP 1.159 +nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix) 1.160 +{ 1.161 + aJarPrefix.Truncate(); 1.162 + return NS_OK; 1.163 +} 1.164 + 1.165 +NS_IMETHODIMP 1.166 +nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus) 1.167 +{ 1.168 + *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED; 1.169 + return NS_OK; 1.170 +} 1.171 + 1.172 +NS_IMETHODIMP 1.173 +nsSystemPrincipal::GetAppId(uint32_t* aAppId) 1.174 +{ 1.175 + *aAppId = nsIScriptSecurityManager::NO_APP_ID; 1.176 + return NS_OK; 1.177 +} 1.178 + 1.179 +NS_IMETHODIMP 1.180 +nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement) 1.181 +{ 1.182 + *aIsInBrowserElement = false; 1.183 + return NS_OK; 1.184 +} 1.185 + 1.186 +NS_IMETHODIMP 1.187 +nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId) 1.188 +{ 1.189 + *aUnknownAppId = false; 1.190 + return NS_OK; 1.191 +} 1.192 + 1.193 +NS_IMETHODIMP 1.194 +nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal) 1.195 +{ 1.196 + *aIsNullPrincipal = false; 1.197 + return NS_OK; 1.198 +} 1.199 + 1.200 +NS_IMETHODIMP 1.201 +nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) 1.202 +{ 1.203 + // No base domain for chrome. 1.204 + return NS_OK; 1.205 +} 1.206 + 1.207 +////////////////////////////////////////// 1.208 +// Methods implementing nsISerializable // 1.209 +////////////////////////////////////////// 1.210 + 1.211 +NS_IMETHODIMP 1.212 +nsSystemPrincipal::Read(nsIObjectInputStream* aStream) 1.213 +{ 1.214 + // no-op: CID is sufficient to identify the mSystemPrincipal singleton 1.215 + return NS_OK; 1.216 +} 1.217 + 1.218 +NS_IMETHODIMP 1.219 +nsSystemPrincipal::Write(nsIObjectOutputStream* aStream) 1.220 +{ 1.221 + // no-op: CID is sufficient to identify the mSystemPrincipal singleton 1.222 + return NS_OK; 1.223 +} 1.224 + 1.225 +///////////////////////////////////////////// 1.226 +// Constructor, Destructor, initialization // 1.227 +///////////////////////////////////////////// 1.228 + 1.229 +nsSystemPrincipal::nsSystemPrincipal() 1.230 +{ 1.231 +} 1.232 + 1.233 +nsSystemPrincipal::~nsSystemPrincipal() 1.234 +{ 1.235 +}