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"
16 #include "nsIUUIDGenerator.h"
18 #include "mozilla/GkRustUtils.h"
20 using namespace mozilla
;
22 ////////////////////////////////////////////////////////////////////////////////
25 NullPrincipalURI::NullPrincipalURI() {}
27 NullPrincipalURI::NullPrincipalURI(const NullPrincipalURI
& aOther
) {
28 mPath
.Assign(aOther
.mPath
);
31 nsresult
NullPrincipalURI::Init() {
32 GkRustUtils::GenerateUUID(mPath
);
33 MOZ_ASSERT(mPath
.Length() == NSID_LENGTH
- 1);
34 MOZ_ASSERT(strlen(mPath
.get()) == NSID_LENGTH
- 1);
40 already_AddRefed
<NullPrincipalURI
> NullPrincipalURI::Create() {
41 RefPtr
<NullPrincipalURI
> uri
= new NullPrincipalURI();
42 nsresult rv
= uri
->Init();
43 NS_ENSURE_SUCCESS(rv
, nullptr);
47 static NS_DEFINE_CID(kNullPrincipalURIImplementationCID
,
48 NS_NULLPRINCIPALURI_IMPLEMENTATION_CID
);
50 NS_IMPL_ADDREF(NullPrincipalURI
)
51 NS_IMPL_RELEASE(NullPrincipalURI
)
53 NS_INTERFACE_MAP_BEGIN(NullPrincipalURI
)
54 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIURI
)
55 if (aIID
.Equals(kNullPrincipalURIImplementationCID
))
56 foundInterface
= static_cast<nsIURI
*>(this);
58 NS_INTERFACE_MAP_ENTRY(nsIURI
)
59 NS_INTERFACE_MAP_ENTRY(nsISizeOf
)
62 ////////////////////////////////////////////////////////////////////////////////
66 NullPrincipalURI::GetAsciiHost(nsACString
& _host
) {
72 NullPrincipalURI::GetAsciiHostPort(nsACString
& _hostport
) {
73 return NS_ERROR_NOT_IMPLEMENTED
;
77 NullPrincipalURI::GetAsciiSpec(nsACString
& _spec
) {
79 // Ignore the return value -- NullPrincipalURI::GetSpec() is infallible.
80 Unused
<< GetSpec(buffer
);
81 // This uses the infallible version of |NS_EscapeURL| as |GetSpec| is
82 // already infallible.
83 NS_EscapeURL(buffer
, esc_OnlyNonASCII
| esc_AlwaysCopy
, _spec
);
88 NullPrincipalURI::GetHost(nsACString
& _host
) {
93 nsresult
NullPrincipalURI::SetHost(const nsACString
& aHost
) {
94 return NS_ERROR_NOT_IMPLEMENTED
;
98 NullPrincipalURI::GetHostPort(nsACString
& _host
) {
99 return NS_ERROR_NOT_IMPLEMENTED
;
102 nsresult
NullPrincipalURI::SetHostPort(const nsACString
& aHost
) {
103 return NS_ERROR_NOT_IMPLEMENTED
;
107 NullPrincipalURI::GetPassword(nsACString
& _password
) {
108 return NS_ERROR_NOT_IMPLEMENTED
;
111 nsresult
NullPrincipalURI::SetPassword(const nsACString
& aPassword
) {
112 return NS_ERROR_NOT_IMPLEMENTED
;
116 NullPrincipalURI::GetPathQueryRef(nsACString
& _path
) {
121 nsresult
NullPrincipalURI::SetPathQueryRef(const nsACString
& aPath
) {
122 return NS_ERROR_NOT_IMPLEMENTED
;
126 NullPrincipalURI::GetFilePath(nsACString
& aFilePath
) {
127 aFilePath
.Truncate();
128 return NS_ERROR_NOT_IMPLEMENTED
;
131 nsresult
NullPrincipalURI::SetFilePath(const nsACString
& aFilePath
) {
132 return NS_ERROR_NOT_IMPLEMENTED
;
136 NullPrincipalURI::GetQuery(nsACString
& aQuery
) {
138 return NS_ERROR_NOT_IMPLEMENTED
;
141 nsresult
NullPrincipalURI::SetQuery(const nsACString
& aQuery
) {
142 return NS_ERROR_NOT_IMPLEMENTED
;
145 nsresult
NullPrincipalURI::SetQueryWithEncoding(const nsACString
& aQuery
,
146 const Encoding
* aEncoding
) {
147 return NS_ERROR_NOT_IMPLEMENTED
;
151 NullPrincipalURI::GetRef(nsACString
& _ref
) {
153 return NS_ERROR_NOT_IMPLEMENTED
;
156 nsresult
NullPrincipalURI::SetRef(const nsACString
& aRef
) {
157 return NS_ERROR_NOT_IMPLEMENTED
;
161 NullPrincipalURI::GetPrePath(nsACString
& _prePath
) {
162 _prePath
= NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME
":");
167 NullPrincipalURI::GetPort(int32_t* _port
) { return NS_ERROR_NOT_IMPLEMENTED
; }
169 nsresult
NullPrincipalURI::SetPort(int32_t aPort
) {
170 return NS_ERROR_NOT_IMPLEMENTED
;
174 NullPrincipalURI::GetScheme(nsACString
& _scheme
) {
175 _scheme
= NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME
);
179 nsresult
NullPrincipalURI::SetScheme(const nsACString
& aScheme
) {
180 return NS_ERROR_NOT_IMPLEMENTED
;
184 NullPrincipalURI::GetSpec(nsACString
& _spec
) {
185 _spec
= NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME
":") + mPath
;
189 // result may contain unescaped UTF-8 characters
191 NullPrincipalURI::GetSpecIgnoringRef(nsACString
& _result
) {
192 return GetSpec(_result
);
196 NullPrincipalURI::GetHasRef(bool* _result
) {
201 nsresult
NullPrincipalURI::SetSpecInternal(const nsACString
& aSpec
) {
202 return NS_ERROR_NOT_IMPLEMENTED
;
206 NullPrincipalURI::GetUsername(nsACString
& _username
) {
207 return NS_ERROR_NOT_IMPLEMENTED
;
210 nsresult
NullPrincipalURI::SetUsername(const nsACString
& aUsername
) {
211 return NS_ERROR_NOT_IMPLEMENTED
;
215 NullPrincipalURI::GetUserPass(nsACString
& _userPass
) {
216 return NS_ERROR_NOT_IMPLEMENTED
;
219 nsresult
NullPrincipalURI::SetUserPass(const nsACString
& aUserPass
) {
220 return NS_ERROR_NOT_IMPLEMENTED
;
223 nsresult
NullPrincipalURI::Clone(nsIURI
** _newURI
) {
224 nsCOMPtr
<nsIURI
> uri
= new NullPrincipalURI(*this);
229 NS_IMPL_ISUPPORTS(NullPrincipalURI::Mutator
, nsIURISetters
, nsIURIMutator
)
232 NullPrincipalURI::Mutate(nsIURIMutator
** aMutator
) {
233 RefPtr
<NullPrincipalURI::Mutator
> mutator
= new NullPrincipalURI::Mutator();
234 nsresult rv
= mutator
->InitFromURI(this);
238 mutator
.forget(aMutator
);
243 NullPrincipalURI::Equals(nsIURI
* aOther
, bool* _equals
) {
245 RefPtr
<NullPrincipalURI
> otherURI
;
246 nsresult rv
= aOther
->QueryInterface(kNullPrincipalURIImplementationCID
,
247 getter_AddRefs(otherURI
));
248 if (NS_SUCCEEDED(rv
)) {
249 *_equals
= mPath
== otherURI
->mPath
;
255 NullPrincipalURI::EqualsExceptRef(nsIURI
* aOther
, bool* _equals
) {
256 // GetRef/SetRef not supported by NullPrincipalURI, so
257 // EqualsExceptRef() is the same as Equals().
258 return Equals(aOther
, _equals
);
262 NullPrincipalURI::Resolve(const nsACString
& aRelativePath
,
263 nsACString
& _resolvedURI
) {
264 _resolvedURI
= aRelativePath
;
269 NullPrincipalURI::SchemeIs(const char* aScheme
, bool* _schemeIs
) {
270 *_schemeIs
= (0 == nsCRT::strcasecmp(NS_NULLPRINCIPAL_SCHEME
, aScheme
));
275 NullPrincipalURI::GetDisplaySpec(nsACString
& aUnicodeSpec
) {
276 return GetSpec(aUnicodeSpec
);
280 NullPrincipalURI::GetDisplayHostPort(nsACString
& aUnicodeHostPort
) {
281 return GetHostPort(aUnicodeHostPort
);
285 NullPrincipalURI::GetDisplayHost(nsACString
& aUnicodeHost
) {
286 return GetHost(aUnicodeHost
);
290 NullPrincipalURI::GetDisplayPrePath(nsACString
& aPrePath
) {
291 return GetPrePath(aPrePath
);
294 void NullPrincipalURI::Serialize(mozilla::ipc::URIParams
& aParams
) {
295 aParams
= mozilla::ipc::NullPrincipalURIParams();
298 bool NullPrincipalURI::Deserialize(const mozilla::ipc::URIParams
& aParams
) {
299 if (aParams
.type() != mozilla::ipc::URIParams::TNullPrincipalURIParams
) {
300 MOZ_ASSERT_UNREACHABLE("unexpected URIParams type");
304 nsresult rv
= Init();
305 NS_ENSURE_SUCCESS(rv
, false);
310 ////////////////////////////////////////////////////////////////////////////////
313 size_t NullPrincipalURI::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf
) const {
314 return mPath
.SizeOfExcludingThisIfUnshared(aMallocSizeOf
);
317 size_t NullPrincipalURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const {
318 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf
);