michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsImageModule.h" michael@0: michael@0: #include "mozilla/ModuleUtils.h" michael@0: #include "nsMimeTypes.h" michael@0: michael@0: #include "ImageFactory.h" michael@0: #include "RasterImage.h" michael@0: #include "SurfaceCache.h" michael@0: michael@0: #include "imgLoader.h" michael@0: #include "imgRequest.h" michael@0: #include "imgRequestProxy.h" michael@0: #include "imgTools.h" michael@0: #include "DiscardTracker.h" michael@0: michael@0: #include "nsICOEncoder.h" michael@0: #include "nsPNGEncoder.h" michael@0: #include "nsJPEGEncoder.h" michael@0: #include "nsBMPEncoder.h" michael@0: michael@0: // objects that just require generic constructors michael@0: using namespace mozilla::image; michael@0: michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(imgLoader, Init) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(imgTools) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsICOEncoder) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGEncoder) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGEncoder) michael@0: NS_GENERIC_FACTORY_CONSTRUCTOR(nsBMPEncoder) michael@0: NS_DEFINE_NAMED_CID(NS_IMGLOADER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_IMGREQUESTPROXY_CID); michael@0: NS_DEFINE_NAMED_CID(NS_IMGTOOLS_CID); michael@0: NS_DEFINE_NAMED_CID(NS_ICOENCODER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_JPEGENCODER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_PNGENCODER_CID); michael@0: NS_DEFINE_NAMED_CID(NS_BMPENCODER_CID); michael@0: michael@0: static const mozilla::Module::CIDEntry kImageCIDs[] = { michael@0: { &kNS_IMGLOADER_CID, false, nullptr, imgLoaderConstructor, }, michael@0: { &kNS_IMGREQUESTPROXY_CID, false, nullptr, imgRequestProxyConstructor, }, michael@0: { &kNS_IMGTOOLS_CID, false, nullptr, imgToolsConstructor, }, michael@0: { &kNS_ICOENCODER_CID, false, nullptr, nsICOEncoderConstructor, }, michael@0: { &kNS_JPEGENCODER_CID, false, nullptr, nsJPEGEncoderConstructor, }, michael@0: { &kNS_PNGENCODER_CID, false, nullptr, nsPNGEncoderConstructor, }, michael@0: { &kNS_BMPENCODER_CID, false, nullptr, nsBMPEncoderConstructor, }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::ContractIDEntry kImageContracts[] = { michael@0: { "@mozilla.org/image/cache;1", &kNS_IMGLOADER_CID }, michael@0: { "@mozilla.org/image/loader;1", &kNS_IMGLOADER_CID }, michael@0: { "@mozilla.org/image/request;1", &kNS_IMGREQUESTPROXY_CID }, michael@0: { "@mozilla.org/image/tools;1", &kNS_IMGTOOLS_CID }, michael@0: { "@mozilla.org/image/encoder;2?type=" IMAGE_ICO_MS, &kNS_ICOENCODER_CID }, michael@0: { "@mozilla.org/image/encoder;2?type=" IMAGE_JPEG, &kNS_JPEGENCODER_CID }, michael@0: { "@mozilla.org/image/encoder;2?type=" IMAGE_PNG, &kNS_PNGENCODER_CID }, michael@0: { "@mozilla.org/image/encoder;2?type=" IMAGE_BMP, &kNS_BMPENCODER_CID }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static const mozilla::Module::CategoryEntry kImageCategories[] = { michael@0: { "Gecko-Content-Viewers", IMAGE_GIF, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_JPEG, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_PJPEG, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_JPG, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_ICO, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_ICO_MS, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_BMP, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_BMP_MS, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_ICON_MS, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_PNG, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "Gecko-Content-Viewers", IMAGE_X_PNG, "@mozilla.org/content/document-loader-factory;1" }, michael@0: { "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" }, michael@0: { nullptr } michael@0: }; michael@0: michael@0: static bool sInitialized = false; michael@0: nsresult michael@0: mozilla::image::InitModule() michael@0: { michael@0: mozilla::image::DiscardTracker::Initialize(); michael@0: mozilla::image::ImageFactory::Initialize(); michael@0: mozilla::image::RasterImage::Initialize(); michael@0: mozilla::image::SurfaceCache::Initialize(); michael@0: imgLoader::GlobalInit(); michael@0: sInitialized = true; michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: mozilla::image::ShutdownModule() michael@0: { michael@0: if (!sInitialized) { michael@0: return; michael@0: } michael@0: imgLoader::Shutdown(); michael@0: mozilla::image::SurfaceCache::Shutdown(); michael@0: mozilla::image::DiscardTracker::Shutdown(); michael@0: sInitialized = false; michael@0: } michael@0: michael@0: static const mozilla::Module kImageModule = { michael@0: mozilla::Module::kVersion, michael@0: kImageCIDs, michael@0: kImageContracts, michael@0: kImageCategories, michael@0: nullptr, michael@0: mozilla::image::InitModule, michael@0: // We need to be careful about shutdown ordering to avoid intermittent crashes michael@0: // when hashtable enumeration decides to destroy modules in an unfortunate michael@0: // order. So our shutdown is invoked explicitly during layout module shutdown. michael@0: nullptr michael@0: }; michael@0: michael@0: NSMODULE_DEFN(nsImageLib2Module) = &kImageModule;