Bug 1528152 [wpt PR 15381] - Quirks: move vertical-align-in-quirks.html to historical...
[gecko.git] / caps / NullPrincipalURI.cpp
blobb5d57d7eeb70b031dedef04c2164916fa317a50b
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"
14 #include "nsEscape.h"
15 #include "nsCRT.h"
16 #include "nsIUUIDGenerator.h"
18 #include "mozilla/GkRustUtils.h"
20 using namespace mozilla;
22 ////////////////////////////////////////////////////////////////////////////////
23 //// NullPrincipalURI
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);
36 return NS_OK;
39 /* static */
40 already_AddRefed<NullPrincipalURI> NullPrincipalURI::Create() {
41 RefPtr<NullPrincipalURI> uri = new NullPrincipalURI();
42 nsresult rv = uri->Init();
43 NS_ENSURE_SUCCESS(rv, nullptr);
44 return uri.forget();
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);
57 else
58 NS_INTERFACE_MAP_ENTRY(nsIURI)
59 NS_INTERFACE_MAP_ENTRY(nsISizeOf)
60 NS_INTERFACE_MAP_END
62 ////////////////////////////////////////////////////////////////////////////////
63 //// nsIURI
65 NS_IMETHODIMP
66 NullPrincipalURI::GetAsciiHost(nsACString& _host) {
67 _host.Truncate();
68 return NS_OK;
71 NS_IMETHODIMP
72 NullPrincipalURI::GetAsciiHostPort(nsACString& _hostport) {
73 return NS_ERROR_NOT_IMPLEMENTED;
76 NS_IMETHODIMP
77 NullPrincipalURI::GetAsciiSpec(nsACString& _spec) {
78 nsAutoCString buffer;
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);
84 return NS_OK;
87 NS_IMETHODIMP
88 NullPrincipalURI::GetHost(nsACString& _host) {
89 _host.Truncate();
90 return NS_OK;
93 nsresult NullPrincipalURI::SetHost(const nsACString& aHost) {
94 return NS_ERROR_NOT_IMPLEMENTED;
97 NS_IMETHODIMP
98 NullPrincipalURI::GetHostPort(nsACString& _host) {
99 return NS_ERROR_NOT_IMPLEMENTED;
102 nsresult NullPrincipalURI::SetHostPort(const nsACString& aHost) {
103 return NS_ERROR_NOT_IMPLEMENTED;
106 NS_IMETHODIMP
107 NullPrincipalURI::GetPassword(nsACString& _password) {
108 return NS_ERROR_NOT_IMPLEMENTED;
111 nsresult NullPrincipalURI::SetPassword(const nsACString& aPassword) {
112 return NS_ERROR_NOT_IMPLEMENTED;
115 NS_IMETHODIMP
116 NullPrincipalURI::GetPathQueryRef(nsACString& _path) {
117 _path = mPath;
118 return NS_OK;
121 nsresult NullPrincipalURI::SetPathQueryRef(const nsACString& aPath) {
122 return NS_ERROR_NOT_IMPLEMENTED;
125 NS_IMETHODIMP
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;
135 NS_IMETHODIMP
136 NullPrincipalURI::GetQuery(nsACString& aQuery) {
137 aQuery.Truncate();
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;
150 NS_IMETHODIMP
151 NullPrincipalURI::GetRef(nsACString& _ref) {
152 _ref.Truncate();
153 return NS_ERROR_NOT_IMPLEMENTED;
156 nsresult NullPrincipalURI::SetRef(const nsACString& aRef) {
157 return NS_ERROR_NOT_IMPLEMENTED;
160 NS_IMETHODIMP
161 NullPrincipalURI::GetPrePath(nsACString& _prePath) {
162 _prePath = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":");
163 return NS_OK;
166 NS_IMETHODIMP
167 NullPrincipalURI::GetPort(int32_t* _port) { return NS_ERROR_NOT_IMPLEMENTED; }
169 nsresult NullPrincipalURI::SetPort(int32_t aPort) {
170 return NS_ERROR_NOT_IMPLEMENTED;
173 NS_IMETHODIMP
174 NullPrincipalURI::GetScheme(nsACString& _scheme) {
175 _scheme = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME);
176 return NS_OK;
179 nsresult NullPrincipalURI::SetScheme(const nsACString& aScheme) {
180 return NS_ERROR_NOT_IMPLEMENTED;
183 NS_IMETHODIMP
184 NullPrincipalURI::GetSpec(nsACString& _spec) {
185 _spec = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":") + mPath;
186 return NS_OK;
189 // result may contain unescaped UTF-8 characters
190 NS_IMETHODIMP
191 NullPrincipalURI::GetSpecIgnoringRef(nsACString& _result) {
192 return GetSpec(_result);
195 NS_IMETHODIMP
196 NullPrincipalURI::GetHasRef(bool* _result) {
197 *_result = false;
198 return NS_OK;
201 nsresult NullPrincipalURI::SetSpecInternal(const nsACString& aSpec) {
202 return NS_ERROR_NOT_IMPLEMENTED;
205 NS_IMETHODIMP
206 NullPrincipalURI::GetUsername(nsACString& _username) {
207 return NS_ERROR_NOT_IMPLEMENTED;
210 nsresult NullPrincipalURI::SetUsername(const nsACString& aUsername) {
211 return NS_ERROR_NOT_IMPLEMENTED;
214 NS_IMETHODIMP
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);
225 uri.forget(_newURI);
226 return NS_OK;
229 NS_IMPL_ISUPPORTS(NullPrincipalURI::Mutator, nsIURISetters, nsIURIMutator)
231 NS_IMETHODIMP
232 NullPrincipalURI::Mutate(nsIURIMutator** aMutator) {
233 RefPtr<NullPrincipalURI::Mutator> mutator = new NullPrincipalURI::Mutator();
234 nsresult rv = mutator->InitFromURI(this);
235 if (NS_FAILED(rv)) {
236 return rv;
238 mutator.forget(aMutator);
239 return NS_OK;
242 NS_IMETHODIMP
243 NullPrincipalURI::Equals(nsIURI* aOther, bool* _equals) {
244 *_equals = false;
245 RefPtr<NullPrincipalURI> otherURI;
246 nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID,
247 getter_AddRefs(otherURI));
248 if (NS_SUCCEEDED(rv)) {
249 *_equals = mPath == otherURI->mPath;
251 return NS_OK;
254 NS_IMETHODIMP
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);
261 NS_IMETHODIMP
262 NullPrincipalURI::Resolve(const nsACString& aRelativePath,
263 nsACString& _resolvedURI) {
264 _resolvedURI = aRelativePath;
265 return NS_OK;
268 NS_IMETHODIMP
269 NullPrincipalURI::SchemeIs(const char* aScheme, bool* _schemeIs) {
270 *_schemeIs = (0 == nsCRT::strcasecmp(NS_NULLPRINCIPAL_SCHEME, aScheme));
271 return NS_OK;
274 NS_IMETHODIMP
275 NullPrincipalURI::GetDisplaySpec(nsACString& aUnicodeSpec) {
276 return GetSpec(aUnicodeSpec);
279 NS_IMETHODIMP
280 NullPrincipalURI::GetDisplayHostPort(nsACString& aUnicodeHostPort) {
281 return GetHostPort(aUnicodeHostPort);
284 NS_IMETHODIMP
285 NullPrincipalURI::GetDisplayHost(nsACString& aUnicodeHost) {
286 return GetHost(aUnicodeHost);
289 NS_IMETHODIMP
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");
301 return false;
304 nsresult rv = Init();
305 NS_ENSURE_SUCCESS(rv, false);
307 return true;
310 ////////////////////////////////////////////////////////////////////////////////
311 //// nsISizeOf
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);