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 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #define ALLOW_LATE_HTTPLOG_H_INCLUDE 1
8 #include "base/basictypes.h"
11 #include "nsIClassInfoImpl.h"
12 #include "mozilla/Components.h"
13 #include "mozilla/ModuleUtils.h"
15 #include "nsSimpleURI.h"
16 #include "nsLoadGroup.h"
17 #include "nsMimeTypes.h"
18 #include "nsDNSPrefetch.h"
19 #include "nsXULAppAPI.h"
20 #include "nsCategoryCache.h"
21 #include "nsIContentSniffer.h"
22 #include "nsStandardURL.h"
23 #include "mozilla/net/BackgroundChannelRegistrar.h"
24 #include "mozilla/net/NeckoChild.h"
25 #include "RedirectChannelRegistrar.h"
26 #include "nsAuthGSSAPI.h"
30 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_LINUX)
31 # define BUILD_NETWORK_INFO_SERVICE 1
34 using namespace mozilla
;
36 typedef nsCategoryCache
<nsIContentSniffer
> ContentSnifferCache
;
37 ContentSnifferCache
* gNetSniffers
= nullptr;
38 ContentSnifferCache
* gDataSniffers
= nullptr;
39 ContentSnifferCache
* gORBSniffers
= nullptr;
40 ContentSnifferCache
* gNetAndORBSniffers
= nullptr;
43 typedef mozilla::net::nsLoadGroup nsLoadGroup
;
44 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsLoadGroup
, Init
)
47 ///////////////////////////////////////////////////////////////////////////////
49 ///////////////////////////////////////////////////////////////////////////////
52 #include "nsHttpHandler.h"
53 #include "Http2Compression.h"
56 #include "nsHttpAuthManager.h"
57 #include "nsHttpActivityDistributor.h"
58 #include "ThrottleQueue.h"
62 NS_IMPL_COMPONENT_FACTORY(net::nsHttpHandler
) {
63 return net::nsHttpHandler::GetInstance().downcast
<nsIHttpProtocolHandler
>();
66 NS_IMPL_COMPONENT_FACTORY(net::nsHttpsHandler
) {
67 auto handler
= MakeRefPtr
<net::nsHttpsHandler
>();
69 if (NS_FAILED(handler
->Init())) {
72 return handler
.forget().downcast
<nsIHttpProtocolHandler
>();
75 #include "WebSocketChannel.h"
76 #include "WebSocketChannelChild.h"
77 namespace mozilla::net
{
78 static BaseWebSocketChannel
* WebSocketChannelConstructor(bool aSecure
) {
80 return new WebSocketChannelChild(aSecure
);
84 return new WebSocketSSLChannel
;
86 return new WebSocketChannel
;
89 #define WEB_SOCKET_HANDLER_CONSTRUCTOR(type, secure) \
90 nsresult type##Constructor(nsISupports* aOuter, REFNSIID aIID, \
94 RefPtr<BaseWebSocketChannel> inst; \
97 if (nullptr != aOuter) { \
98 rv = NS_ERROR_NO_AGGREGATION; \
101 inst = WebSocketChannelConstructor(secure); \
102 return inst->QueryInterface(aIID, aResult); \
105 WEB_SOCKET_HANDLER_CONSTRUCTOR(WebSocketChannel
, false)
106 WEB_SOCKET_HANDLER_CONSTRUCTOR(WebSocketSSLChannel
, true)
107 #undef WEB_SOCKET_HANDLER_CONSTRUCTOR
108 } // namespace mozilla::net
110 ///////////////////////////////////////////////////////////////////////////////
112 #include "nsStreamConverterService.h"
113 #include "nsMultiMixedConv.h"
114 #include "nsHTTPCompressConv.h"
115 #include "mozTXTToHTMLConv.h"
116 #include "nsUnknownDecoder.h"
118 ///////////////////////////////////////////////////////////////////////////////
120 #include "nsIndexedToHTML.h"
122 nsresult
NS_NewMultiMixedConv(nsMultiMixedConv
** result
);
123 nsresult
MOZ_NewTXTToHTMLConv(mozTXTToHTMLConv
** result
);
124 nsresult
NS_NewHTTPCompressConv(mozilla::net::nsHTTPCompressConv
** result
);
125 nsresult
NS_NewStreamConv(nsStreamConverterService
** aStreamConv
);
127 #define INDEX_TO_HTML "?from=application/http-index-format&to=text/html"
128 #define MULTI_MIXED_X "?from=multipart/x-mixed-replace&to=*/*"
129 #define MULTI_MIXED "?from=multipart/mixed&to=*/*"
130 #define MULTI_BYTERANGES "?from=multipart/byteranges&to=*/*"
131 #define UNKNOWN_CONTENT "?from=" UNKNOWN_CONTENT_TYPE "&to=*/*"
132 #define GZIP_TO_UNCOMPRESSED "?from=gzip&to=uncompressed"
133 #define XGZIP_TO_UNCOMPRESSED "?from=x-gzip&to=uncompressed"
134 #define BROTLI_TO_UNCOMPRESSED "?from=br&to=uncompressed"
135 #define COMPRESS_TO_UNCOMPRESSED "?from=compress&to=uncompressed"
136 #define XCOMPRESS_TO_UNCOMPRESSED "?from=x-compress&to=uncompressed"
137 #define DEFLATE_TO_UNCOMPRESSED "?from=deflate&to=uncompressed"
139 static const mozilla::Module::CategoryEntry kNeckoCategories
[] = {
140 {NS_ISTREAMCONVERTER_KEY
, INDEX_TO_HTML
, ""},
141 {NS_ISTREAMCONVERTER_KEY
, MULTI_MIXED_X
, ""},
142 {NS_ISTREAMCONVERTER_KEY
, MULTI_MIXED
, ""},
143 {NS_ISTREAMCONVERTER_KEY
, MULTI_BYTERANGES
, ""},
144 {NS_ISTREAMCONVERTER_KEY
, UNKNOWN_CONTENT
, ""},
145 {NS_ISTREAMCONVERTER_KEY
, GZIP_TO_UNCOMPRESSED
, ""},
146 {NS_ISTREAMCONVERTER_KEY
, XGZIP_TO_UNCOMPRESSED
, ""},
147 {NS_ISTREAMCONVERTER_KEY
, BROTLI_TO_UNCOMPRESSED
, ""},
148 {NS_ISTREAMCONVERTER_KEY
, COMPRESS_TO_UNCOMPRESSED
, ""},
149 {NS_ISTREAMCONVERTER_KEY
, XCOMPRESS_TO_UNCOMPRESSED
, ""},
150 {NS_ISTREAMCONVERTER_KEY
, DEFLATE_TO_UNCOMPRESSED
, ""},
151 NS_BINARYDETECTOR_CATEGORYENTRY
,
154 nsresult
CreateNewStreamConvServiceFactory(nsISupports
* aOuter
, REFNSIID aIID
,
157 return NS_ERROR_INVALID_POINTER
;
161 return NS_ERROR_NO_AGGREGATION
;
163 RefPtr
<nsStreamConverterService
> inst
;
164 nsresult rv
= NS_NewStreamConv(getter_AddRefs(inst
));
169 rv
= inst
->QueryInterface(aIID
, aResult
);
176 nsresult
CreateNewMultiMixedConvFactory(nsISupports
* aOuter
, REFNSIID aIID
,
179 return NS_ERROR_INVALID_POINTER
;
183 return NS_ERROR_NO_AGGREGATION
;
185 RefPtr
<nsMultiMixedConv
> inst
;
186 nsresult rv
= NS_NewMultiMixedConv(getter_AddRefs(inst
));
191 rv
= inst
->QueryInterface(aIID
, aResult
);
198 nsresult
CreateNewTXTToHTMLConvFactory(nsISupports
* aOuter
, REFNSIID aIID
,
201 return NS_ERROR_INVALID_POINTER
;
205 return NS_ERROR_NO_AGGREGATION
;
207 RefPtr
<mozTXTToHTMLConv
> inst
;
208 nsresult rv
= MOZ_NewTXTToHTMLConv(getter_AddRefs(inst
));
213 rv
= inst
->QueryInterface(aIID
, aResult
);
220 nsresult
CreateNewHTTPCompressConvFactory(nsISupports
* aOuter
, REFNSIID aIID
,
223 return NS_ERROR_INVALID_POINTER
;
227 return NS_ERROR_NO_AGGREGATION
;
229 RefPtr
<mozilla::net::nsHTTPCompressConv
> inst
;
230 nsresult rv
= NS_NewHTTPCompressConv(getter_AddRefs(inst
));
235 rv
= inst
->QueryInterface(aIID
, aResult
);
242 nsresult
CreateNewUnknownDecoderFactory(nsISupports
* aOuter
, REFNSIID aIID
,
245 return NS_ERROR_NULL_POINTER
;
250 return NS_ERROR_NO_AGGREGATION
;
253 RefPtr
<nsUnknownDecoder
> inst
= new nsUnknownDecoder();
254 return inst
->QueryInterface(aIID
, aResult
);
257 nsresult
CreateNewBinaryDetectorFactory(nsISupports
* aOuter
, REFNSIID aIID
,
260 return NS_ERROR_NULL_POINTER
;
265 return NS_ERROR_NO_AGGREGATION
;
268 RefPtr
<nsBinaryDetector
> inst
= new nsBinaryDetector();
269 return inst
->QueryInterface(aIID
, aResult
);
272 ///////////////////////////////////////////////////////////////////////////////
273 // Module implementation for the net library
275 // Net module startup hook
276 nsresult
nsNetStartup() {
277 mozilla::net::nsStandardURL::InitGlobalObjects();
281 // Net module shutdown hook
282 void nsNetShutdown() {
283 // Release the url parser that the stdurl is holding.
284 mozilla::net::nsStandardURL::ShutdownGlobalObjects();
286 // Release global state used by the URL helper module.
287 net_ShutdownURLHelper();
289 net_ShutdownURLHelperOSX();
292 // Release DNS service reference.
293 nsDNSPrefetch::Shutdown();
295 // Release the Websocket Admission Manager
296 mozilla::net::WebSocketChannel::Shutdown();
298 mozilla::net::Http2CompressionCleanup();
300 mozilla::net::RedirectChannelRegistrar::Shutdown();
302 mozilla::net::BackgroundChannelRegistrar::Shutdown();
304 nsAuthGSSAPI::Shutdown();
307 gNetSniffers
= nullptr;
308 delete gDataSniffers
;
309 gDataSniffers
= nullptr;
311 gORBSniffers
= nullptr;
312 delete gNetAndORBSniffers
;
313 gNetAndORBSniffers
= nullptr;
316 extern const mozilla::Module kNeckoModule
= {
317 mozilla::Module::kVersion
,
324 mozilla::Module::ALLOW_IN_SOCKET_PROCESS
};