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"
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!");
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);
45 NS_INTERFACE_MAP_ENTRY(nsIURI
)
46 NS_INTERFACE_MAP_ENTRY(nsISizeOf
)
49 ////////////////////////////////////////////////////////////////////////////////
53 nsNullPrincipalURI::GetAsciiHost(nsACString
&_host
)
60 nsNullPrincipalURI::GetAsciiSpec(nsACString
&_spec
)
63 (void)GetSpec(buffer
);
64 NS_EscapeURL(buffer
, esc_OnlyNonASCII
| esc_AlwaysCopy
, _spec
);
69 nsNullPrincipalURI::GetHost(nsACString
&_host
)
76 nsNullPrincipalURI::SetHost(const nsACString
&aHost
)
78 return NS_ERROR_NOT_IMPLEMENTED
;
82 nsNullPrincipalURI::GetHostPort(nsACString
&_host
)
84 return NS_ERROR_NOT_IMPLEMENTED
;
88 nsNullPrincipalURI::SetHostPort(const nsACString
&aHost
)
90 return NS_ERROR_NOT_IMPLEMENTED
;
94 nsNullPrincipalURI::GetOriginCharset(nsACString
&_charset
)
101 nsNullPrincipalURI::GetPassword(nsACString
&_password
)
103 return NS_ERROR_NOT_IMPLEMENTED
;
107 nsNullPrincipalURI::SetPassword(const nsACString
&aPassword
)
109 return NS_ERROR_NOT_IMPLEMENTED
;
113 nsNullPrincipalURI::GetPath(nsACString
&_path
)
120 nsNullPrincipalURI::SetPath(const nsACString
&aPath
)
122 return NS_ERROR_NOT_IMPLEMENTED
;
126 nsNullPrincipalURI::GetRef(nsACString
&_ref
)
129 return NS_ERROR_NOT_IMPLEMENTED
;
133 nsNullPrincipalURI::SetRef(const nsACString
&aRef
)
135 return NS_ERROR_NOT_IMPLEMENTED
;
139 nsNullPrincipalURI::GetPrePath(nsACString
&_prePath
)
141 _prePath
= mScheme
+ NS_LITERAL_CSTRING(":");
146 nsNullPrincipalURI::GetPort(int32_t *_port
)
148 return NS_ERROR_NOT_IMPLEMENTED
;
152 nsNullPrincipalURI::SetPort(int32_t aPort
)
154 return NS_ERROR_NOT_IMPLEMENTED
;
158 nsNullPrincipalURI::GetScheme(nsACString
&_scheme
)
165 nsNullPrincipalURI::SetScheme(const nsACString
&aScheme
)
167 return NS_ERROR_NOT_IMPLEMENTED
;
171 nsNullPrincipalURI::GetSpec(nsACString
&_spec
)
173 _spec
= mScheme
+ NS_LITERAL_CSTRING(":") + mPath
;
177 // result may contain unescaped UTF-8 characters
179 nsNullPrincipalURI::GetSpecIgnoringRef(nsACString
&result
)
181 return GetSpec(result
);
185 nsNullPrincipalURI::GetHasRef(bool *result
)
192 nsNullPrincipalURI::SetSpec(const nsACString
&aSpec
)
194 return NS_ERROR_NOT_IMPLEMENTED
;
198 nsNullPrincipalURI::GetUsername(nsACString
&_username
)
200 return NS_ERROR_NOT_IMPLEMENTED
;
204 nsNullPrincipalURI::SetUsername(const nsACString
&aUsername
)
206 return NS_ERROR_NOT_IMPLEMENTED
;
210 nsNullPrincipalURI::GetUserPass(nsACString
&_userPass
)
212 return NS_ERROR_NOT_IMPLEMENTED
;
216 nsNullPrincipalURI::SetUserPass(const nsACString
&aUserPass
)
218 return NS_ERROR_NOT_IMPLEMENTED
;
222 nsNullPrincipalURI::Clone(nsIURI
**_newURI
)
224 nsCOMPtr
<nsIURI
> uri
=
225 new nsNullPrincipalURI(mScheme
+ NS_LITERAL_CSTRING(":") + mPath
);
231 nsNullPrincipalURI::CloneIgnoringRef(nsIURI
**_newURI
)
233 // GetRef/SetRef not supported by nsNullPrincipalURI, so
234 // CloneIgnoringRef() is the same as Clone().
235 return Clone(_newURI
);
239 nsNullPrincipalURI::Equals(nsIURI
*aOther
, bool *_equals
)
242 nsNullPrincipalURI
*otherURI
;
243 nsresult rv
= aOther
->QueryInterface(kNullPrincipalURIImplementationCID
,
245 if (NS_SUCCEEDED(rv
)) {
246 *_equals
= (mScheme
== otherURI
->mScheme
&& mPath
== otherURI
->mPath
);
247 NS_RELEASE(otherURI
);
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
);
261 nsNullPrincipalURI::Resolve(const nsACString
&aRelativePath
,
262 nsACString
&_resolvedURI
)
264 _resolvedURI
= aRelativePath
;
269 nsNullPrincipalURI::SchemeIs(const char *aScheme
, bool *_schemeIs
)
271 *_schemeIs
= (0 == nsCRT::strcasecmp(mScheme
.get(), aScheme
));
275 ////////////////////////////////////////////////////////////////////////////////
279 nsNullPrincipalURI::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const
281 return mScheme
.SizeOfExcludingThisIfUnshared(aMallocSizeOf
) +
282 mPath
.SizeOfExcludingThisIfUnshared(aMallocSizeOf
);
286 nsNullPrincipalURI::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
287 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf
);