Source code

Revision control

Other Tools

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/. */
6
7
#include "NullPrincipalURI.h"
8
9
#include "mozilla/DebugOnly.h"
10
#include "mozilla/MemoryReporting.h"
11
12
#include "mozilla/ipc/URIParams.h"
13
14
#include "nsEscape.h"
15
#include "nsCRT.h"
16
17
#include "mozilla/GkRustUtils.h"
18
19
using namespace mozilla;
20
21
////////////////////////////////////////////////////////////////////////////////
22
//// NullPrincipalURI
23
24
NullPrincipalURI::NullPrincipalURI() {
25
GkRustUtils::GenerateUUID(mPath);
26
MOZ_ASSERT(mPath.Length() == NSID_LENGTH - 1);
27
MOZ_ASSERT(strlen(mPath.get()) == NSID_LENGTH - 1);
28
}
29
30
NullPrincipalURI::NullPrincipalURI(const NullPrincipalURI& aOther) {
31
mPath.Assign(aOther.mPath);
32
}
33
34
static NS_DEFINE_CID(kNullPrincipalURIImplementationCID,
35
NS_NULLPRINCIPALURI_IMPLEMENTATION_CID);
36
37
NS_IMPL_ADDREF(NullPrincipalURI)
38
NS_IMPL_RELEASE(NullPrincipalURI)
39
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
48
49
////////////////////////////////////////////////////////////////////////////////
50
//// nsIURI
51
52
NS_IMETHODIMP
53
NullPrincipalURI::GetAsciiHost(nsACString& _host) {
54
_host.Truncate();
55
return NS_OK;
56
}
57
58
NS_IMETHODIMP
59
NullPrincipalURI::GetAsciiHostPort(nsACString& _hostport) {
60
return NS_ERROR_NOT_IMPLEMENTED;
61
}
62
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;
72
}
73
74
NS_IMETHODIMP
75
NullPrincipalURI::GetHost(nsACString& _host) {
76
_host.Truncate();
77
return NS_OK;
78
}
79
80
nsresult NullPrincipalURI::SetHost(const nsACString& aHost) {
81
return NS_ERROR_NOT_IMPLEMENTED;
82
}
83
84
NS_IMETHODIMP
85
NullPrincipalURI::GetHostPort(nsACString& _host) {
86
return NS_ERROR_NOT_IMPLEMENTED;
87
}
88
89
nsresult NullPrincipalURI::SetHostPort(const nsACString& aHost) {
90
return NS_ERROR_NOT_IMPLEMENTED;
91
}
92
93
NS_IMETHODIMP
94
NullPrincipalURI::GetPassword(nsACString& _password) {
95
return NS_ERROR_NOT_IMPLEMENTED;
96
}
97
98
nsresult NullPrincipalURI::SetPassword(const nsACString& aPassword) {
99
return NS_ERROR_NOT_IMPLEMENTED;
100
}
101
102
NS_IMETHODIMP
103
NullPrincipalURI::GetPathQueryRef(nsACString& _path) {
104
_path = mPath;
105
return NS_OK;
106
}
107
108
nsresult NullPrincipalURI::SetPathQueryRef(const nsACString& aPath) {
109
return NS_ERROR_NOT_IMPLEMENTED;
110
}
111
112
NS_IMETHODIMP
113
NullPrincipalURI::GetFilePath(nsACString& aFilePath) {
114
aFilePath.Truncate();
115
return NS_ERROR_NOT_IMPLEMENTED;
116
}
117
118
nsresult NullPrincipalURI::SetFilePath(const nsACString& aFilePath) {
119
return NS_ERROR_NOT_IMPLEMENTED;
120
}
121
122
NS_IMETHODIMP
123
NullPrincipalURI::GetQuery(nsACString& aQuery) {
124
aQuery.Truncate();
125
return NS_ERROR_NOT_IMPLEMENTED;
126
}
127
128
nsresult NullPrincipalURI::SetQuery(const nsACString& aQuery) {
129
return NS_ERROR_NOT_IMPLEMENTED;
130
}
131
132
nsresult NullPrincipalURI::SetQueryWithEncoding(const nsACString& aQuery,
133
const Encoding* aEncoding) {
134
return NS_ERROR_NOT_IMPLEMENTED;
135
}
136
137
NS_IMETHODIMP
138
NullPrincipalURI::GetRef(nsACString& _ref) {
139
_ref.Truncate();
140
return NS_ERROR_NOT_IMPLEMENTED;
141
}
142
143
nsresult NullPrincipalURI::SetRef(const nsACString& aRef) {
144
return NS_ERROR_NOT_IMPLEMENTED;
145
}
146
147
NS_IMETHODIMP
148
NullPrincipalURI::GetPrePath(nsACString& _prePath) {
149
_prePath = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":");
150
return NS_OK;
151
}
152
153
NS_IMETHODIMP
154
NullPrincipalURI::GetPort(int32_t* _port) { return NS_ERROR_NOT_IMPLEMENTED; }
155
156
nsresult NullPrincipalURI::SetPort(int32_t aPort) {
157
return NS_ERROR_NOT_IMPLEMENTED;
158
}
159
160
NS_IMETHODIMP
161
NullPrincipalURI::GetScheme(nsACString& _scheme) {
162
_scheme = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME);
163
return NS_OK;
164
}
165
166
nsresult NullPrincipalURI::SetScheme(const nsACString& aScheme) {
167
return NS_ERROR_NOT_IMPLEMENTED;
168
}
169
170
NS_IMETHODIMP
171
NullPrincipalURI::GetSpec(nsACString& _spec) {
172
_spec = NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":") + mPath;
173
return NS_OK;
174
}
175
176
// result may contain unescaped UTF-8 characters
177
NS_IMETHODIMP
178
NullPrincipalURI::GetSpecIgnoringRef(nsACString& _result) {
179
return GetSpec(_result);
180
}
181
182
NS_IMETHODIMP
183
NullPrincipalURI::GetHasRef(bool* _result) {
184
*_result = false;
185
return NS_OK;
186
}
187
188
nsresult NullPrincipalURI::SetSpecInternal(const nsACString& aSpec) {
189
return NS_ERROR_NOT_IMPLEMENTED;
190
}
191
192
NS_IMETHODIMP
193
NullPrincipalURI::GetUsername(nsACString& _username) {
194
return NS_ERROR_NOT_IMPLEMENTED;
195
}
196
197
nsresult NullPrincipalURI::SetUsername(const nsACString& aUsername) {
198
return NS_ERROR_NOT_IMPLEMENTED;
199
}
200
201
NS_IMETHODIMP
202
NullPrincipalURI::GetUserPass(nsACString& _userPass) {
203
return NS_ERROR_NOT_IMPLEMENTED;
204
}
205
206
nsresult NullPrincipalURI::SetUserPass(const nsACString& aUserPass) {
207
return NS_ERROR_NOT_IMPLEMENTED;
208
}
209
210
nsresult NullPrincipalURI::Clone(nsIURI** _newURI) {
211
nsCOMPtr<nsIURI> uri = new NullPrincipalURI(*this);
212
uri.forget(_newURI);
213
return NS_OK;
214
}
215
216
NS_IMPL_ISUPPORTS(NullPrincipalURI::Mutator, nsIURISetters, nsIURIMutator)
217
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;
224
}
225
mutator.forget(aMutator);
226
return NS_OK;
227
}
228
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;
237
}
238
return NS_OK;
239
}
240
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);
246
}
247
248
NS_IMETHODIMP
249
NullPrincipalURI::Resolve(const nsACString& aRelativePath,
250
nsACString& _resolvedURI) {
251
_resolvedURI = aRelativePath;
252
return NS_OK;
253
}
254
255
NS_IMETHODIMP
256
NullPrincipalURI::SchemeIs(const char* aScheme, bool* _schemeIs) {
257
*_schemeIs = (0 == nsCRT::strcasecmp(NS_NULLPRINCIPAL_SCHEME, aScheme));
258
return NS_OK;
259
}
260
261
NS_IMETHODIMP
262
NullPrincipalURI::GetDisplaySpec(nsACString& aUnicodeSpec) {
263
return GetSpec(aUnicodeSpec);
264
}
265
266
NS_IMETHODIMP
267
NullPrincipalURI::GetDisplayHostPort(nsACString& aUnicodeHostPort) {
268
return GetHostPort(aUnicodeHostPort);
269
}
270
271
NS_IMETHODIMP
272
NullPrincipalURI::GetDisplayHost(nsACString& aUnicodeHost) {
273
return GetHost(aUnicodeHost);
274
}
275
276
NS_IMETHODIMP
277
NullPrincipalURI::GetDisplayPrePath(nsACString& aPrePath) {
278
return GetPrePath(aPrePath);
279
}
280
281
void NullPrincipalURI::Serialize(mozilla::ipc::URIParams& aParams) {
282
aParams = mozilla::ipc::NullPrincipalURIParams();
283
}
284
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;
289
}
290
return true;
291
}
292
293
////////////////////////////////////////////////////////////////////////////////
294
//// nsISizeOf
295
296
size_t NullPrincipalURI::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
297
return mPath.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
298
}
299
300
size_t NullPrincipalURI::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
301
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
302
}