Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set sw=2 ts=8 et tw=80 : */
3 :
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/. */
7 :
8 : #ifndef mozilla_net_NeckoCommon_h
9 : #define mozilla_net_NeckoCommon_h
10 :
11 : #include "nsXULAppAPI.h"
12 : #include "prenv.h"
13 : #include "nsPrintfCString.h"
14 : #include "mozilla/Preferences.h"
15 :
16 : namespace mozilla { namespace dom {
17 : class TabChild;
18 : } // namespace dom
19 : } // namespace mozilla
20 :
21 : #if defined(DEBUG)
22 : # define NECKO_ERRORS_ARE_FATAL_DEFAULT true
23 : #else
24 : # define NECKO_ERRORS_ARE_FATAL_DEFAULT false
25 : #endif
26 :
27 : // TODO: Eventually remove NECKO_MAYBE_ABORT and DROP_DEAD (bug 575494).
28 : // Still useful for catching listener interfaces we don't yet support across
29 : // processes, etc.
30 :
31 : #define NECKO_MAYBE_ABORT(msg) \
32 : do { \
33 : bool abort = NECKO_ERRORS_ARE_FATAL_DEFAULT; \
34 : const char *e = PR_GetEnv("NECKO_ERRORS_ARE_FATAL"); \
35 : if (e) \
36 : abort = (*e == '0') ? false : true; \
37 : if (abort) { \
38 : msg.Append(" (set NECKO_ERRORS_ARE_FATAL=0 in your environment to " \
39 : "convert this error into a warning.)"); \
40 : NS_RUNTIMEABORT(msg.get()); \
41 : } else { \
42 : msg.Append(" (set NECKO_ERRORS_ARE_FATAL=1 in your environment to " \
43 : "convert this warning into a fatal error.)"); \
44 : NS_WARNING(msg.get()); \
45 : } \
46 : } while (0)
47 :
48 : #define DROP_DEAD() \
49 : do { \
50 : nsPrintfCString msg("NECKO ERROR: '%s' UNIMPLEMENTED", \
51 : __FUNCTION__); \
52 : NECKO_MAYBE_ABORT(msg); \
53 : return NS_ERROR_NOT_IMPLEMENTED; \
54 : } while (0)
55 :
56 : #define ENSURE_CALLED_BEFORE_ASYNC_OPEN() \
57 : do { \
58 : if (mIsPending || mWasOpened) { \
59 : nsPrintfCString msg("'%s' called after AsyncOpen: %s +%d", \
60 : __FUNCTION__, __FILE__, __LINE__); \
61 : NECKO_MAYBE_ABORT(msg); \
62 : } \
63 : NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); \
64 : NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED); \
65 : } while (0)
66 :
67 : // Fails call if made after request observers (on-modify-request, etc) have been
68 : // called
69 :
70 : #define ENSURE_CALLED_BEFORE_CONNECT() \
71 : do { \
72 : if (mRequestObserversCalled) { \
73 : nsPrintfCString msg("'%s' called too late: %s +%d", \
74 : __FUNCTION__, __FILE__, __LINE__); \
75 : NECKO_MAYBE_ABORT(msg); \
76 : if (mIsPending) \
77 : return NS_ERROR_IN_PROGRESS; \
78 : MOZ_ASSERT(mWasOpened); \
79 : return NS_ERROR_ALREADY_OPENED; \
80 : } \
81 : } while (0)
82 :
83 : namespace mozilla {
84 : namespace net {
85 :
86 : inline bool
87 2344 : IsNeckoChild()
88 : {
89 : static bool didCheck = false;
90 : static bool amChild = false;
91 :
92 2344 : if (!didCheck) {
93 3 : didCheck = true;
94 3 : amChild = (XRE_GetProcessType() == GeckoProcessType_Content);
95 : }
96 2344 : return amChild;
97 : }
98 :
99 : namespace NeckoCommonInternal {
100 : extern bool gSecurityDisabled;
101 : extern bool gRegisteredBool;
102 : } // namespace NeckoCommonInternal
103 :
104 : // This should always return true unless xpcshell tests are being used
105 : inline bool
106 6 : UsingNeckoIPCSecurity()
107 : {
108 6 : return !NeckoCommonInternal::gSecurityDisabled;
109 : }
110 :
111 : inline bool
112 3 : MissingRequiredTabChild(mozilla::dom::TabChild* tabChild,
113 : const char* context)
114 : {
115 3 : if (UsingNeckoIPCSecurity()) {
116 0 : if (!tabChild) {
117 : printf_stderr("WARNING: child tried to open %s IPDL channel w/o "
118 0 : "security info\n", context);
119 0 : return true;
120 : }
121 : }
122 3 : return false;
123 : }
124 :
125 :
126 : } // namespace net
127 : } // namespace mozilla
128 :
129 : #endif // mozilla_net_NeckoCommon_h
130 :
|