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 "NullPrincipalURI.h"
9 #include "mozilla/DebugOnly.h"
10 #include "mozilla/MemoryReporting.h"
12 #include "mozilla/ipc/URIParams.h"
17 #include "mozilla/GkRustUtils.h"
19 using namespace mozilla
;
21 ////////////////////////////////////////////////////////////////////////////////
24 NullPrincipalURI::NullPrincipalURI() {
25 GkRustUtils::GenerateUUID(mPath
);
26 MOZ_ASSERT(mPath
.Length() == NSID_LENGTH
- 1);
27 MOZ_ASSERT(strlen(mPath
.get()) == NSID_LENGTH
- 1);
30 NullPrincipalURI::NullPrincipalURI(const NullPrincipalURI
& aOther
) {
31 mPath
.Assign(aOther
.mPath
);
34 static NS_DEFINE_CID(kNullPrincipalURIImplementationCID
,
35 NS_NULLPRINCIPALURI_IMPLEMENTATION_CID
);
37 NS_IMPL_ADDREF(NullPrincipalURI
)
38 NS_IMPL_RELEASE(NullPrincipalURI
)
40 NS_INTERFACE_MAP_BEGIN(NullPrincipalURI
)
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 NullPrincipalURI::GetAsciiHost(nsACString
& _host
) {
59 NullPrincipalURI::GetAsciiHostPort(nsACString
& _hostport
) {
60 return NS_ERROR_NOT_IMPLEMENTED
;
64 NullPrincipalURI::GetAsciiSpec(nsACString
& _spec
) {
66 // Ignore the return value -- NullPrincipalURI::GetSpec() is infallible.
67 Unused
<< GetSpec(buffer
);
68 // This uses the infallible version of |NS_EscapeURL| as |GetSpec| is
69 // already infallible.
70 NS_EscapeURL(buffer
, esc_OnlyNonASCII
| esc_AlwaysCopy
, _spec
);
75 NullPrincipalURI::GetHost(nsACString
& _host
) {
80 nsresult
NullPrincipalURI::SetHost(const nsACString
& aHost
) {
81 return NS_ERROR_NOT_IMPLEMENTED
;
85 NullPrincipalURI::GetHostPort(nsACString
& _host
) {
86 return NS_ERROR_NOT_IMPLEMENTED
;
89 nsresult
NullPrincipalURI::SetHostPort(const nsACString
& aHost
) {
90 return NS_ERROR_NOT_IMPLEMENTED
;
94 NullPrincipalURI::GetPassword(nsACString
& _password
) {
95 return NS_ERROR_NOT_IMPLEMENTED
;
98 nsresult
NullPrincipalURI::SetPassword(const nsACString
& aPassword
) {
99 return NS_ERROR_NOT_IMPLEMENTED
;
103 NullPrincipalURI::GetPathQueryRef(nsACString
& _path
) {
108 nsresult
NullPrincipalURI::SetPathQueryRef(const nsACString
& aPath
) {
109 return NS_ERROR_NOT_IMPLEMENTED
;
113 NullPrincipalURI::GetFilePath(nsACString
& aFilePath
) {
114 aFilePath
.Truncate();
115 return NS_ERROR_NOT_IMPLEMENTED
;
118 nsresult
NullPrincipalURI::SetFilePath(const nsACString
& aFilePath
) {
119 return NS_ERROR_NOT_IMPLEMENTED
;
123 NullPrincipalURI::GetQuery(nsACString
& aQuery
) {
125 return NS_ERROR_NOT_IMPLEMENTED
;
128 nsresult
NullPrincipalURI::SetQuery(const nsACString
& aQuery
) {
129 return NS_ERROR_NOT_IMPLEMENTED
;
132 nsresult
NullPrincipalURI::SetQueryWithEncoding(const nsACString
& aQuery
,
133 const Encoding
* aEncoding
) {
134 return NS_ERROR_NOT_IMPLEMENTED
;
138 NullPrincipalURI::GetRef(nsACString
& _ref
) {
140 return NS_ERROR_NOT_IMPLEMENTED
;
143 nsresult
NullPrincipalURI::SetRef(const nsACString
& aRef
) {
144 return NS_ERROR_NOT_IMPLEMENTED
;
148 NullPrincipalURI::GetPrePath(nsACString
& _prePath
) {
149 _prePath
= nsLiteralCString(NS_NULLPRINCIPAL_SCHEME
":");
154 NullPrincipalURI::GetPort(int32_t* _port
) { return NS_ERROR_NOT_IMPLEMENTED
; }
156 nsresult
NullPrincipalURI::SetPort(int32_t aPort
) {
157 return NS_ERROR_NOT_IMPLEMENTED
;
161 NullPrincipalURI::GetScheme(nsACString
& _scheme
) {
162 _scheme
= nsLiteralCString(NS_NULLPRINCIPAL_SCHEME
);
166 nsresult
NullPrincipalURI::SetScheme(const nsACString
& aScheme
) {
167 return NS_ERROR_NOT_IMPLEMENTED
;
171 NullPrincipalURI::GetSpec(nsACString
& _spec
) {
172 _spec
= nsLiteralCString(NS_NULLPRINCIPAL_SCHEME
":") + mPath
;
176 // result may contain unescaped UTF-8 characters
178 NullPrincipalURI::GetSpecIgnoringRef(nsACString
& _result
) {
179 return GetSpec(_result
);
183 NullPrincipalURI::GetHasRef(bool* _result
) {
188 nsresult
NullPrincipalURI::SetSpecInternal(const nsACString
& aSpec
) {
189 return NS_ERROR_NOT_IMPLEMENTED
;
193 NullPrincipalURI::GetUsername(nsACString
& _username
) {
194 return NS_ERROR_NOT_IMPLEMENTED
;
197 nsresult
NullPrincipalURI::SetUsername(const nsACString
& aUsername
) {
198 return NS_ERROR_NOT_IMPLEMENTED
;
202 NullPrincipalURI::GetUserPass(nsACString
& _userPass
) {
203 return NS_ERROR_NOT_IMPLEMENTED
;
206 nsresult
NullPrincipalURI::SetUserPass(const nsACString
& aUserPass
) {
207 return NS_ERROR_NOT_IMPLEMENTED
;
210 nsresult
NullPrincipalURI::Clone(nsIURI
** _newURI
) {
211 nsCOMPtr
<nsIURI
> uri
= new NullPrincipalURI(*this);
216 NS_IMPL_ISUPPORTS(NullPrincipalURI::Mutator
, nsIURISetters
, nsIURIMutator
)
219 NullPrincipalURI::Mutate(nsIURIMutator
** aMutator
) {
220 RefPtr
<NullPrincipalURI::Mutator
> mutator
= new NullPrincipalURI::Mutator();
221 nsresult rv
= mutator
->InitFromURI(this);
225 mutator
.forget(aMutator
);
230 NullPrincipalURI::Equals(nsIURI
* aOther
, bool* _equals
) {
232 RefPtr
<NullPrincipalURI
> otherURI
;
233 nsresult rv
= aOther
->QueryInterface(kNullPrincipalURIImplementationCID
,
234 getter_AddRefs(otherURI
));
235 if (NS_SUCCEEDED(rv
)) {
236 *_equals
= mPath
== otherURI
->mPath
;
242 NullPrincipalURI::EqualsExceptRef(nsIURI
* aOther
, bool* _equals
) {
243 // GetRef/SetRef not supported by NullPrincipalURI, so
244 // EqualsExceptRef() is the same as Equals().
245 return Equals(aOther
, _equals
);
249 NullPrincipalURI::Resolve(const nsACString
& aRelativePath
,
250 nsACString
& _resolvedURI
) {
251 _resolvedURI
= aRelativePath
;
256 NullPrincipalURI::SchemeIs(const char* aScheme
, bool* _schemeIs
) {
257 *_schemeIs
= (0 == nsCRT::strcasecmp(NS_NULLPRINCIPAL_SCHEME
, aScheme
));
262 NullPrincipalURI::GetDisplaySpec(nsACString
& aUnicodeSpec
) {
263 return GetSpec(aUnicodeSpec
);
267 NullPrincipalURI::GetDisplayHostPort(nsACString
& aUnicodeHostPort
) {
268 return GetHostPort(aUnicodeHostPort
);
272 NullPrincipalURI::GetDisplayHost(nsACString
& aUnicodeHost
) {
273 return GetHost(aUnicodeHost
);
277 NullPrincipalURI::GetDisplayPrePath(nsACString
& aPrePath
) {
278 return GetPrePath(aPrePath
);
281 void NullPrincipalURI::Serialize(mozilla::ipc::URIParams
& aParams
) {
282 aParams
= mozilla::ipc::NullPrincipalURIParams();
285 bool NullPrincipalURI::Deserialize(const mozilla::ipc::URIParams
& aParams
) {
286 if (aParams
.type() != mozilla::ipc::URIParams::TNullPrincipalURIParams
) {
287 MOZ_ASSERT_UNREACHABLE("unexpected URIParams type");
293 ////////////////////////////////////////////////////////////////////////////////
296 size_t NullPrincipalURI::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
) const {
297 return mPath
.SizeOfExcludingThisIfUnshared(aMallocSizeOf
);
300 size_t NullPrincipalURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const {
301 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf
);