Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/build/nsXPCOM.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#ifndef nsXPCOM_h__
8
#define nsXPCOM_h__
9
10
#include "nscore.h"
11
#include "nsXPCOMCID.h"
12
13
#ifdef __cplusplus
14
#define DECL_CLASS(c) class c
15
#define DECL_STRUCT(c) struct c
16
#else
17
#define DECL_CLASS(c) typedef struct c c
18
#define DECL_STRUCT(c) typedef struct c c
19
#endif
20
21
DECL_CLASS(nsISupports);
22
DECL_CLASS(nsIModule);
23
DECL_CLASS(nsIComponentManager);
24
DECL_CLASS(nsIComponentRegistrar);
25
DECL_CLASS(nsIServiceManager);
26
DECL_CLASS(nsIFile);
27
DECL_CLASS(nsIDirectoryServiceProvider);
28
DECL_CLASS(nsIMemory);
29
DECL_CLASS(nsIDebug2);
30
31
#ifdef __cplusplus
32
extern bool gXPCOMShuttingDown;
33
extern bool gXPCOMThreadsShutDown;
34
#endif
35
36
#ifdef __cplusplus
37
#include "nsStringFwd.h"
38
namespace mozilla {
39
struct Module;
40
} // namespace mozilla
41
#endif
42
43
/**
44
 * Initialises XPCOM. You must call one of the NS_InitXPCOM methods
45
 * before proceeding to use xpcom. The one exception is that you may
46
 * call NS_NewLocalFile to create a nsIFile.
47
 *
48
 * @note Use <CODE>NS_NewLocalFile</CODE> or <CODE>NS_NewNativeLocalFile</CODE>
49
 *       to create the file object you supply as the bin directory path in this
50
 *       call. The function may be safely called before the rest of XPCOM or
51
 *       embedding has been initialised.
52
 *
53
 * @param aResult          The service manager.  You may pass null.
54
 *
55
 * @param aBinDirectory    The directory containing the component
56
 *                         registry and runtime libraries;
57
 *                         or use <CODE>nullptr</CODE> to use the working
58
 *                         directory.
59
 *
60
 * @param aAppFileLocationProvider The object to be used by Gecko that
61
 *                         specifies to Gecko where to find profiles, the
62
 *                         component registry preferences and so on; or use
63
 *                         <CODE>nullptr</CODE> for the default behaviour.
64
 *
65
 * @see NS_NewLocalFile
66
 * @see nsIFile
67
 * @see nsIDirectoryServiceProvider
68
 *
69
 * @return NS_OK for success;
70
 *         NS_ERROR_NOT_INITIALIZED if static globals were not initialized,
71
 *         which can happen if XPCOM is reloaded, but did not completly
72
 *         shutdown. Other error codes indicate a failure during
73
 *         initialisation.
74
 */
75
XPCOM_API(nsresult)
76
NS_InitXPCOM2(nsIServiceManager** aResult,
77
              nsIFile* aBinDirectory,
78
              nsIDirectoryServiceProvider* aAppFileLocationProvider);
79
80
/**
81
 * Initialize only minimal components of XPCOM. This ensures nsThreadManager,
82
 * logging, and timers will work.
83
 */
84
XPCOM_API(nsresult)
85
NS_InitMinimalXPCOM();
86
87
/**
88
 * Shutdown XPCOM. You must call this method after you are finished
89
 * using xpcom.
90
 *
91
 * @param aServMgr          The service manager which was returned by NS_InitXPCOM.
92
 *                          This will release servMgr.  You may pass null.
93
 *
94
 * @return NS_OK for success;
95
 *         other error codes indicate a failure during initialisation.
96
 */
97
XPCOM_API(nsresult) NS_ShutdownXPCOM(nsIServiceManager* aServMgr);
98
99
100
/**
101
 * Public Method to access to the service manager.
102
 *
103
 * @param aResult Interface pointer to the service manager
104
 *
105
 * @return NS_OK for success;
106
 *         other error codes indicate a failure during initialisation.
107
 */
