lists.torproject.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

tbb-commits

Thread Start a new thread
Download
Threads by month
  • ----- 2025 -----
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2021 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2020 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2019 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2018 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2017 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2016 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2015 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2014 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
tbb-commits@lists.torproject.org

  • 1 participants
  • 18541 discussions
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 23970: Printing to a file is broken with Linux content sandboxing enabled
by gk@torproject.org 15 Dec '17

15 Dec '17
commit 2a11447e4fb8ec6d64031cc41bdcef97603343cb Author: Richard Pospesel <richard(a)torproject.org> Date: Mon Nov 27 14:40:05 2017 -0800 Bug 23970: Printing to a file is broken with Linux content sandboxing enabled Ported over firefox patch 2797f193a147 (Bug 1309205 Part 2) --- gfx/2d/2D.h | 7 + gfx/2d/Factory.cpp | 23 ++- gfx/2d/NativeFontResourceFontconfig.cpp | 65 +++++++ gfx/2d/NativeFontResourceFontconfig.h | 41 +++++ gfx/2d/RecordedEvent.cpp | 21 +-- gfx/2d/RecordedEvent.h | 10 +- gfx/2d/ScaledFontFontconfig.cpp | 315 ++++++++++++++++++++++++++++++++ gfx/2d/ScaledFontFontconfig.h | 59 +++++- gfx/2d/ScaledFontWin.cpp | 17 ++ gfx/2d/ScaledFontWin.h | 4 + gfx/2d/moz.build | 1 + 11 files changed, 540 insertions(+), 23 deletions(-) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index 3d5fb52ad925..0b95f37cb1c3 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -1388,6 +1388,13 @@ public: CreateNativeFontResource(uint8_t *aData, uint32_t aSize, FontType aType); /** + * This creates a scaled font of the given type based on font descriptor + * data retrieved from ScaledFont::GetFontDescriptor. + */ + static already_AddRefed<ScaledFont> + CreateScaledFontFromFontDescriptor(FontType aType, const uint8_t* aData, uint32_t aDataLength, Float aSize); + + /** * This creates a scaled font with an associated cairo_scaled_font_t, and * must be used when using the Cairo backend. The NativeFont and * cairo_scaled_font_t* parameters must correspond to the same font. diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp index ceebce690afb..bfe93d82c0ef 100644 --- a/gfx/2d/Factory.cpp +++ b/gfx/2d/Factory.cpp @@ -32,6 +32,7 @@ #ifdef MOZ_WIDGET_GTK #include "ScaledFontFontconfig.h" +#include "NativeFontResourceFontconfig.h" #endif #ifdef WIN32 @@ -534,8 +535,10 @@ Factory::CreateNativeFontResource(uint8_t *aData, uint32_t aSize, return NativeFontResourceGDI::Create(aData, aSize, /* aNeedsCairo = */ true); } -#elif XP_DARWIN +#elif defined(XP_DARWIN) return NativeFontResourceMac::Create(aData, aSize); +#elif defined(MOZ_WIDGET_GTK) + return NativeFontResourceFontconfig::Create(aData, aSize); #else gfxWarning() << "Unable to create cairo scaled font from truetype data"; return nullptr; @@ -548,6 +551,24 @@ Factory::CreateNativeFontResource(uint8_t *aData, uint32_t aSize, } already_AddRefed<ScaledFont> +Factory::CreateScaledFontFromFontDescriptor(FontType aType, const uint8_t* aData, uint32_t aDataLength, Float aSize) +{ + switch (aType) { +#ifdef WIN32 + case FontType::GDI: + return ScaledFontWin::CreateFromFontDescriptor(aData, aDataLength, aSize); +#endif +#ifdef MOZ_WIDGET_GTK + case FontType::FONTCONFIG: + return ScaledFontFontconfig::CreateFromFontDescriptor(aData, aDataLength, aSize); +#endif + default: + gfxWarning() << "Invalid type specified for ScaledFont font descriptor"; + return nullptr; + } +} + +already_AddRefed<ScaledFont> Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont) { #ifdef USE_CAIRO diff --git a/gfx/2d/NativeFontResourceFontconfig.cpp b/gfx/2d/NativeFontResourceFontconfig.cpp new file mode 100644 index 000000000000..a205f98fae08 --- /dev/null +++ b/gfx/2d/NativeFontResourceFontconfig.cpp @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 "NativeFontResourceFontconfig.h" +#include "ScaledFontFontconfig.h" +#include "Logging.h" + +namespace mozilla { +namespace gfx { + +NativeFontResourceFontconfig::NativeFontResourceFontconfig(UniquePtr<uint8_t[]>&& aFontData, FT_Face aFace) + : mFontData(Move(aFontData)), + mFace(aFace) +{ +} + +NativeFontResourceFontconfig::~NativeFontResourceFontconfig() +{ + if (mFace) { + FT_Done_Face(mFace); + mFace = nullptr; + } +} + +already_AddRefed<NativeFontResourceFontconfig> +NativeFontResourceFontconfig::Create(uint8_t *aFontData, uint32_t aDataLength) +{ + if (!aFontData || !aDataLength) { + return nullptr; + } + UniquePtr<uint8_t[]> fontData(new uint8_t[aDataLength]); + memcpy(fontData.get(), aFontData, aDataLength); + + FT_Face face; + if (FT_New_Memory_Face(Factory::GetFTLibrary(), fontData.get(), aDataLength, 0, &face) != FT_Err_Ok) { + return nullptr; + } + if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != FT_Err_Ok) { + FT_Done_Face(face); + return nullptr; + } + + RefPtr<NativeFontResourceFontconfig> resource = + new NativeFontResourceFontconfig(Move(fontData), face); + return resource.forget(); +} + +already_AddRefed<ScaledFont> +NativeFontResourceFontconfig::CreateScaledFont(uint32_t aIndex, Float aGlyphSize, + const uint8_t* aInstanceData, uint32_t aInstanceDataLength) +{ + if (aInstanceDataLength < sizeof(ScaledFontFontconfig::InstanceData)) { + gfxWarning() << "Fontconfig scaled font instance data is truncated."; + return nullptr; + } + return ScaledFontFontconfig::CreateFromInstanceData( + *reinterpret_cast<const ScaledFontFontconfig::InstanceData*>(aInstanceData), + mFace, nullptr, 0, aGlyphSize); +} + +} // gfx +} // mozilla diff --git a/gfx/2d/NativeFontResourceFontconfig.h b/gfx/2d/NativeFontResourceFontconfig.h new file mode 100644 index 000000000000..e2c386198896 --- /dev/null +++ b/gfx/2d/NativeFontResourceFontconfig.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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_gfx_NativeFontResourceFontconfig_h +#define mozilla_gfx_NativeFontResourceFontconfig_h + +#include "2D.h" + +#include <cairo-ft.h> + +namespace mozilla { +namespace gfx { + +class NativeFontResourceFontconfig final : public NativeFontResource +{ +public: + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(NativeFontResourceFontconfig) + + static already_AddRefed<NativeFontResourceFontconfig> + Create(uint8_t *aFontData, uint32_t aDataLength); + + already_AddRefed<ScaledFont> + CreateScaledFont(uint32_t aIndex, Float aGlyphSize, + const uint8_t* aInstanceData, uint32_t aInstanceDataLength) final; + + ~NativeFontResourceFontconfig(); + +private: + NativeFontResourceFontconfig(UniquePtr<uint8_t[]>&& aFontData, FT_Face aFace); + + UniquePtr<uint8_t[]> mFontData; + FT_Face mFace; +}; + +} // gfx +} // mozilla + +#endif // mozilla_gfx_NativeFontResourceFontconfig_h diff --git a/gfx/2d/RecordedEvent.cpp b/gfx/2d/RecordedEvent.cpp index 3bfc5c8f6333..684ce180db1e 100644 --- a/gfx/2d/RecordedEvent.cpp +++ b/gfx/2d/RecordedEvent.cpp @@ -1595,18 +1595,13 @@ RecordedFontDescriptor::~RecordedFontDescriptor() bool RecordedFontDescriptor::PlayEvent(Translator *aTranslator) const { - MOZ_ASSERT(mType == FontType::GDI); - - NativeFont nativeFont; - nativeFont.mType = (NativeFontType)mType; - nativeFont.mFont = (void*)&mData[0]; - RefPtr<ScaledFont> font = - Factory::CreateScaledFontForNativeFont(nativeFont, mFontSize); - -#ifdef USE_CAIRO_SCALED_FONT - static_cast<ScaledFontBase*>(font.get())->PopulateCairoScaledFont(); -#endif + Factory::CreateScaledFontFromFontDescriptor(mType, mData.data(), mData.size(), mFontSize); + if (!font) { + gfxDevCrash(LogReason::InvalidFont) << + "Failed creating ScaledFont of type " << int(mType) << " from font descriptor"; + return false; + } aTranslator->AddScaledFont(mRefPtr, font); return true; @@ -1620,7 +1615,7 @@ RecordedFontDescriptor::RecordToStream(std::ostream &aStream) const WriteElement(aStream, mFontSize); WriteElement(aStream, mRefPtr); WriteElement(aStream, (size_t)mData.size()); - aStream.write((char*)&mData[0], mData.size()); + aStream.write((char*)mData.data(), mData.size()); } void @@ -1646,7 +1641,7 @@ RecordedFontDescriptor::RecordedFontDescriptor(istream &aStream) size_t size; ReadElement(aStream, size); mData.resize(size); - aStream.read((char*)&mData[0], size); + aStream.read((char*)mData.data(), size); } bool diff --git a/gfx/2d/RecordedEvent.h b/gfx/2d/RecordedEvent.h index bf660ba243c4..dcf4d9e36e02 100644 --- a/gfx/2d/RecordedEvent.h +++ b/gfx/2d/RecordedEvent.h @@ -1047,7 +1047,7 @@ private: uint8_t *mData; RecordedFontDetails mFontDetails; - bool mGetFontFileDataSucceeded = false; + bool mGetFontFileDataSucceeded; MOZ_IMPLICIT RecordedFontData(std::istream &aStream); }; @@ -1055,7 +1055,7 @@ private: class RecordedFontDescriptor : public RecordedEvent { public: - static void FontDescCb(const uint8_t *aData, uint32_t aSize, + static void FontDescCb(const uint8_t* aData, uint32_t aSize, Float aFontSize, void* aBaton) { auto recordedFontDesc = static_cast<RecordedFontDescriptor*>(aBaton); @@ -1108,9 +1108,11 @@ public: RecordedScaledFontCreation(ScaledFont* aScaledFont, RecordedFontDetails aFontDetails) - : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aScaledFont) + : RecordedEvent(SCALEDFONTCREATION) + , mRefPtr(aScaledFont) , mFontDataKey(aFontDetails.fontDataKey) - , mGlyphSize(aFontDetails.glyphSize) , mIndex(aFontDetails.index) + , mGlyphSize(aFontDetails.glyphSize) + , mIndex(aFontDetails.index) { aScaledFont->GetFontInstanceData(FontInstanceDataProc, this); } diff --git a/gfx/2d/ScaledFontFontconfig.cpp b/gfx/2d/ScaledFontFontconfig.cpp index d4751f86dac1..0695eebbeaa7 100644 --- a/gfx/2d/ScaledFontFontconfig.cpp +++ b/gfx/2d/ScaledFontFontconfig.cpp @@ -10,6 +10,10 @@ #include "skia/include/ports/SkTypeface_cairo.h" #endif +#include FT_TRUETYPE_TABLES_H + +#include <fontconfig/fcfreetype.h> + namespace mozilla { namespace gfx { @@ -43,5 +47,316 @@ SkTypeface* ScaledFontFontconfig::GetSkTypeface() } #endif +bool +ScaledFontFontconfig::GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) +{ + bool success = false; + // Lock the Cairo scaled font to force it to resolve the Fontconfig pattern to an FT_Face. + if (FT_Face face = cairo_ft_scaled_font_lock_face(GetCairoScaledFont())) { + FT_ULong length = 0; + // Request the SFNT file. This may not always succeed for all font types. + if (FT_Load_Sfnt_Table(face, 0, 0, nullptr, &length) == FT_Err_Ok) { + uint8_t* fontData = new uint8_t[length]; + if (FT_Load_Sfnt_Table(face, 0, 0, fontData, &length) == FT_Err_Ok) { + aDataCallback(fontData, length, 0, mSize, aBaton); + success = true; + } + delete[] fontData; + } + cairo_ft_scaled_font_unlock_face(GetCairoScaledFont()); + } + return success; +} + +ScaledFontFontconfig::InstanceData::InstanceData(cairo_scaled_font_t* aScaledFont, FcPattern* aPattern) + : mFlags(0) + , mHintStyle(FC_HINT_NONE) + , mSubpixelOrder(FC_RGBA_UNKNOWN) + , mLcdFilter(FC_LCD_LEGACY) +{ + // Record relevant Fontconfig properties into instance data. + FcBool autohint; + if (FcPatternGetBool(aPattern, FC_AUTOHINT, 0, &autohint) == FcResultMatch && autohint) { + mFlags |= AUTOHINT; + } + FcBool bitmap; + if (FcPatternGetBool(aPattern, FC_EMBEDDED_BITMAP, 0, &bitmap) == FcResultMatch && bitmap) { + mFlags |= EMBEDDED_BITMAP; + } + FcBool embolden; + if (FcPatternGetBool(aPattern, FC_EMBOLDEN, 0, &embolden) == FcResultMatch && embolden) { + mFlags |= EMBOLDEN; + } + FcBool vertical; + if (FcPatternGetBool(aPattern, FC_VERTICAL_LAYOUT, 0, &vertical) == FcResultMatch && vertical) { + mFlags |= VERTICAL_LAYOUT; + } + + FcBool antialias; + if (FcPatternGetBool(aPattern, FC_ANTIALIAS, 0, &antialias) != FcResultMatch || antialias) { + mFlags |= ANTIALIAS; + + // Only record subpixel order and lcd filtering if antialiasing is enabled. + int rgba; + if (FcPatternGetInteger(aPattern, FC_RGBA, 0, &rgba) == FcResultMatch) { + mSubpixelOrder = rgba; + } + int filter; + if (FcPatternGetInteger(aPattern, FC_LCD_FILTER, 0, &filter) == FcResultMatch) { + mLcdFilter = filter; + } + } + + cairo_font_options_t* fontOptions = cairo_font_options_create(); + cairo_scaled_font_get_font_options(aScaledFont, fontOptions); + // For printer fonts, Cairo hint metrics and hinting will be disabled. + // For other fonts, allow hint metrics and hinting. + if (cairo_font_options_get_hint_metrics(fontOptions) != CAIRO_HINT_METRICS_OFF) { + mFlags |= HINT_METRICS; + + FcBool hinting; + if (FcPatternGetBool(aPattern, FC_HINTING, 0, &hinting) != FcResultMatch || hinting) { + int hintstyle; + if (FcPatternGetInteger(aPattern, FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch) { + hintstyle = FC_HINT_FULL; + } + mHintStyle = hintstyle; + } + } + cairo_font_options_destroy(fontOptions); + + // Some fonts supply an adjusted size or otherwise use the font matrix for italicization. + // Record the scale and the skew to accomodate both of these cases. + cairo_matrix_t fontMatrix; + cairo_scaled_font_get_font_matrix(aScaledFont, &fontMatrix); + mScale = Float(fontMatrix.xx); + mSkew = Float(fontMatrix.xy); +} + +void +ScaledFontFontconfig::InstanceData::SetupPattern(FcPattern* aPattern) const +{ + if (mFlags & AUTOHINT) { + FcPatternAddBool(aPattern, FC_AUTOHINT, FcTrue); + } + if (mFlags & EMBEDDED_BITMAP) { + FcPatternAddBool(aPattern, FC_EMBEDDED_BITMAP, FcTrue); + } + if (mFlags & EMBOLDEN) { + FcPatternAddBool(aPattern, FC_EMBOLDEN, FcTrue); + } + if (mFlags & VERTICAL_LAYOUT) { + FcPatternAddBool(aPattern, FC_VERTICAL_LAYOUT, FcTrue); + } + + if (mFlags & ANTIALIAS) { + FcPatternAddBool(aPattern, FC_ANTIALIAS, FcTrue); + if (mSubpixelOrder != FC_RGBA_UNKNOWN) { + FcPatternAddInteger(aPattern, FC_RGBA, mSubpixelOrder); + } + if (mLcdFilter != FC_LCD_LEGACY) { + FcPatternAddInteger(aPattern, FC_LCD_FILTER, mLcdFilter); + } + } else { + FcPatternAddBool(aPattern, FC_ANTIALIAS, FcFalse); + } + + if (mHintStyle) { + FcPatternAddBool(aPattern, FC_HINTING, FcTrue); + FcPatternAddInteger(aPattern, FC_HINT_STYLE, mHintStyle); + } else { + FcPatternAddBool(aPattern, FC_HINTING, FcFalse); + } +} + +void +ScaledFontFontconfig::InstanceData::SetupFontOptions(cairo_font_options_t* aFontOptions) const +{ + // Try to build a sane initial set of Cairo font options based on the Fontconfig + // pattern. + if (mFlags & HINT_METRICS) { + // For regular (non-printer) fonts, enable hint metrics as well as hinting + // and (possibly subpixel) antialiasing. + cairo_font_options_set_hint_metrics(aFontOptions, CAIRO_HINT_METRICS_ON); + + cairo_hint_style_t hinting; + switch (mHintStyle) { + case FC_HINT_NONE: + hinting = CAIRO_HINT_STYLE_NONE; + break; + case FC_HINT_SLIGHT: + hinting = CAIRO_HINT_STYLE_SLIGHT; + break; + case FC_HINT_MEDIUM: + default: + hinting = CAIRO_HINT_STYLE_MEDIUM; + break; + case FC_HINT_FULL: + hinting = CAIRO_HINT_STYLE_FULL; + break; + } + cairo_font_options_set_hint_style(aFontOptions, hinting); + + if (mFlags & ANTIALIAS) { + cairo_subpixel_order_t subpixel = CAIRO_SUBPIXEL_ORDER_DEFAULT; + switch (mSubpixelOrder) { + case FC_RGBA_RGB: + subpixel = CAIRO_SUBPIXEL_ORDER_RGB; + break; + case FC_RGBA_BGR: + subpixel = CAIRO_SUBPIXEL_ORDER_BGR; + break; + case FC_RGBA_VRGB: + subpixel = CAIRO_SUBPIXEL_ORDER_VRGB; + break; + case FC_RGBA_VBGR: + subpixel = CAIRO_SUBPIXEL_ORDER_VBGR; + break; + default: + break; + } + if (subpixel != CAIRO_SUBPIXEL_ORDER_DEFAULT) { + cairo_font_options_set_antialias(aFontOptions, CAIRO_ANTIALIAS_SUBPIXEL); + cairo_font_options_set_subpixel_order(aFontOptions, subpixel); + } else { + cairo_font_options_set_antialias(aFontOptions, CAIRO_ANTIALIAS_GRAY); + } + } else { + cairo_font_options_set_antialias(aFontOptions, CAIRO_ANTIALIAS_NONE); + } + } else { + // For printer fonts, disable hint metrics and hinting. Don't allow subpixel + // antialiasing. + cairo_font_options_set_hint_metrics(aFontOptions, CAIRO_HINT_METRICS_OFF); + cairo_font_options_set_hint_style(aFontOptions, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_antialias(aFontOptions, + mFlags & ANTIALIAS ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE); + } +} + +void +ScaledFontFontconfig::InstanceData::SetupFontMatrix(cairo_matrix_t* aFontMatrix) const +{ + // Build a font matrix that will reproduce a possibly adjusted size + // and any italics/skew. This is just the concatenation of a simple + // scale matrix with a matrix that skews on the X axis. + cairo_matrix_init(aFontMatrix, mScale, 0, mSkew, mScale, 0, 0); +} + +bool +ScaledFontFontconfig::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) +{ + InstanceData instance(GetCairoScaledFont(), mPattern); + + aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), aBaton); + return true; +} + +bool +ScaledFontFontconfig::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) +{ + // Check if the Fontconfig pattern uses a font file and index to specify which + // font to load. If so, record these as a font descriptor along with any instance + // data required to rebuild a scaled font from it. + FcChar8* pathname = nullptr; + if (FcPatternGetString(mPattern, FC_FILE, 0, &pathname) != FcResultMatch) { + return false; + } + int index = 0; + FcPatternGetInteger(mPattern, FC_INDEX, 0, &index); + if (index < 0) { + return false; + } + + size_t pathLength = strlen(reinterpret_cast<char*>(pathname)) + 1; + size_t dataLength = sizeof(FontDescriptor) + pathLength; + uint8_t* data = new uint8_t[dataLength]; + FontDescriptor* desc = reinterpret_cast<FontDescriptor*>(data); + desc->mPathLength = pathLength; + desc->mIndex = index; + desc->mInstanceData = InstanceData(GetCairoScaledFont(), mPattern); + memcpy(data + sizeof(FontDescriptor), pathname, pathLength); + + aCb(data, dataLength, mSize, aBaton); + return true; +} + +already_AddRefed<ScaledFont> +ScaledFontFontconfig::CreateFromInstanceData(const InstanceData& aInstanceData, + FT_Face aFace, const char* aPathname, uint32_t aIndex, + Float aSize) + +{ + FcPattern* pattern = FcPatternCreate(); + if (!pattern) { + gfxWarning() << "Failing initializing Fontconfig pattern for scaled font"; + return nullptr; + } + if (aFace) { + FcPatternAddFTFace(pattern, FC_FT_FACE, aFace); + } else { + FcPatternAddString(pattern, FC_FILE, reinterpret_cast<const FcChar8*>(aPathname)); + FcPatternAddInteger(pattern, FC_INDEX, aIndex); + } + FcPatternAddDouble(pattern, FC_PIXEL_SIZE, aSize); + aInstanceData.SetupPattern(pattern); + + cairo_font_face_t* font = cairo_ft_font_face_create_for_pattern(pattern); + if (cairo_font_face_status(font) != CAIRO_STATUS_SUCCESS) { + gfxWarning() << "Failed creating Cairo font face for Fontconfig pattern"; + FcPatternDestroy(pattern); + return nullptr; + } + + cairo_matrix_t sizeMatrix; + aInstanceData.SetupFontMatrix(&sizeMatrix); + + cairo_matrix_t identityMatrix; + cairo_matrix_init_identity(&identityMatrix); + + cairo_font_options_t *fontOptions = cairo_font_options_create(); + aInstanceData.SetupFontOptions(fontOptions); + + cairo_scaled_font_t* cairoScaledFont = + cairo_scaled_font_create(font, &sizeMatrix, &identityMatrix, fontOptions); + + cairo_font_options_destroy(fontOptions); + cairo_font_face_destroy(font); + + if (cairo_scaled_font_status(cairoScaledFont) != CAIRO_STATUS_SUCCESS) { + gfxWarning() << "Failed creating Cairo scaled font for font face"; + FcPatternDestroy(pattern); + return nullptr; + } + + RefPtr<ScaledFontFontconfig> scaledFont = + new ScaledFontFontconfig(cairoScaledFont, pattern, aSize); + + FcPatternDestroy(pattern); + + return scaledFont.forget(); +} + +already_AddRefed<ScaledFont> +ScaledFontFontconfig::CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize) +{ + if (aDataLength < sizeof(FontDescriptor)) { + gfxWarning() << "Fontconfig font descriptor is truncated."; + return nullptr; + } + const FontDescriptor* desc = reinterpret_cast<const FontDescriptor*>(aData); + if (desc->mPathLength < 1 || + desc->mPathLength > aDataLength - sizeof(FontDescriptor)) { + gfxWarning() << "Pathname in Fontconfig font descriptor has invalid size."; + return nullptr; + } + const char* pathname = reinterpret_cast<const char*>(aData + sizeof(FontDescriptor)); + if (pathname[desc->mPathLength - 1] != '\0') { + gfxWarning() << "Pathname in Fontconfig font descriptor is not terminated."; + return nullptr; + } + return CreateFromInstanceData(desc->mInstanceData, nullptr, pathname, desc->mIndex, aSize); +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/2d/ScaledFontFontconfig.h b/gfx/2d/ScaledFontFontconfig.h index 4d4e8217dc1f..b24928d9db05 100644 --- a/gfx/2d/ScaledFontFontconfig.h +++ b/gfx/2d/ScaledFontFontconfig.h @@ -8,26 +8,75 @@ #include "ScaledFontBase.h" -#include <fontconfig/fontconfig.h> -#include <cairo.h> +#include <cairo-ft.h> namespace mozilla { namespace gfx { +class NativeFontResourceFontconfig; + class ScaledFontFontconfig : public ScaledFontBase { public: - MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontFontconfig) + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontFontconfig, override) ScaledFontFontconfig(cairo_scaled_font_t* aScaledFont, FcPattern* aPattern, Float aSize); ~ScaledFontFontconfig(); - virtual FontType GetType() const { return FontType::FONTCONFIG; } + FontType GetType() const override { return FontType::FONTCONFIG; } #ifdef USE_SKIA - virtual SkTypeface* GetSkTypeface(); + SkTypeface* GetSkTypeface() override; #endif + bool GetFontFileData(FontFileDataOutput aDataCallback, void* aBaton) override; + + bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override; + + bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override; + + static already_AddRefed<ScaledFont> + CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize); + private: + friend class NativeFontResourceFontconfig; + + struct InstanceData + { + enum { + ANTIALIAS = 1 << 0, + AUTOHINT = 1 << 1, + EMBEDDED_BITMAP = 1 << 2, + EMBOLDEN = 1 << 3, + VERTICAL_LAYOUT = 1 << 4, + HINT_METRICS = 1 << 5 + }; + + InstanceData(cairo_scaled_font_t* aScaledFont, FcPattern* aPattern); + + void SetupPattern(FcPattern* aPattern) const; + void SetupFontOptions(cairo_font_options_t* aFontOptions) const; + void SetupFontMatrix(cairo_matrix_t* aFontMatrix) const; + + uint8_t mFlags; + uint8_t mHintStyle; + uint8_t mSubpixelOrder; + uint8_t mLcdFilter; + Float mScale; + Float mSkew; + }; + + struct FontDescriptor + { + uint32_t mPathLength; + uint32_t mIndex; + InstanceData mInstanceData; + }; + + static already_AddRefed<ScaledFont> + CreateFromInstanceData(const InstanceData& aInstanceData, + FT_Face aFace, const char* aPathname, uint32_t aIndex, + Float aSize); + FcPattern* mPattern; }; diff --git a/gfx/2d/ScaledFontWin.cpp b/gfx/2d/ScaledFontWin.cpp index 2ebae21e5c04..b80bbea872e2 100644 --- a/gfx/2d/ScaledFontWin.cpp +++ b/gfx/2d/ScaledFontWin.cpp @@ -72,6 +72,23 @@ ScaledFontWin::GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) return true; } +already_AddRefed<ScaledFont> +ScaledFontWin::CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize) +{ + NativeFont nativeFont; + nativeFont.mType = NativeFontType::GDI_FONT_FACE; + nativeFont.mFont = (void*)aData; + + RefPtr<ScaledFont> font = + Factory::CreateScaledFontForNativeFont(nativeFont, aSize); + +#ifdef USE_CAIRO_SCALED_FONT + static_cast<ScaledFontBase*>(font.get())->PopulateCairoScaledFont(); +#endif + + return font.forget(); +} + AntialiasMode ScaledFontWin::GetDefaultAAMode() { diff --git a/gfx/2d/ScaledFontWin.h b/gfx/2d/ScaledFontWin.h index c07b263d7285..fe5816707d00 100644 --- a/gfx/2d/ScaledFontWin.h +++ b/gfx/2d/ScaledFontWin.h @@ -25,6 +25,10 @@ public: bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override; virtual bool GetFontDescriptor(FontDescriptorOutput aCb, void* aBaton) override; + + static already_AddRefed<ScaledFont> + CreateFromFontDescriptor(const uint8_t* aData, uint32_t aDataLength, Float aSize); + virtual AntialiasMode GetDefaultAAMode() override; #ifdef USE_SKIA diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build index ad095503d97e..545ac6823390 100644 --- a/gfx/2d/moz.build +++ b/gfx/2d/moz.build @@ -91,6 +91,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'windows': if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'): SOURCES += [ + 'NativeFontResourceFontconfig.cpp', 'ScaledFontFontconfig.cpp', ]
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 23970: Printing to a file is broken with Linux content sandboxing enabled
by gk@torproject.org 15 Dec '17

