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 "mozilla/Preferences.h"
12 #include "mozilla/Variant.h"
13 #include "nsIRequest.h"
14 #include "nsPrintfCString.h"
15 #include "nsXULAppAPI.h"
18 class nsIStreamListener
;
24 } // namespace mozilla
27 # define NECKO_ERRORS_ARE_FATAL_DEFAULT true
29 # define NECKO_ERRORS_ARE_FATAL_DEFAULT false
32 // TODO: Eventually remove NECKO_MAYBE_ABORT and DROP_DEAD (bug 575494).
33 // Still useful for catching listener interfaces we don't yet support across
36 #define NECKO_MAYBE_ABORT(msg) \
38 bool abort = NECKO_ERRORS_ARE_FATAL_DEFAULT; \
39 const char* e = PR_GetEnv("NECKO_ERRORS_ARE_FATAL"); \
40 if (e) abort = (*e == '0') ? false : true; \
43 " (set NECKO_ERRORS_ARE_FATAL=0 in your environment " \
44 "to convert this error into a warning.)"); \
45 MOZ_CRASH_UNSAFE(msg.get()); \
48 " (set NECKO_ERRORS_ARE_FATAL=1 in your environment " \
49 "to convert this warning into a fatal error.)"); \
50 NS_WARNING(msg.get()); \
56 nsPrintfCString msg("NECKO ERROR: '%s' UNIMPLEMENTED", __FUNCTION__); \
57 NECKO_MAYBE_ABORT(msg); \
58 return NS_ERROR_NOT_IMPLEMENTED; \
61 #define ENSURE_CALLED_BEFORE_ASYNC_OPEN() \
63 if (LoadIsPending() || LoadWasOpened()) { \
64 nsPrintfCString msg("'%s' called after AsyncOpen: %s +%d", __FUNCTION__, \
65 __FILE__, __LINE__); \
66 NECKO_MAYBE_ABORT(msg); \
68 NS_ENSURE_TRUE(!LoadIsPending(), NS_ERROR_IN_PROGRESS); \
69 NS_ENSURE_TRUE(!LoadWasOpened(), NS_ERROR_ALREADY_OPENED); \
72 // Fails call if made after request observers (on-modify-request, etc) have been
75 #define ENSURE_CALLED_BEFORE_CONNECT() \
77 if (LoadRequestObserversCalled()) { \
78 nsPrintfCString msg("'%s' called too late: %s +%d", __FUNCTION__, \
79 __FILE__, __LINE__); \
80 NECKO_MAYBE_ABORT(msg); \
81 if (LoadIsPending()) return NS_ERROR_IN_PROGRESS; \
82 MOZ_ASSERT(LoadWasOpened()); \
83 return NS_ERROR_ALREADY_OPENED; \
90 inline bool IsNeckoChild() {
91 static bool didCheck
= false;
92 static bool amChild
= false;
96 amChild
= (XRE_GetProcessType() == GeckoProcessType_Content
);
101 inline bool IsSocketProcessChild() {
102 static bool amChild
= (XRE_GetProcessType() == GeckoProcessType_Socket
);
106 class HttpChannelSecurityWarningReporter
: public nsISupports
{
108 [[nodiscard
]] virtual nsresult
ReportSecurityMessage(
109 const nsAString
& aMessageTag
, const nsAString
& aMessageCategory
) = 0;
110 [[nodiscard
]] virtual nsresult
LogBlockedCORSRequest(
111 const nsAString
& aMessage
, const nsACString
& aCategory
,
112 bool aIsWarning
= false) = 0;
113 [[nodiscard
]] virtual nsresult
LogMimeTypeMismatch(
114 const nsACString
& aMessageName
, bool aWarning
, const nsAString
& aURL
,
115 const nsAString
& aContentType
) = 0;
118 struct OnStartRequestParams
{
119 nsCOMPtr
<nsIRequest
> request
;
121 struct OnDataAvailableParams
{
122 nsCOMPtr
<nsIRequest
> request
;
127 struct OnStopRequestParams
{
128 nsCOMPtr
<nsIRequest
> request
;
131 struct OnAfterLastPartParams
{
134 using StreamListenerFunction
=
135 mozilla::Variant
<OnStartRequestParams
, OnDataAvailableParams
,
136 OnStopRequestParams
, OnAfterLastPartParams
>;
138 nsresult
ForwardStreamListenerFunctions(nsTArray
<StreamListenerFunction
> aCalls
,
139 nsIStreamListener
* aParent
);
142 } // namespace mozilla
144 #endif // mozilla_net_NeckoCommon_h