netwerk/ipc/NeckoCommon.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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"
    12 #include "prenv.h"
    13 #include "nsPrintfCString.h"
    14 #include "mozilla/Preferences.h"
    16 namespace mozilla { namespace dom {
    17 class TabChild;
    18 }}
    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 
    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.
    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)
    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)
    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)
    66 // Fails call if made after request observers (on-modify-request, etc) have been
    67 // called
    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)
    82 namespace mozilla {
    83 namespace net {
    85 inline bool 
    86 IsNeckoChild() 
    87 {
    88   static bool didCheck = false;
    89   static bool amChild = false;
    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 }
   103 namespace NeckoCommonInternal {
   104   extern bool gSecurityDisabled;
   105   extern bool gRegisteredBool;
   106 }
   108 // This should always return true unless xpcshell tests are being used
   109 inline bool
   110 UsingNeckoIPCSecurity()
   111 {
   113   if (!NeckoCommonInternal::gRegisteredBool) {
   114     Preferences::AddBoolVarCache(&NeckoCommonInternal::gSecurityDisabled,
   115                                  "network.disable.ipc.security");
   116     NeckoCommonInternal::gRegisteredBool = true;
   117   }
   118   return !NeckoCommonInternal::gSecurityDisabled;
   119 }
   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 }
   136 } // namespace net
   137 } // namespace mozilla
   139 #endif // mozilla_net_NeckoCommon_h

mercurial