15 Dec '17
commit 8d7757dbd40f4619f84dc51853c81186a22b0160 Author: Richard Pospesel <richard(a)torproject.org> Date: Mon Nov 27 14:41:39 2017 -0800 Bug 23970: Printing to a file is broken with Linux content sandboxing enabled Ported over firefox patch 5b9702d8fe4e (Bug 1309205 Part 3) --- modules/libpref/init/all.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index dd78fec1ee75..198028eeb96c 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1106,7 +1106,7 @@ pref("print.print_edge_right", 0); pref("print.print_edge_bottom", 0); // Print via the parent process. This is only used when e10s is enabled. -#if defined(XP_WIN) || defined(XP_MACOSX) +#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX) pref("print.print_via_parent", true); #else pref("print.print_via_parent", false);
1 0
0 0
[tor-browser-build/master] Bug 24561: Add our scripts to check the authenticode/mar signing
by gk@torproject.org 14 Dec '17

14 Dec '17
commit c0915fc6a4b51418ace4d5a59f77bb63b57da3d2 Author: Georg Koppen <gk(a)torproject.org> Date: Wed Dec 13 10:53:26 2017 +0000 Bug 24561: Add our scripts to check the authenticode/mar signing --- tools/authenticode_check.sh | 96 +++++++++++++++++++++++++++++++++++++++ tools/marsigning_check.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 203 insertions(+) diff --git a/tools/authenticode_check.sh b/tools/authenticode_check.sh new file mode 100755 index 0000000..c94682d --- /dev/null +++ b/tools/authenticode_check.sh @@ -0,0 +1,96 @@ +#!/bin/sh + +# Copyright (c) 2017, The Tor Project, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# * Neither the names of the copyright owners nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Usage: +# 1) Let OSSLSIGNCODE point to your osslsigncode binary +# 2) Change into the directory containing the .exe files and the sha256sums-unsigned-build.txt +# 3) Run /path/to/authenticode_check.sh + +if [ -z "$OSSLSIGNCODE" ] +then + echo "The path to your osslsigncode binary is missing!" + exit 1 +fi + +UNSIGNED_BUNDLES=0 +BADSIGNED_BUNDLES=0 + +mkdir tmp + +for f in `ls *.exe`; do + SHA256_TXT=`grep "$f" sha256sums-unsigned-build.txt` + + # Test 1: Is the .exe file still unsigned? I.e. does its SHA-256 sum still + # match the one we had before we signed the .exe file? If so, notify us + # later and exit. + if [ "$SHA256_TXT" = "`sha256sum $f`" ] + then + echo "$f has still the SHA-256 sum of the unsigned bundle!" + UNSIGNED_BUNDLES=`expr $UNSIGNED_BUNDLES + 1` + fi + + # Test 2: Do we get the old SHA-256 sum after stripping the authenticode + # signature? If not, notify us later and exit. + if [ "$UNSIGNED_BUNDLES" = "0" ] + then + # At least we seem to have attempted to sign the bundle. Let's see if we + # succeeded by stripping the signature. This behavior is reproducible. + # Thus, we know if we don't get the same SHA-256 sum we did not sign the + # bundle correctly. + echo "Trying to strip the authenticode signature of $f..." + ${OSSLSIGNCODE} remove-signature $f tmp/$f + cd tmp + if ! [ "$SHA256_TXT" = "`sha256sum $f`" ] + then + echo "$f does not have the SHA-256 sum of the unsigned bundle!" + BADSIGNED_BUNDLES=`expr $BADSIGNED_BUNDLES + 1` + fi + cd .. + fi +done + +rm -rf tmp/ + +if ! [ "$UNSIGNED_BUNDLES" = "0" ] +then + echo "We got $UNSIGNED_BUNDLES unsigned bundle(s), exiting..." + exit 1 +fi + +if ! [ "$BADSIGNED_BUNDLES" = "0" ] +then + echo "We got $BADSIGNED_BUNDLES badly signed bundle(s), exiting..." + exit 1 +fi + +echo "The signatures are fine." +exit 0 diff --git a/tools/marsigning_check.sh b/tools/marsigning_check.sh new file mode 100755 index 0000000..41b3b4d --- /dev/null +++ b/tools/marsigning_check.sh @@ -0,0 +1,107 @@ +#!/bin/sh + +# Copyright (c) 2016, The Tor Project, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: + +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# +# * Neither the names of the copyright owners nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Usage: +# 1) Let SIGNMAR point to your signmar binary +# 2) Let LD_LIBRARY_PATH point to the mar-tools directory +# 3) Change into the directory containing the MAR files and the +# sha256sums-unsigned-build.txt/sha256sums-unsigned-build.incrementals.txt. +# 4) Run /path/to/marsigning_check.sh + +if [ -z "$SIGNMAR" ] +then + echo "The path to your signmar binary is missing!" + exit 1 +fi + +if [ -z "$LD_LIBRARY_PATH" ] +then + echo "The library search path to your mar-tools directory is missing!" + exit 1 +fi + +UNSIGNED_MARS=0 +BADSIGNED_MARS=0 + +mkdir tmp + +for f in `ls *.mar`; do + case $f in + *.incremental.mar) SHA256_TXT=`grep "$f" \ + sha256sums-unsigned-build.incrementals.txt`;; + *) SHA256_TXT=`grep "$f" sha256sums-unsigned-build.txt`;; + esac + + # Test 1: Is the .mar file still unsigned? I.e. does its SHA-256 sum still + # match the one we had before we signed it? If so, notify us later and exit. + if [ "$SHA256_TXT" = "`sha256sum $f`" ] + then + echo "$f has still the SHA-256 sum of the unsigned MAR file!" + UNSIGNED_MARS=`expr $UNSIGNED_MARS + 1` + fi + + # Test 2: Do we get the old SHA-256 sum after stripping the MAR signature? If + # not, notify us later and exit. + if [ "$UNSIGNED_MARS" = "0" ] + then + # At least we seem to have attempted to sign the MAR file. Let's see if we + # succeeded by stripping the signature. This behavior is reproducible. + # Thus, we know if we don't get the same SHA-256 sum we did not sign the + # bundle correctly. + echo "Trying to strip the MAR signature of $f..." + ${SIGNMAR} -r $f tmp/$f + cd tmp + if ! [ "$SHA256_TXT" = "`sha256sum $f`" ] + then + echo "$f does not have the SHA-256 sum of the unsigned MAR file!" + BADSIGNED_MARS=`expr $BADSIGNED_MARS + 1` + fi + cd .. + fi +done + +rm -rf tmp/ + +if ! [ "$UNSIGNED_MARS" = "0" ] +then + echo "We got $UNSIGNED_MARS unsigned MAR file(s), exiting..." + exit 1 +fi + +if ! [ "$BADSIGNED_MARS" = "0" ] +then + echo "We got $BADSIGNED_MARS badly signed MAR file(s), exiting..." + exit 1 +fi + +echo "The signatures are fine." +exit 0
1 0
0 0
[tor-launcher/master] Bug 24624: tbb-logo.svg may cause network access
by gk@torproject.org 14 Dec '17

