caps/src/nsNullPrincipalURI.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 * vim: sw=2 ts=2 sts=2 expandtab
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsNullPrincipalURI.h"
michael@0 8
michael@0 9 #include "mozilla/MemoryReporting.h"
michael@0 10
michael@0 11 #include "nsNetUtil.h"
michael@0 12 #include "nsEscape.h"
michael@0 13 #include "nsCRT.h"
michael@0 14
michael@0 15 ////////////////////////////////////////////////////////////////////////////////
michael@0 16 //// nsNullPrincipalURI
michael@0 17
michael@0 18 nsNullPrincipalURI::nsNullPrincipalURI(const nsCString &aSpec)
michael@0 19 {
michael@0 20 int32_t dividerPosition = aSpec.FindChar(':');
michael@0 21 NS_ASSERTION(dividerPosition != -1, "Malformed URI!");
michael@0 22
michael@0 23 int32_t n = aSpec.Left(mScheme, dividerPosition);
michael@0 24 NS_ASSERTION(n == dividerPosition, "Storing the scheme failed!");
michael@0 25
michael@0 26 int32_t count = aSpec.Length() - dividerPosition - 1;
michael@0 27 n = aSpec.Mid(mPath, dividerPosition + 1, count);
michael@0 28 NS_ASSERTION(n == count, "Storing the path failed!");
michael@0 29
michael@0 30 ToLowerCase(mScheme);
michael@0 31 }
michael@0 32
michael@0 33 static NS_DEFINE_CID(kNullPrincipalURIImplementationCID,
michael@0 34 NS_NULLPRINCIPALURI_IMPLEMENTATION_CID);
michael@0 35
michael@0 36 NS_IMPL_ADDREF(nsNullPrincipalURI)
michael@0 37 NS_IMPL_RELEASE(nsNullPrincipalURI)
michael@0 38
michael@0 39 NS_INTERFACE_MAP_BEGIN(nsNullPrincipalURI)
michael@0 40 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI)
michael@0 41 if (aIID.Equals(kNullPrincipalURIImplementationCID))
michael@0 42 foundInterface = static_cast<nsIURI *>(this);
michael@0 43 else
michael@0 44 NS_INTERFACE_MAP_ENTRY(nsIURI)
michael@0 45 NS_INTERFACE_MAP_ENTRY(nsISizeOf)
michael@0 46 NS_INTERFACE_MAP_END
michael@0 47
michael@0 48 ////////////////////////////////////////////////////////////////////////////////
michael@0 49 //// nsIURI
michael@0 50
michael@0 51 NS_IMETHODIMP
michael@0 52 nsNullPrincipalURI::GetAsciiHost(nsACString &_host)
michael@0 53 {
michael@0 54 _host.Truncate();
michael@0 55 return NS_OK;
michael@0 56 }
michael@0 57
michael@0 58 NS_IMETHODIMP
michael@0 59 nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec)
michael@0 60 {
michael@0 61 nsAutoCString buffer;
michael@0 62 (void)GetSpec(buffer);
michael@0 63 NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec);
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 NS_IMETHODIMP
michael@0 68 nsNullPrincipalURI::GetHost(nsACString &_host)
michael@0 69 {
michael@0 70 _host.Truncate();
michael@0 71 return NS_OK;
michael@0 72 }
michael@0 73
michael@0 74 NS_IMETHODIMP
michael@0 75 nsNullPrincipalURI::SetHost(const nsACString &aHost)
michael@0 76 {
michael@0 77 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 78 }
michael@0 79
michael@0 80 NS_IMETHODIMP
michael@0 81 nsNullPrincipalURI::GetHostPort(nsACString &_host)
michael@0 82 {
michael@0 83 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 84 }
michael@0 85
michael@0 86 NS_IMETHODIMP
michael@0 87 nsNullPrincipalURI::SetHostPort(const nsACString &aHost)
michael@0 88 {
michael@0 89 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 90 }
michael@0 91
michael@0 92 NS_IMETHODIMP
michael@0 93 nsNullPrincipalURI::GetOriginCharset(nsACString &_charset)
michael@0 94 {
michael@0 95 _charset.Truncate();
michael@0 96 return NS_OK;
michael@0 97 }
michael@0 98
michael@0 99 NS_IMETHODIMP
michael@0 100 nsNullPrincipalURI::GetPassword(nsACString &_password)
michael@0 101 {
michael@0 102 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 103 }
michael@0 104
michael@0 105 NS_IMETHODIMP
michael@0 106 nsNullPrincipalURI::SetPassword(const nsACString &aPassword)
michael@0 107 {
michael@0 108 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 109 }
michael@0 110
michael@0 111 NS_IMETHODIMP
michael@0 112 nsNullPrincipalURI::GetPath(nsACString &_path)
michael@0 113 {
michael@0 114 _path = mPath;
michael@0 115 return NS_OK;
michael@0 116 }
michael@0 117
michael@0 118 NS_IMETHODIMP
michael@0 119 nsNullPrincipalURI::SetPath(const nsACString &aPath)
michael@0 120 {
michael@0 121 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 122 }
michael@0 123
michael@0 124 NS_IMETHODIMP
michael@0 125 nsNullPrincipalURI::GetRef(nsACString &_ref)
michael@0 126 {
michael@0 127 _ref.Truncate();
michael@0 128 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 129 }
michael@0 130
michael@0 131 NS_IMETHODIMP
michael@0 132 nsNullPrincipalURI::SetRef(const nsACString &aRef)
michael@0 133 {
michael@0 134 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 135 }
michael@0 136
michael@0 137 NS_IMETHODIMP
michael@0 138 nsNullPrincipalURI::GetPrePath(nsACString &_prePath)
michael@0 139 {
michael@0 140 _prePath = mScheme + NS_LITERAL_CSTRING(":");
michael@0 141 return NS_OK;
michael@0 142 }
michael@0 143
michael@0 144 NS_IMETHODIMP
michael@0 145 nsNullPrincipalURI::GetPort(int32_t *_port)
michael@0 146 {
michael@0 147 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 148 }
michael@0 149
michael@0 150 NS_IMETHODIMP
michael@0 151 nsNullPrincipalURI::SetPort(int32_t aPort)
michael@0 152 {
michael@0 153 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 154 }
michael@0 155
michael@0 156 NS_IMETHODIMP
michael@0 157 nsNullPrincipalURI::GetScheme(nsACString &_scheme)
michael@0 158 {
michael@0 159 _scheme = mScheme;
michael@0 160 return NS_OK;
michael@0 161 }
michael@0 162
michael@0 163 NS_IMETHODIMP
michael@0 164 nsNullPrincipalURI::SetScheme(const nsACString &aScheme)
michael@0 165 {
michael@0 166 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 167 }
michael@0 168
michael@0 169 NS_IMETHODIMP
michael@0 170 nsNullPrincipalURI::GetSpec(nsACString &_spec)
michael@0 171 {
michael@0 172 _spec = mScheme + NS_LITERAL_CSTRING(":") + mPath;
michael@0 173 return NS_OK;
michael@0 174 }
michael@0 175
michael@0 176 // result may contain unescaped UTF-8 characters
michael@0 177 NS_IMETHODIMP
michael@0 178 nsNullPrincipalURI::GetSpecIgnoringRef(nsACString &result)
michael@0 179 {
michael@0 180 return GetSpec(result);
michael@0 181 }
michael@0 182
michael@0 183 NS_IMETHODIMP
michael@0 184 nsNullPrincipalURI::GetHasRef(bool *result)
michael@0 185 {
michael@0 186 *result = false;
michael@0 187 return NS_OK;
michael@0 188 }
michael@0 189
michael@0 190 NS_IMETHODIMP
michael@0 191 nsNullPrincipalURI::SetSpec(const nsACString &aSpec)
michael@0 192 {
michael@0 193 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 194 }
michael@0 195
michael@0 196 NS_IMETHODIMP
michael@0 197 nsNullPrincipalURI::GetUsername(nsACString &_username)
michael@0 198 {
michael@0 199 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 200 }
michael@0 201
michael@0 202 NS_IMETHODIMP
michael@0 203 nsNullPrincipalURI::SetUsername(const nsACString &aUsername)
michael@0 204 {
michael@0 205 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 206 }
michael@0 207
michael@0 208 NS_IMETHODIMP
michael@0 209 nsNullPrincipalURI::GetUserPass(nsACString &_userPass)
michael@0 210 {
michael@0 211 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 212 }
michael@0 213
michael@0 214 NS_IMETHODIMP
michael@0 215 nsNullPrincipalURI::SetUserPass(const nsACString &aUserPass)
michael@0 216 {
michael@0 217 return NS_ERROR_NOT_IMPLEMENTED;
michael@0 218 }
michael@0 219
michael@0 220 NS_IMETHODIMP
michael@0 221 nsNullPrincipalURI::Clone(nsIURI **_newURI)
michael@0 222 {
michael@0 223 nsCOMPtr<nsIURI> uri =
michael@0 224 new nsNullPrincipalURI(mScheme + NS_LITERAL_CSTRING(":") + mPath);
michael@0 225 uri.forget(_newURI);
michael@0 226 return NS_OK;
michael@0 227 }
michael@0 228
michael@0 229 NS_IMETHODIMP
michael@0 230 nsNullPrincipalURI::CloneIgnoringRef(nsIURI **_newURI)
michael@0 231 {
michael@0 232 // GetRef/SetRef not supported by nsNullPrincipalURI, so
michael@0 233 // CloneIgnoringRef() is the same as Clone().
michael@0 234 return Clone(_newURI);
michael@0 235 }
michael@0 236
michael@0 237 NS_IMETHODIMP
michael@0 238 nsNullPrincipalURI::Equals(nsIURI *aOther, bool *_equals)
michael@0 239 {
michael@0 240 *_equals = false;
michael@0 241 nsNullPrincipalURI *otherURI;
michael@0 242 nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID,
michael@0 243 (void **)&otherURI);
michael@0 244 if (NS_SUCCEEDED(rv)) {
michael@0 245 *_equals = (mScheme == otherURI->mScheme && mPath == otherURI->mPath);
michael@0 246 NS_RELEASE(otherURI);
michael@0 247 }
michael@0 248 return NS_OK;
michael@0 249 }
michael@0 250
michael@0 251 NS_IMETHODIMP
michael@0 252 nsNullPrincipalURI::EqualsExceptRef(nsIURI *aOther, bool *_equals)
michael@0 253 {
michael@0 254 // GetRef/SetRef not supported by nsNullPrincipalURI, so
michael@0 255 // EqualsExceptRef() is the same as Equals().
michael@0 256 return Equals(aOther, _equals);
michael@0 257 }
michael@0 258
michael@0 259 NS_IMETHODIMP
michael@0 260 nsNullPrincipalURI::Resolve(const nsACString &aRelativePath,
michael@0 261 nsACString &_resolvedURI)
michael@0 262 {
michael@0 263 _resolvedURI = aRelativePath;
michael@0 264 return NS_OK;
michael@0 265 }
michael@0 266
michael@0 267 NS_IMETHODIMP
michael@0 268 nsNullPrincipalURI::SchemeIs(const char *aScheme, bool *_schemeIs)
michael@0 269 {
michael@0 270 *_schemeIs = (0 == nsCRT::strcasecmp(mScheme.get(), aScheme));
michael@0 271 return NS_OK;
michael@0 272 }
michael@0 273
michael@0 274 ////////////////////////////////////////////////////////////////////////////////
michael@0 275 //// nsISizeOf
michael@0 276
michael@0 277 size_t
michael@0 278 nsNullPrincipalURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
michael@0 279 {
michael@0 280 return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
michael@0 281 mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
michael@0 282 }
michael@0 283
michael@0 284 size_t
michael@0 285 nsNullPrincipalURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
michael@0 286 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
michael@0 287 }
michael@0 288

mercurial