Bug 1708422: part 8) Move `mozInlineSpellChecker::CheckWordsAndAddRangesForMisspellin...
[gecko.git] / netwerk / build / nsNetModule.cpp
blob347e2a18a3fd096b98328f837371402657e13c3a
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"
10 #include "nsCOMPtr.h"
11 #include "nsIClassInfoImpl.h"
12 #include "mozilla/Components.h"
13 #include "mozilla/ModuleUtils.h"
14 #include "nscore.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"
28 #include "nsNetCID.h"
30 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_LINUX)
31 # define BUILD_NETWORK_INFO_SERVICE 1
32 #endif
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;
42 #define static
43 typedef mozilla::net::nsLoadGroup nsLoadGroup;
44 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsLoadGroup, Init)
45 #undef static
47 ///////////////////////////////////////////////////////////////////////////////
48 // protocols
49 ///////////////////////////////////////////////////////////////////////////////
51 // http/https
52 #include "nsHttpHandler.h"
53 #include "Http2Compression.h"
54 #undef LOG
55 #undef LOG_ENABLED
56 #include "nsHttpAuthManager.h"
57 #include "nsHttpActivityDistributor.h"
58 #include "ThrottleQueue.h"
59 #undef LOG
60 #undef LOG_ENABLED
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())) {
70 return nullptr;
72 return handler.forget().downcast<nsIHttpProtocolHandler>();
75 #include "WebSocketChannel.h"
76 #include "WebSocketChannelChild.h"
77 namespace mozilla::net {
78 static BaseWebSocketChannel* WebSocketChannelConstructor(bool aSecure) {
79 if (IsNeckoChild()) {
80 return new WebSocketChannelChild(aSecure);
83 if (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, \
91 void** aResult) { \
92 nsresult rv; \
94 RefPtr<BaseWebSocketChannel> inst; \
96 *aResult = nullptr; \
97 if (nullptr != aOuter) { \
98 rv = NS_ERROR_NO_AGGREGATION; \
99 return rv; \
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,
152 {nullptr}};
154 nsresult CreateNewStreamConvServiceFactory(nsISupports* aOuter, REFNSIID aIID,
155 void** aResult) {
156 if (!aResult) {
157 return NS_ERROR_INVALID_POINTER;
159 if (aOuter) {
160 *aResult = nullptr;
161 return NS_ERROR_NO_AGGREGATION;
163 RefPtr<nsStreamConverterService> inst;
164 nsresult rv = NS_NewStreamConv(getter_AddRefs(inst));
165 if (NS_FAILED(rv)) {
166 *aResult = nullptr;
167 return rv;
169 rv = inst->QueryInterface(aIID, aResult);
170 if (NS_FAILED(rv)) {
171 *aResult = nullptr;
173 return rv;
176 nsresult CreateNewMultiMixedConvFactory(nsISupports* aOuter, REFNSIID aIID,
177 void** aResult) {
178 if (!aResult) {
179 return NS_ERROR_INVALID_POINTER;
181 if (aOuter) {
182 *aResult = nullptr;
183 return NS_ERROR_NO_AGGREGATION;
185 RefPtr<nsMultiMixedConv> inst;
186 nsresult rv = NS_NewMultiMixedConv(getter_AddRefs(inst));
187 if (NS_FAILED(rv)) {
188 *aResult = nullptr;
189 return rv;
191 rv = inst->QueryInterface(aIID, aResult);
192 if (NS_FAILED(rv)) {
193 *aResult = nullptr;
195 return rv;
198 nsresult CreateNewTXTToHTMLConvFactory(nsISupports* aOuter, REFNSIID aIID,
199 void** aResult) {
200 if (!aResult) {
201 return NS_ERROR_INVALID_POINTER;
203 if (aOuter) {
204 *aResult = nullptr;
205 return NS_ERROR_NO_AGGREGATION;
207 RefPtr<mozTXTToHTMLConv> inst;
208 nsresult rv = MOZ_NewTXTToHTMLConv(getter_AddRefs(inst));
209 if (NS_FAILED(rv)) {
210 *aResult = nullptr;
211 return rv;
213 rv = inst->QueryInterface(aIID, aResult);
214 if (NS_FAILED(rv)) {
215 *aResult = nullptr;
217 return rv;
220 nsresult CreateNewHTTPCompressConvFactory(nsISupports* aOuter, REFNSIID aIID,
221 void** aResult) {
222 if (!aResult) {
223 return NS_ERROR_INVALID_POINTER;
225 if (aOuter) {
226 *aResult = nullptr;
227 return NS_ERROR_NO_AGGREGATION;
229 RefPtr<mozilla::net::nsHTTPCompressConv> inst;
230 nsresult rv = NS_NewHTTPCompressConv(getter_AddRefs(inst));
231 if (NS_FAILED(rv)) {
232 *aResult = nullptr;
233 return rv;
235 rv = inst->QueryInterface(aIID, aResult);
236 if (NS_FAILED(rv)) {
237 *aResult = nullptr;
239 return rv;
242 nsresult CreateNewUnknownDecoderFactory(nsISupports* aOuter, REFNSIID aIID,
243 void** aResult) {
244 if (!aResult) {
245 return NS_ERROR_NULL_POINTER;
247 *aResult = nullptr;
249 if (aOuter) {
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,
258 void** aResult) {
259 if (!aResult) {
260 return NS_ERROR_NULL_POINTER;
262 *aResult = nullptr;
264 if (aOuter) {
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();
278 return NS_OK;
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();
288 #ifdef XP_MACOSX
289 net_ShutdownURLHelperOSX();
290 #endif
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();
306 delete gNetSniffers;
307 gNetSniffers = nullptr;
308 delete gDataSniffers;
309 gDataSniffers = nullptr;
310 delete gORBSniffers;
311 gORBSniffers = nullptr;
312 delete gNetAndORBSniffers;
313 gNetAndORBSniffers = nullptr;
316 extern const mozilla::Module kNeckoModule = {
317 mozilla::Module::kVersion,
318 nullptr,
319 nullptr,
320 kNeckoCategories,
321 nullptr,
322 nullptr,
323 nullptr,
324 mozilla::Module::ALLOW_IN_SOCKET_PROCESS};