Bug 1807268 - Re-enable verifyShowClipboardSuggestionsToggleTest UI test r=jajohnson
[gecko.git] / netwerk / build / nsNetModule.cpp
bloba54275b697850f3a192549350d4b82d8f39d9b39
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 #ifdef MOZ_AUTH_EXTENSION
26 # include "nsAuthGSSAPI.h"
27 #endif
29 #include "nsNetCID.h"
31 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(XP_LINUX)
32 # define BUILD_NETWORK_INFO_SERVICE 1
33 #endif
35 using namespace mozilla;
37 using ContentSnifferCache = nsCategoryCache<nsIContentSniffer>;
38 ContentSnifferCache* gNetSniffers = nullptr;
39 ContentSnifferCache* gDataSniffers = nullptr;
40 ContentSnifferCache* gORBSniffers = nullptr;
41 ContentSnifferCache* gNetAndORBSniffers = nullptr;
43 #define static
44 using nsLoadGroup = mozilla::net::nsLoadGroup;
45 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsLoadGroup, Init)
46 #undef static
48 ///////////////////////////////////////////////////////////////////////////////
49 // protocols
50 ///////////////////////////////////////////////////////////////////////////////
52 // http/https
53 #include "nsHttpHandler.h"
54 #include "Http2Compression.h"
55 #undef LOG
56 #undef LOG_ENABLED
57 #include "nsHttpAuthManager.h"
58 #include "nsHttpActivityDistributor.h"
59 #include "ThrottleQueue.h"
60 #undef LOG
61 #undef LOG_ENABLED
63 NS_IMPL_COMPONENT_FACTORY(net::nsHttpHandler) {
64 return net::nsHttpHandler::GetInstance().downcast<nsIHttpProtocolHandler>();
67 NS_IMPL_COMPONENT_FACTORY(net::nsHttpsHandler) {
68 auto handler = MakeRefPtr<net::nsHttpsHandler>();
70 if (NS_FAILED(handler->Init())) {
71 return nullptr;
73 return handler.forget().downcast<nsIHttpProtocolHandler>();
76 #include "WebSocketChannel.h"
77 #include "WebSocketChannelChild.h"
78 namespace mozilla::net {
79 static BaseWebSocketChannel* WebSocketChannelConstructor(bool aSecure) {
80 if (IsNeckoChild()) {
81 return new WebSocketChannelChild(aSecure);
84 if (aSecure) {
85 return new WebSocketSSLChannel;
87 return new WebSocketChannel;
90 #define WEB_SOCKET_HANDLER_CONSTRUCTOR(type, secure) \
91 nsresult type##Constructor(REFNSIID aIID, void** aResult) { \
92 RefPtr<BaseWebSocketChannel> inst; \
94 *aResult = nullptr; \
95 inst = WebSocketChannelConstructor(secure); \
96 return inst->QueryInterface(aIID, aResult); \
99 WEB_SOCKET_HANDLER_CONSTRUCTOR(WebSocketChannel, false)
100 WEB_SOCKET_HANDLER_CONSTRUCTOR(WebSocketSSLChannel, true)
101 #undef WEB_SOCKET_HANDLER_CONSTRUCTOR
102 } // namespace mozilla::net
104 ///////////////////////////////////////////////////////////////////////////////
106 #include "nsStreamConverterService.h"
107 #include "nsMultiMixedConv.h"
108 #include "nsHTTPCompressConv.h"
109 #include "mozTXTToHTMLConv.h"
110 #include "nsUnknownDecoder.h"
112 ///////////////////////////////////////////////////////////////////////////////
114 #include "nsIndexedToHTML.h"
116 nsresult NS_NewMultiMixedConv(nsMultiMixedConv** result);
117 nsresult MOZ_NewTXTToHTMLConv(mozTXTToHTMLConv** result);
118 nsresult NS_NewHTTPCompressConv(mozilla::net::nsHTTPCompressConv** result);
119 nsresult NS_NewStreamConv(nsStreamConverterService** aStreamConv);
121 nsresult CreateNewStreamConvServiceFactory(REFNSIID aIID, void** aResult) {
122 if (!aResult) {
123 return NS_ERROR_INVALID_POINTER;
125 RefPtr<nsStreamConverterService> inst;
126 nsresult rv = NS_NewStreamConv(getter_AddRefs(inst));
127 if (NS_FAILED(rv)) {
128 *aResult = nullptr;
129 return rv;
131 rv = inst->QueryInterface(aIID, aResult);
132 if (NS_FAILED(rv)) {
133 *aResult = nullptr;
135 return rv;
138 nsresult CreateNewMultiMixedConvFactory(REFNSIID aIID, void** aResult) {
139 if (!aResult) {
140 return NS_ERROR_INVALID_POINTER;
142 RefPtr<nsMultiMixedConv> inst;
143 nsresult rv = NS_NewMultiMixedConv(getter_AddRefs(inst));
144 if (NS_FAILED(rv)) {
145 *aResult = nullptr;
146 return rv;
148 rv = inst->QueryInterface(aIID, aResult);
149 if (NS_FAILED(rv)) {
150 *aResult = nullptr;
152 return rv;
155 nsresult CreateNewTXTToHTMLConvFactory(REFNSIID aIID, void** aResult) {
156 if (!aResult) {
157 return NS_ERROR_INVALID_POINTER;
159 RefPtr<mozTXTToHTMLConv> inst;
160 nsresult rv = MOZ_NewTXTToHTMLConv(getter_AddRefs(inst));
161 if (NS_FAILED(rv)) {
162 *aResult = nullptr;
163 return rv;
165 rv = inst->QueryInterface(aIID, aResult);
166 if (NS_FAILED(rv)) {
167 *aResult = nullptr;
169 return rv;
172 nsresult CreateNewHTTPCompressConvFactory(REFNSIID aIID, void** aResult) {
173 if (!aResult) {
174 return NS_ERROR_INVALID_POINTER;
176 RefPtr<mozilla::net::nsHTTPCompressConv> inst;
177 nsresult rv = NS_NewHTTPCompressConv(getter_AddRefs(inst));
178 if (NS_FAILED(rv)) {
179 *aResult = nullptr;
180 return rv;
182 rv = inst->QueryInterface(aIID, aResult);
183 if (NS_FAILED(rv)) {
184 *aResult = nullptr;
186 return rv;
189 nsresult CreateNewUnknownDecoderFactory(REFNSIID aIID, void** aResult) {
190 if (!aResult) {
191 return NS_ERROR_NULL_POINTER;
193 *aResult = nullptr;
195 RefPtr<nsUnknownDecoder> inst = new nsUnknownDecoder();
196 return inst->QueryInterface(aIID, aResult);
199 nsresult CreateNewBinaryDetectorFactory(REFNSIID aIID, void** aResult) {
200 if (!aResult) {
201 return NS_ERROR_NULL_POINTER;
203 *aResult = nullptr;
205 RefPtr<nsBinaryDetector> inst = new nsBinaryDetector();
206 return inst->QueryInterface(aIID, aResult);
209 ///////////////////////////////////////////////////////////////////////////////
210 // Module implementation for the net library
212 // Net module startup hook
213 nsresult nsNetStartup() {
214 mozilla::net::nsStandardURL::InitGlobalObjects();
215 return NS_OK;
218 // Net module shutdown hook
219 void nsNetShutdown() {
220 // Release the url parser that the stdurl is holding.
221 mozilla::net::nsStandardURL::ShutdownGlobalObjects();
223 // Release global state used by the URL helper module.
224 net_ShutdownURLHelper();
225 #ifdef XP_MACOSX
226 net_ShutdownURLHelperOSX();
227 #endif
229 // Release DNS service reference.
230 nsDNSPrefetch::Shutdown();
232 // Release the Websocket Admission Manager
233 mozilla::net::WebSocketChannel::Shutdown();
235 mozilla::net::Http2CompressionCleanup();
237 #ifdef MOZ_AUTH_EXTENSION
238 nsAuthGSSAPI::Shutdown();
239 #endif
241 delete gNetSniffers;
242 gNetSniffers = nullptr;
243 delete gDataSniffers;
244 gDataSniffers = nullptr;
245 delete gORBSniffers;
246 gORBSniffers = nullptr;
247 delete gNetAndORBSniffers;
248 gNetAndORBSniffers = nullptr;