Bumping gaia.json for 4 gaia revision(s) a=gaia-bump
[gecko.git] / caps / nsNullPrincipalURI.cpp
blob629626de67b0bc9ef1e01d835ad2c844b9cec02f
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=2 sts=2 expandtab
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsNullPrincipalURI.h"
9 #include "mozilla/DebugOnly.h"
10 #include "mozilla/MemoryReporting.h"
12 #include "nsNetUtil.h"
13 #include "nsEscape.h"
14 #include "nsCRT.h"
16 ////////////////////////////////////////////////////////////////////////////////
17 //// nsNullPrincipalURI
19 nsNullPrincipalURI::nsNullPrincipalURI(const nsCString &aSpec)
21 int32_t dividerPosition = aSpec.FindChar(':');
22 NS_ASSERTION(dividerPosition != -1, "Malformed URI!");
24 mozilla::DebugOnly<int32_t> n = aSpec.Left(mScheme, dividerPosition);
25 NS_ASSERTION(n == dividerPosition, "Storing the scheme failed!");
27 int32_t count = aSpec.Length() - dividerPosition - 1;
28 n = aSpec.Mid(mPath, dividerPosition + 1, count);
29 NS_ASSERTION(n == count, "Storing the path failed!");
31 ToLowerCase(mScheme);
34 static NS_DEFINE_CID(kNullPrincipalURIImplementationCID,
35 NS_NULLPRINCIPALURI_IMPLEMENTATION_CID);
37 NS_IMPL_ADDREF(nsNullPrincipalURI)
38 NS_IMPL_RELEASE(nsNullPrincipalURI)
40 NS_INTERFACE_MAP_BEGIN(nsNullPrincipalURI)
41 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI)
42 if (aIID.Equals(kNullPrincipalURIImplementationCID))
43 foundInterface = static_cast<nsIURI *>(this);
44 else
45 NS_INTERFACE_MAP_ENTRY(nsIURI)
46 NS_INTERFACE_MAP_ENTRY(nsISizeOf)
47 NS_INTERFACE_MAP_END
49 ////////////////////////////////////////////////////////////////////////////////
50 //// nsIURI
52 NS_IMETHODIMP
53 nsNullPrincipalURI::GetAsciiHost(nsACString &_host)
55 _host.Truncate();
56 return NS_OK;
59 NS_IMETHODIMP
60 nsNullPrincipalURI::GetAsciiSpec(nsACString &_spec)
62 nsAutoCString buffer;
63 (void)GetSpec(buffer);
64 NS_EscapeURL(buffer, esc_OnlyNonASCII | esc_AlwaysCopy, _spec);
65 return NS_OK;
68 NS_IMETHODIMP
69 nsNullPrincipalURI::GetHost(nsACString &_host)
71 _host.Truncate();
72 return NS_OK;
75 NS_IMETHODIMP
76 nsNullPrincipalURI::SetHost(const nsACString &aHost)
78 return NS_ERROR_NOT_IMPLEMENTED;
81 NS_IMETHODIMP
82 nsNullPrincipalURI::GetHostPort(nsACString &_host)
84 return NS_ERROR_NOT_IMPLEMENTED;
87 NS_IMETHODIMP
88 nsNullPrincipalURI::SetHostPort(const nsACString &aHost)
90 return NS_ERROR_NOT_IMPLEMENTED;
93 NS_IMETHODIMP
94 nsNullPrincipalURI::GetOriginCharset(nsACString &_charset)
96 _charset.Truncate();
97 return NS_OK;
100 NS_IMETHODIMP
101 nsNullPrincipalURI::GetPassword(nsACString &_password)
103 return NS_ERROR_NOT_IMPLEMENTED;
106 NS_IMETHODIMP
107 nsNullPrincipalURI::SetPassword(const nsACString &aPassword)
109 return NS_ERROR_NOT_IMPLEMENTED;
112 NS_IMETHODIMP
113 nsNullPrincipalURI::GetPath(nsACString &_path)
115 _path = mPath;
116 return NS_OK;
119 NS_IMETHODIMP
120 nsNullPrincipalURI::SetPath(const nsACString &aPath)
122 return NS_ERROR_NOT_IMPLEMENTED;
125 NS_IMETHODIMP
126 nsNullPrincipalURI::GetRef(nsACString &_ref)
128 _ref.Truncate();
129 return NS_ERROR_NOT_IMPLEMENTED;
132 NS_IMETHODIMP
133 nsNullPrincipalURI::SetRef(const nsACString &aRef)
135 return NS_ERROR_NOT_IMPLEMENTED;
138 NS_IMETHODIMP
139 nsNullPrincipalURI::GetPrePath(nsACString &_prePath)
141 _prePath = mScheme + NS_LITERAL_CSTRING(":");
142 return NS_OK;
145 NS_IMETHODIMP
146 nsNullPrincipalURI::GetPort(int32_t *_port)
148 return NS_ERROR_NOT_IMPLEMENTED;
151 NS_IMETHODIMP
152 nsNullPrincipalURI::SetPort(int32_t aPort)
154 return NS_ERROR_NOT_IMPLEMENTED;
157 NS_IMETHODIMP
158 nsNullPrincipalURI::GetScheme(nsACString &_scheme)
160 _scheme = mScheme;
161 return NS_OK;
164 NS_IMETHODIMP
165 nsNullPrincipalURI::SetScheme(const nsACString &aScheme)
167 return NS_ERROR_NOT_IMPLEMENTED;
170 NS_IMETHODIMP
171 nsNullPrincipalURI::GetSpec(nsACString &_spec)
173 _spec = mScheme + NS_LITERAL_CSTRING(":") + mPath;
174 return NS_OK;
177 // result may contain unescaped UTF-8 characters
178 NS_IMETHODIMP
179 nsNullPrincipalURI::GetSpecIgnoringRef(nsACString &result)
181 return GetSpec(result);
184 NS_IMETHODIMP
185 nsNullPrincipalURI::GetHasRef(bool *result)
187 *result = false;
188 return NS_OK;
191 NS_IMETHODIMP
192 nsNullPrincipalURI::SetSpec(const nsACString &aSpec)
194 return NS_ERROR_NOT_IMPLEMENTED;
197 NS_IMETHODIMP
198 nsNullPrincipalURI::GetUsername(nsACString &_username)
200 return NS_ERROR_NOT_IMPLEMENTED;
203 NS_IMETHODIMP
204 nsNullPrincipalURI::SetUsername(const nsACString &aUsername)
206 return NS_ERROR_NOT_IMPLEMENTED;
209 NS_IMETHODIMP
210 nsNullPrincipalURI::GetUserPass(nsACString &_userPass)
212 return NS_ERROR_NOT_IMPLEMENTED;
215 NS_IMETHODIMP
216 nsNullPrincipalURI::SetUserPass(const nsACString &aUserPass)
218 return NS_ERROR_NOT_IMPLEMENTED;
221 NS_IMETHODIMP
222 nsNullPrincipalURI::Clone(nsIURI **_newURI)
224 nsCOMPtr<nsIURI> uri =
225 new nsNullPrincipalURI(mScheme + NS_LITERAL_CSTRING(":") + mPath);
226 uri.forget(_newURI);
227 return NS_OK;
230 NS_IMETHODIMP
231 nsNullPrincipalURI::CloneIgnoringRef(nsIURI **_newURI)
233 // GetRef/SetRef not supported by nsNullPrincipalURI, so
234 // CloneIgnoringRef() is the same as Clone().
235 return Clone(_newURI);
238 NS_IMETHODIMP
239 nsNullPrincipalURI::Equals(nsIURI *aOther, bool *_equals)
241 *_equals = false;
242 nsNullPrincipalURI *otherURI;
243 nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID,
244 (void **)&otherURI);
245 if (NS_SUCCEEDED(rv)) {
246 *_equals = (mScheme == otherURI->mScheme && mPath == otherURI->mPath);
247 NS_RELEASE(otherURI);
249 return NS_OK;
252 NS_IMETHODIMP
253 nsNullPrincipalURI::EqualsExceptRef(nsIURI *aOther, bool *_equals)
255 // GetRef/SetRef not supported by nsNullPrincipalURI, so
256 // EqualsExceptRef() is the same as Equals().
257 return Equals(aOther, _equals);
260 NS_IMETHODIMP
261 nsNullPrincipalURI::Resolve(const nsACString &aRelativePath,
262 nsACString &_resolvedURI)
264 _resolvedURI = aRelativePath;
265 return NS_OK;
268 NS_IMETHODIMP
269 nsNullPrincipalURI::SchemeIs(const char *aScheme, bool *_schemeIs)
271 *_schemeIs = (0 == nsCRT::strcasecmp(mScheme.get(), aScheme));
272 return NS_OK;
275 ////////////////////////////////////////////////////////////////////////////////
276 //// nsISizeOf
278 size_t
279 nsNullPrincipalURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
281 return mScheme.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
282 mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
285 size_t
286 nsNullPrincipalURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
287 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);