netwerk/ipc/NeckoCommon.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial