Other Tools

1
/*
2
* DO NOT EDIT. THIS FILE IS GENERATED FROM /builds/worker/workspace/build/src/netwerk/base/nsIURIMutator.idl
3
*/
4
5
#ifndef __gen_nsIURIMutator_h__
6
#define __gen_nsIURIMutator_h__
7
8
9
#ifndef __gen_nsISupports_h__
10
#include "nsISupports.h"
11
#endif
12
13
/* For IDL files that don't want to include root IDL files. */
14
#ifndef NS_NO_VTABLE
15
#define NS_NO_VTABLE
16
#endif
17
class nsIURI; /* forward declaration */
18
19
class nsIObjectInputStream; /* forward declaration */
20
21
class nsIURIMutator; /* forward declaration */
22
23
#include "nsString.h"
24
#include "nsCOMPtr.h"
25
#include <functional>
26
#undef SetPort // XXX Windows!
27
namespace mozilla {
28
class Encoding;
29
}
30
namespace mozilla {
31
namespace ipc {
32
class URIParams;
33
} // namespace ipc
34
} // namespace mozilla
35
template <class T>
36
class BaseURIMutator
37
{
38
// This is the base class that can be extended by implementors of nsIURIMutator
39
// in order to avoid code duplication
40
// Class type T should be the type of the class that implements nsIURI
41
protected:
42
virtual T* Create()
43
{
44
return new T();
45
}
46
MOZ_MUST_USE nsresult InitFromURI(T* aURI)
47
{
48
nsCOMPtr<nsIURI> clone;
49
nsresult rv = aURI->Clone(getter_AddRefs(clone));
50
if (NS_FAILED(rv)) {
51
return rv;
52
}
53
mURI = static_cast<T*>(clone.get());
54
return NS_OK;
55
}
56
MOZ_MUST_USE nsresult InitFromInputStream(nsIObjectInputStream* aStream)
57
{
58
RefPtr<T> uri = Create();
59
nsresult rv = uri->ReadPrivate(aStream);
60
if (NS_FAILED(rv)) {
61
return rv;
62
}
63
mURI = uri.forget();
64
return NS_OK;
65
}
66
MOZ_MUST_USE nsresult InitFromIPCParams(const mozilla::ipc::URIParams& aParams)
67
{
68
RefPtr<T> uri = Create();
69
bool ret = uri->Deserialize(aParams);
70
if (!ret) {
71
return NS_ERROR_FAILURE;
72
}
73
mURI = uri.forget();
74
return NS_OK;
75
}
76
MOZ_MUST_USE nsresult InitFromSpec(const nsACString& aSpec)
77
{
78
nsresult rv = NS_OK;
79
RefPtr<T> uri;
80
if (mURI) {
81
// This only works because all other Init methods create a new object
82
mURI.swap(uri);
83
} else {
84
uri = Create();
85
}
86
rv = uri->SetSpecInternal(aSpec);
87
if (NS_FAILED(rv)) {
88
return rv;
89
}
90
mURI = uri.forget();
91
return NS_OK;
92
}
93
RefPtr<T> mURI;
94
};
95
// Since most implementations of nsIURIMutator would extend BaseURIMutator,
96
// some methods would have the same implementation. We provide a useful macro
97
// to avoid code duplication.
98
#define NS_DEFINE_NSIMUTATOR_COMMON \
99
MOZ_MUST_USE NS_IMETHOD \
100
Deserialize(const mozilla::ipc::URIParams& aParams) override \
101
{ \
102
return InitFromIPCParams(aParams); \
103
} \
104
\
105
MOZ_MUST_USE NS_IMETHOD \
106
Finalize(nsIURI** aURI) override \
107
{ \
108
mURI.forget(aURI); return NS_OK; \
109
} \
110
\
111
MOZ_MUST_USE NS_IMETHOD \
112
SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override \
113
{ \
114
if (aMutator) NS_ADDREF(*aMutator = this); \
115
return InitFromSpec(aSpec); \
116
} \
117
// Implements AddRef, Release and QueryInterface for the mutator
118
#define NS_IMPL_NSIURIMUTATOR_ISUPPORTS(aClass, ...) \
119
NS_IMPL_ADDREF(aClass) \
120
NS_IMPL_RELEASE(aClass) \
121
NS_IMPL_NSIURIMUTATOR_QUERY_INTERFACE(aClass, __VA_ARGS__) \
122
// The list of interfaces is queried and an AddRef-ed pointer is returned if
123
// there is a match. Otherwise, we call QueryInterface on mURI and return.
124
// The reason for this specialized QueryInterface implementation is that we
125
// we want to be able to instantiate the mutator for a given CID of a
126
// nsIURI implementation, call nsISerializable.Read() on the mutator to
127
// deserialize the URI then QueryInterface the mutator to an nsIURI interface.
128
// See bug 1442239.
129
// If you QueryInterface a mutator to an interface of the URI
130
// implementation this is similar to calling Finalize.
131
#define NS_IMPL_NSIURIMUTATOR_QUERY_INTERFACE(aClass, ...) \
132
static_assert(MOZ_ARG_COUNT(__VA_ARGS__) > 0, \
133
"Need more arguments"); \
134
NS_INTERFACE_MAP_BEGIN(aClass) \
135
nsCOMPtr<nsIURI> uri; \
136
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIMutator) \
137
MOZ_FOR_EACH(NS_INTERFACE_MAP_ENTRY, (), (__VA_ARGS__)) \
138
if (aIID.Equals(NS_GET_IID(nsIClassInfo))) { \
139
foundInterface = nullptr; \
140
} else \
141
if (mURI && \
142
NS_SUCCEEDED(mURI->QueryInterface(aIID, getter_AddRefs(uri)))) { \
143
mURI = nullptr; \
144
foundInterface = uri.get(); \
145
} else \
146
NS_INTERFACE_MAP_END \
147
148
/* starting interface: nsIURISetSpec */
149
#define NS_IURISETSPEC_IID_STR "1fc53257-898b-4c5e-b69c-05bc84b4cd8f"
150
151
#define NS_IURISETSPEC_IID \
152
{0x1fc53257, 0x898b, 0x4c5e, \
153
{ 0xb6, 0x9c, 0x05, 0xbc, 0x84, 0xb4, 0xcd, 0x8f }}
154
155
class NS_NO_VTABLE nsIURISetSpec : public nsISupports {
156
public:
157
158
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IURISETSPEC_IID)
159
160
/* [must_use] nsIURIMutator setSpec (in AUTF8String aSpec); */
161
MOZ_MUST_USE NS_IMETHOD SetSpec(const nsACString& aSpec, nsIURIMutator **_retval) = 0;
162
163
};
164
165
NS_DEFINE_STATIC_IID_ACCESSOR(nsIURISetSpec, NS_IURISETSPEC_IID)
166
167
/* Use this macro when declaring classes that implement this interface. */
168
#define NS_DECL_NSIURISETSPEC \
169
MOZ_MUST_USE NS_IMETHOD SetSpec(const nsACString& aSpec, nsIURIMutator **_retval) override;
170
171
/* Use this macro when declaring the members of this interface when the
172
class doesn't implement the interface. This is useful for forwarding. */
173
#define NS_DECL_NON_VIRTUAL_NSIURISETSPEC \
174
MOZ_MUST_USE nsresult SetSpec(const nsACString& aSpec, nsIURIMutator **_retval);
175
176
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
177
#define NS_FORWARD_NSIURISETSPEC(_to) \
178
MOZ_MUST_USE NS_IMETHOD SetSpec(const nsACString& aSpec, nsIURIMutator **_retval) override { return _to SetSpec(aSpec, _retval); }
179
180
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
181
#define NS_FORWARD_SAFE_NSIURISETSPEC(_to) \
182
MOZ_MUST_USE NS_IMETHOD SetSpec(const nsACString& aSpec, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetSpec(aSpec, _retval); }
183
184
185
/* starting interface: nsIURISetters */
186
#define NS_IURISETTERS_IID_STR "5403a6ec-99d7-405e-8b45-9f805bbdfcef"
187
188
#define NS_IURISETTERS_IID \
189
{0x5403a6ec, 0x99d7, 0x405e, \
190
{ 0x8b, 0x45, 0x9f, 0x80, 0x5b, 0xbd, 0xfc, 0xef }}
191
192
class NS_NO_VTABLE nsIURISetters : public nsIURISetSpec {
193
public:
194
195
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IURISETTERS_IID)
196
197
/* [must_use] nsIURIMutator setScheme (in AUTF8String aScheme); */
198
MOZ_MUST_USE NS_IMETHOD SetScheme(const nsACString& aScheme, nsIURIMutator **_retval) = 0;
199
200
/* [must_use] nsIURIMutator setUserPass (in AUTF8String aUserPass); */
201
MOZ_MUST_USE NS_IMETHOD SetUserPass(const nsACString& aUserPass, nsIURIMutator **_retval) = 0;
202
203
/* [must_use] nsIURIMutator setUsername (in AUTF8String aUsername); */
204
MOZ_MUST_USE NS_IMETHOD SetUsername(const nsACString& aUsername, nsIURIMutator **_retval) = 0;
205
206
/* [must_use] nsIURIMutator setPassword (in AUTF8String aPassword); */
207
MOZ_MUST_USE NS_IMETHOD SetPassword(const nsACString& aPassword, nsIURIMutator **_retval) = 0;
208
209
/* [must_use] nsIURIMutator setHostPort (in AUTF8String aHostPort); */
210
MOZ_MUST_USE NS_IMETHOD SetHostPort(const nsACString& aHostPort, nsIURIMutator **_retval) = 0;
211
212
/* [must_use] nsIURIMutator setHost (in AUTF8String aHost); */
213
MOZ_MUST_USE NS_IMETHOD SetHost(const nsACString& aHost, nsIURIMutator **_retval) = 0;
214
215
/* [must_use] nsIURIMutator setPort (in long aPort); */
216
MOZ_MUST_USE NS_IMETHOD SetPort(int32_t aPort, nsIURIMutator **_retval) = 0;
217
218
/* [must_use] nsIURIMutator setPathQueryRef (in AUTF8String aPathQueryRef); */
219
MOZ_MUST_USE NS_IMETHOD SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator **_retval) = 0;
220
221
/* [must_use] nsIURIMutator setRef (in AUTF8String aRef); */
222
MOZ_MUST_USE NS_IMETHOD SetRef(const nsACString& aRef, nsIURIMutator **_retval) = 0;
223
224
/* [must_use] nsIURIMutator setFilePath (in AUTF8String aFilePath); */
225
MOZ_MUST_USE NS_IMETHOD SetFilePath(const nsACString& aFilePath, nsIURIMutator **_retval) = 0;
226
227
/* [must_use] nsIURIMutator setQuery (in AUTF8String aQuery); */
228
MOZ_MUST_USE NS_IMETHOD SetQuery(const nsACString& aQuery, nsIURIMutator **_retval) = 0;
229
230
/* [must_use,noscript] nsIURIMutator setQueryWithEncoding (in AUTF8String query, in Encoding encoding); */
231
MOZ_MUST_USE NS_IMETHOD SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding * encoding, nsIURIMutator **_retval) = 0;
232
233
};
234
235
NS_DEFINE_STATIC_IID_ACCESSOR(nsIURISetters, NS_IURISETTERS_IID)
236
237
/* Use this macro when declaring classes that implement this interface. */
238
#define NS_DECL_NSIURISETTERS \
239
MOZ_MUST_USE NS_IMETHOD SetScheme(const nsACString& aScheme, nsIURIMutator **_retval) override; \
240
MOZ_MUST_USE NS_IMETHOD SetUserPass(const nsACString& aUserPass, nsIURIMutator **_retval) override; \
241
MOZ_MUST_USE NS_IMETHOD SetUsername(const nsACString& aUsername, nsIURIMutator **_retval) override; \
242
MOZ_MUST_USE NS_IMETHOD SetPassword(const nsACString& aPassword, nsIURIMutator **_retval) override; \
243
MOZ_MUST_USE NS_IMETHOD SetHostPort(const nsACString& aHostPort, nsIURIMutator **_retval) override; \
244
MOZ_MUST_USE NS_IMETHOD SetHost(const nsACString& aHost, nsIURIMutator **_retval) override; \
245
MOZ_MUST_USE NS_IMETHOD SetPort(int32_t aPort, nsIURIMutator **_retval) override; \
246
MOZ_MUST_USE NS_IMETHOD SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator **_retval) override; \
247
MOZ_MUST_USE NS_IMETHOD SetRef(const nsACString& aRef, nsIURIMutator **_retval) override; \
248
MOZ_MUST_USE NS_IMETHOD SetFilePath(const nsACString& aFilePath, nsIURIMutator **_retval) override; \
249
MOZ_MUST_USE NS_IMETHOD SetQuery(const nsACString& aQuery, nsIURIMutator **_retval) override; \
250
MOZ_MUST_USE NS_IMETHOD SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding * encoding, nsIURIMutator **_retval) override;
251
252
/* Use this macro when declaring the members of this interface when the
253
class doesn't implement the interface. This is useful for forwarding. */
254
#define NS_DECL_NON_VIRTUAL_NSIURISETTERS \
255
MOZ_MUST_USE nsresult SetScheme(const nsACString& aScheme, nsIURIMutator **_retval); \
256
MOZ_MUST_USE nsresult SetUserPass(const nsACString& aUserPass, nsIURIMutator **_retval); \
257
MOZ_MUST_USE nsresult SetUsername(const nsACString& aUsername, nsIURIMutator **_retval); \
258
MOZ_MUST_USE nsresult SetPassword(const nsACString& aPassword, nsIURIMutator **_retval); \
259
MOZ_MUST_USE nsresult SetHostPort(const nsACString& aHostPort, nsIURIMutator **_retval); \
260
MOZ_MUST_USE nsresult SetHost(const nsACString& aHost, nsIURIMutator **_retval); \
261
MOZ_MUST_USE nsresult SetPort(int32_t aPort, nsIURIMutator **_retval); \
262
MOZ_MUST_USE nsresult SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator **_retval); \
263
MOZ_MUST_USE nsresult SetRef(const nsACString& aRef, nsIURIMutator **_retval); \
264
MOZ_MUST_USE nsresult SetFilePath(const nsACString& aFilePath, nsIURIMutator **_retval); \
265
MOZ_MUST_USE nsresult SetQuery(const nsACString& aQuery, nsIURIMutator **_retval); \
266
MOZ_MUST_USE nsresult SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding * encoding, nsIURIMutator **_retval);
267
268
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
269
#define NS_FORWARD_NSIURISETTERS(_to) \
270
MOZ_MUST_USE NS_IMETHOD SetScheme(const nsACString& aScheme, nsIURIMutator **_retval) override { return _to SetScheme(aScheme, _retval); } \
271
MOZ_MUST_USE NS_IMETHOD SetUserPass(const nsACString& aUserPass, nsIURIMutator **_retval) override { return _to SetUserPass(aUserPass, _retval); } \
272
MOZ_MUST_USE NS_IMETHOD SetUsername(const nsACString& aUsername, nsIURIMutator **_retval) override { return _to SetUsername(aUsername, _retval); } \
273
MOZ_MUST_USE NS_IMETHOD SetPassword(const nsACString& aPassword, nsIURIMutator **_retval) override { return _to SetPassword(aPassword, _retval); } \
274
MOZ_MUST_USE NS_IMETHOD SetHostPort(const nsACString& aHostPort, nsIURIMutator **_retval) override { return _to SetHostPort(aHostPort, _retval); } \
275
MOZ_MUST_USE NS_IMETHOD SetHost(const nsACString& aHost, nsIURIMutator **_retval) override { return _to SetHost(aHost, _retval); } \
276
MOZ_MUST_USE NS_IMETHOD SetPort(int32_t aPort, nsIURIMutator **_retval) override { return _to SetPort(aPort, _retval); } \
277
MOZ_MUST_USE NS_IMETHOD SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator **_retval) override { return _to SetPathQueryRef(aPathQueryRef, _retval); } \
278
MOZ_MUST_USE NS_IMETHOD SetRef(const nsACString& aRef, nsIURIMutator **_retval) override { return _to SetRef(aRef, _retval); } \
279
MOZ_MUST_USE NS_IMETHOD SetFilePath(const nsACString& aFilePath, nsIURIMutator **_retval) override { return _to SetFilePath(aFilePath, _retval); } \
280
MOZ_MUST_USE NS_IMETHOD SetQuery(const nsACString& aQuery, nsIURIMutator **_retval) override { return _to SetQuery(aQuery, _retval); } \
281
MOZ_MUST_USE NS_IMETHOD SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding * encoding, nsIURIMutator **_retval) override { return _to SetQueryWithEncoding(query, encoding, _retval); }
282
283
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
284
#define NS_FORWARD_SAFE_NSIURISETTERS(_to) \
285
MOZ_MUST_USE NS_IMETHOD SetScheme(const nsACString& aScheme, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetScheme(aScheme, _retval); } \
286
MOZ_MUST_USE NS_IMETHOD SetUserPass(const nsACString& aUserPass, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetUserPass(aUserPass, _retval); } \
287
MOZ_MUST_USE NS_IMETHOD SetUsername(const nsACString& aUsername, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetUsername(aUsername, _retval); } \
288
MOZ_MUST_USE NS_IMETHOD SetPassword(const nsACString& aPassword, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetPassword(aPassword, _retval); } \
289
MOZ_MUST_USE NS_IMETHOD SetHostPort(const nsACString& aHostPort, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostPort(aHostPort, _retval); } \
290
MOZ_MUST_USE NS_IMETHOD SetHost(const nsACString& aHost, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetHost(aHost, _retval); } \
291
MOZ_MUST_USE NS_IMETHOD SetPort(int32_t aPort, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetPort(aPort, _retval); } \
292
MOZ_MUST_USE NS_IMETHOD SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetPathQueryRef(aPathQueryRef, _retval); } \
293
MOZ_MUST_USE NS_IMETHOD SetRef(const nsACString& aRef, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetRef(aRef, _retval); } \
294
MOZ_MUST_USE NS_IMETHOD SetFilePath(const nsACString& aFilePath, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetFilePath(aFilePath, _retval); } \
295
MOZ_MUST_USE NS_IMETHOD SetQuery(const nsACString& aQuery, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetQuery(aQuery, _retval); } \
296
MOZ_MUST_USE NS_IMETHOD SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding * encoding, nsIURIMutator **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->SetQueryWithEncoding(query, encoding, _retval); }
297
298
299
// Using this macro instead of NS_FORWARD_SAFE_NSIURISETTERS makes chaining
300
// setter operations possible.
301
#define NS_FORWARD_SAFE_NSIURISETTERS_RET(_to) \
302
MOZ_MUST_USE NS_IMETHOD \
303
SetScheme(const nsACString& aScheme, nsIURIMutator** aMutator) override \
304
{ \
305
if (aMutator) NS_ADDREF(*aMutator = this); \
306
return !_to ? NS_ERROR_NULL_POINTER : _to->SetScheme(aScheme); \
307
} \
308
MOZ_MUST_USE NS_IMETHOD \
309
SetUserPass(const nsACString& aUserPass, nsIURIMutator** aMutator) override \
310
{ \
311
if (aMutator) NS_ADDREF(*aMutator = this); \
312
return !_to ? NS_ERROR_NULL_POINTER : _to->SetUserPass(aUserPass); \
313
} \
314
MOZ_MUST_USE NS_IMETHOD \
315
SetUsername(const nsACString& aUsername, nsIURIMutator** aMutator) override \
316
{ \
317
if (aMutator) NS_ADDREF(*aMutator = this); \
318
return !_to ? NS_ERROR_NULL_POINTER : _to->SetUsername(aUsername); \
319
} \
320
MOZ_MUST_USE NS_IMETHOD \
321
SetPassword(const nsACString& aPassword, nsIURIMutator** aMutator) override \
322
{ \
323
if (aMutator) NS_ADDREF(*aMutator = this); \
324
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPassword(aPassword); \
325
} \
326
MOZ_MUST_USE NS_IMETHOD \
327
SetHostPort(const nsACString& aHostPort, nsIURIMutator** aMutator) override \
328
{ \
329
if (aMutator) NS_ADDREF(*aMutator = this); \
330
return !_to ? NS_ERROR_NULL_POINTER : _to->SetHostPort(aHostPort); \
331
} \
332
MOZ_MUST_USE NS_IMETHOD \
333
SetHost(const nsACString& aHost, nsIURIMutator** aMutator) override \
334
{ \
335
if (aMutator) NS_ADDREF(*aMutator = this); \
336
return !_to ? NS_ERROR_NULL_POINTER : _to->SetHost(aHost); \
337
} \
338
MOZ_MUST_USE NS_IMETHOD \
339
SetPort(int32_t aPort, nsIURIMutator** aMutator) override \
340
{ \
341
if (aMutator) NS_ADDREF(*aMutator = this); \
342
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPort(aPort); \
343
} \
344
MOZ_MUST_USE NS_IMETHOD \
345
SetPathQueryRef(const nsACString& aPathQueryRef, nsIURIMutator** aMutator) override \
346
{ \
347
if (aMutator) NS_ADDREF(*aMutator = this); \
348
return !_to ? NS_ERROR_NULL_POINTER : _to->SetPathQueryRef(aPathQueryRef); \
349
} \
350
MOZ_MUST_USE NS_IMETHOD \
351
SetRef(const nsACString& aRef, nsIURIMutator** aMutator) override \
352
{ \
353
if (aMutator) NS_ADDREF(*aMutator = this); \
354
return !_to ? NS_ERROR_NULL_POINTER : _to->SetRef(aRef); \
355
} \
356
MOZ_MUST_USE NS_IMETHOD \
357
SetFilePath(const nsACString& aFilePath, nsIURIMutator** aMutator) override \
358
{ \
359
if (aMutator) NS_ADDREF(*aMutator = this); \
360
return !_to ? NS_ERROR_NULL_POINTER : _to->SetFilePath(aFilePath); \
361
} \
362
MOZ_MUST_USE NS_IMETHOD \
363
SetQuery(const nsACString& aQuery, nsIURIMutator** aMutator) override \
364
{ \
365
if (aMutator) NS_ADDREF(*aMutator = this); \
366
return !_to ? NS_ERROR_NULL_POINTER : _to->SetQuery(aQuery); \
367
} \
368
MOZ_MUST_USE NS_IMETHOD \
369
SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding *encoding, nsIURIMutator** aMutator) override \
370
{ \
371
if (aMutator) NS_ADDREF(*aMutator = this); \
372
return !_to ? NS_ERROR_NULL_POINTER : _to->SetQueryWithEncoding(query, encoding); \
373
} \
374
375
/* starting interface: nsIURIMutator */
376
#define NS_IURIMUTATOR_IID_STR "4d1f3103-1c44-4dcd-b717-5d22a697a7d9"
377
378
#define NS_IURIMUTATOR_IID \
379
{0x4d1f3103, 0x1c44, 0x4dcd, \
380
{ 0xb7, 0x17, 0x5d, 0x22, 0xa6, 0x97, 0xa7, 0xd9 }}
381
382
class NS_NO_VTABLE nsIURIMutator : public nsIURISetters {
383
public:
384
385
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IURIMUTATOR_IID)
386
387
/* [must_use,noscript,notxpcom] nsresult deserialize (in const_URIParams_ref aParams); */
388
MOZ_MUST_USE NS_IMETHOD Deserialize(const mozilla::ipc::URIParams & aParams) = 0;
389
390
/* [must_use] nsIURI finalize (); */
391
MOZ_MUST_USE NS_IMETHOD Finalize(nsIURI **_retval) = 0;
392
393
};
394
395
NS_DEFINE_STATIC_IID_ACCESSOR(nsIURIMutator, NS_IURIMUTATOR_IID)
396
397
/* Use this macro when declaring classes that implement this interface. */
398
#define NS_DECL_NSIURIMUTATOR \
399
MOZ_MUST_USE NS_IMETHOD Deserialize(const mozilla::ipc::URIParams & aParams) override; \
400
MOZ_MUST_USE NS_IMETHOD Finalize(nsIURI **_retval) override;
401
402
/* Use this macro when declaring the members of this interface when the
403
class doesn't implement the interface. This is useful for forwarding. */
404
#define NS_DECL_NON_VIRTUAL_NSIURIMUTATOR \
405
MOZ_MUST_USE nsresult Deserialize(const mozilla::ipc::URIParams & aParams); \
406
MOZ_MUST_USE nsresult Finalize(nsIURI **_retval);
407
408
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
409
#define NS_FORWARD_NSIURIMUTATOR(_to) \
410
MOZ_MUST_USE NS_IMETHOD Deserialize(const mozilla::ipc::URIParams & aParams) override { return _to Deserialize(aParams); } \
411
MOZ_MUST_USE NS_IMETHOD Finalize(nsIURI **_retval) override { return _to Finalize(_retval); }
412
413
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
414
#define NS_FORWARD_SAFE_NSIURIMUTATOR(_to) \
415
MOZ_MUST_USE NS_IMETHOD Deserialize(const mozilla::ipc::URIParams & aParams) override; \
416
MOZ_MUST_USE NS_IMETHOD Finalize(nsIURI **_retval) override { return !_to ? NS_ERROR_NULL_POINTER : _to->Finalize(_retval); }
417
418
419
// This templated struct is used to extract the class type of the method
420
// passed to NS_MutatorMethod.
421
template <typename Method>
422
struct nsMethodTypeTraits;
423
template <class C, typename R, typename... As>
424
struct nsMethodTypeTraits<R(C::*)(As...)>
425
{
426
typedef C class_type;
427
};
428
#ifdef NS_HAVE_STDCALL
429
template <class C, typename R, typename... As>
430
struct nsMethodTypeTraits<R(__stdcall C::*)(As...)>
431
{
432
typedef C class_type;
433
};
434
#endif
435
// This helper returns a std::function that will be applied on the
436
// nsIURIMutator. The type of `Interface` will be deduced from the method type.
437
// aMethod will be called on the target object if it successfully QIs to
438
// `Interface`, and the arguments will be passed to the call.
439
template <typename Method, typename... Args>
440
const std::function<nsresult(nsIURIMutator*)>
441
NS_MutatorMethod(Method aMethod, Args ...aArgs)
442
{
443
// Capture arguments by value, otherwise we crash.
444
return [=](nsIURIMutator* aMutator) {
445
typedef typename nsMethodTypeTraits<Method>::class_type Interface;
446
nsresult rv;
447
nsCOMPtr<Interface> target = do_QueryInterface(aMutator, &rv);
448
NS_ENSURE_SUCCESS(rv, rv);
449
rv = (target->*aMethod)(aArgs...);
450
if (NS_FAILED(rv)) return rv;
451
return NS_OK;
452
};
453
}
454
// This class provides a useful helper that allows chaining of setter operations
455
class MOZ_STACK_CLASS NS_MutateURI
456
{
457
public:
458
explicit NS_MutateURI(nsIURI* aURI);
459
explicit NS_MutateURI(const char * aContractID);
460
explicit NS_MutateURI(nsIURIMutator* m)
461
{
462
mStatus = m ? NS_OK : NS_ERROR_NULL_POINTER;
463
mMutator = m;
464
NS_ENSURE_SUCCESS_VOID(mStatus);
465
}
466
NS_MutateURI& SetSpec(const nsACString& aSpec)
467
{
468
if (NS_FAILED(mStatus)) {
469
return *this;
470
}
471
mStatus = mMutator->SetSpec(aSpec, nullptr);
472
return *this;
473
}
474
NS_MutateURI& SetScheme(const nsACString& aScheme)
475
{
476
if (NS_FAILED(mStatus)) {
477
return *this;
478
}
479
mStatus = mMutator->SetScheme(aScheme, nullptr);
480
NS_ENSURE_SUCCESS(mStatus, *this);
481
return *this;
482
}
483
NS_MutateURI& SetUserPass(const nsACString& aUserPass)
484
{
485
if (NS_FAILED(mStatus)) {
486
return *this;
487
}
488
mStatus = mMutator->SetUserPass(aUserPass, nullptr);
489
return *this;
490
}
491
NS_MutateURI& SetUsername(const nsACString& aUsername)
492
{
493
if (NS_FAILED(mStatus)) {
494
return *this;
495
}
496
mStatus = mMutator->SetUsername(aUsername, nullptr);
497
NS_ENSURE_SUCCESS(mStatus, *this);
498
return *this;
499
}
500
NS_MutateURI& SetPassword(const nsACString& aPassword)
501
{
502
if (NS_FAILED(mStatus)) {
503
return *this;
504
}
505
mStatus = mMutator->SetPassword(aPassword, nullptr);
506
NS_ENSURE_SUCCESS(mStatus, *this);
507
return *this;
508
}
509
NS_MutateURI& SetHostPort(const nsACString& aHostPort)
510
{
511
if (NS_FAILED(mStatus)) {
512
return *this;
513
}
514
mStatus = mMutator->SetHostPort(aHostPort, nullptr);
515
NS_ENSURE_SUCCESS(mStatus, *this);
516
return *this;
517
}
518
NS_MutateURI& SetHost(const nsACString& aHost)
519
{
520
if (NS_FAILED(mStatus)) {
521
return *this;
522
}
523
mStatus = mMutator->SetHost(aHost, nullptr);
524
NS_ENSURE_SUCCESS(mStatus, *this);
525
return *this;
526
}
527
NS_MutateURI& SetPort(int32_t aPort)
528
{
529
if (NS_FAILED(mStatus)) {
530
return *this;
531
}
532
mStatus = mMutator->SetPort(aPort, nullptr);
533
NS_ENSURE_SUCCESS(mStatus, *this);
534
return *this;
535
}
536
NS_MutateURI& SetPathQueryRef(const nsACString& aPathQueryRef)
537
{
538
if (NS_FAILED(mStatus)) {
539
return *this;
540
}
541
mStatus = mMutator->SetPathQueryRef(aPathQueryRef, nullptr);
542
NS_ENSURE_SUCCESS(mStatus, *this);
543
return *this;
544
}
545
NS_MutateURI& SetRef(const nsACString& aRef)
546
{
547
if (NS_FAILED(mStatus)) {
548
return *this;
549
}
550
mStatus = mMutator->SetRef(aRef, nullptr);
551
NS_ENSURE_SUCCESS(mStatus, *this);
552
return *this;
553
}
554
NS_MutateURI& SetFilePath(const nsACString& aFilePath)
555
{
556
if (NS_FAILED(mStatus)) {
557
return *this;
558
}
559
mStatus = mMutator->SetFilePath(aFilePath, nullptr);
560
NS_ENSURE_SUCCESS(mStatus, *this);
561
return *this;
562
}
563
NS_MutateURI& SetQuery(const nsACString& aQuery)
564
{
565
if (NS_FAILED(mStatus)) {
566
return *this;
567
}
568
mStatus = mMutator->SetQuery(aQuery, nullptr);
569
NS_ENSURE_SUCCESS(mStatus, *this);
570
return *this;
571
}
572
NS_MutateURI& SetQueryWithEncoding(const nsACString& query, const mozilla::Encoding *encoding)
573
{
574
if (NS_FAILED(mStatus)) {
575
return *this;
576
}
577
mStatus = mMutator->SetQueryWithEncoding(query, encoding, nullptr);
578
NS_ENSURE_SUCCESS(mStatus, *this);
579
return *this;
580
}
581
/**
582
* This method allows consumers to call the methods declared in other
583
* interfaces implemented by the mutator object.
584
*
585
* Example:
586
* nsCOMPtr<nsIURI> uri;
587
* nsresult rv = NS_MutateURI(new URIClass::Mutator())
588
* .SetSpec(aSpec)
589
* .Apply(NS_MutatorMethod(&SomeInterface::Method, arg1, arg2))
590
* .Finalize(uri);
591
*
592
* If mMutator does not implement SomeInterface, do_QueryInterface will fail
593
* and the method will not be called.
594
* If aMethod does not exist, or if there is a mismatch between argument
595
* types, or the number of arguments, then there will be a compile error.
596
*/
597
NS_MutateURI& Apply(const std::function<nsresult(nsIURIMutator*)>& aFunction)
598
{
599
if (NS_FAILED(mStatus)) {
600
return *this;
601
}
602
mStatus = aFunction(mMutator);
603
return *this;
604
}
605
template <class C>
606
MOZ_MUST_USE nsresult Finalize(nsCOMPtr<C>& aURI)
607
{
608
NS_ENSURE_SUCCESS(mStatus, mStatus);
609
nsCOMPtr<nsIURI> uri;
610
mStatus = mMutator->Finalize(getter_AddRefs(uri));
611
NS_ENSURE_SUCCESS(mStatus, mStatus);
612
aURI = do_QueryInterface(uri, &mStatus);
613
NS_ENSURE_SUCCESS(mStatus, mStatus);
614
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
615
return NS_OK;
616
}
617
// Overload for nsIURI to avoid query interface.
618
MOZ_MUST_USE nsresult Finalize(nsCOMPtr<nsIURI>& aURI)
619
{
620
if (NS_FAILED(mStatus)) return mStatus;
621
mStatus = mMutator->Finalize(getter_AddRefs(aURI));
622
NS_ENSURE_SUCCESS(mStatus, mStatus);
623
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
624
return NS_OK;
625
}
626
template <class C>
627
MOZ_MUST_USE nsresult Finalize(C** aURI)
628
{
629
NS_ENSURE_SUCCESS(mStatus, mStatus);
630
nsCOMPtr<nsIURI> uri;
631
mStatus = mMutator->Finalize(getter_AddRefs(uri));
632
NS_ENSURE_SUCCESS(mStatus, mStatus);
633
nsCOMPtr<C> result = do_QueryInterface(uri, &mStatus);
634
NS_ENSURE_SUCCESS(mStatus, mStatus);
635
result.forget(aURI);
636
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
637
return NS_OK;
638
}
639
MOZ_MUST_USE nsresult Finalize(nsIURI** aURI)
640
{
641
if (NS_FAILED(mStatus)) return mStatus;
642
mStatus = mMutator->Finalize(aURI);
643
NS_ENSURE_SUCCESS(mStatus, mStatus);
644
mStatus = NS_ERROR_NOT_AVAILABLE; // Second call to Finalize should fail.
645
return NS_OK;
646
}
647
nsresult GetStatus() { return mStatus; }
648
private:
649
nsresult mStatus;
650
nsCOMPtr<nsIURIMutator> mMutator;
651
};
652
653
#endif /* __gen_nsIURIMutator_h__ */