2002-09-12 05:07:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2014-04-08 22:51:34 +00:00
|
|
|
#include "nsImageModule.h"
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2013-01-08 21:40:47 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2015-01-18 09:27:16 +00:00
|
|
|
#include "DecodePool.h"
|
2013-09-28 18:28:42 +00:00
|
|
|
#include "ImageFactory.h"
|
2014-09-23 22:32:16 +00:00
|
|
|
#include "ShutdownTracker.h"
|
2013-10-22 11:37:59 +00:00
|
|
|
#include "SurfaceCache.h"
|
2010-07-28 21:51:37 +00:00
|
|
|
|
2014-09-22 21:30:20 +00:00
|
|
|
#include "gfxPrefs.h"
|
2002-09-12 05:07:28 +00:00
|
|
|
#include "imgLoader.h"
|
|
|
|
#include "imgRequest.h"
|
|
|
|
#include "imgRequestProxy.h"
|
2008-01-13 04:15:20 +00:00
|
|
|
#include "imgTools.h"
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2011-08-25 20:09:05 +00:00
|
|
|
#include "nsICOEncoder.h"
|
2005-08-31 22:15:33 +00:00
|
|
|
#include "nsPNGEncoder.h"
|
2005-11-15 18:10:08 +00:00
|
|
|
#include "nsJPEGEncoder.h"
|
2011-08-25 20:09:05 +00:00
|
|
|
#include "nsBMPEncoder.h"
|
2005-08-31 22:15:33 +00:00
|
|
|
|
2002-09-12 05:07:28 +00:00
|
|
|
// objects that just require generic constructors
|
2012-01-06 16:02:27 +00:00
|
|
|
using namespace mozilla::image;
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2009-07-15 07:22:40 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(imgLoader, Init)
|
2002-09-12 05:07:28 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(imgRequestProxy)
|
2008-01-13 04:15:20 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(imgTools)
|
2011-08-25 20:09:05 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsICOEncoder)
|
2005-11-15 18:10:08 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsJPEGEncoder)
|
2005-08-31 22:15:33 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPNGEncoder)
|
2011-08-25 20:09:05 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBMPEncoder)
|
2010-06-10 18:11:40 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_IMGLOADER_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_IMGREQUESTPROXY_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_IMGTOOLS_CID);
|
2011-08-25 20:09:05 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_ICOENCODER_CID);
|
2010-06-10 18:11:40 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_JPEGENCODER_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_PNGENCODER_CID);
|
2011-08-25 20:09:05 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_BMPENCODER_CID);
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module::CIDEntry kImageCIDs[] = {
|
2013-08-23 19:51:00 +00:00
|
|
|
{ &kNS_IMGLOADER_CID, false, nullptr, imgLoaderConstructor, },
|
|
|
|
{ &kNS_IMGREQUESTPROXY_CID, false, nullptr, imgRequestProxyConstructor, },
|
|
|
|
{ &kNS_IMGTOOLS_CID, false, nullptr, imgToolsConstructor, },
|
|
|
|
{ &kNS_ICOENCODER_CID, false, nullptr, nsICOEncoderConstructor, },
|
|
|
|
{ &kNS_JPEGENCODER_CID, false, nullptr, nsJPEGEncoderConstructor, },
|
|
|
|
{ &kNS_PNGENCODER_CID, false, nullptr, nsPNGEncoderConstructor, },
|
|
|
|
{ &kNS_BMPENCODER_CID, false, nullptr, nsBMPEncoderConstructor, },
|
|
|
|
{ nullptr }
|
2010-06-10 18:11:40 +00:00
|
|
|
};
|
2003-01-10 01:21:14 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module::ContractIDEntry kImageContracts[] = {
|
|
|
|
{ "@mozilla.org/image/cache;1", &kNS_IMGLOADER_CID },
|
|
|
|
{ "@mozilla.org/image/loader;1", &kNS_IMGLOADER_CID },
|
|
|
|
{ "@mozilla.org/image/request;1", &kNS_IMGREQUESTPROXY_CID },
|
|
|
|
{ "@mozilla.org/image/tools;1", &kNS_IMGTOOLS_CID },
|
2013-01-08 21:40:47 +00:00
|
|
|
{ "@mozilla.org/image/encoder;2?type=" IMAGE_ICO_MS, &kNS_ICOENCODER_CID },
|
|
|
|
{ "@mozilla.org/image/encoder;2?type=" IMAGE_JPEG, &kNS_JPEGENCODER_CID },
|
|
|
|
{ "@mozilla.org/image/encoder;2?type=" IMAGE_PNG, &kNS_PNGENCODER_CID },
|
|
|
|
{ "@mozilla.org/image/encoder;2?type=" IMAGE_BMP, &kNS_BMPENCODER_CID },
|
2013-08-23 19:51:00 +00:00
|
|
|
{ nullptr }
|
2010-06-10 18:11:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const mozilla::Module::CategoryEntry kImageCategories[] = {
|
2013-01-08 21:40:47 +00:00
|
|
|
{ "Gecko-Content-Viewers", IMAGE_GIF, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_JPEG, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_PJPEG, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_JPG, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_ICO, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_ICO_MS, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_BMP, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_BMP_MS, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_ICON_MS, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_PNG, "@mozilla.org/content/document-loader-factory;1" },
|
|
|
|
{ "Gecko-Content-Viewers", IMAGE_X_PNG, "@mozilla.org/content/document-loader-factory;1" },
|
2010-06-10 18:11:40 +00:00
|
|
|
{ "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" },
|
2013-08-23 19:51:00 +00:00
|
|
|
{ nullptr }
|
2002-09-12 05:07:28 +00:00
|
|
|
};
|
|
|
|
|
2014-04-08 22:51:34 +00:00
|
|
|
static bool sInitialized = false;
|
|
|
|
nsresult
|
|
|
|
mozilla::image::InitModule()
|
2002-09-12 05:07:28 +00:00
|
|
|
{
|
2014-09-22 21:30:20 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Make sure the preferences are initialized
|
|
|
|
gfxPrefs::GetSingleton();
|
|
|
|
|
2014-09-23 22:32:16 +00:00
|
|
|
mozilla::image::ShutdownTracker::Initialize();
|
2013-09-28 18:28:42 +00:00
|
|
|
mozilla::image::ImageFactory::Initialize();
|
2015-01-18 09:27:16 +00:00
|
|
|
mozilla::image::DecodePool::Initialize();
|
2013-10-22 11:37:59 +00:00
|
|
|
mozilla::image::SurfaceCache::Initialize();
|
2012-06-26 04:20:12 +00:00
|
|
|
imgLoader::GlobalInit();
|
2014-04-08 22:51:34 +00:00
|
|
|
sInitialized = true;
|
2002-09-12 05:07:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-08 22:51:34 +00:00
|
|
|
void
|
|
|
|
mozilla::image::ShutdownModule()
|
2002-09-12 05:07:28 +00:00
|
|
|
{
|
2014-04-08 22:51:34 +00:00
|
|
|
if (!sInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-04 23:00:42 +00:00
|
|
|
imgLoader::Shutdown();
|
2013-10-22 11:37:59 +00:00
|
|
|
mozilla::image::SurfaceCache::Shutdown();
|
2014-04-08 22:51:34 +00:00
|
|
|
sInitialized = false;
|
2002-09-12 05:07:28 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module kImageModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kImageCIDs,
|
|
|
|
kImageContracts,
|
|
|
|
kImageCategories,
|
2013-08-23 19:51:00 +00:00
|
|
|
nullptr,
|
2014-04-08 22:51:34 +00:00
|
|
|
mozilla::image::InitModule,
|
|
|
|
// We need to be careful about shutdown ordering to avoid intermittent crashes
|
|
|
|
// when hashtable enumeration decides to destroy modules in an unfortunate
|
|
|
|
// order. So our shutdown is invoked explicitly during layout module shutdown.
|
|
|
|
nullptr
|
2010-06-10 18:11:40 +00:00
|
|
|
};
|
2002-09-12 05:07:28 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
NSMODULE_DEFN(nsImageLib2Module) = &kImageModule;
|