-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnsbase.h
374 lines (288 loc) · 10.4 KB
/
nsbase.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
///////////////////////////////////////////////////////////////////////////////
// Name: nsbase.h
// Purpose: wxwebconnect: embedded web browser control library
// Author: Benjamin I. Williams
// Modified by:
// Created: 2006-10-10
// RCS-ID:
// Copyright: (C) Copyright 2006-2010, Kirix Corporation, All Rights Reserved.
// Licence: wxWindows Library Licence, Version 3.1
///////////////////////////////////////////////////////////////////////////////
#ifndef __WXWEBCONNECT_NSBASE_H
#define __WXWEBCONNECT_NSBASE_H
#ifdef WIN32
#define XP_WIN
#endif
#include "jspubtd.h"
///////////////////////////////////////////////////////////////////////////////
// types, forwards, etc
///////////////////////////////////////////////////////////////////////////////
class nsAString;
class nsACString;
class nsISupports;
class nsIServiceManager;
class nsIComponentManager;
class nsIComponentRegistrar;
class nsIDirectoryServiceProvider;
class nsIFile;
class nsILocalFile;
struct nsStringContainer;
struct nsCStringContainer;
typedef size_t PRSize;
typedef unsigned char PRUint8;
typedef unsigned short int PRUint16;
typedef short int PRInt16;
typedef unsigned int PRUint32;
typedef int PRInt32;
typedef int PRBool;
typedef PRUint32 nsresult;
typedef unsigned long nsrefcnt;
#ifdef _MSC_VER
typedef wchar_t PRUnichar;
typedef __int64 PRInt64;
typedef unsigned __int64 PRUint64;
#else
typedef PRUint16 PRUnichar;
typedef long long PRInt64;
typedef unsigned long long PRUint64;
#endif
typedef PRUint64 PRTime;
#define PR_CALLBACK
///////////////////////////////////////////////////////////////////////////////
// constants
///////////////////////////////////////////////////////////////////////////////
const PRUint32 PR_UINT32_MAX = 4294967295U;
const PRBool PR_TRUE = 1;
const PRBool PR_FALSE = 0;
#define nsnull 0
///////////////////////////////////////////////////////////////////////////////
// function declarations
///////////////////////////////////////////////////////////////////////////////
nsresult XPCOMGlueStartup(const char* xpcom_dll_path);
bool SetupJSFunctions(const char* js_dll_path);
nsresult NS_InitXPCOM2(nsIServiceManager** result, nsIFile* bin_directory, nsIDirectoryServiceProvider* app_file_location_provider);
void* NS_Alloc(PRSize size);
void NS_Free(void* ptr);
nsresult NS_GetServiceManager(nsIServiceManager** result);
nsresult NS_GetComponentManager(nsIComponentManager** result);
nsresult NS_GetComponentRegistrar(nsIComponentRegistrar** result);
nsresult NS_StringContainerInit(nsStringContainer& str);
nsresult NS_StringContainerInit2(nsStringContainer& str, const PRUnichar* str_data, PRUint32 len = PR_UINT32_MAX, PRUint32 flags = 0);
void NS_StringContainerFinish(nsStringContainer& str);
nsresult NS_NewNativeLocalFile(const nsACString& path, PRBool follow_links, nsILocalFile** result);
nsresult NS_StringSetData(nsAString& str, const PRUnichar* str_data, PRUint32 len);
PRUint32 NS_StringGetData(const nsAString& str, const PRUnichar** str_data, PRBool* terminated = NULL);
nsresult NS_CStringContainerInit(nsCStringContainer& str);
nsresult NS_CStringContainerInit2(nsCStringContainer& str, const char* str_data, PRUint32 len = PR_UINT32_MAX, PRUint32 flags = 0);
void NS_CStringContainerFinish(nsCStringContainer& str);
PRUint32 NS_CStringGetData(const nsACString& str, const char** str_data, PRBool* terminated = NULL);
typedef JSString *(*JS_ValueToStringFunc)(JSContext *context, jsval val);
extern JS_ValueToStringFunc JS_ValueToStringImpl;
#if defined(XULRUNNER_192)
typedef char *(*JS_GetStringBytesFunc)(JSString *str);
extern JS_GetStringBytesFunc JS_GetStringBytesImpl;
#elif defined(XULRUNNER_20)
typedef char *(*JS_EncodeStringFunc)(JSContext *context, JSString *str);
extern JS_EncodeStringFunc JS_EncodeStringImpl;
typedef char *(*JS_freeFunc)(JSContext *context, void *p);
extern JS_freeFunc JS_freeImpl;
#endif
///////////////////////////////////////////////////////////////////////////////
// macros and interface implementations
///////////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
#define NS_IMETHOD virtual nsresult __stdcall
#define NS_IMETHOD_(retval) virtual retval __stdcall
#define NS_IMETHODIMP nsresult __stdcall
#define NS_IMETHODIMP_(retval) retval __stdcall
#define NS_CALLBACK(func) nsresult __stdcall func
#else
#define NS_IMETHOD virtual nsresult
#define NS_IMETHOD_(retval) virtual retval
#define NS_IMETHODIMP nsresult
#define NS_IMETHODIMP_(retval) retval
#define NS_CALLBACK(func) nsresult func
#endif
#if (!defined(_MSC_VER) || (_MSC_VER > 600))
#define NS_SPECIALIZE_TEMPLATE template <>
#else
#define NS_SPECIALIZE_TEMPLATE
#endif
#define NS_REINTERPRET_CAST(type,obj) reinterpret_cast<type>(obj)
#define NS_STATIC_CAST(type,obj) static_cast<type>(obj)
#define NS_SUCCEEDED(result) (((result) & 0x80000000) == 0)
#define NS_FAILED(result) ((result & 0x80000000))
#define NS_LIKELY(x)
#define NS_UNLIKELY(x)
#define NS_INIT_ISUPPORTS()
#define NS_FASTCALL
#define NS_CONSTRUCTOR_FASTCALL
#define NS_COM
#define NS_COM_GLUE
#define HAVE_CPP_ACCESS_CHANGING_USING
#define NS_ENSURE_ARG_POINTER(arg)
#define NS_PRECONDITION(x,y)
#define NS_ERROR_ABORT ((nsresult)0x80004004L)
#define NS_ERROR_FAILURE ((nsresult)0x80004005)
#define NS_ERROR_INVALID_POINTER ((nsresult)0x80004003)
#define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
#define NS_ERROR_OUT_OF_MEMORY ((nsresult)0x8007000e)
#define NS_ERROR_NO_INTERFACE ((nsresult)0x80004002)
#define NS_ERROR_NO_AGGREGATION ((nsresult)0x80040110)
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult)0x80004001)
#define NS_ERROR_BASE ((nsresult)0xC1F30000)
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
#define NS_OK ((nsresult)0)
#define NS_GET_IID(iface) nsGetIID<iface>::GetIID()
#define NS_DECL_ISUPPORTS \
public: \
NS_IMETHOD QueryInterface(const nsIID& iid, void** result); \
NS_IMETHOD_(nsrefcnt) AddRef(); \
NS_IMETHOD_(nsrefcnt) Release(); \
private: \
refcount_holder m_refcount_holder; \
public:
#define NS_IMPL_ADDREF(class_name) \
NS_IMETHODIMP_(nsrefcnt) class_name::AddRef() { \
return ++m_refcount_holder.ref_count; \
}
#define NS_IMPL_RELEASE(class_name) \
NS_IMETHODIMP_(nsrefcnt) class_name::Release() { \
if (--m_refcount_holder.ref_count == 0) { \
delete this; \
return 0; \
} \
return m_refcount_holder.ref_count; \
}
#define NS_INTERFACE_MAP_BEGIN(class_name) \
NS_IMETHODIMP class_name::QueryInterface(const nsIID& iid, void** result) { \
*result = 0; \
#define NS_INTERFACE_MAP_ENTRY(iface) \
if (iid.Equals(NS_GET_IID(iface))) { \
this->AddRef(); \
*result = static_cast<void*>(static_cast<iface*>(this)); \
return NS_OK; \
}
#define NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(iface1, iface2) \
if (iid.Equals(NS_GET_IID(iface1))) { \
this->AddRef(); \
*result = static_cast<void*>(static_cast<iface1*>(static_cast<iface2*>(this))); \
return NS_OK; \
}
#define NS_INTERFACE_MAP_END \
return NS_ERROR_NO_INTERFACE; \
}
#define NS_IMPL_ISUPPORTS1(class_name, iface) \
NS_IMPL_ADDREF(class_name) \
NS_IMPL_RELEASE(class_name) \
NS_IMETHODIMP class_name::QueryInterface(const nsIID& iid, void** result) { \
*result = 0; \
if (iid.Equals(NS_GET_IID(iface))) { \
this->AddRef(); \
*result = static_cast<void*>(static_cast<iface*>(this)); \
return NS_OK; \
} \
if (iid.Equals(NS_GET_IID(nsISupports))) { \
this->AddRef(); \
*result = static_cast<void*>(static_cast<nsISupports*>(static_cast<iface*>(this))); \
return NS_OK; \
} \
return NS_ERROR_NO_INTERFACE; \
}
#ifdef WIN32
#define NS_DECLARE_STATIC_IID_ACCESSOR(iid) \
static const nsIID& GetIID() { \
static nsIID nsiid = iid; \
return nsiid; \
}
#else
#define NS_DECLARE_STATIC_IID_ACCESSOR(...) \
static const nsIID& GetIID() { \
static nsIID nsiid = __VA_ARGS__; \
return nsiid; \
}
#endif
#define NS_DEFINE_STATIC_IID_ACCESSOR(iid) NS_DECLARE_STATIC_IID_ACCESSOR(iid)
//#define NS_DEFINE_STATIC_IID_ACCESSOR(iface, iid)
class refcount_holder
{
public:
long ref_count;
refcount_holder()
{
ref_count = 0;
}
};
template <class T>
inline nsrefcnt ns_if_addref(T ptr)
{
if (ptr)
return ptr->AddRef();
return 0;
}
#define NS_IF_ADDREF(ptr) ns_if_addref((ptr))
#define NS_ADDREF(ptr) (ptr)->AddRef();
///////////////////////////////////////////////////////////////////////////////
// iid stuff
///////////////////////////////////////////////////////////////////////////////
struct nsID
{
PRUint32 m0;
PRUint16 m1;
PRUint16 m2;
PRUint8 m3[8];
PRBool Equals(const nsID& c) const
{
size_t i;
if (m0 != c.m0)
return PR_FALSE;
if (m1 != c.m1)
return PR_FALSE;
if (m2 != c.m2)
return PR_FALSE;
for (i = 0; i < 8; ++i)
{
if (m3[i] != c.m3[i])
return PR_FALSE;
}
return PR_TRUE;
}
};
typedef nsID nsIID;
typedef nsID nsCID;
#define REFNSIID const nsIID&
// helper class because nsISupports doesn't have a
// built-in GetIID()
template <class T>
struct nsGetIID
{
static const nsIID& GetIID()
{
return T::GetIID();
}
};
NS_SPECIALIZE_TEMPLATE
struct nsGetIID<nsISupports>
{
static const nsIID& GetIID()
{
static nsIID iid = /*NS_ISUPPORTS_IID*/
{ 0x00000000, 0x0000, 0x0000,
{0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}
};
return iid;
}
};
// these are here so that if the gecko sdk is used,
// all the other headers are not dragged in
#define nsXPCOM_h__
#define nsTraceRefcnt_h___
#define nscore_h___
#define nsISupportsImpl_h__
#define nsError_h__
#define nsID_h__
#define nsDebug_h___
#define nsCOMPtr_h___
#define nsStringAPI_h__
#define nsISupportsUtils_h__
#endif