108
XPCOM_API(nsresult) NS_GetServiceManager(nsIServiceManager** aResult);
109
110
/**
111
 * Public Method to access to the component manager.
112
 *
113
 * @param aResult Interface pointer to the service
114
 *
115
 * @return NS_OK for success;
116
 *         other error codes indicate a failure during initialisation.
117
 */
118
XPCOM_API(nsresult) NS_GetComponentManager(nsIComponentManager** aResult);
119
120
121
/**
122
 * Public Method to access to the component registration manager.
123
 *
124
 * @param aResult Interface pointer to the service
125
 *
126
 * @return NS_OK for success;
127
 *         other error codes indicate a failure during initialisation.
128
 */
129
XPCOM_API(nsresult) NS_GetComponentRegistrar(nsIComponentRegistrar** aResult);
130
131
/**
132
 * Public Method to access to the memory manager.  See nsIMemory
133
 *
134
 * @param aResult Interface pointer to the memory manager
135
 *
136
 * @return NS_OK for success;
137
 *         other error codes indicate a failure during initialisation.
138
 */
139
XPCOM_API(nsresult) NS_GetMemoryManager(nsIMemory** aResult);
140
141
/**
142
 * Public Method to create an instance of a nsIFile.  This function
143
 * may be called prior to NS_InitXPCOM.
144
 *
145
 *   @param aPath
146
 *       A string which specifies a full file path to a
147
 *       location.  Relative paths will be treated as an
148
 *       error (NS_ERROR_FILE_UNRECOGNIZED_PATH).
149
 *       |NS_NewNativeLocalFile|'s path must be in the
150
 *       filesystem charset.
151
 *   @param aFollowLinks
152
 *       This attribute will determine if the nsLocalFile will auto
153
 *       resolve symbolic links.  By default, this value will be false
154
 *       on all non unix systems.  On unix, this attribute is effectively
155
 *       a noop.
156
 * @param aResult Interface pointer to a new instance of an nsIFile
157
 *
158
 * @return NS_OK for success;
159
 *         other error codes indicate a failure.
160
 */
161
162
#ifdef __cplusplus
163
164
XPCOM_API(nsresult) NS_NewLocalFile(const nsAString& aPath,
165
                                    bool aFollowLinks,
166
                                    nsIFile** aResult);
167
168
XPCOM_API(nsresult) NS_NewNativeLocalFile(const nsACString& aPath,
169
                                          bool aFollowLinks,
170
                                          nsIFile** aResult);
171
172
// Use NS_NewLocalFile if you already have a UTF-16 string.
173
// Otherwise non-ASCII paths will break on some platforms
174
// including Windows.
175
class NS_ConvertUTF16toUTF8;
176
nsresult NS_NewNativeLocalFile(const NS_ConvertUTF16toUTF8& aPath,
177
                               bool aFollowLinks,
178
                               nsIFile** aResult) = delete;
179
180
#endif
181
182
/**
183
 * Support for warnings, assertions, and debugging breaks.
184
 */
185
186
enum
187
{
188
  NS_DEBUG_WARNING = 0,
189
  NS_DEBUG_ASSERTION = 1,
190
  NS_DEBUG_BREAK = 2,
191
  NS_DEBUG_ABORT = 3
192
};
193
194
/**
195
 * Print a runtime assertion. This function is available in both debug and
196
 * release builds.
197
 *
198
 * @note Based on the value of aSeverity and the XPCOM_DEBUG_BREAK
199
 * environment variable, this function may cause the application to
200
 * print the warning, print a stacktrace, break into a debugger, or abort
201
 * immediately.
202
 *
203
 * @param aSeverity A NS_DEBUG_* value
204
 * @param aStr   A readable error message (ASCII, may be null)
205
 * @param aExpr  The expression evaluated (may be null)
206
 * @param aFile  The source file containing the assertion (may be null)
207
 * @param aLine  The source file line number (-1 indicates no line number)
208
 */
