2002-09-12 09:07:28 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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 09:07:28 +04:00
|
|
|
|
2014-04-09 02:51:34 +04:00
|
|
|
#include "nsImageModule.h"
|
|
|
|
|
2010-06-10 22:11:40 +04:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2020-05-27 21:51:25 +03:00
|
|
|
#include "mozilla/StaticPrefs_image.h"
|
2002-09-12 09:07:28 +04:00
|
|
|
|
2015-01-18 12:27:16 +03:00
|
|
|
#include "DecodePool.h"
|
2013-09-28 22:28:42 +04:00
|
|
|
#include "ImageFactory.h"
|
2020-05-27 21:51:25 +03:00
|
|
|
#include "nsICategoryManager.h"
|
2014-09-24 02:32:16 +04:00
|
|
|
#include "ShutdownTracker.h"
|
2013-10-22 15:37:59 +04:00
|
|
|
#include "SurfaceCache.h"
|
2002-09-12 09:07:28 +04:00
|
|
|
#include "imgLoader.h"
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
using namespace mozilla::image;
|
2002-09-12 09:07:28 +04:00
|
|
|
|
2020-05-27 21:51:25 +03:00
|
|
|
struct ImageEnablementCookie {
|
|
|
|
bool (*mIsEnabled)();
|
|
|
|
const nsLiteralCString mMimeType;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void UpdateContentViewerRegistration(const char* aPref, void* aData) {
|
|
|
|
auto* cookie = static_cast<ImageEnablementCookie*>(aData);
|
|
|
|
|
|
|
|
nsCOMPtr<nsICategoryManager> catMan =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
|
|
|
|
if (!catMan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-01 11:29:29 +03:00
|
|
|
static nsLiteralCString kCategory = "Gecko-Content-Viewers"_ns;
|
|
|
|
static nsLiteralCString kContractId =
|
|
|
|
"@mozilla.org/content/plugin/document-loader-factory;1"_ns;
|
2020-05-27 21:51:25 +03:00
|
|
|
|
|
|
|
if (cookie->mIsEnabled()) {
|
|
|
|
catMan->AddCategoryEntry(kCategory, cookie->mMimeType, kContractId,
|
|
|
|
false /* aPersist */, true /* aReplace */);
|
|
|
|
} else {
|
|
|
|
catMan->DeleteCategoryEntry(
|
|
|
|
kCategory, cookie->mMimeType, false /* aPersist */
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 02:51:34 +04:00
|
|
|
static bool sInitialized = false;
|
2016-05-19 15:31:15 +03:00
|
|
|
nsresult mozilla::image::EnsureModuleInitialized() {
|
2014-09-23 01:30:20 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-05-19 15:31:15 +03:00
|
|
|
|
|
|
|
if (sInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:51:25 +03:00
|
|
|
static ImageEnablementCookie kAVIFCookie = {
|
2020-07-01 11:29:29 +03:00
|
|
|
mozilla::StaticPrefs::image_avif_enabled, "image/avif"_ns};
|
2020-05-28 05:43:40 +03:00
|
|
|
static ImageEnablementCookie kWebPCookie = {
|
2020-07-01 11:29:29 +03:00
|
|
|
mozilla::StaticPrefs::image_webp_enabled, "image/webp"_ns};
|
2020-05-27 21:51:25 +03:00
|
|
|
Preferences::RegisterCallbackAndCall(UpdateContentViewerRegistration,
|
|
|
|
"image.avif.enabled", &kAVIFCookie);
|
2020-05-28 05:43:40 +03:00
|
|
|
Preferences::RegisterCallbackAndCall(UpdateContentViewerRegistration,
|
|
|
|
"image.webp.enabled", &kWebPCookie);
|
2020-05-27 21:51:25 +03:00
|
|
|
|
2014-09-24 02:32:16 +04:00
|
|
|
mozilla::image::ShutdownTracker::Initialize();
|
2013-09-28 22:28:42 +04:00
|
|
|
mozilla::image::ImageFactory::Initialize();
|
2015-01-18 12:27:16 +03:00
|
|
|
mozilla::image::DecodePool::Initialize();
|
2013-10-22 15:37:59 +04:00
|
|
|
mozilla::image::SurfaceCache::Initialize();
|
2012-06-26 08:20:12 +04:00
|
|
|
imgLoader::GlobalInit();
|
2014-04-09 02:51:34 +04:00
|
|
|
sInitialized = true;
|
2002-09-12 09:07:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-09 02:51:34 +04:00
|
|
|
void mozilla::image::ShutdownModule() {
|
|
|
|
if (!sInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
2008-09-05 03:00:42 +04:00
|
|
|
imgLoader::Shutdown();
|
2013-10-22 15:37:59 +04:00
|
|
|
mozilla::image::SurfaceCache::Shutdown();
|
2014-04-09 02:51:34 +04:00
|
|
|
sInitialized = false;
|
2002-09-12 09:07:28 +04:00
|
|
|
}
|