Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #include "nsImageModule.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/ModuleUtils.h" |
michael@0 | 10 | #include "nsMimeTypes.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "ImageFactory.h" |
michael@0 | 13 | #include "RasterImage.h" |
michael@0 | 14 | #include "SurfaceCache.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "imgLoader.h" |
michael@0 | 17 | #include "imgRequest.h" |
michael@0 | 18 | #include "imgRequestProxy.h" |
michael@0 | 19 | #include "imgTools.h" |
michael@0 | 20 | #include "DiscardTracker.h" |
michael@0 | 21 | |
michael@0 | 22 | #include "nsICOEncoder.h" |
michael@0 | 23 | #include "nsPNGEncoder.h" |
michael@0 | 24 | #include "nsJPEGEncoder.h" |
michael@0 | 25 | #include "nsBMPEncoder.h" |
michael@0 | 26 | |
michael@0 | 27 | // objects that just require generic constructors |
michael@0 | 28 | using namespace mozilla::image; |
michael@0 | 29 | |
michael@0 | 30 | NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(imgLoader, Init) |
michael@0 | 31 | NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy) |
michael@0 | 32 | NS_GENERIC_FACTORY_CONSTRUCTOR(imgTools) |
michael@0 | 33 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsICOEncoder) |
michael@0 | 34 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGEncoder) |
michael@0 | 35 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGEncoder) |
michael@0 | 36 | NS_GENERIC_FACTORY_CONSTRUCTOR(nsBMPEncoder) |
michael@0 | 37 | NS_DEFINE_NAMED_CID(NS_IMGLOADER_CID); |
michael@0 | 38 | NS_DEFINE_NAMED_CID(NS_IMGREQUESTPROXY_CID); |
michael@0 | 39 | NS_DEFINE_NAMED_CID(NS_IMGTOOLS_CID); |
michael@0 | 40 | NS_DEFINE_NAMED_CID(NS_ICOENCODER_CID); |
michael@0 | 41 | NS_DEFINE_NAMED_CID(NS_JPEGENCODER_CID); |
michael@0 | 42 | NS_DEFINE_NAMED_CID(NS_PNGENCODER_CID); |
michael@0 | 43 | NS_DEFINE_NAMED_CID(NS_BMPENCODER_CID); |
michael@0 | 44 | |
michael@0 | 45 | static const mozilla::Module::CIDEntry kImageCIDs[] = { |
michael@0 | 46 | { &kNS_IMGLOADER_CID, false, nullptr, imgLoaderConstructor, }, |
michael@0 | 47 | { &kNS_IMGREQUESTPROXY_CID, false, nullptr, imgRequestProxyConstructor, }, |
michael@0 | 48 | { &kNS_IMGTOOLS_CID, false, nullptr, imgToolsConstructor, }, |
michael@0 | 49 | { &kNS_ICOENCODER_CID, false, nullptr, nsICOEncoderConstructor, }, |
michael@0 | 50 | { &kNS_JPEGENCODER_CID, false, nullptr, nsJPEGEncoderConstructor, }, |
michael@0 | 51 | { &kNS_PNGENCODER_CID, false, nullptr, nsPNGEncoderConstructor, }, |
michael@0 | 52 | { &kNS_BMPENCODER_CID, false, nullptr, nsBMPEncoderConstructor, }, |
michael@0 | 53 | { nullptr } |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | static const mozilla::Module::ContractIDEntry kImageContracts[] = { |
michael@0 | 57 | { "@mozilla.org/image/cache;1", &kNS_IMGLOADER_CID }, |
michael@0 | 58 | { "@mozilla.org/image/loader;1", &kNS_IMGLOADER_CID }, |
michael@0 | 59 | { "@mozilla.org/image/request;1", &kNS_IMGREQUESTPROXY_CID }, |
michael@0 | 60 | { "@mozilla.org/image/tools;1", &kNS_IMGTOOLS_CID }, |
michael@0 | 61 | { "@mozilla.org/image/encoder;2?type=" IMAGE_ICO_MS, &kNS_ICOENCODER_CID }, |
michael@0 | 62 | { "@mozilla.org/image/encoder;2?type=" IMAGE_JPEG, &kNS_JPEGENCODER_CID }, |
michael@0 | 63 | { "@mozilla.org/image/encoder;2?type=" IMAGE_PNG, &kNS_PNGENCODER_CID }, |
michael@0 | 64 | { "@mozilla.org/image/encoder;2?type=" IMAGE_BMP, &kNS_BMPENCODER_CID }, |
michael@0 | 65 | { nullptr } |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | static const mozilla::Module::CategoryEntry kImageCategories[] = { |
michael@0 | 69 | { "Gecko-Content-Viewers", IMAGE_GIF, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 70 | { "Gecko-Content-Viewers", IMAGE_JPEG, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 71 | { "Gecko-Content-Viewers", IMAGE_PJPEG, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 72 | { "Gecko-Content-Viewers", IMAGE_JPG, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 73 | { "Gecko-Content-Viewers", IMAGE_ICO, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 74 | { "Gecko-Content-Viewers", IMAGE_ICO_MS, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 75 | { "Gecko-Content-Viewers", IMAGE_BMP, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 76 | { "Gecko-Content-Viewers", IMAGE_BMP_MS, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 77 | { "Gecko-Content-Viewers", IMAGE_ICON_MS, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 78 | { "Gecko-Content-Viewers", IMAGE_PNG, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 79 | { "Gecko-Content-Viewers", IMAGE_X_PNG, "@mozilla.org/content/document-loader-factory;1" }, |
michael@0 | 80 | { "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" }, |
michael@0 | 81 | { nullptr } |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | static bool sInitialized = false; |
michael@0 | 85 | nsresult |
michael@0 | 86 | mozilla::image::InitModule() |
michael@0 | 87 | { |
michael@0 | 88 | mozilla::image::DiscardTracker::Initialize(); |
michael@0 | 89 | mozilla::image::ImageFactory::Initialize(); |
michael@0 | 90 | mozilla::image::RasterImage::Initialize(); |
michael@0 | 91 | mozilla::image::SurfaceCache::Initialize(); |
michael@0 | 92 | imgLoader::GlobalInit(); |
michael@0 | 93 | sInitialized = true; |
michael@0 | 94 | return NS_OK; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | void |
michael@0 | 98 | mozilla::image::ShutdownModule() |
michael@0 | 99 | { |
michael@0 | 100 | if (!sInitialized) { |
michael@0 | 101 | return; |
michael@0 | 102 | } |
michael@0 | 103 | imgLoader::Shutdown(); |
michael@0 | 104 | mozilla::image::SurfaceCache::Shutdown(); |
michael@0 | 105 | mozilla::image::DiscardTracker::Shutdown(); |
michael@0 | 106 | sInitialized = false; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | static const mozilla::Module kImageModule = { |
michael@0 | 110 | mozilla::Module::kVersion, |
michael@0 | 111 | kImageCIDs, |
michael@0 | 112 | kImageContracts, |
michael@0 | 113 | kImageCategories, |
michael@0 | 114 | nullptr, |
michael@0 | 115 | mozilla::image::InitModule, |
michael@0 | 116 | // We need to be careful about shutdown ordering to avoid intermittent crashes |
michael@0 | 117 | // when hashtable enumeration decides to destroy modules in an unfortunate |
michael@0 | 118 | // order. So our shutdown is invoked explicitly during layout module shutdown. |
michael@0 | 119 | nullptr |
michael@0 | 120 | }; |
michael@0 | 121 | |
michael@0 | 122 | NSMODULE_DEFN(nsImageLib2Module) = &kImageModule; |