209
XPCOM_API(void) NS_DebugBreak(uint32_t aSeverity,
210
                              const char* aStr, const char* aExpr,
211
                              const char* aFile, int32_t aLine);
212
213
/**
214
 * Perform a stack-walk to a debugging log under various
215
 * circumstances. Used to aid debugging of leaked object graphs.
216
 *
217
 * The NS_Log* functions are available in both debug and release
218
 * builds of XPCOM, but the output will be useless unless binary
219
 * debugging symbols for all modules in the stacktrace are available.
220
 */
221
222
/**
223
 * By default, refcount logging is enabled at NS_InitXPCOM and
224
 * refcount statistics are printed at NS_ShutdownXPCOM. NS_LogInit and
225
 * NS_LogTerm allow applications to enable logging earlier and delay
226
 * printing of logging statistics. They should always be used as a
227
 * matched pair.
228
 */
229
XPCOM_API(void) NS_LogInit();
230
231
XPCOM_API(void) NS_LogTerm();
232
233
#ifdef __cplusplus
234
/**
235
 * A helper class that calls NS_LogInit in its constructor and
236
 * NS_LogTerm in its destructor.
237
 */
238
239
class ScopedLogging
240
{
241
public:
242
    ScopedLogging()
243
3
    {
244
3
        NS_LogInit();
245
3
    }
246
247
    ~ScopedLogging()
248
0
    {
249
0
        NS_LogTerm();
250
0
    }
251
};
252
#endif
253
254
/**
255
 * Log construction and destruction of objects. Processing tools can use the
256
 * stacktraces printed by these functions to identify objects that are being
257
 * leaked.
258
 *
259
 * @param aPtr          A pointer to the concrete object.
260
 * @param aTypeName     The class name of the type
261
 * @param aInstanceSize The size of the type
262
 */
263
264
XPCOM_API(void) NS_LogCtor(void* aPtr, const char* aTypeName,
265
                           uint32_t aInstanceSize);
266
267
XPCOM_API(void) NS_LogDtor(void* aPtr, const char* aTypeName,
268
                           uint32_t aInstanceSize);
269
270
/**
271
 * Log a stacktrace when an XPCOM object's refcount is incremented or
272
 * decremented. Processing tools can use the stacktraces printed by these
273
 * functions to identify objects that were leaked due to XPCOM references.
274
 *
275
 * @param aPtr          A pointer to the concrete object
276
 * @param aNewRefCnt    The new reference count.
277
 * @param aTypeName     The class name of the type
278
 * @param aInstanceSize The size of the type
279
 */
280
XPCOM_API(void) NS_LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
281
                             const char* aTypeName, uint32_t aInstanceSize);
282
283
XPCOM_API(void) NS_LogRelease(void* aPtr, nsrefcnt aNewRefCnt,
284
                              const char* aTypeName);
285
286
/**
287
 * Log reference counting performed by COMPtrs. Processing tools can
288
 * use the stacktraces printed by these functions to simplify reports
289
 * about leaked objects generated from the data printed by
290
 * NS_LogAddRef/NS_LogRelease.
291
 *
292
 * @param aCOMPtr the address of the COMPtr holding a strong reference
293
 * @param aObject the object being referenced by the COMPtr
294
 */
295
296
XPCOM_API(void) NS_LogCOMPtrAddRef(void* aCOMPtr, nsISupports* aObject);
297
298
XPCOM_API(void) NS_LogCOMPtrRelease(void* aCOMPtr, nsISupports* aObject);
299
300
/**
301
 * The XPCOM cycle collector analyzes and breaks reference cycles between
302
 * participating XPCOM objects. All objects in the cycle must implement
303
 * nsCycleCollectionParticipant to break cycles correctly.
304
 */
