1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifndef mozilla_net_NeckoCommon_h
9 #define mozilla_net_NeckoCommon_h
11 #include "nsXULAppAPI.h"
13 #include "nsPrintfCString.h"
14 #include "mozilla/Preferences.h"
16 namespace mozilla
{ namespace dom
{
21 # define NECKO_ERRORS_ARE_FATAL_DEFAULT true
23 # define NECKO_ERRORS_ARE_FATAL_DEFAULT false
26 // TODO: Eventually remove NECKO_MAYBE_ABORT and DROP_DEAD (bug 575494).
27 // Still useful for catching listener interfaces we don't yet support across
30 #define NECKO_MAYBE_ABORT(msg) \
32 bool abort = NECKO_ERRORS_ARE_FATAL_DEFAULT; \
33 const char *e = PR_GetEnv("NECKO_ERRORS_ARE_FATAL"); \
35 abort = (*e == '0') ? false : true; \
37 msg.Append(" (set NECKO_ERRORS_ARE_FATAL=0 in your environment to " \
38 "convert this error into a warning.)"); \
39 NS_RUNTIMEABORT(msg.get()); \
41 msg.Append(" (set NECKO_ERRORS_ARE_FATAL=1 in your environment to " \
42 "convert this warning into a fatal error.)"); \
43 NS_WARNING(msg.get()); \
49 nsPrintfCString msg("NECKO ERROR: '%s' UNIMPLEMENTED", \
51 NECKO_MAYBE_ABORT(msg); \
52 return NS_ERROR_NOT_IMPLEMENTED; \
55 #define ENSURE_CALLED_BEFORE_ASYNC_OPEN() \
57 if (mIsPending || mWasOpened) { \
58 nsPrintfCString msg("'%s' called after AsyncOpen: %s +%d", \
59 __FUNCTION__, __FILE__, __LINE__); \
60 NECKO_MAYBE_ABORT(msg); \
62 NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); \
63 NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED); \
66 // Fails call if made after request observers (on-modify-request, etc) have been
69 #define ENSURE_CALLED_BEFORE_CONNECT() \
71 if (mRequestObserversCalled) { \
72 nsPrintfCString msg("'%s' called too late: %s +%d", \
73 __FUNCTION__, __FILE__, __LINE__); \
74 NECKO_MAYBE_ABORT(msg); \
76 return NS_ERROR_IN_PROGRESS; \
77 MOZ_ASSERT(mWasOpened); \
78 return NS_ERROR_ALREADY_OPENED; \
88 static bool didCheck
= false;
89 static bool amChild
= false;
92 // This allows independent necko-stacks (instead of single stack in chrome)
94 // TODO: Remove eventually when no longer supported (bug 571126)
95 const char * e
= PR_GetEnv("NECKO_SEPARATE_STACKS");
97 amChild
= (XRE_GetProcessType() == GeckoProcessType_Content
);
103 namespace NeckoCommonInternal
{
104 extern bool gSecurityDisabled
;
105 extern bool gRegisteredBool
;
108 // This should always return true unless xpcshell tests are being used
110 UsingNeckoIPCSecurity()
113 if (!NeckoCommonInternal::gRegisteredBool
) {
114 Preferences::AddBoolVarCache(&NeckoCommonInternal::gSecurityDisabled
,
115 "network.disable.ipc.security");
116 NeckoCommonInternal::gRegisteredBool
= true;
118 return !NeckoCommonInternal::gSecurityDisabled
;
122 MissingRequiredTabChild(mozilla::dom::TabChild
* tabChild
,
125 if (UsingNeckoIPCSecurity()) {
127 printf_stderr("WARNING: child tried to open %s IPDL channel w/o "
128 "security info\n", context
);
137 } // namespace mozilla
139 #endif // mozilla_net_NeckoCommon_h