|
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 }} |
|
19 |
|
20 #if defined(DEBUG) || defined(ENABLE_TESTS) |
|
21 # define NECKO_ERRORS_ARE_FATAL_DEFAULT true |
|
22 #else |
|
23 # define NECKO_ERRORS_ARE_FATAL_DEFAULT false |
|
24 #endif |
|
25 |
|
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 |
|
28 // processes, etc. |
|
29 |
|
30 #define NECKO_MAYBE_ABORT(msg) \ |
|
31 do { \ |
|
32 bool abort = NECKO_ERRORS_ARE_FATAL_DEFAULT; \ |
|
33 const char *e = PR_GetEnv("NECKO_ERRORS_ARE_FATAL"); \ |
|
34 if (e) \ |
|
35 abort = (*e == '0') ? false : true; \ |
|
36 if (abort) { \ |
|
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()); \ |
|
40 } else { \ |
|
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()); \ |
|
44 } \ |
|
45 } while (0) |
|
46 |
|
47 #define DROP_DEAD() \ |
|
48 do { \ |
|
49 nsPrintfCString msg("NECKO ERROR: '%s' UNIMPLEMENTED", \ |
|
50 __FUNCTION__); \ |
|
51 NECKO_MAYBE_ABORT(msg); \ |
|
52 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
53 } while (0) |
|
54 |
|
55 #define ENSURE_CALLED_BEFORE_ASYNC_OPEN() \ |
|
56 do { \ |
|
57 if (mIsPending || mWasOpened) { \ |
|
58 nsPrintfCString msg("'%s' called after AsyncOpen: %s +%d", \ |
|
59 __FUNCTION__, __FILE__, __LINE__); \ |
|
60 NECKO_MAYBE_ABORT(msg); \ |
|
61 } \ |
|
62 NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); \ |
|
63 NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED); \ |
|
64 } while (0) |
|
65 |
|
66 // Fails call if made after request observers (on-modify-request, etc) have been |
|
67 // called |
|
68 |
|
69 #define ENSURE_CALLED_BEFORE_CONNECT() \ |
|
70 do { \ |
|
71 if (mRequestObserversCalled) { \ |
|
72 nsPrintfCString msg("'%s' called too late: %s +%d", \ |
|
73 __FUNCTION__, __FILE__, __LINE__); \ |
|
74 NECKO_MAYBE_ABORT(msg); \ |
|
75 if (mIsPending) \ |
|
76 return NS_ERROR_IN_PROGRESS; \ |
|
77 MOZ_ASSERT(mWasOpened); \ |
|
78 return NS_ERROR_ALREADY_OPENED; \ |
|
79 } \ |
|
80 } while (0) |
|
81 |
|
82 namespace mozilla { |
|
83 namespace net { |
|
84 |
|
85 inline bool |
|
86 IsNeckoChild() |
|
87 { |
|
88 static bool didCheck = false; |
|
89 static bool amChild = false; |
|
90 |
|
91 if (!didCheck) { |
|
92 // This allows independent necko-stacks (instead of single stack in chrome) |
|
93 // to still be run. |
|
94 // TODO: Remove eventually when no longer supported (bug 571126) |
|
95 const char * e = PR_GetEnv("NECKO_SEPARATE_STACKS"); |
|
96 if (!e) |
|
97 amChild = (XRE_GetProcessType() == GeckoProcessType_Content); |
|
98 didCheck = true; |
|
99 } |
|
100 return amChild; |
|
101 } |
|
102 |
|
103 namespace NeckoCommonInternal { |
|
104 extern bool gSecurityDisabled; |
|
105 extern bool gRegisteredBool; |
|
106 } |
|
107 |
|
108 // This should always return true unless xpcshell tests are being used |
|
109 inline bool |
|
110 UsingNeckoIPCSecurity() |
|
111 { |
|
112 |
|
113 if (!NeckoCommonInternal::gRegisteredBool) { |
|
114 Preferences::AddBoolVarCache(&NeckoCommonInternal::gSecurityDisabled, |
|
115 "network.disable.ipc.security"); |
|
116 NeckoCommonInternal::gRegisteredBool = true; |
|
117 } |
|
118 return !NeckoCommonInternal::gSecurityDisabled; |
|
119 } |
|
120 |
|
121 inline bool |
|
122 MissingRequiredTabChild(mozilla::dom::TabChild* tabChild, |
|
123 const char* context) |
|
124 { |
|
125 if (UsingNeckoIPCSecurity()) { |
|
126 if (!tabChild) { |
|
127 printf_stderr("WARNING: child tried to open %s IPDL channel w/o " |
|
128 "security info\n", context); |
|
129 return true; |
|
130 } |
|
131 } |
|
132 return false; |
|
133 } |
|
134 |
|
135 |
|
136 } // namespace net |
|
137 } // namespace mozilla |
|
138 |
|
139 #endif // mozilla_net_NeckoCommon_h |
|
140 |