Bug 1702311 [wpt PR 28319] - Windows system colors with a dark color-scheme, a=testonly
[gecko.git] / caps / NullPrincipalURI.cpp
blob02176f1ea32486f1f491940dff91f37f04b5b6a2
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"
17 #include "mozilla/GkRustUtils.h"
19 using namespace mozilla;
21 ////////////////////////////////////////////////////////////////////////////////
22 //// NullPrincipalURI
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);
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 NullPrincipalURI::GetAsciiHost(nsACString& _host) {
54 _host.Truncate();
55 return NS_OK;
58 NS_IMETHODIMP
59 NullPrincipalURI::GetAsciiHostPort(nsACString& _hostport) {
60 return NS_ERROR_NOT_IMPLEMENTED;
63 NS_IMETHODIMP
64 NullPrincipalURI::GetAsciiSpec(nsACString& _spec) {
65 nsAutoCString buffer;
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);
71 return NS_OK;
74 NS_IMETHODIMP
75 NullPrincipalURI::GetHost(nsACString& _host) {
76 _host.Truncate();
77 return NS_OK;
80 nsresult NullPrincipalURI::SetHost(const nsACString& aHost) {
81 return NS_ERROR_NOT_IMPLEMENTED;
84 NS_IMETHODIMP
85 NullPrincipalURI::GetHostPort(nsACString& _host) {
86 return NS_ERROR_NOT_IMPLEMENTED;
89 nsresult NullPrincipalURI::SetHostPort(const nsACString& aHost) {
90 return NS_ERROR_NOT_IMPLEMENTED;
93 NS_IMETHODIMP
94 NullPrincipalURI::GetPassword(nsACString& _password) {
95 return NS_ERROR_NOT_IMPLEMENTED;
98 nsresult NullPrincipalURI::SetPassword(const nsACString& aPassword) {
99 return NS_ERROR_NOT_IMPLEMENTED;
102 NS_IMETHODIMP
103 NullPrincipalURI::GetPathQueryRef(nsACString& _path) {
104 _path = mPath;
105 return NS_OK;
108 nsresult NullPrincipalURI::SetPathQueryRef(const nsACString& aPath) {
109 return NS_ERROR_NOT_IMPLEMENTED;
112 NS_IMETHODIMP
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;
122 NS_IMETHODIMP
123 NullPrincipalURI::GetQuery(nsACString& aQuery) {
124 aQuery.Truncate();
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;
137 NS_IMETHODIMP
138 NullPrincipalURI::GetRef(nsACString& _ref) {
139 _ref.Truncate();
140 return NS_ERROR_NOT_IMPLEMENTED;
143 nsresult NullPrincipalURI::SetRef(const nsACString& aRef) {
144 return NS_ERROR_NOT_IMPLEMENTED;
147 NS_IMETHODIMP
148 NullPrincipalURI::GetPrePath(nsACString& _prePath) {
149 _prePath = nsLiteralCString(NS_NULLPRINCIPAL_SCHEME ":");
150 return NS_OK;
153 NS_IMETHODIMP
154 NullPrincipalURI::GetPort(int32_t* _port) { return NS_ERROR_NOT_IMPLEMENTED; }
156 nsresult NullPrincipalURI::SetPort(int32_t aPort) {
157 return NS_ERROR_NOT_IMPLEMENTED;
160 NS_IMETHODIMP
161 NullPrincipalURI::GetScheme(nsACString& _scheme) {
162 _scheme = nsLiteralCString(NS_NULLPRINCIPAL_SCHEME);
163 return NS_OK;
166 nsresult NullPrincipalURI::SetScheme(const nsACString& aScheme) {
167 return NS_ERROR_NOT_IMPLEMENTED;
170 NS_IMETHODIMP
171 NullPrincipalURI::GetSpec(nsACString& _spec) {
172 _spec = nsLiteralCString(NS_NULLPRINCIPAL_SCHEME ":") + mPath;
173 return NS_OK;
176 // result may contain unescaped UTF-8 characters
177 NS_IMETHODIMP
178 NullPrincipalURI::GetSpecIgnoringRef(nsACString& _result) {
179 return GetSpec(_result);
182 NS_IMETHODIMP
183 NullPrincipalURI::GetHasRef(bool* _result) {
184 *_result = false;
185 return NS_OK;
188 nsresult NullPrincipalURI::SetSpecInternal(const nsACString& aSpec) {
189 return NS_ERROR_NOT_IMPLEMENTED;
192 NS_IMETHODIMP
193 NullPrincipalURI::GetUsername(nsACString& _username) {
194 return NS_ERROR_NOT_IMPLEMENTED;
197 nsresult NullPrincipalURI::SetUsername(const nsACString& aUsername) {
198 return NS_ERROR_NOT_IMPLEMENTED;
201 NS_IMETHODIMP
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);
212 uri.forget(_newURI);
213 return NS_OK;
216 NS_IMPL_ISUPPORTS(NullPrincipalURI::Mutator, nsIURISetters, nsIURIMutator)
218 NS_IMETHODIMP
219 NullPrincipalURI::Mutate(nsIURIMutator** aMutator) {
220 RefPtr<NullPrincipalURI::Mutator> mutator = new NullPrincipalURI::Mutator();
221 nsresult rv = mutator->InitFromURI(this);
222 if (NS_FAILED(rv)) {
223 return rv;
225 mutator.forget(aMutator);
226 return NS_OK;
229 NS_IMETHODIMP
230 NullPrincipalURI::Equals(nsIURI* aOther, bool* _equals) {
231 *_equals = false;
232 RefPtr<NullPrincipalURI> otherURI;
233 nsresult rv = aOther->QueryInterface(kNullPrincipalURIImplementationCID,
234 getter_AddRefs(otherURI));
235 if (NS_SUCCEEDED(rv)) {
236 *_equals = mPath == otherURI->mPath;
238 return NS_OK;
241 NS_IMETHODIMP
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);
248 NS_IMETHODIMP
249 NullPrincipalURI::Resolve(const nsACString& aRelativePath,
250 nsACString& _resolvedURI) {
251 _resolvedURI = aRelativePath;
252 return NS_OK;
255 NS_IMETHODIMP
256 NullPrincipalURI::SchemeIs(const char* aScheme, bool* _schemeIs) {
257 *_schemeIs = (0 == nsCRT::strcasecmp(NS_NULLPRINCIPAL_SCHEME, aScheme));
258 return NS_OK;
261 NS_IMETHODIMP
262 NullPrincipalURI::GetDisplaySpec(nsACString& aUnicodeSpec) {
263 return GetSpec(aUnicodeSpec);
266 NS_IMETHODIMP
267 NullPrincipalURI::GetDisplayHostPort(nsACString& aUnicodeHostPort) {
268 return GetHostPort(aUnicodeHostPort);
271 NS_IMETHODIMP
272 NullPrincipalURI::GetDisplayHost(nsACString& aUnicodeHost) {
273 return GetHost(aUnicodeHost);
276 NS_IMETHODIMP
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");
288 return false;
290 return true;
293 ////////////////////////////////////////////////////////////////////////////////
294 //// nsISizeOf
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);