Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
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 | /* The privileged system principal. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "nscore.h" |
michael@0 | 9 | #include "nsSystemPrincipal.h" |
michael@0 | 10 | #include "nsIComponentManager.h" |
michael@0 | 11 | #include "nsIServiceManager.h" |
michael@0 | 12 | #include "nsIURL.h" |
michael@0 | 13 | #include "nsCOMPtr.h" |
michael@0 | 14 | #include "nsXPIDLString.h" |
michael@0 | 15 | #include "nsReadableUtils.h" |
michael@0 | 16 | #include "nsCRT.h" |
michael@0 | 17 | #include "nsString.h" |
michael@0 | 18 | #include "nsIClassInfoImpl.h" |
michael@0 | 19 | #include "nsIScriptSecurityManager.h" |
michael@0 | 20 | #include "pratom.h" |
michael@0 | 21 | |
michael@0 | 22 | NS_IMPL_CLASSINFO(nsSystemPrincipal, nullptr, |
michael@0 | 23 | nsIClassInfo::SINGLETON | nsIClassInfo::MAIN_THREAD_ONLY, |
michael@0 | 24 | NS_SYSTEMPRINCIPAL_CID) |
michael@0 | 25 | NS_IMPL_QUERY_INTERFACE_CI(nsSystemPrincipal, |
michael@0 | 26 | nsIPrincipal, |
michael@0 | 27 | nsISerializable) |
michael@0 | 28 | NS_IMPL_CI_INTERFACE_GETTER(nsSystemPrincipal, |
michael@0 | 29 | nsIPrincipal, |
michael@0 | 30 | nsISerializable) |
michael@0 | 31 | |
michael@0 | 32 | NS_IMETHODIMP_(MozExternalRefCountType) |
michael@0 | 33 | nsSystemPrincipal::AddRef() |
michael@0 | 34 | { |
michael@0 | 35 | NS_PRECONDITION(int32_t(refcount) >= 0, "illegal refcnt"); |
michael@0 | 36 | nsrefcnt count = ++refcount; |
michael@0 | 37 | NS_LOG_ADDREF(this, count, "nsSystemPrincipal", sizeof(*this)); |
michael@0 | 38 | return count; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | NS_IMETHODIMP_(MozExternalRefCountType) |
michael@0 | 42 | nsSystemPrincipal::Release() |
michael@0 | 43 | { |
michael@0 | 44 | NS_PRECONDITION(0 != refcount, "dup release"); |
michael@0 | 45 | nsrefcnt count = --refcount; |
michael@0 | 46 | NS_LOG_RELEASE(this, count, "nsSystemPrincipal"); |
michael@0 | 47 | if (count == 0) { |
michael@0 | 48 | delete this; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | return count; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | static const char SYSTEM_PRINCIPAL_SPEC[] = "[System Principal]"; |
michael@0 | 55 | |
michael@0 | 56 | void |
michael@0 | 57 | nsSystemPrincipal::GetScriptLocation(nsACString &aStr) |
michael@0 | 58 | { |
michael@0 | 59 | aStr.Assign(SYSTEM_PRINCIPAL_SPEC); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | #ifdef DEBUG |
michael@0 | 63 | void nsSystemPrincipal::dumpImpl() |
michael@0 | 64 | { |
michael@0 | 65 | fprintf(stderr, "nsSystemPrincipal (%p)\n", this); |
michael@0 | 66 | } |
michael@0 | 67 | #endif |
michael@0 | 68 | |
michael@0 | 69 | |
michael@0 | 70 | /////////////////////////////////////// |
michael@0 | 71 | // Methods implementing nsIPrincipal // |
michael@0 | 72 | /////////////////////////////////////// |
michael@0 | 73 | |
michael@0 | 74 | NS_IMETHODIMP |
michael@0 | 75 | nsSystemPrincipal::Equals(nsIPrincipal *other, bool *result) |
michael@0 | 76 | { |
michael@0 | 77 | *result = (other == this); |
michael@0 | 78 | return NS_OK; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | NS_IMETHODIMP |
michael@0 | 82 | nsSystemPrincipal::EqualsConsideringDomain(nsIPrincipal *other, bool *result) |
michael@0 | 83 | { |
michael@0 | 84 | return Equals(other, result); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | NS_IMETHODIMP |
michael@0 | 88 | nsSystemPrincipal::Subsumes(nsIPrincipal *other, bool *result) |
michael@0 | 89 | { |
michael@0 | 90 | *result = true; |
michael@0 | 91 | return NS_OK; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | NS_IMETHODIMP |
michael@0 | 95 | nsSystemPrincipal::SubsumesConsideringDomain(nsIPrincipal *other, bool *result) |
michael@0 | 96 | { |
michael@0 | 97 | *result = true; |
michael@0 | 98 | return NS_OK; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | NS_IMETHODIMP |
michael@0 | 102 | nsSystemPrincipal::CheckMayLoad(nsIURI* uri, bool aReport, bool aAllowIfInheritsPrincipal) |
michael@0 | 103 | { |
michael@0 | 104 | return NS_OK; |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | NS_IMETHODIMP |
michael@0 | 108 | nsSystemPrincipal::GetHashValue(uint32_t *result) |
michael@0 | 109 | { |
michael@0 | 110 | *result = NS_PTR_TO_INT32(this); |
michael@0 | 111 | return NS_OK; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | NS_IMETHODIMP |
michael@0 | 115 | nsSystemPrincipal::GetURI(nsIURI** aURI) |
michael@0 | 116 | { |
michael@0 | 117 | *aURI = nullptr; |
michael@0 | 118 | return NS_OK; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | NS_IMETHODIMP |
michael@0 | 122 | nsSystemPrincipal::GetOrigin(char** aOrigin) |
michael@0 | 123 | { |
michael@0 | 124 | *aOrigin = ToNewCString(NS_LITERAL_CSTRING(SYSTEM_PRINCIPAL_SPEC)); |
michael@0 | 125 | return *aOrigin ? NS_OK : NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | NS_IMETHODIMP |
michael@0 | 129 | nsSystemPrincipal::GetCsp(nsIContentSecurityPolicy** aCsp) |
michael@0 | 130 | { |
michael@0 | 131 | *aCsp = nullptr; |
michael@0 | 132 | return NS_OK; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | NS_IMETHODIMP |
michael@0 | 136 | nsSystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp) |
michael@0 | 137 | { |
michael@0 | 138 | // CSP on a null principal makes no sense |
michael@0 | 139 | return NS_OK; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | NS_IMETHODIMP |
michael@0 | 143 | nsSystemPrincipal::GetDomain(nsIURI** aDomain) |
michael@0 | 144 | { |
michael@0 | 145 | *aDomain = nullptr; |
michael@0 | 146 | return NS_OK; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | NS_IMETHODIMP |
michael@0 | 150 | nsSystemPrincipal::SetDomain(nsIURI* aDomain) |
michael@0 | 151 | { |
michael@0 | 152 | return NS_OK; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | NS_IMETHODIMP |
michael@0 | 156 | nsSystemPrincipal::GetJarPrefix(nsACString& aJarPrefix) |
michael@0 | 157 | { |
michael@0 | 158 | aJarPrefix.Truncate(); |
michael@0 | 159 | return NS_OK; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | NS_IMETHODIMP |
michael@0 | 163 | nsSystemPrincipal::GetAppStatus(uint16_t* aAppStatus) |
michael@0 | 164 | { |
michael@0 | 165 | *aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED; |
michael@0 | 166 | return NS_OK; |
michael@0 | 167 | } |
michael@0 | 168 | |
michael@0 | 169 | NS_IMETHODIMP |
michael@0 | 170 | nsSystemPrincipal::GetAppId(uint32_t* aAppId) |
michael@0 | 171 | { |
michael@0 | 172 | *aAppId = nsIScriptSecurityManager::NO_APP_ID; |
michael@0 | 173 | return NS_OK; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | NS_IMETHODIMP |
michael@0 | 177 | nsSystemPrincipal::GetIsInBrowserElement(bool* aIsInBrowserElement) |
michael@0 | 178 | { |
michael@0 | 179 | *aIsInBrowserElement = false; |
michael@0 | 180 | return NS_OK; |
michael@0 | 181 | } |
michael@0 | 182 | |
michael@0 | 183 | NS_IMETHODIMP |
michael@0 | 184 | nsSystemPrincipal::GetUnknownAppId(bool* aUnknownAppId) |
michael@0 | 185 | { |
michael@0 | 186 | *aUnknownAppId = false; |
michael@0 | 187 | return NS_OK; |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | NS_IMETHODIMP |
michael@0 | 191 | nsSystemPrincipal::GetIsNullPrincipal(bool* aIsNullPrincipal) |
michael@0 | 192 | { |
michael@0 | 193 | *aIsNullPrincipal = false; |
michael@0 | 194 | return NS_OK; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | NS_IMETHODIMP |
michael@0 | 198 | nsSystemPrincipal::GetBaseDomain(nsACString& aBaseDomain) |
michael@0 | 199 | { |
michael@0 | 200 | // No base domain for chrome. |
michael@0 | 201 | return NS_OK; |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | ////////////////////////////////////////// |
michael@0 | 205 | // Methods implementing nsISerializable // |
michael@0 | 206 | ////////////////////////////////////////// |
michael@0 | 207 | |
michael@0 | 208 | NS_IMETHODIMP |
michael@0 | 209 | nsSystemPrincipal::Read(nsIObjectInputStream* aStream) |
michael@0 | 210 | { |
michael@0 | 211 | // no-op: CID is sufficient to identify the mSystemPrincipal singleton |
michael@0 | 212 | return NS_OK; |
michael@0 | 213 | } |
michael@0 | 214 | |
michael@0 | 215 | NS_IMETHODIMP |
michael@0 | 216 | nsSystemPrincipal::Write(nsIObjectOutputStream* aStream) |
michael@0 | 217 | { |
michael@0 | 218 | // no-op: CID is sufficient to identify the mSystemPrincipal singleton |
michael@0 | 219 | return NS_OK; |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | ///////////////////////////////////////////// |
michael@0 | 223 | // Constructor, Destructor, initialization // |
michael@0 | 224 | ///////////////////////////////////////////// |
michael@0 | 225 | |
michael@0 | 226 | nsSystemPrincipal::nsSystemPrincipal() |
michael@0 | 227 | { |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | nsSystemPrincipal::~nsSystemPrincipal() |
michael@0 | 231 | { |
michael@0 | 232 | } |