Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / libpr0n / build / nsImageModule.cpp
blobe6781fda2f265da90b884acac4edf6b0da648e4c
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Stuart Parmenter <pavlov@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsImgBuildDefines.h"
42 #ifdef XP_MAC
43 #define IMG_BUILD_gif 1
44 #define IMG_BUILD_bmp 1
45 #define IMG_BUILD_png 1
46 #define IMG_BUILD_jpeg 1
47 #define IMG_BUILD_xbm 1
48 #endif
50 #include "nsIGenericFactory.h"
51 #include "nsIModule.h"
52 #include "nsICategoryManager.h"
53 #include "nsXPCOMCID.h"
54 #include "nsServiceManagerUtils.h"
56 #include "imgContainer.h"
57 #include "imgLoader.h"
58 #include "imgRequest.h"
59 #include "imgRequestProxy.h"
60 #include "imgTools.h"
62 #ifdef IMG_BUILD_DECODER_gif
63 // gif
64 #include "nsGIFDecoder2.h"
65 #endif
67 #ifdef IMG_BUILD_DECODER_bmp
68 // bmp/ico
69 #include "nsBMPDecoder.h"
70 #include "nsICODecoder.h"
71 #endif
73 #ifdef IMG_BUILD_DECODER_png
74 // png
75 #include "nsPNGDecoder.h"
76 #endif
78 #ifdef IMG_BUILD_DECODER_jpeg
79 // jpeg
80 #include "nsJPEGDecoder.h"
81 #endif
83 #ifdef IMG_BUILD_DECODER_xbm
84 // xbm
85 #include "nsXBMDecoder.h"
86 #endif
89 #ifdef IMG_BUILD_ENCODER_png
90 // png
91 #include "nsPNGEncoder.h"
92 #endif
93 #ifdef IMG_BUILD_ENCODER_jpeg
94 // jpeg
95 #include "nsJPEGEncoder.h"
96 #endif
99 // objects that just require generic constructors
101 NS_GENERIC_FACTORY_CONSTRUCTOR(imgContainer)
102 NS_GENERIC_FACTORY_CONSTRUCTOR(imgLoader)
103 NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy)
104 NS_GENERIC_FACTORY_CONSTRUCTOR(imgTools)
106 #ifdef IMG_BUILD_DECODER_gif
107 // gif
108 NS_GENERIC_FACTORY_CONSTRUCTOR(nsGIFDecoder2)
109 #endif
111 #ifdef IMG_BUILD_DECODER_jpeg
112 // jpeg
113 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGDecoder)
114 #endif
115 #ifdef IMG_BUILD_ENCODER_jpeg
116 // jpeg
117 NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGEncoder)
118 #endif
120 #ifdef IMG_BUILD_DECODER_bmp
121 // bmp
122 NS_GENERIC_FACTORY_CONSTRUCTOR(nsICODecoder)
123 NS_GENERIC_FACTORY_CONSTRUCTOR(nsBMPDecoder)
124 #endif
126 #ifdef IMG_BUILD_DECODER_png
127 // png
128 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGDecoder)
129 #endif
130 #ifdef IMG_BUILD_ENCODER_png
131 // png
132 NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGEncoder)
133 #endif
135 #ifdef IMG_BUILD_DECODER_xbm
136 // xbm
137 NS_GENERIC_FACTORY_CONSTRUCTOR(nsXBMDecoder)
138 #endif
140 static const char* gImageMimeTypes[] = {
141 #ifdef IMG_BUILD_DECODER_gif
142 "image/gif",
143 #endif
144 #ifdef IMG_BUILD_DECODER_jpeg
145 "image/jpeg",
146 "image/pjpeg",
147 "image/jpg",
148 #endif
149 #ifdef IMG_BUILD_DECODER_bmp
150 "image/x-icon",
151 "image/vnd.microsoft.icon",
152 "image/bmp",
153 "image/x-ms-bmp",
154 #endif
155 #ifdef IMG_BUILD_DECODER_png
156 "image/png",
157 "image/x-png",
158 #endif
159 #ifdef IMG_BUILD_DECODER_xbm
160 "image/x-xbitmap",
161 "image/x-xbm",
162 "image/xbm"
163 #endif
166 static NS_METHOD ImageRegisterProc(nsIComponentManager *aCompMgr,
167 nsIFile *aPath,
168 const char *registryLocation,
169 const char *componentType,
170 const nsModuleComponentInfo *info) {
171 nsresult rv;
172 nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
173 if (NS_FAILED(rv))
174 return rv;
175 for (unsigned i = 0; i < sizeof(gImageMimeTypes)/sizeof(*gImageMimeTypes); i++) {
176 catMan->AddCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes[i],
177 "@mozilla.org/content/document-loader-factory;1",
178 PR_TRUE, PR_TRUE, nsnull);
181 catMan->AddCategoryEntry("content-sniffing-services", "@mozilla.org/image/loader;1",
182 "@mozilla.org/image/loader;1", PR_TRUE, PR_TRUE,
183 nsnull);
184 return NS_OK;
187 static NS_METHOD ImageUnregisterProc(nsIComponentManager *aCompMgr,
188 nsIFile *aPath,
189 const char *registryLocation,
190 const nsModuleComponentInfo *info) {
191 nsresult rv;
192 nsCOMPtr<nsICategoryManager> catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
193 if (NS_FAILED(rv))
194 return rv;
195 for (unsigned i = 0; i < sizeof(gImageMimeTypes)/sizeof(*gImageMimeTypes); i++)
196 catMan->DeleteCategoryEntry("Gecko-Content-Viewers", gImageMimeTypes[i], PR_TRUE);
198 return NS_OK;
201 static const nsModuleComponentInfo components[] =
203 { "image cache",
204 NS_IMGLOADER_CID,
205 "@mozilla.org/image/cache;1",
206 imgLoaderConstructor, },
207 { "image container",
208 NS_IMGCONTAINER_CID,
209 "@mozilla.org/image/container;1",
210 imgContainerConstructor, },
211 { "image loader",
212 NS_IMGLOADER_CID,
213 "@mozilla.org/image/loader;1",
214 imgLoaderConstructor,
215 ImageRegisterProc, /* register the decoder mime types here */
216 ImageUnregisterProc, },
217 { "image request proxy",
218 NS_IMGREQUESTPROXY_CID,
219 "@mozilla.org/image/request;1",
220 imgRequestProxyConstructor, },
221 { "image tools",
222 NS_IMGTOOLS_CID,
223 "@mozilla.org/image/tools;1",
224 imgToolsConstructor, },
226 #ifdef IMG_BUILD_DECODER_gif
227 // gif
228 { "GIF Decoder",
229 NS_GIFDECODER2_CID,
230 "@mozilla.org/image/decoder;2?type=image/gif",
231 nsGIFDecoder2Constructor, },
232 #endif
234 #ifdef IMG_BUILD_DECODER_jpeg
235 // jpeg
236 { "JPEG decoder",
237 NS_JPEGDECODER_CID,
238 "@mozilla.org/image/decoder;2?type=image/jpeg",
239 nsJPEGDecoderConstructor, },
240 { "JPEG decoder",
241 NS_JPEGDECODER_CID,
242 "@mozilla.org/image/decoder;2?type=image/pjpeg",
243 nsJPEGDecoderConstructor, },
244 { "JPEG decoder",
245 NS_JPEGDECODER_CID,
246 "@mozilla.org/image/decoder;2?type=image/jpg",
247 nsJPEGDecoderConstructor, },
248 #endif
249 #ifdef IMG_BUILD_ENCODER_jpeg
250 // jpeg (encoder)
251 { "JPEG Encoder",
252 NS_JPEGENCODER_CID,
253 "@mozilla.org/image/encoder;2?type=image/jpeg",
254 nsJPEGEncoderConstructor, },
255 #endif
257 #ifdef IMG_BUILD_DECODER_bmp
258 // bmp
259 { "ICO Decoder",
260 NS_ICODECODER_CID,
261 "@mozilla.org/image/decoder;2?type=image/x-icon",
262 nsICODecoderConstructor, },
263 { "ICO Decoder",
264 NS_ICODECODER_CID,
265 "@mozilla.org/image/decoder;2?type=image/vnd.microsoft.icon",
266 nsICODecoderConstructor, },
267 { "BMP Decoder",
268 NS_BMPDECODER_CID,
269 "@mozilla.org/image/decoder;2?type=image/bmp",
270 nsBMPDecoderConstructor, },
271 { "BMP Decoder",
272 NS_BMPDECODER_CID,
273 "@mozilla.org/image/decoder;2?type=image/x-ms-bmp",
274 nsBMPDecoderConstructor, },
275 #endif
277 #ifdef IMG_BUILD_DECODER_png
278 // png
279 { "PNG Decoder",
280 NS_PNGDECODER_CID,
281 "@mozilla.org/image/decoder;2?type=image/png",
282 nsPNGDecoderConstructor, },
283 { "PNG Decoder",
284 NS_PNGDECODER_CID,
285 "@mozilla.org/image/decoder;2?type=image/x-png",
286 nsPNGDecoderConstructor, },
287 #endif
288 #ifdef IMG_BUILD_ENCODER_png
289 // png
290 { "PNG Encoder",
291 NS_PNGENCODER_CID,
292 "@mozilla.org/image/encoder;2?type=image/png",
293 nsPNGEncoderConstructor, },
294 #endif
296 #ifdef IMG_BUILD_DECODER_xbm
297 // xbm
298 { "XBM Decoder",
299 NS_XBMDECODER_CID,
300 "@mozilla.org/image/decoder;2?type=image/x-xbitmap",
301 nsXBMDecoderConstructor, },
302 { "XBM Decoder",
303 NS_XBMDECODER_CID,
304 "@mozilla.org/image/decoder;2?type=image/x-xbm",
305 nsXBMDecoderConstructor, },
306 { "XBM Decoder",
307 NS_XBMDECODER_CID,
308 "@mozilla.org/image/decoder;2?type=image/xbm",
309 nsXBMDecoderConstructor, },
310 #endif
313 static nsresult
314 imglib_Initialize(nsIModule* aSelf)
316 imgLoader::InitCache();
317 return NS_OK;
320 static void
321 imglib_Shutdown(nsIModule* aSelf)
323 imgLoader::Shutdown();
326 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(nsImageLib2Module, components,
327 imglib_Initialize, imglib_Shutdown)