commit 9dadb90813c148d623d3bd35b629eebf499d27c4 Author: Richard Pospesel richard@torproject.org Date: Mon Nov 27 13:57:32 2017 -0800
Bug 23970: Printing to a file is broken with Linux content sandboxing enabled
Ported over firefox patch 5c25a123203a (Bug 1309205 Part 1) --- gfx/2d/2D.h | 12 ++++++++++++ gfx/2d/Factory.cpp | 25 +++++++++++++++++++++++++ gfx/thebes/gfxAndroidPlatform.h | 4 +--- gfx/thebes/gfxFT2FontList.cpp | 10 +++++----- gfx/thebes/gfxFontconfigFonts.h | 5 ++--- gfx/thebes/gfxPlatform.cpp | 4 ++++ gfx/thebes/gfxPlatform.h | 5 +++++ gfx/thebes/gfxPlatformGtk.cpp | 10 ++++++++++ gfx/thebes/gfxPlatformGtk.h | 2 ++ 9 files changed, 66 insertions(+), 11 deletions(-)
diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index c1fba3463a8f..3d5fb52ad925 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -41,6 +41,9 @@ typedef _cairo_scaled_font cairo_scaled_font_t; struct _FcPattern; typedef _FcPattern FcPattern;
+struct FT_LibraryRec_; +typedef FT_LibraryRec_* FT_Library; + struct ID3D11Texture2D; struct ID3D11Device; struct ID2D1Device; @@ -1483,6 +1486,15 @@ public: CreateCGGlyphRenderingOptions(const Color &aFontSmoothingBackgroundColor); #endif
+#ifdef MOZ_ENABLE_FREETYPE + static void SetFTLibrary(FT_Library aFTLibrary); + static FT_Library GetFTLibrary(); + +private: + static FT_Library mFTLibrary; +public: +#endif + #ifdef WIN32 static already_AddRefed<DrawTarget> CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat);
diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp index 5cd5d14eaba1..ceebce690afb 100644 --- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -156,6 +156,10 @@ namespace gfx { // In Gecko, this value is managed by gfx.logging.level in gfxPrefs. int32_t LoggingPrefs::sGfxLogLevel = LOG_DEFAULT;
+#ifdef MOZ_ENABLE_FREETYPE +FT_Library Factory::mFTLibrary = nullptr; +#endif + #ifdef WIN32 ID3D11Device *Factory::mD3D11Device = nullptr; ID2D1Device *Factory::mD2D1Device = nullptr; @@ -192,6 +196,12 @@ Factory::ShutDown() delete sConfig; sConfig = nullptr; } + +#ifdef MOZ_ENABLE_FREETYPE + if (mFTLibrary) { + mFTLibrary = nullptr; + } +#endif }
bool @@ -579,6 +589,21 @@ Factory::CreateDualDrawTarget(DrawTarget *targetA, DrawTarget *targetB) }
+#ifdef MOZ_ENABLE_FREETYPE +void +Factory::SetFTLibrary(FT_Library aFTLibrary) +{ + mFTLibrary = aFTLibrary; +} + +FT_Library +Factory::GetFTLibrary() +{ + MOZ_ASSERT(mFTLibrary); + return mFTLibrary; +} +#endif + #ifdef WIN32 already_AddRefed<DrawTarget> Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceFormat aFormat) diff --git a/gfx/thebes/gfxAndroidPlatform.h b/gfx/thebes/gfxAndroidPlatform.h index 30e7c89babeb..889928da86a7 100644 --- a/gfx/thebes/gfxAndroidPlatform.h +++ b/gfx/thebes/gfxAndroidPlatform.h @@ -19,8 +19,6 @@ namespace mozilla { }; using mozilla::dom::FontListEntry;
-typedef struct FT_LibraryRec_ *FT_Library; - class gfxAndroidPlatform : public gfxPlatform { public: gfxAndroidPlatform(); @@ -60,7 +58,7 @@ public: virtual bool FontHintingEnabled() override; virtual bool RequiresLinearZoom() override;
- FT_Library GetFTLibrary(); + FT_Library GetFTLibrary() override;
virtual bool CanRenderContentToDataSurface() const override { return true; diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index 8a652df0dd34..2d9e09efe1c0 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -13,7 +13,6 @@ #include "mozilla/UniquePtr.h" #include "mozilla/UniquePtrExtensions.h" #include "nsIInputStream.h" -#define gfxToolkitPlatform gfxAndroidPlatform
#include "nsXULAppAPI.h" #include <dirent.h> @@ -85,7 +84,8 @@ public:
NS_ASSERTION(!aFontEntry->mFilename.IsEmpty(), "can't use AutoFTFace for fonts without a filename"); - FT_Library ft = gfxToolkitPlatform::GetPlatform()->GetFTLibrary(); + FT_Library ft = gfxPlatform::GetPlatform()->GetFTLibrary(); + MOZ_ASSERT(ft);
// A relative path (no initial "/") means this is a resource in // omnijar, not an installed font on the device. @@ -256,7 +256,7 @@ FT2FontEntry::CreateFontEntry(const nsAString& aFontName, // eventually deleted. FT_Face face; FT_Error error = - FT_New_Memory_Face(gfxToolkitPlatform::GetPlatform()->GetFTLibrary(), + FT_New_Memory_Face(gfxPlatform::GetPlatform()->GetFTLibrary(), aFontData, aLength, 0, &face); if (error != FT_Err_Ok) { free((void*)aFontData); @@ -974,7 +974,7 @@ gfxFT2FontList::AppendFacesFromFontFile(const nsCString& aFileName, return; }
- FT_Library ftLibrary = gfxAndroidPlatform::GetPlatform()->GetFTLibrary(); + FT_Library ftLibrary = gfxPlatform::GetPlatform()->GetFTLibrary(); FT_Face dummy; if (FT_Err_Ok == FT_New_Face(ftLibrary, aFileName.get(), -1, &dummy)) { LOG(("reading font info via FreeType for %s", aFileName.get())); @@ -1126,7 +1126,7 @@ gfxFT2FontList::AppendFacesFromOmnijarEntry(nsZipArchive* aArchive, return; }
- FT_Library ftLibrary = gfxAndroidPlatform::GetPlatform()->GetFTLibrary(); + FT_Library ftLibrary = gfxPlatform::GetPlatform()->GetFTLibrary();
FT_Face dummy; if (FT_Err_Ok != FT_New_Memory_Face(ftLibrary, buf.get(), bufSize, 0, &dummy)) { diff --git a/gfx/thebes/gfxFontconfigFonts.h b/gfx/thebes/gfxFontconfigFonts.h index cea9d0dbfaf2..cd59cfc68c62 100644 --- a/gfx/thebes/gfxFontconfigFonts.h +++ b/gfx/thebes/gfxFontconfigFonts.h @@ -55,6 +55,8 @@ public: const uint8_t* aFontData, uint32_t aLength);
+ static FT_Library GetFTLibrary(); + private:
virtual gfxFont *GetFontAt(int32_t i, uint32_t aCh = 0x20); @@ -116,9 +118,6 @@ private: nsIAtom *aLanguage, nsTArray<nsString>& aGenericFamilies);
- - friend class gfxSystemFcFontEntry; - static FT_Library GetFTLibrary(); };
#endif /* GFX_FONTCONFIG_FONTS_H */ diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 2e4ec990f8b3..4843554d655b 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -752,6 +752,10 @@ gfxPlatform::Init() NS_RUNTIMEABORT("Could not initialize gfxFontCache"); }
+#ifdef MOZ_ENABLE_FREETYPE + Factory::SetFTLibrary(gPlatform->GetFTLibrary()); +#endif + /* Create and register our CMS Override observer. */ gPlatform->mSRGBOverrideObserver = new SRGBOverrideObserver(); Preferences::AddWeakObserver(gPlatform->mSRGBOverrideObserver, GFX_PREF_CMS_FORCE_SRGB); diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 68bb99ea44e9..5ef792b67a40 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -39,6 +39,7 @@ class nsIAtom; class nsIObserver; class SRGBOverrideObserver; class gfxTextPerfMetrics; +typedef struct FT_LibraryRec_ *FT_Library;
namespace mozilla { namespace gl { @@ -681,6 +682,10 @@ public: */ virtual void ImportGPUDeviceData(const mozilla::gfx::GPUDeviceData& aData);
+ virtual FT_Library GetFTLibrary() { + return nullptr; + } + protected: gfxPlatform(); virtual ~gfxPlatform(); diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp index 9d7f512f27a7..c8661a433111 100644 --- a/gfx/thebes/gfxPlatformGtk.cpp +++ b/gfx/thebes/gfxPlatformGtk.cpp @@ -348,6 +348,16 @@ gfxPlatformGtk::MakePlatformFont(const nsAString& aFontName, aFontData, aLength); }
+FT_Library +gfxPlatformGtk::GetFTLibrary() +{ + if (sUseFcFontList) { + return gfxFcPlatformFontList::GetFTLibrary(); + } + + return gfxPangoFontGroup::GetFTLibrary(); +} + bool gfxPlatformGtk::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) { diff --git a/gfx/thebes/gfxPlatformGtk.h b/gfx/thebes/gfxPlatformGtk.h index 982390d1867b..d0c6079bd943 100644 --- a/gfx/thebes/gfxPlatformGtk.h +++ b/gfx/thebes/gfxPlatformGtk.h @@ -95,6 +95,8 @@ public: */ virtual void FlushContentDrawing() override;
+ FT_Library GetFTLibrary() override; + #if (MOZ_WIDGET_GTK == 2) static void SetGdkDrawable(cairo_surface_t *target, GdkDrawable *drawable);