summaryrefslogtreecommitdiffstats
path: root/image/build
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /image/build
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'image/build')
-rw-r--r--image/build/components.conf85
-rw-r--r--image/build/moz.build26
-rw-r--r--image/build/nsImageModule.cpp88
-rw-r--r--image/build/nsImageModule.h20
4 files changed, 219 insertions, 0 deletions
diff --git a/image/build/components.conf b/image/build/components.conf
new file mode 100644
index 0000000000..182d1cd1af
--- /dev/null
+++ b/image/build/components.conf
@@ -0,0 +1,85 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Headers = [
+ '/image/build/nsImageModule.h',
+]
+
+InitFunc = 'mozilla::image::EnsureModuleInitialized'
+# This is called by LayoutModuleDtor to ensure it happens at the right time
+# during shutdown.
+# UnloadFunc = 'mozilla::image::ShutdownModule'
+
+Classes = [
+ # XXX We would like to get rid of the imgLoader factory constructor. See the
+ # comment documenting the imgLoader constructor.
+ {
+ 'cid': '{c1354898-e3fe-4602-88a7-c4520c21cb4e}',
+ 'contract_ids': [
+ '@mozilla.org/image/cache;1',
+ '@mozilla.org/image/loader;1',
+ ],
+ 'type': 'imgLoader',
+ 'headers': ['imgLoader.h'],
+ 'init_method': 'Init',
+ 'categories': {
+ 'content-sniffing-services': '@mozilla.org/image/loader;1',
+ 'orb-content-sniffers': '@mozilla.org/image/loader;1',
+ 'net-and-orb-content-sniffers': '@mozilla.org/image/loader;1',
+ },
+ },
+ {
+ 'cid': '{f6fcd651-164b-4416-b001-9c8c393fd93b}',
+ 'contract_ids': [
+ '@mozilla.org/image-blocker-content-policy;1',
+ ],
+ 'type': 'mozilla::image::ImageBlocker',
+ 'headers': ['ImageBlocker.h'],
+ 'categories': {'content-policy': '@mozilla.org/image-blocker-content-policy;1'},
+ },
+ {
+ 'cid': '{20557898-1dd2-11b2-8f65-9c462ee2bc95}',
+ 'contract_ids': ['@mozilla.org/image/request;1'],
+ 'type': 'imgRequestProxy',
+ 'headers': ['imgRequestProxy.h'],
+ },
+ {
+ 'cid': '{3d8fa16d-c9e1-4b50-bdef-2c7ae249967a}',
+ 'contract_ids': ['@mozilla.org/image/tools;1'],
+ 'type': 'mozilla::image::imgTools',
+ 'headers': ['/image/imgTools.h'],
+ },
+ {
+ 'cid': '{13a5320c-4c91-4fa4-bd16-b081a3ba8c0b}',
+ 'contract_ids': ['@mozilla.org/image/encoder;2?type=image/bmp'],
+ 'type': 'nsBMPEncoder',
+ 'headers': ['/image/encoders/bmp/nsBMPEncoder.h'],
+ },
+ {
+ 'cid': '{92ae3ab2-8968-41b1-8709-b6123bceaf21}',
+ 'contract_ids': ['@mozilla.org/image/encoder;2?type=image/vnd.microsoft.icon'],
+ 'type': 'nsICOEncoder',
+ 'headers': ['/image/encoders/ico/nsICOEncoder.h'],
+ },
+ {
+ 'cid': '{ac2bb8fe-eeeb-4572-b40f-be03932b56e0}',
+ 'contract_ids': ['@mozilla.org/image/encoder;2?type=image/jpeg'],
+ 'type': 'nsJPEGEncoder',
+ 'headers': ['/image/encoders/jpeg/nsJPEGEncoder.h'],
+ },
+ {
+ 'cid': '{38d1592e-b81e-432b-86f8-471878bbfe07}',
+ 'contract_ids': ['@mozilla.org/image/encoder;2?type=image/png'],
+ 'type': 'nsPNGEncoder',
+ 'headers': ['/image/encoders/png/nsPNGEncoder.h'],
+ },
+ {
+ 'cid': '{a8e5a8e5-bebf-4512-9f50-e41e4748ce28}',
+ 'contract_ids': ['@mozilla.org/image/encoder;2?type=image/webp'],
+ 'type': 'nsWebPEncoder',
+ 'headers': ['/image/encoders/webp/nsWebPEncoder.h'],
+ },
+]
diff --git a/image/build/moz.build b/image/build/moz.build
new file mode 100644
index 0000000000..7ba10e42b9
--- /dev/null
+++ b/image/build/moz.build
@@ -0,0 +1,26 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+EXPORTS += [
+ "nsImageModule.h",
+]
+
+SOURCES += [
+ "nsImageModule.cpp",
+]
+
+XPCOM_MANIFESTS += [
+ "components.conf",
+]
+
+FINAL_LIBRARY = "xul"
+LOCAL_INCLUDES += [
+ "/image",
+ "/image/encoders/bmp",
+ "/image/encoders/ico",
+ "/image/encoders/jpeg",
+ "/image/encoders/png",
+]
diff --git a/image/build/nsImageModule.cpp b/image/build/nsImageModule.cpp
new file mode 100644
index 0000000000..28fb8bb330
--- /dev/null
+++ b/image/build/nsImageModule.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * 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/. */
+
+#include "nsImageModule.h"
+
+#include "mozilla/ModuleUtils.h"
+#include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs_image.h"
+
+#include "DecodePool.h"
+#include "ImageFactory.h"
+#include "nsICategoryManager.h"
+#include "nsServiceManagerUtils.h"
+#include "ShutdownTracker.h"
+#include "SurfaceCache.h"
+#include "imgLoader.h"
+
+using namespace mozilla::image;
+
+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;
+ }
+
+ static nsLiteralCString kCategory = "Gecko-Content-Viewers"_ns;
+ static nsLiteralCString kContractId =
+ "@mozilla.org/content/plugin/document-loader-factory;1"_ns;
+
+ if (cookie->mIsEnabled()) {
+ catMan->AddCategoryEntry(kCategory, cookie->mMimeType, kContractId,
+ false /* aPersist */, true /* aReplace */);
+ } else {
+ catMan->DeleteCategoryEntry(
+ kCategory, cookie->mMimeType, false /* aPersist */
+ );
+ }
+}
+
+static bool sInitialized = false;
+nsresult mozilla::image::EnsureModuleInitialized() {
+ MOZ_ASSERT(NS_IsMainThread());
+
+ if (sInitialized) {
+ return NS_OK;
+ }
+
+ static ImageEnablementCookie kAVIFCookie = {
+ mozilla::StaticPrefs::image_avif_enabled, "image/avif"_ns};
+ static ImageEnablementCookie kJXLCookie = {
+ mozilla::StaticPrefs::image_jxl_enabled, "image/jxl"_ns};
+ static ImageEnablementCookie kWebPCookie = {
+ mozilla::StaticPrefs::image_webp_enabled, "image/webp"_ns};
+ Preferences::RegisterCallbackAndCall(UpdateContentViewerRegistration,
+ "image.avif.enabled", &kAVIFCookie);
+ Preferences::RegisterCallbackAndCall(UpdateContentViewerRegistration,
+ "image.jxl.enabled", &kJXLCookie);
+ Preferences::RegisterCallbackAndCall(UpdateContentViewerRegistration,
+ "image.webp.enabled", &kWebPCookie);
+
+ mozilla::image::ShutdownTracker::Initialize();
+ mozilla::image::ImageFactory::Initialize();
+ mozilla::image::DecodePool::Initialize();
+ mozilla::image::SurfaceCache::Initialize();
+ imgLoader::GlobalInit();
+ sInitialized = true;
+ return NS_OK;
+}
+
+void mozilla::image::ShutdownModule() {
+ if (!sInitialized) {
+ return;
+ }
+ imgLoader::Shutdown();
+ mozilla::image::SurfaceCache::Shutdown();
+ sInitialized = false;
+}
diff --git a/image/build/nsImageModule.h b/image/build/nsImageModule.h
new file mode 100644
index 0000000000..130e59b868
--- /dev/null
+++ b/image/build/nsImageModule.h
@@ -0,0 +1,20 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef mozilla_image_build_nsImageModule_h
+#define mozilla_image_build_nsImageModule_h
+
+#include "nsError.h"
+
+namespace mozilla {
+namespace image {
+
+nsresult EnsureModuleInitialized();
+void ShutdownModule();
+
+} /* namespace image */
+} /* namespace mozilla */
+
+#endif // mozilla_image_build_nsImageModule_h