1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/caps/src/nsNullPrincipalURI.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,288 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 sts=2 expandtab 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "nsNullPrincipalURI.h" 1.11 + 1.12 +#include "mozilla/MemoryReporting.h" 1.13 + 1.14 +#include "nsNetUtil.h" 1.15 +#include "nsEscape.h" 1.16 +#include "nsCRT.h" 1.17 + 1.18 +//////////////////////////////////////////////////////////////////////////////// 1.19 +//// nsNullPrincipalURI 1.20 + 1.21 +nsNullPrincipalURI::nsNullPrincipalURI(const nsCString &aSpec) 1.22 +{ 1.23 + int32_t dividerPosition = aSpec.FindChar(':'); 1.24 + NS_ASSERTION(dividerPosition != -1, "Malformed URI!"); 1.25 + 1.26 + int32_t n = aSpec.Left(mScheme, dividerPosition); 1.27 + NS_ASSERTION(n == dividerPosition, "Storing the scheme failed!"); 1.28 + 1.29 + int32_t count = aSpec.Length() - dividerPosition - 1; 1.30 + n = aSpec.Mid(mPath, dividerPosition + 1, count); 1.31 + NS_ASSERTION(n == count, "Storing the path failed!"); 1.32 + 1.33 + ToLowerCase(mScheme); 1.34 +} 1.35 + 1.36 +static NS_DEFINE_CID(kNullPrincipalURIImplementationCID, 1.37 + NS_NULLPRINCIPALURI_IMPLEMENTATION_CID); 1.38 + 1.39 +NS_IMPL_ADDREF(nsNullPrincipalURI) 1.40 +NS_IMPL_RELEASE(nsNullPrincipalURI) 1.41 + 1.42 +NS_INTERFACE_MAP_BEGIN(nsNullPrincipalURI) 1.43 + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI) 1.44 + if (aIID.Equals(kNullPrincipalURIImplementationCID)) 1.45 + foundInterface = static_cast<nsIURI *>(this); 1.46 + else 1.47 + NS_INTERFACE_MAP_ENTRY(nsIURI) 1.48 + NS_INTERFACE_MAP_ENTRY(nsISizeOf) 1.49 +NS_INTERFACE_MAP_END 1.50 + 1.51 +//////////////////////////////////////////////////////////////////////////////// 1.52 +//// nsIURI 1.53 + 1.54 +NS_IMETHODIMP 1.55 +nsNullPrincipalURI::GetAsciiHost(nsACString &_host) 1.56 +{ 1.57 + _host.Truncate(); 1.58 + return NS_OK; 1.59 +} 1.60 + 1.61 +NS_IMETHODIMP 1.62 +nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec) 1.63 +{ 1.64 + nsAutoCString buffer; 1.65 + (void)GetSpec(buffer); 1.66 + NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec); 1.67 + return NS_OK; 1.68 +} 1.69 + 1.70 +NS_IMETHODIMP 1.71 +nsNullPrincipalURI::GetHost(nsACString &_host) 1.72 +{ 1.73 + _host.Truncate(); 1.74 + return NS_OK; 1.75 +} 1.76 + 1.77 +NS_IMETHODIMP 1.78 +nsNullPrincipalURI::SetHost(const nsACString &aHost) 1.79 +{ 1.80 + return NS_ERROR_NOT_IMPLEMENTED; 1.81 +} 1.82 + 1.83 +NS_IMETHODIMP 1.84 +nsNullPrincipalURI::GetHostPort(nsACString &_host) 1.85 +{ 1.86 + return NS_ERROR_NOT_IMPLEMENTED; 1.87 +} 1.88 + 1.89 +NS_IMETHODIMP 1.90 +nsNullPrincipalURI::SetHostPort(const nsACString &aHost) 1.91 +{ 1.92 + return NS_ERROR_NOT_IMPLEMENTED; 1.93 +} 1.94 + 1.95 +NS_IMETHODIMP 1.96 +nsNullPrincipalURI::GetOriginCharset(nsACString &_charset) 1.97 +{ 1.98 + _charset.Truncate(); 1.99 + return NS_OK; 1.100 +} 1.101 + 1.102 +NS_IMETHODIMP 1.103 +nsNullPrincipalURI::GetPassword(nsACString &_password) 1.104 +{ 1.105 + return NS_ERROR_NOT_IMPLEMENTED; 1.106 +} 1.107 + 1.108 +NS_IMETHODIMP 1.109 +nsNullPrincipalURI::SetPassword(const nsACString &aPassword) 1.110 +{ 1.111 + return NS_ERROR_NOT_IMPLEMENTED; 1.112 +} 1.113 + 1.114 +NS_IMETHODIMP 1.115 +nsNullPrincipalURI::GetPath(nsACString &_path) 1.116 +{ 1.117 + _path = mPath; 1.118 + return NS_OK; 1.119 +} 1.120 + 1.121 +NS_IMETHODIMP 1.122 +nsNullPrincipalURI::SetPath(const nsACString &aPath) 1.123 +{ 1.124 + return NS_ERROR_NOT_IMPLEMENTED; 1.125 +} 1.126 + 1.127 +NS_IMETHODIMP 1.128 +nsNullPrincipalURI::GetRef(nsACString &_ref) 1.129 +{ 1.130 + _ref.Truncate(); 1.131 + return NS_ERROR_NOT_IMPLEMENTED; 1.132 +} 1.133 + 1.134 +NS_IMETHODIMP 1.135 +nsNullPrincipalURI::SetRef(const nsACString &aRef) 1.136 +{ 1.137 + return NS_ERROR_NOT_IMPLEMENTED; 1.138 +} 1.139 + 1.140 +NS_IMETHODIMP 1.141 +nsNullPrincipalURI::GetPrePath(nsACString &_prePath) 1.142 +{ 1.143 + _prePath = mScheme + NS_LITERAL_CSTRING(":"); 1.144 + return NS_OK; 1.145 +} 1.146 + 1.147 +NS_IMETHODIMP 1.148 +nsNullPrincipalURI::GetPort(int32_t *_port) 1.149 +{ 1.150 + return NS_ERROR_NOT_IMPLEMENTED; 1.151 +} 1.152 + 1.153 +NS_IMETHODIMP 1.154 +nsNullPrincipalURI::SetPort(int32_t aPort) 1.155 +{ 1.156 + return NS_ERROR_NOT_IMPLEMENTED; 1.157 +} 1.158 + 1.159 +NS_IMETHODIMP 1.160 +nsNullPrincipalURI::GetScheme(nsACString &_scheme) 1.161 +{ 1.162 + _scheme = mScheme; 1.163 + return NS_OK; 1.164 +} 1.165 + 1.166 +NS_IMETHODIMP 1.167 +nsNullPrincipalURI::SetScheme(const nsACString &aScheme) 1.168 +{ 1.169 + return NS_ERROR_NOT_IMPLEMENTED; 1.170 +} 1.171 + 1.172 +NS_IMETHODIMP 1.173 +nsNullPrincipalURI::GetSpec(nsACString &_spec) 1.174 +{ 1.175 + _spec = mScheme + NS_LITERAL_CSTRING(":") + mPath; 1.176 + return NS_OK; 1.177 +} 1.178 + 1.179 +// result may contain unescaped UTF-8 characters 1.180 +NS_IMETHODIMP 1.181 +nsNullPrincipalURI::GetSpecIgnoringRef(nsACString &result) 1.182 +{ 1.183 + return GetSpec(result); 1.184 +} 1.185 + 1.186 +NS_IMETHODIMP 1.187 +nsNullPrincipalURI::GetHasRef(bool *result) 1.188 +{ 1.189 + *result = false; 1.190 + return NS_OK; 1.191 +} 1.192 + 1.193 +NS_IMETHODIMP 1.194 +nsNullPrincipalURI::SetSpec(const nsACString &aSpec) 1.195 +{ 1.196 + return NS_ERROR_NOT_IMPLEMENTED; 1.197 +} 1.198 + 1.199 +NS_IMETHODIMP 1.200 +nsNullPrincipalURI::GetUsername(nsACString &_username) 1.201 +{ 1.202 + return NS_ERROR_NOT_IMPLEMENTED; 1.203 +} 1.204 + 1.205 +NS_IMETHODIMP 1.206 +nsNullPrincipalURI::SetUsername(const nsACString &aUsername) 1.207 +{ 1.208 + return NS_ERROR_NOT_IMPLEMENTED; 1.209 +} 1.210 + 1.211 +NS_IMETHODIMP 1.212 +nsNullPrincipalURI::GetUserPass(nsACString &_userPass) 1.213 +{ 1.214 + return NS_ERROR_NOT_IMPLEMENTED; 1.215 +} 1.216 + 1.217 +NS_IMETHODIMP 1.218 +nsNullPrincipalURI::SetUserPass(const nsACString &aUserPass) 1.219 +{ 1.220 + return NS_ERROR_NOT_IMPLEMENTED; 1.221 +} 1.222 + 1.223 +NS_IMETHODIMP 1.224 +nsNullPrincipalURI::Clone(nsIURI **_newURI) 1.225 +{ 1.226 + nsCOMPtr<nsIURI> uri = 1.227 + new nsNullPrincipalURI(mScheme + NS_LITERAL_CSTRING(":") + mPath); 1.228 + uri.forget(_newURI); 1.229 + return NS_OK; 1.230 +} 1.231 + 1.232 +NS_IMETHODIMP 1.233 +nsNullPrincipalURI::CloneIgnoringRef(nsIURI **_newURI) 1.234 +{ 1.235 + // GetRef/SetRef not supported by nsNullPrincipalURI, so 1.236 + // CloneIgnoringRef() is the same as Clone(). 1.237 + return Clone(_newURI); 1.238 +} 1.239 + 1.240 +NS_IMETHODIMP 1.241 +nsNullPrincipalURI::Equals(nsIURI *aOther, bool *_equals) 1.242 +{ 1.243 + *_equals = false; 1.244 + nsNullPrincipalURI *otherURI; 1.245 + nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID, 1.246 + (void **)&otherURI); 1.247 + if (NS_SUCCEEDED(rv)) { 1.248 + *_equals = (mScheme == otherURI->mScheme && mPath == otherURI->mPath); 1.249 + NS_RELEASE(otherURI); 1.250 + } 1.251 + return NS_OK; 1.252 +} 1.253 + 1.254 +NS_IMETHODIMP 1.255 +nsNullPrincipalURI::EqualsExceptRef(nsIURI *aOther, bool *_equals) 1.256 +{ 1.257 + // GetRef/SetRef not supported by nsNullPrincipalURI, so 1.258 + // EqualsExceptRef() is the same as Equals(). 1.259 + return Equals(aOther, _equals); 1.260 +} 1.261 + 1.262 +NS_IMETHODIMP 1.263 +nsNullPrincipalURI::Resolve(const nsACString &aRelativePath, 1.264 + nsACString &_resolvedURI) 1.265 +{ 1.266 + _resolvedURI = aRelativePath; 1.267 + return NS_OK; 1.268 +} 1.269 + 1.270 +NS_IMETHODIMP 1.271 +nsNullPrincipalURI::SchemeIs(const char *aScheme, bool *_schemeIs) 1.272 +{ 1.273 + *_schemeIs = (0 == nsCRT::strcasecmp(mScheme.get(), aScheme)); 1.274 + return NS_OK; 1.275 +} 1.276 + 1.277 +//////////////////////////////////////////////////////////////////////////////// 1.278 +//// nsISizeOf 1.279 + 1.280 +size_t 1.281 +nsNullPrincipalURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.282 +{ 1.283 + return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) + 1.284 + mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf); 1.285 +} 1.286 + 1.287 +size_t 1.288 +nsNullPrincipalURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { 1.289 + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); 1.290 +} 1.291 +