/work/obj-fuzz/dist/include/mozilla/net/NeckoCommon.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 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 | 0 | # 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 | 0 | do { \ |
33 | 0 | bool abort = NECKO_ERRORS_ARE_FATAL_DEFAULT; \ |
34 | 0 | const char *e = PR_GetEnv("NECKO_ERRORS_ARE_FATAL"); \ |
35 | 0 | if (e) \ |
36 | 0 | abort = (*e == '0') ? false : true; \ |
37 | 0 | if (abort) { \ |
38 | 0 | msg.AppendLiteral(" (set NECKO_ERRORS_ARE_FATAL=0 in your environment " \ |
39 | 0 | "to convert this error into a warning.)"); \ |
40 | 0 | MOZ_CRASH_UNSAFE_OOL(msg.get()); \ |
41 | 0 | } else { \ |
42 | 0 | msg.AppendLiteral(" (set NECKO_ERRORS_ARE_FATAL=1 in your environment " \ |
43 | 0 | "to convert this warning into a fatal error.)"); \ |
44 | 0 | NS_WARNING(msg.get()); \ |
45 | 0 | } \ |
46 | 0 | } while (0) |
47 | | |
48 | | #define DROP_DEAD() \ |
49 | 0 | do { \ |
50 | 0 | nsPrintfCString msg("NECKO ERROR: '%s' UNIMPLEMENTED", \ |
51 | 0 | __FUNCTION__); \ |
52 | 0 | NECKO_MAYBE_ABORT(msg); \ |
53 | 0 | return NS_ERROR_NOT_IMPLEMENTED; \ |
54 | 0 | } while (0) |
55 | | |
56 | | #define ENSURE_CALLED_BEFORE_ASYNC_OPEN() \ |
57 | 0 | do { \ |
58 | 0 | if (mIsPending || mWasOpened) { \ |
59 | 0 | nsPrintfCString msg("'%s' called after AsyncOpen: %s +%d", \ |
60 | 0 | __FUNCTION__, __FILE__, __LINE__); \ |
61 | 0 | NECKO_MAYBE_ABORT(msg); \ |
62 | 0 | } \ |
63 | 0 | NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS); \ |
64 | 0 | NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_ALREADY_OPENED); \ |
65 | 0 | } 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 | 0 | do { \ |
72 | 0 | if (mRequestObserversCalled) { \ |
73 | 0 | nsPrintfCString msg("'%s' called too late: %s +%d", \ |
74 | 0 | __FUNCTION__, __FILE__, __LINE__); \ |
75 | 0 | NECKO_MAYBE_ABORT(msg); \ |
76 | 0 | if (mIsPending) \ |
77 | 0 | return NS_ERROR_IN_PROGRESS; \ |
78 | 0 | MOZ_ASSERT(mWasOpened); \ |
79 | 0 | return NS_ERROR_ALREADY_OPENED; \ |
80 | 0 | } \ |
81 | 0 | } while (0) |
82 | | |
83 | | namespace mozilla { |
84 | | namespace net { |
85 | | |
86 | | inline bool |
87 | | IsNeckoChild() |
88 | 367 | { |
89 | 367 | static bool didCheck = false; |
90 | 367 | static bool amChild = false; |
91 | 367 | |
92 | 367 | if (!didCheck) { |
93 | 3 | didCheck = true; |
94 | 3 | amChild = (XRE_GetProcessType() == GeckoProcessType_Content) && !recordreplay::IsMiddleman(); |
95 | 3 | } |
96 | 367 | return amChild; |
97 | 367 | } |
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 | | UsingNeckoIPCSecurity() |
107 | 0 | { |
108 | 0 | return !NeckoCommonInternal::gSecurityDisabled; |
109 | 0 | } |
110 | | |
111 | | inline bool |
112 | | MissingRequiredTabChild(mozilla::dom::TabChild* tabChild, |
113 | | const char* context) |
114 | 0 | { |
115 | 0 | if (UsingNeckoIPCSecurity()) { |
116 | 0 | if (!tabChild) { |
117 | 0 | printf_stderr("WARNING: child tried to open %s IPDL channel w/o " |
118 | 0 | "security info\n", context); |
119 | 0 | return true; |
120 | 0 | } |
121 | 0 | } |
122 | 0 | return false; |
123 | 0 | } |
124 | | |
125 | | } // namespace net |
126 | | } // namespace mozilla |
127 | | |
128 | | #endif // mozilla_net_NeckoCommon_h |