14 Dec '17
commit c22a773ffaeb0398d8be0119f6e89f3c8161e4aa Author: Kathy Brade <brade(a)pearlcrescent.com> Date: Thu Dec 14 10:14:15 2017 -0500 Bug 24624: tbb-logo.svg may cause network access Remove www.w3.org DTD, unused xlink namespace declaration, and "Generator" comment. --- src/chrome/skin/tbb-logo.svg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/chrome/skin/tbb-logo.svg b/src/chrome/skin/tbb-logo.svg index 26cd158..8be32c2 100644 --- a/src/chrome/skin/tbb-logo.svg +++ b/src/chrome/skin/tbb-logo.svg @@ -1,7 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> -<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> -<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" +<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 328.6 66.3" enable-background="new 0 0 328.6 66.3" xml:space="preserve"> <g> <g>
1 0
0 0
[tor-launcher/master] Bug 24623: revise "country that censors Tor" text
by gk@torproject.org 14 Dec '17

14 Dec '17
commit 12baf2b089479b3e043dbfad8ac246a5226feeae Author: Kathy Brade <brade(a)pearlcrescent.com> Date: Thu Dec 14 09:51:11 2017 -0500 Bug 24623: revise "country that censors Tor" text List Egypt, China, Turkey as countries that may block Tor. This list was derived from data provided by OONI. --- src/chrome/locale/en/network-settings.dtd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chrome/locale/en/network-settings.dtd b/src/chrome/locale/en/network-settings.dtd index 240154c..85645d7 100644 --- a/src/chrome/locale/en/network-settings.dtd +++ b/src/chrome/locale/en/network-settings.dtd @@ -10,7 +10,7 @@ <!-- For "first run" wizard: --> <!ENTITY torSettings.connectPrompt "Click “Connect” to connect to Tor."> -<!ENTITY torSettings.configurePrompt "Click “Configure” to adjust network settings if you are in a country that censors Tor (such as China, Iran, Syria) or if you are connecting from a private network that requires a proxy."> +<!ENTITY torSettings.configurePrompt "Click “Configure” to adjust network settings if you are in a country that censors Tor (such as Egypt, China, Turkey) or if you are connecting from a private network that requires a proxy."> <!ENTITY torSettings.configure "Configure"> <!ENTITY torSettings.connect "Connect">
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 23016: "Print to File" does not create the expected file in non-English locales
by gk@torproject.org 14 Dec '17