305
306
#ifdef __cplusplus
307
308
class nsCycleCollectionParticipant;
309
class nsCycleCollectingAutoRefCnt;
310
311
XPCOM_API(void) NS_CycleCollectorSuspect3(void* aPtr,
312
                                          nsCycleCollectionParticipant* aCp,
313
                                          nsCycleCollectingAutoRefCnt* aRefCnt,
314
                                          bool* aShouldDelete);
315
316
XPCOM_API(void)
317
NS_CycleCollectorSuspectUsingNursery(void* aPtr,
318
                                     nsCycleCollectionParticipant* aCp,
319
                                     nsCycleCollectingAutoRefCnt* aRefCnt,
320
                                     bool* aShouldDelete);
321
322
#endif
323
324
/**
325
 * Categories (in the category manager service) used by XPCOM:
326
 */
327
328
/**
329
 * A category which is read after component registration but before
330
 * the "xpcom-startup" notifications. Each category entry is treated
331
 * as the contract ID of a service which implements
332
 * nsIDirectoryServiceProvider. Each directory service provider is
333
 * installed in the global directory service.
334
 */
335
3
#define XPCOM_DIRECTORY_PROVIDER_CATEGORY "xpcom-directory-providers"
336
337
/**
338
 * A category which is read after component registration but before
339
 * NS_InitXPCOM returns. Each category entry is treated as the contractID of
340
 * a service: each service is instantiated, and if it implements nsIObserver
341
 * the nsIObserver.observe method is called with the "xpcom-startup" topic.
342
 */
343
3
#define NS_XPCOM_STARTUP_CATEGORY "xpcom-startup"
344
345
346
/**
347
 * Observer topics (in the observer service) used by XPCOM:
348
 */
349
350
/**
351
 * At XPCOM startup after component registration is complete, the
352
 * following topic is notified. In order to receive this notification,
353
 * component must register their contract ID in the category manager,
354
 *
355
 * @see NS_XPCOM_STARTUP_CATEGORY
356
 */
357
3
#define NS_XPCOM_STARTUP_OBSERVER_ID "xpcom-startup"
358
359
/**
360
 * At XPCOM shutdown, this topic is notified just before "xpcom-shutdown".
361
 * Components should only use this to mark themselves as 'being destroyed'.
362
 * Nothing should be dispatched to any event loop.
363
 */
364
0
#define NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID "xpcom-will-shutdown"
365
366
/**
367
 * At XPCOM shutdown, this topic is notified. All components must
368
 * release any interface references to objects in other modules when
369
 * this topic is notified.
370
 */
371
3
#define NS_XPCOM_SHUTDOWN_OBSERVER_ID "xpcom-shutdown"
372
373
/**
374
 * This topic is notified when an entry was added to a category in the
375
 * category manager. The subject of the notification will be the name of
376
 * the added entry as an nsISupportsCString, and the data will be the
377
 * name of the category. The notification will occur on the main thread.
378
 */
379
#define NS_XPCOM_CATEGORY_ENTRY_ADDED_OBSERVER_ID \
380
369
  "xpcom-category-entry-added"
381
382
/**
383
 * This topic is notified when an entry was removed from a category in the
384
 * category manager. The subject of the notification will be the name of
385
 * the removed entry as an nsISupportsCString, and the data will be the
386
 * name of the category. The notification will occur on the main thread.
387
 */
388
#define NS_XPCOM_CATEGORY_ENTRY_REMOVED_OBSERVER_ID \
389
0
  "xpcom-category-entry-removed"
390
391
/**
392
 * This topic is notified when an a category was cleared in the category
393
 * manager. The subject of the notification will be the category manager,
394
 * and the data will be the name of the cleared category.
395
 * The notification will occur on the main thread.
396
 */
397
0
#define NS_XPCOM_CATEGORY_CLEARED_OBSERVER_ID "xpcom-category-cleared"
398
399
XPCOM_API(nsresult) NS_GetDebug(nsIDebug2** aResult);
400
401
#endif