From 630d19190596d993c993548abaa18855a502b258 Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Wed, 6 Feb 2019 06:54:39 -0800 Subject: [PATCH] #501: basic support (doesn't work yet, doesn't crash) from M1294490 --- browser/components/BrowserComponents.manifest | 1 + config/Makefile.in | 1 + config/config.mk | 1 + config/external/moz.build | 3 + configure.in | 90 +++++++++++++++++++ image/DecoderFactory.cpp | 8 ++ image/DecoderFactory.h | 1 + image/build/nsImageModule.cpp | 1 + image/decoders/moz.build | 1 + image/imgLoader.cpp | 5 ++ netwerk/mime/nsMimeTypes.h | 1 + toolkit/library/moz.build | 3 + .../exthandler/nsExternalHelperAppService.cpp | 4 + 13 files changed, 120 insertions(+) diff --git a/browser/components/BrowserComponents.manifest b/browser/components/BrowserComponents.manifest index 0fffa476e2..0ddd91ebe5 100644 --- a/browser/components/BrowserComponents.manifest +++ b/browser/components/BrowserComponents.manifest @@ -15,6 +15,7 @@ contract @mozilla.org/uriloader/content-handler;1?type=image/gif {5d0ce354-df01- contract @mozilla.org/uriloader/content-handler;1?type=image/jpeg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} contract @mozilla.org/uriloader/content-handler;1?type=image/jpg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} contract @mozilla.org/uriloader/content-handler;1?type=image/png {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} +contract @mozilla.org/uriloader/content-handler;1?type=image/webp {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} contract @mozilla.org/uriloader/content-handler;1?type=image/bmp {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} contract @mozilla.org/uriloader/content-handler;1?type=image/x-icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} contract @mozilla.org/uriloader/content-handler;1?type=image/vnd.microsoft.icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} diff --git a/config/Makefile.in b/config/Makefile.in index c08f2a76da..4f5d1430c9 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -72,6 +72,7 @@ export:: $(export-preqs) -DMOZ_NATIVE_JPEG=$(MOZ_NATIVE_JPEG) \ -DMOZ_NATIVE_LIBEVENT=$(MOZ_NATIVE_LIBEVENT) \ -DMOZ_NATIVE_LIBVPX=$(MOZ_NATIVE_LIBVPX) \ + -DMOZ_NATIVE_LIBWEBP=$(MOZ_NATIVE_LIBWEBP) \ -DMOZ_NATIVE_ICU=$(MOZ_NATIVE_ICU) \ $(srcdir)/system-headers | $(PERL) $(topsrcdir)/nsprpub/config/make-system-wrappers.pl system_wrappers $(INSTALL) system_wrappers $(DIST) diff --git a/config/config.mk b/config/config.mk index d0de93df2b..bd680b029c 100644 --- a/config/config.mk +++ b/config/config.mk @@ -301,6 +301,7 @@ OS_INCLUDES := \ $(NSPR_CFLAGS) $(NSS_CFLAGS) \ $(MOZ_JPEG_CFLAGS) \ $(MOZ_PNG_CFLAGS) \ + $(MOZ_WEBP_CFLAGS) \ $(MOZ_ZLIB_CFLAGS) \ $(MOZ_PIXMAN_CFLAGS) \ $(NULL) diff --git a/config/external/moz.build b/config/external/moz.build index f524d82ac1..3bc60a1a53 100644 --- a/config/external/moz.build +++ b/config/external/moz.build @@ -36,6 +36,9 @@ if CONFIG['MOZ_WEBM_ENCODER']: if CONFIG['MOZ_VPX'] and not CONFIG['MOZ_NATIVE_LIBVPX']: external_dirs += ['media/libvpx'] +if CONFIG['MOZ_WEBP'] and not CONFIG['MOZ_NATIVE_WEBP']: + external_dirs += ['media/libwebp'] + if not CONFIG['MOZ_NATIVE_PNG']: external_dirs += ['media/libpng'] diff --git a/configure.in b/configure.in index 70f4e4b875..0dde5d2a0b 100644 --- a/configure.in +++ b/configure.in @@ -52,6 +52,7 @@ dnl Set the version number of the libs included with mozilla dnl ======================================================== MOZJPEG=62 MOZPNG=10619 +MOZWEBP=0x201 NSPR_VERSION=4 NSPR_MINVER=4.12 NSS_VERSION=3 @@ -3667,6 +3668,82 @@ fi # SKIP_LIBRARY_CHECKS AC_SUBST(MOZ_PNG_ARM_NEON) +dnl ======================================================== +dnl system WEBP Support +dnl ======================================================== +MOZ_ARG_WITH_STRING(system-webp, +[ --with-system-webp[=PFX] + Use system libwebp [installed at prefix PFX]], + WEBP_DIR=$withval) + +_SAVE_CFLAGS=$CFLAGS +_SAVE_LDFLAGS=$LDFLAGS +_SAVE_LIBS=$LIBS +if test -n "${WEBP_DIR}" -a "${WEBP_DIR}" != "yes"; then + CFLAGS="-I${WEBP_DIR}/include $CFLAGS" + LDFLAGS="-L${WEBP_DIR}/lib $LDFLAGS" +fi +if test -z "$WEBP_DIR" -o "$WEBP_DIR" = no; then + MOZ_NATIVE_WEBP= +else + AC_CHECK_LIB(webp, WebPGetDecoderVersion, [MOZ_NATIVE_WEBP=1 MOZ_WEBP_LIBS="-lwebp"], + [MOZ_NATIVE_WEBP= MOZ_WEBP_CFLAGS= MOZ_WEBP_LIBS=]) +fi +if test "$MOZ_NATIVE_WEBP" = 1; then + AC_TRY_COMPILE([ #include ], + [ #if WEBP_DECODER_ABI_VERSION < $MOZWEBP + #error "Insufficient libwebp decoder version ($MOZWEBP required)." + #endif ], + MOZ_NATIVE_WEBP=1, + AC_MSG_ERROR([--with-system-webp requested but no working libwebp found])) +fi +CFLAGS=$_SAVE_CFLAGS +LDFLAGS=$_SAVE_LDFLAGS +LIBS=$_SAVE_LIBS + +if test "${WEBP_DIR}" -a -d "${WEBP_DIR}" -a "$MOZ_NATIVE_WEBP" = 1; then + MOZ_WEBP_CFLAGS="-I${WEBP_DIR}/include" + MOZ_WEBP_LIBS="-L${WEBP_DIR}/lib ${MOZ_WEBP_LIBS}" +fi + +dnl ======================================================== +dnl system WEBP Support +dnl ======================================================== +MOZ_ARG_WITH_STRING(system-webp, +[ --with-system-webp[=PFX] + Use system libwebp [installed at prefix PFX]], + WEBP_DIR=$withval) + +_SAVE_CFLAGS=$CFLAGS +_SAVE_LDFLAGS=$LDFLAGS +_SAVE_LIBS=$LIBS +if test -n "${WEBP_DIR}" -a "${WEBP_DIR}" != "yes"; then + CFLAGS="-I${WEBP_DIR}/include $CFLAGS" + LDFLAGS="-L${WEBP_DIR}/lib $LDFLAGS" +fi +if test -z "$WEBP_DIR" -o "$WEBP_DIR" = no; then + MOZ_NATIVE_WEBP= +else + AC_CHECK_LIB(webp, WebPGetDecoderVersion, [MOZ_NATIVE_WEBP=1 MOZ_WEBP_LIBS="-lwebp"], + [MOZ_NATIVE_WEBP= MOZ_WEBP_CFLAGS= MOZ_WEBP_LIBS=]) +fi +if test "$MOZ_NATIVE_WEBP" = 1; then + AC_TRY_COMPILE([ #include ], + [ #if WEBP_DECODER_ABI_VERSION < $MOZWEBP + #error "Insufficient libwebp decoder version ($MOZWEBP required)." + #endif ], + MOZ_NATIVE_WEBP=1, + AC_MSG_ERROR([--with-system-webp requested but no working libwebp found])) +fi +CFLAGS=$_SAVE_CFLAGS +LDFLAGS=$_SAVE_LDFLAGS +LIBS=$_SAVE_LIBS + +if test "${WEBP_DIR}" -a -d "${WEBP_DIR}" -a "$MOZ_NATIVE_WEBP" = 1; then + MOZ_WEBP_CFLAGS="-I${WEBP_DIR}/include" + MOZ_WEBP_LIBS="-L${WEBP_DIR}/lib ${MOZ_WEBP_LIBS}" +fi + dnl ======================================================== dnl system HunSpell Support dnl ======================================================== @@ -3727,6 +3804,7 @@ MOZ_WAVE=1 MOZ_SAMPLE_TYPE_FLOAT32= MOZ_SAMPLE_TYPE_S16= MOZ_WEBM=1 +MOZ_WEBP=1 MOZ_GSTREAMER= MOZ_DIRECTSHOW= MOZ_WMF= @@ -5451,6 +5529,14 @@ AC_SUBST(MOZ_NATIVE_LIBVPX) AC_SUBST_LIST(MOZ_LIBVPX_CFLAGS) AC_SUBST_LIST(MOZ_LIBVPX_LIBS) +if test "$MOZ_WEBP"; then + AC_DEFINE(MOZ_WEBP) +fi + +if test "$MOZ_WEBP"; then + AC_DEFINE(MOZ_WEBP) +fi + if test "$MOZ_WEBM"; then if test "$MOZ_SAMPLE_TYPE_FLOAT32"; then MOZ_VORBIS=1 @@ -8926,6 +9012,7 @@ HOST_CXXFLAGS=`echo \ AC_SUBST(MOZ_NATIVE_JPEG) AC_SUBST(MOZ_NATIVE_PNG) +AC_SUBST(MOZ_NATIVE_WEBP) AC_SUBST(MOZ_NATIVE_BZ2) AC_SUBST_LIST(MOZ_JPEG_CFLAGS) @@ -8934,6 +9021,8 @@ AC_SUBST_LIST(MOZ_BZ2_CFLAGS) AC_SUBST_LIST(MOZ_BZ2_LIBS) AC_SUBST_LIST(MOZ_PNG_CFLAGS) AC_SUBST_LIST(MOZ_PNG_LIBS) +AC_SUBST(MOZ_WEBP_CFLAGS) +AC_SUBST_LIST(MOZ_WEBP_LIBS) if test "$MOZ_WIDGET_TOOLKIT" = gonk -a -n "$MOZ_NUWA_PROCESS"; then export MOZ_NUWA_PROCESS @@ -9031,6 +9120,7 @@ AC_SUBST(MOZ_WAVE) AC_SUBST(MOZ_VORBIS) AC_SUBST(MOZ_TREMOR) AC_SUBST(MOZ_WEBM) +AC_SUBST(MOZ_WEBP) AC_SUBST(MOZ_WMF) AC_SUBST(MOZ_FFMPEG) AC_SUBST(MOZ_FMP4) diff --git a/image/DecoderFactory.cpp b/image/DecoderFactory.cpp index 8320297c26..1872a7e815 100644 --- a/image/DecoderFactory.cpp +++ b/image/DecoderFactory.cpp @@ -16,6 +16,7 @@ #include "nsBMPDecoder.h" #include "nsICODecoder.h" #include "nsIconDecoder.h" +#include "nsWEBPDecoder.h" namespace mozilla { @@ -62,6 +63,10 @@ DecoderFactory::GetDecoderType(const char* aMimeType) // Icon } else if (!strcmp(aMimeType, IMAGE_ICON_MS)) { type = DecoderType::ICON; + + // WEBP + } else if (!strcmp(aMimeType, IMAGE_WEBP)) { + type = DecoderType::WEBP; } return type; @@ -97,6 +102,9 @@ DecoderFactory::GetDecoder(DecoderType aType, case DecoderType::ICON: decoder = new nsIconDecoder(aImage); break; + case DecoderType::WEBP: + decoder = new nsWEBPDecoder(aImage); + break; default: MOZ_ASSERT_UNREACHABLE("Unknown decoder type"); } diff --git a/image/DecoderFactory.h b/image/DecoderFactory.h index f7a6bfe60c..db80ff4770 100644 --- a/image/DecoderFactory.h +++ b/image/DecoderFactory.h @@ -35,6 +35,7 @@ enum class DecoderType BMP, ICO, ICON, + WEBP, UNKNOWN }; diff --git a/image/build/nsImageModule.cpp b/image/build/nsImageModule.cpp index 6bc4c04a6b..2776557398 100644 --- a/image/build/nsImageModule.cpp +++ b/image/build/nsImageModule.cpp @@ -78,6 +78,7 @@ static const mozilla::Module::CategoryEntry kImageCategories[] = { { "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" }, + { "Gecko-Content-Viewers", IMAGE_WEBP, "@mozilla.org/content/document-loader-factory;1" }, { "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" }, { nullptr } }; diff --git a/image/decoders/moz.build b/image/decoders/moz.build index 126bf670d8..edd6578578 100644 --- a/image/decoders/moz.build +++ b/image/decoders/moz.build @@ -30,6 +30,7 @@ UNIFIED_SOURCES += [ 'nsIconDecoder.cpp', 'nsJPEGDecoder.cpp', 'nsPNGDecoder.cpp', + 'nsWEBPDecoder.cpp', ] # Decoders need RasterImage.h diff --git a/image/imgLoader.cpp b/image/imgLoader.cpp index bfe7c23184..618a6ee359 100644 --- a/image/imgLoader.cpp +++ b/image/imgLoader.cpp @@ -2585,6 +2585,11 @@ imgLoader::GetMimeTypeFromContent(const char* aContents, !memcmp(aContents, "\000\000\002\000", 4))) { aContentType.AssignLiteral(IMAGE_ICO); + // WebPs always begin with RIFF, a 32-bit length, and WEBP. + } else if (aLength >= 12 && !memcmp(aContents, "RIFF", 4) && + !memcmp(aContents + 8, "WEBP", 4)) { + aContentType.AssignLiteral(IMAGE_WEBP); + } else { /* none of the above? I give up */ return NS_ERROR_NOT_AVAILABLE; diff --git a/netwerk/mime/nsMimeTypes.h b/netwerk/mime/nsMimeTypes.h index c10f02024a..fd9a047715 100644 --- a/netwerk/mime/nsMimeTypes.h +++ b/netwerk/mime/nsMimeTypes.h @@ -100,6 +100,7 @@ #define IMAGE_XBM "image/x-xbitmap" #define IMAGE_XBM2 "image/x-xbm" #define IMAGE_XBM3 "image/xbm" +#define IMAGE_WEBP "image/webp" #define IMAGE_ART "image/x-jg" #define IMAGE_TIFF "image/tiff" #define IMAGE_BMP "image/bmp" diff --git a/toolkit/library/moz.build b/toolkit/library/moz.build index 8f416d1bf4..7cd320fa58 100644 --- a/toolkit/library/moz.build +++ b/toolkit/library/moz.build @@ -221,6 +221,9 @@ if CONFIG['MOZ_NATIVE_JPEG']: if CONFIG['MOZ_NATIVE_PNG']: OS_LIBS += CONFIG['MOZ_PNG_LIBS'] +if CONFIG['MOZ_NATIVE_WEBP']: + OS_LIBS += CONFIG['MOZ_WEBP_LIBS'] + if CONFIG['MOZ_NATIVE_HUNSPELL']: OS_LIBS += CONFIG['MOZ_HUNSPELL_LIBS'] diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index fc2f238564..18a14b87b9 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -507,6 +507,9 @@ static nsDefaultMimeTypeEntry defaultMimeEntries [] = { IMAGE_JPEG, "jpeg" }, { IMAGE_JPEG, "jpg" }, { IMAGE_SVG_XML, "svg" }, +#ifdef MOZ_WEBP + { IMAGE_WEBP, "webp" }, +#endif { TEXT_HTML, "html" }, { TEXT_HTML, "htm" }, { APPLICATION_XPINSTALL, "xpi" }, @@ -584,6 +587,7 @@ static nsExtraMimeTypeEntry extraMimeEntries [] = { IMAGE_TIFF, "tiff,tif", "TIFF Image" }, { IMAGE_XBM, "xbm", "XBM Image" }, { IMAGE_SVG_XML, "svg", "Scalable Vector Graphics" }, + { IMAGE_WEBP, "webp", "WebP Image" }, { MESSAGE_RFC822, "eml", "RFC-822 data" }, { TEXT_PLAIN, "txt,text", "Text File" }, { TEXT_HTML, "html,htm,shtml,ehtml", "HyperText Markup Language" },