14 Dec '17
commit 8ea9839478bfddd4f078f16c9268edf1755e9cb0 Author: Richard Pospesel <richard(a)torproject.org> Date: Wed Nov 15 10:48:38 2017 -0800 Bug 23016: "Print to File" does not create the expected file in non-English locales The Problem: During firefox and Web Content process startup, ::OverrideDefaultLocaleIfNeeded() is called which will conditionally ::setlocale() to "C.UTF-8" or "C" based off of the javascript.use_us_english_locale preference (to prevent fingerprinting based on how dates and what-not are formatted). Sometime after this call in the Web Content process the locale is set to the system's locale which effectively stomps over the work done by the ::OverrideDefaultLocaleIfNeeded() call. As a result, the firefox process and the Web Content process are configured to use different locales; firefox uses "C.UTF-8" while Web Content uses "" (system default). On Linux, the "Print to File" printer is a default GTK printer whose name is localized based off of the process's locale. The GTK print dialog is hosted in the firefox process and therefore the printer name will be 'Print to File.' This process sends this name over to the Web Content process, which iterates over the list of printers and finds one whose name matches. However, as the Web Content process's locale is set to system, its printer names will be localized and in the language of the system, so no printer with the name 'Print to File' will be found, and printing fails. This is why disabling javascript.use_us_english_locale fixes the issue. It also explains why disabling multi-process mode via the browser.tabs.remote.autostart.2 preference fixes the issue; one process means the printer-name is never used as a selector and also means no mismatched locale can happen. The Solution: The fix for this issue is to first check the javascript.use_us_english_locale preference each place in code where setlocale occurs, particularly in the nsLocaleService object which is the particular code path which overrides setlocale in the Web Content process. --- intl/locale/nsLocaleService.cpp | 72 +++++++++++++++++++++++++++------------ xpcom/build/XPCOMInit.cpp | 14 ++++++-- xpcom/io/nsNativeCharsetUtils.cpp | 14 ++++++-- 3 files changed, 73 insertions(+), 27 deletions(-) diff --git a/intl/locale/nsLocaleService.cpp b/intl/locale/nsLocaleService.cpp index 6d45ec9afa2a..e89ff32346cd 100644 --- a/intl/locale/nsLocaleService.cpp +++ b/intl/locale/nsLocaleService.cpp @@ -12,6 +12,7 @@ #include "nsTArray.h" #include "nsString.h" #include "mozilla/UniquePtr.h" +#include "mozilla/Preferences.h" #include <ctype.h> @@ -93,12 +94,20 @@ protected: // nsLocaleService::nsLocaleService(void) { + // conditionally use us english locale when initialization locale objects + const auto use_us_english_locale = + mozilla::Preferences::GetBool("javascript.use_us_english_locale", false); + #ifdef XP_WIN nsAutoString xpLocale; + // 1033 is default english us locale LCID + // https://msdn.microsoft.com/en-us/library/ms912047(v=winembedded.10).aspx + const LCID en_US_lcid = 1033; + // // get the system LCID // - LCID win_lcid = GetSystemDefaultLCID(); + LCID win_lcid = use_us_english_locale ? en_US_lcid : GetSystemDefaultLCID(); NS_ENSURE_TRUE_VOID(win_lcid); nsWin32Locale::GetXPLocale(win_lcid, xpLocale); nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale)); @@ -107,7 +116,7 @@ nsLocaleService::nsLocaleService(void) // // get the application LCID // - win_lcid = GetUserDefaultLCID(); + win_lcid = use_us_english_locale ? en_US_lcid : GetUserDefaultLCID(); NS_ENSURE_TRUE_VOID(win_lcid); nsWin32Locale::GetXPLocale(win_lcid, xpLocale); rv = NewLocale(xpLocale, getter_AddRefs(mApplicationLocale)); @@ -118,7 +127,7 @@ nsLocaleService::nsLocaleService(void) NS_ENSURE_TRUE_VOID(resultLocale); // Get system configuration - const char* lang = getenv("LANG"); + const char* lang = use_us_english_locale ? "en-US" : getenv("LANG"); nsAutoString xpLocale, platformLocale; nsAutoString category, category_platform; @@ -127,7 +136,19 @@ nsLocaleService::nsLocaleService(void) for( i = 0; i < LocaleListLength; i++ ) { nsresult result; // setlocale( , "") evaluates LC_* and LANG - char* lc_temp = setlocale(posix_locale_category[i], ""); + const auto current_posix_locale_category = posix_locale_category[i]; + const char* lc_temp = nullptr; + + if (use_us_english_locale) { + lc_temp = setlocale(current_posix_locale_category, "C.UTF-8"); + if (lc_temp == nullptr) { + lc_temp = setlocale(current_posix_locale_category, "C"); + } + } + else { + lc_temp = setlocale(current_posix_locale_category, ""); + } + CopyASCIItoUTF16(LocaleList[i], category); category_platform = category; category_platform.AppendLiteral("##PLATFORM"); @@ -163,30 +184,37 @@ nsLocaleService::nsLocaleService(void) #endif // XP_UNIX #ifdef XP_MACOSX - // Get string representation of user's current locale - CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent(); - CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef); - ::CFRetain(userLocaleStr); - - AutoTArray<UniChar, 32> buffer; - int size = ::CFStringGetLength(userLocaleStr); - buffer.SetLength(size + 1); - CFRange range = ::CFRangeMake(0, size); - ::CFStringGetCharacters(userLocaleStr, range, buffer.Elements()); - buffer[size] = 0; - - // Convert the locale string to the format that Mozilla expects - nsAutoString xpLocale(reinterpret_cast<char16_t*>(buffer.Elements())); - xpLocale.ReplaceChar('_', '-'); + nsAutoString xpLocale; + + if (use_us_english_locale) { + xpLocale = NS_LITERAL_STRING("en-US").get(); + } + else { + // Get string representation of user's current locale + CFLocaleRef userLocaleRef = ::CFLocaleCopyCurrent(); + CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef); + ::CFRetain(userLocaleStr); + + AutoTArray<UniChar, 32> buffer; + int size = ::CFStringGetLength(userLocaleStr); + buffer.SetLength(size + 1); + CFRange range = ::CFRangeMake(0, size); + ::CFStringGetCharacters(userLocaleStr, range, buffer.Elements()); + buffer[size] = 0; + + // Convert the locale string to the format that Mozilla expects + xpLocale = reinterpret_cast<char16_t*>(buffer.Elements()); + xpLocale.ReplaceChar('_', '-'); + + ::CFRelease(userLocaleStr); + ::CFRelease(userLocaleRef); + } nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale)); if (NS_SUCCEEDED(rv)) { mApplicationLocale = mSystemLocale; } - ::CFRelease(userLocaleStr); - ::CFRelease(userLocaleRef); - NS_ASSERTION(mApplicationLocale, "Failed to create locale objects"); #endif // XP_MACOSX } diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp index c72ea48d77c8..4fe9c93de2ec 100644 --- a/xpcom/build/XPCOMInit.cpp +++ b/xpcom/build/XPCOMInit.cpp @@ -11,6 +11,7 @@ #include "mozilla/Poison.h" #include "mozilla/SharedThreadPool.h" #include "mozilla/XPCOM.h" +#include "mozilla/Preferences.h" #include "nsXULAppAPI.h" #include "nsXPCOMPrivate.h" @@ -571,11 +572,18 @@ NS_InitXPCOM2(nsIServiceManager** aResult, } #ifndef ANDROID + // If the locale hasn't already been setup by our embedder, - // get us out of the "C" locale and into the system - if (strcmp(setlocale(LC_ALL, nullptr), "C") == 0) { - setlocale(LC_ALL, ""); + // get us out of the "C" locale and into the system, + // but only do so if we aren't force using english locale + if (mozilla::Preferences::GetBool("javascript.use_us_english_locale", false)) { + setlocale(LC_ALL, "C.UTF-8") || setlocale(LC_ALL, "C"); + } else { + if (strcmp(setlocale(LC_ALL, nullptr), "C") == 0) { + setlocale(LC_ALL, ""); + } } + #endif #if defined(XP_UNIX) diff --git a/xpcom/io/nsNativeCharsetUtils.cpp b/xpcom/io/nsNativeCharsetUtils.cpp index e53307af5628..f81c1179256b 100644 --- a/xpcom/io/nsNativeCharsetUtils.cpp +++ b/xpcom/io/nsNativeCharsetUtils.cpp @@ -48,6 +48,7 @@ NS_ShutdownNativeCharsetUtils() #include <stdlib.h> // mbtowc, wctomb #include <locale.h> // setlocale #include "mozilla/Mutex.h" +#include "mozilla/Preferences.h" #include "nscore.h" #include "nsAString.h" #include "nsReadableUtils.h" @@ -316,7 +317,12 @@ nsNativeCharsetConverter::LazyInit() // NS_StartupNativeCharsetUtils, assume we are called early enough that // we are the first to care about the locale's charset. if (!gLock) { - setlocale(LC_CTYPE, ""); + + if (mozilla::Preferences::GetBool("javascript.use_us_english_locale", false)) { + setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "C"); + } else { + setlocale(LC_CTYPE, ""); + } } const char* blank_list[] = { "", nullptr }; const char** native_charset_list = blank_list; @@ -884,7 +890,11 @@ NS_StartupNativeCharsetUtils() // XXX we assume that we are called early enough that we should // always be the first to care about the locale's charset. // - setlocale(LC_CTYPE, ""); + if (mozilla::Preferences::GetBool("javascript.use_us_english_locale", false)) { + setlocale(LC_CTYPE, "C.UTF-8") || setlocale(LC_CTYPE, "C"); + } else { + setlocale(LC_CTYPE, ""); + } nsNativeCharsetConverter::GlobalInit(); }
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 1372072 - Part 2: Add a test case for check whether network information API has been spoofed correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein, baku
by gk@torproject.org 14 Dec '17

14 Dec '17
commit a72faadea544a71ae5ca95ec816f2684c205b56a Author: Tim Huang <tihuang(a)mozilla.com> Date: Wed Dec 13 15:35:50 2017 -0200 Bug 1372072 - Part 2: Add a test case for check whether network information API has been spoofed correctly when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku This adds a test case to test that network information is correctly spoofed when 'privacy.resistFingerprinting' is true. Firefox ESR 52 does not have the navigation object inside workers. Thus, the worker test was removed. MozReview-Commit-ID: Lt6HZlFrcja --HG-- extra : rebase_source : 70d44115532549814af9fce3af9fe379e36bca80 --- .../resistfingerprinting/test/browser/browser.ini | 1 + .../test/browser/browser_netInfo.js | 32 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini index 4b81c91d8c6c..b596f437caa2 100644 --- a/browser/components/resistfingerprinting/test/browser/browser.ini +++ b/browser/components/resistfingerprinting/test/browser/browser.ini @@ -4,6 +4,7 @@ support-files = file_dummy.html head.js +[browser_netInfo.js] [browser_roundedWindow_dialogWindow.js] [browser_roundedWindow_newWindow.js] [browser_roundedWindow_open_max.js] diff --git a/browser/components/resistfingerprinting/test/browser/browser_netInfo.js b/browser/components/resistfingerprinting/test/browser/browser_netInfo.js new file mode 100644 index 000000000000..7c6114212ffd --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_netInfo.js @@ -0,0 +1,32 @@ +/** + * Bug 1372072 - A test case for check whether network information API has been + * spoofed correctly when 'privacy.resistFingerprinting' is true; + */ + +const TEST_PATH = "http://example.net/browser/browser/" + + "components/resistfingerprinting/test/browser/" + +async function testWindow() { + // Open a tab to test network information in a content. + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, TEST_PATH + "file_dummy.html"); + + await ContentTask.spawn(tab.linkedBrowser, null, async function() { + ok("connection" in content.navigator, "navigator.connection should exist"); + + is(content.navigator.connection.type, "unknown", "The connection type is spoofed correctly"); + }); + + await BrowserTestUtils.removeTab(tab); +} + +add_task(async function runTest() { + await SpecialPowers.pushPrefEnv({"set": + [ + ["privacy.resistFingerprinting", true], + ["dom.netinfo.enabled", true] + ] + }); + + await testWindow(); +});
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r=arthuredelstein, baku
by gk@torproject.org 14 Dec '17

14 Dec '17
commit a1beadc5b70e1b6e4727506656723684cf3225bf Author: Tim Huang <tihuang(a)mozilla.com> Date: Wed Dec 13 15:29:00 2017 -0200 Bug 1372072 - Part 1: Spoofing network information API and blocking ontypechange event when 'privacy.resistFingerprinting' is true. r=arthuredelstein,baku This patch makes the network information API always returns the default type 'unknown' and blocking the ontypechange event while connection type changed when 'privacy. resistFingerprinting' is true. MozReview-Commit-ID: 4eOdHgAGtyY --HG-- extra : rebase_source : 78449fb4888b787062ff2139e36c219e0eac0b2c --- dom/network/Connection.cpp | 3 ++- dom/network/Connection.h | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dom/network/Connection.cpp b/dom/network/Connection.cpp index 3bf6f40384a6..cc06b5e14b6a 100644 --- a/dom/network/Connection.cpp +++ b/dom/network/Connection.cpp @@ -78,7 +78,8 @@ Connection::Notify(const hal::NetworkInformation& aNetworkInfo) UpdateFromNetworkInfo(aNetworkInfo); - if (previousType == mType) { + if (previousType == mType || + nsContentUtils::ShouldResistFingerprinting()) { return; } diff --git a/dom/network/Connection.h b/dom/network/Connection.h index 907aea144bc0..19e00d93c907 100644 --- a/dom/network/Connection.h +++ b/dom/network/Connection.h @@ -13,6 +13,7 @@ #include "mozilla/dom/NetworkInformationBinding.h" #include "nsCycleCollectionParticipant.h" #include "nsINetworkProperties.h" +#include "nsContentUtils.h" namespace mozilla { @@ -44,7 +45,11 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; - ConnectionType Type() const { return mType; } + ConnectionType Type() const + { + return nsContentUtils::ShouldResistFingerprinting() ? + static_cast<ConnectionType>(ConnectionType::Unknown) : mType; + } IMPL_EVENT_HANDLER(typechange)
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 24398: Plugin-container process exhausts memory
by gk@torproject.org 13 Dec '17

13 Dec '17
commit cef2fe28a238d7e445d7c5b4292bfe27c1b71bca Author: Georg Koppen <gk(a)torproject.org> Date: Wed Dec 13 14:15:57 2017 +0000 Bug 24398: Plugin-container process exhausts memory The plugin-container process can thrash/crash due to increasing memory consumption after our workaround for bug 24052. The patch provided by a cypherpunk (bug thanks!) deals with that as far as the Developer Tools are concerned. --- devtools/shared/DevToolsUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devtools/shared/DevToolsUtils.js b/devtools/shared/DevToolsUtils.js index d44184fd6b8e..926420154fe5 100644 --- a/devtools/shared/DevToolsUtils.js +++ b/devtools/shared/DevToolsUtils.js @@ -559,7 +559,8 @@ function newChannelForURL(url, { policy, window, principal }) { try { return NetUtil.newChannel(channelOptions); - } catch (e) { + } catch (e if e.name === "NS_ERROR_UNKNOWN_PROTOCOL" && + !(url.startsWith("file://"))) { // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel() // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't // supported by Windows, so we also need to handle the exception here if
1 0
0 0
[tor-browser/tor-browser-52.5.2esr-7.5-2] Bug 23104: Add a default line height compensation
by gk@torproject.org 13 Dec '17

13 Dec '17
commit 89d8bc54cfe6a4cd999ab1f16f434c4fb809b643 Author: Igor Oliveira <igor.oliveira(a)posteo.net> Date: Sun Dec 10 18:16:59 2017 -0200 Bug 23104: Add a default line height compensation Many fonts have issues with their vertical metrics. they are used to influence the height of ascenders and depth of descenders. Gecko uses it to calculate the line height (font height + ascender + descender), however because of that idiosyncratic behavior across multiple operating systems, it can be used to identify the user's OS. The solution proposed in the patch uses a default factor to be multiplied with the font size, simulating the concept of ascender and descender. This way all operating systems will have the same line height only and only if the frame is outside the chrome. --- layout/generic/ReflowInput.cpp | 16 +++++++++---- tbb-tests/mochitest.ini | 1 + tbb-tests/test_tor_bug23104.html | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp index 42f4a24b5314..cda602c50431 100644 --- a/layout/generic/ReflowInput.cpp +++ b/layout/generic/ReflowInput.cpp @@ -30,6 +30,7 @@ #include "CounterStyleManager.h" #include <algorithm> #include "mozilla/dom/HTMLInputElement.h" +#include "nsContentUtils.h" #ifdef DEBUG #undef NOISY_VERTICAL_ALIGN @@ -2759,7 +2760,7 @@ ReflowInput::CalculateBlockSideMargins(nsIAtom* aFrameType) // For risk management, we use preference to control the behavior, and // eNoExternalLeading is the old behavior. static nscoord -GetNormalLineHeight(nsFontMetrics* aFontMetrics) +GetNormalLineHeight(nsIContent* aContent, nsFontMetrics* aFontMetrics) { NS_PRECONDITION(nullptr != aFontMetrics, "no font metrics"); @@ -2768,6 +2769,12 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics) nscoord externalLeading = aFontMetrics->ExternalLeading(); nscoord internalLeading = aFontMetrics->InternalLeading(); nscoord emHeight = aFontMetrics->EmHeight(); + + if (nsContentUtils::ShouldResistFingerprinting() && + !aContent->IsInChromeDocument()) { + return NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR); + } + switch (GetNormalLineHeightCalcControl()) { case eIncludeExternalLeading: normalLineHeight = emHeight+ internalLeading + externalLeading; @@ -2786,7 +2793,8 @@ GetNormalLineHeight(nsFontMetrics* aFontMetrics) } static inline nscoord -ComputeLineHeight(nsStyleContext* aStyleContext, +ComputeLineHeight(nsIContent* aContent, + nsStyleContext* aStyleContext, nscoord aBlockBSize, float aFontSizeInflation) { @@ -2821,7 +2829,7 @@ ComputeLineHeight(nsStyleContext* aStyleContext, RefPtr<nsFontMetrics> fm = nsLayoutUtils:: GetFontMetricsForStyleContext(aStyleContext, aFontSizeInflation); - return GetNormalLineHeight(fm); + return GetNormalLineHeight(aContent, fm); } nscoord @@ -2844,7 +2852,7 @@ ReflowInput::CalcLineHeight(nsIContent* aContent, NS_PRECONDITION(aStyleContext, "Must have a style context"); nscoord lineHeight = - ComputeLineHeight(aStyleContext, aBlockBSize, aFontSizeInflation); + ComputeLineHeight(aContent, aStyleContext, aBlockBSize, aFontSizeInflation); NS_ASSERTION(lineHeight >= 0, "ComputeLineHeight screwed up"); diff --git a/tbb-tests/mochitest.ini b/tbb-tests/mochitest.ini index 3d2e7c9db803..fca972a51211 100644 --- a/tbb-tests/mochitest.ini +++ b/tbb-tests/mochitest.ini @@ -10,3 +10,4 @@ support-files = [test_tor_bug2875.html] [test_tor_bug4755.html] [test_tor_bug5856.html] +[test_tor_bug23104.html] diff --git a/tbb-tests/test_tor_bug23104.html b/tbb-tests/test_tor_bug23104.html new file mode 100644 index 000000000000..ae73a3446037 --- /dev/null +++ b/tbb-tests/test_tor_bug23104.html @@ -0,0 +1,51 @@ +<!DOCTYPE HTML> +<meta charset="UTF-8"> +<html> +<head> + <title>Test for Tor Bug #23104: CSS line-height reveals the platform Tor browser is running</title> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> + <style type="text/css"> + span { + background-color: #000; + color: #fff; + font-size: 16.5px; + } + </style> +</head> +<body> +<span id="test1">Test1</span> +<span id="test2">كلمة</span> +<span id="test3">ação</span> +<script type="application/javascript;version=1.7"> + +let setPref = function* (key, value) { + return new Promise(function(resolve, reject) { + SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve); + }); +} + +function getStyle(el, styleprop) { + el = document.getElementById(el); + return document.defaultView.getComputedStyle(el, null).getPropertyValue(styleprop); +} + +function validateElement(elementName, isFingerprintResistent) { + var fontSize = getStyle(elementName, 'font-size'); + var lineHeight = getStyle(elementName, 'line-height'); + var validationCb = isFingerprintResistent ? is : isnot; + validationCb(parseFloat(lineHeight), parseFloat(fontSize) * 1.2, 'Line Height validation'); +} + +add_task(function* () { + for (let resistFingerprintingValue of [true, false]) { + yield setPref("privacy.resistFingerprinting", resistFingerprintingValue); + for (let elementId of ['test1', 'test2', 'test3']) { + validateElement(elementId, resistFingerprintingValue); + } + } +}); + +</script> +</body> +</html>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 1514
  • 1515
  • 1516
  • 1517
  • 1518
  • 1519
  • 1520
  • ...
  • 1855
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.