2008-10-01 07:04:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
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/. */
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2008-10-01 07:04:10 +04:00
|
|
|
|
|
|
|
#include "gfxUserFontSet.h"
|
|
|
|
#include "gfxPlatform.h"
|
2017-02-16 20:16:09 +03:00
|
|
|
#include "gfxPrefs.h"
|
2012-03-16 07:31:01 +04:00
|
|
|
#include "nsIProtocolHandler.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "gfxFontConstants.h"
|
2014-11-06 07:42:50 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-05-22 08:39:47 +04:00
|
|
|
#include "mozilla/Services.h"
|
2015-11-25 08:48:16 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-04-17 18:17:22 +04:00
|
|
|
#include "gfxPlatformFontList.h"
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
|
|
|
#include "mozilla/PostTraversalTask.h"
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2010-10-07 11:59:19 +04:00
|
|
|
#include "opentype-sanitiser.h"
|
|
|
|
#include "ots-memory-stream.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-10-29 06:45:42 +03:00
|
|
|
mozilla::LogModule*
|
2012-10-30 03:32:10 +04:00
|
|
|
gfxUserFontSet::GetUserFontsLog()
|
|
|
|
{
|
2015-10-29 06:45:42 +03:00
|
|
|
static LazyLogModule sLog("userfonts");
|
2012-10-30 03:32:10 +04:00
|
|
|
return sLog;
|
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gfxUserFontSet::GetUserFontsLog(), mozilla::LogLevel::Debug, args)
|
|
|
|
#define LOG_ENABLED() MOZ_LOG_TEST(gfxUserFontSet::GetUserFontsLog(), mozilla::LogLevel::Debug)
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2012-11-02 04:57:25 +04:00
|
|
|
static uint64_t sFontSetGeneration = 0;
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2010-10-07 11:59:19 +04:00
|
|
|
// Based on ots::ExpandingMemoryStream from ots-memory-stream.h,
|
|
|
|
// adapted to use Mozilla allocators and to allow the final
|
|
|
|
// memory buffer to be adopted by the client.
|
|
|
|
class ExpandingMemoryStream : public ots::OTSStream {
|
|
|
|
public:
|
|
|
|
ExpandingMemoryStream(size_t initial, size_t limit)
|
|
|
|
: mLength(initial), mLimit(limit), mOff(0) {
|
2015-04-01 08:29:55 +03:00
|
|
|
mPtr = moz_xmalloc(mLength);
|
2010-10-07 11:59:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~ExpandingMemoryStream() {
|
2015-04-01 08:29:55 +03:00
|
|
|
free(mPtr);
|
2010-10-07 11:59:19 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 14:14:34 +03:00
|
|
|
// Return the buffer, resized to fit its contents (as it may have been
|
|
|
|
// over-allocated during growth), and give up ownership of it so the
|
|
|
|
// caller becomes responsible to call free() when finished with it.
|
2010-10-07 11:59:19 +04:00
|
|
|
void* forget() {
|
2016-05-03 14:14:34 +03:00
|
|
|
void* p = moz_xrealloc(mPtr, mOff);
|
2012-07-30 18:20:58 +04:00
|
|
|
mPtr = nullptr;
|
2010-10-07 11:59:19 +04:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
bool WriteRaw(const void* data, size_t length) {
|
2010-10-07 11:59:19 +04:00
|
|
|
if ((mOff + length > mLength) ||
|
|
|
|
(mLength > std::numeric_limits<size_t>::max() - mOff)) {
|
|
|
|
if (mLength == mLimit) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
size_t newLength = (mLength + 1) * 2;
|
|
|
|
if (newLength < mLength) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (newLength > mLimit) {
|
|
|
|
newLength = mLimit;
|
|
|
|
}
|
2015-04-01 08:29:55 +03:00
|
|
|
mPtr = moz_xrealloc(mPtr, newLength);
|
2010-10-07 11:59:19 +04:00
|
|
|
mLength = newLength;
|
|
|
|
return WriteRaw(data, length);
|
|
|
|
}
|
|
|
|
std::memcpy(static_cast<char*>(mPtr) + mOff, data, length);
|
|
|
|
mOff += length;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Seek(off_t position) {
|
|
|
|
if (position < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (static_cast<size_t>(position) > mLength) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mOff = position;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
off_t Tell() const {
|
|
|
|
return mOff;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void* mPtr;
|
|
|
|
size_t mLength;
|
|
|
|
const size_t mLimit;
|
|
|
|
off_t mOff;
|
|
|
|
};
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::gfxUserFontEntry(gfxUserFontSet* aFontSet,
|
2014-07-09 11:08:52 +04:00
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-07-09 11:08:52 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2017-04-20 10:00:59 +03:00
|
|
|
gfxCharacterMap* aUnicodeRanges,
|
2016-01-07 08:03:05 +03:00
|
|
|
uint8_t aFontDisplay)
|
2014-09-08 11:23:20 +04:00
|
|
|
: gfxFontEntry(NS_LITERAL_STRING("userfont")),
|
2014-09-25 07:16:53 +04:00
|
|
|
mUserFontLoadState(STATUS_NOT_LOADED),
|
|
|
|
mFontDataLoadingState(NOT_LOADING),
|
2014-07-09 11:08:52 +04:00
|
|
|
mUnsupportedFormat(false),
|
2016-01-07 08:03:05 +03:00
|
|
|
mFontDisplay(aFontDisplay),
|
2014-07-09 11:08:52 +04:00
|
|
|
mLoader(nullptr),
|
|
|
|
mFontSet(aFontSet)
|
|
|
|
{
|
2014-10-02 06:32:06 +04:00
|
|
|
MOZ_ASSERT(aWeight != 0,
|
|
|
|
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
|
2014-09-08 11:23:20 +04:00
|
|
|
mIsUserFontContainer = true;
|
2014-07-09 11:08:52 +04:00
|
|
|
mSrcList = aFontFaceSrcList;
|
|
|
|
mSrcIndex = 0;
|
|
|
|
mWeight = aWeight;
|
|
|
|
mStretch = aStretch;
|
2015-10-19 05:16:43 +03:00
|
|
|
mStyle = aStyle;
|
2014-07-09 11:08:52 +04:00
|
|
|
mFeatureSettings.AppendElements(aFeatureSettings);
|
|
|
|
mLanguageOverride = aLanguageOverride;
|
2017-04-20 10:00:59 +03:00
|
|
|
mCharacterMap = aUnicodeRanges;
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::~gfxUserFontEntry()
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
// Assert that we don't drop any gfxUserFontEntry objects during a Servo
|
|
|
|
// traversal, since PostTraversalTask objects can hold raw pointers to
|
|
|
|
// gfxUserFontEntry objects.
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal());
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::Matches(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-09-08 11:23:20 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2017-04-20 10:00:59 +03:00
|
|
|
gfxCharacterMap* aUnicodeRanges,
|
2016-01-07 08:03:05 +03:00
|
|
|
uint8_t aFontDisplay)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
|
|
|
return mWeight == aWeight &&
|
|
|
|
mStretch == aStretch &&
|
2015-10-19 05:16:43 +03:00
|
|
|
mStyle == aStyle &&
|
2014-07-09 11:08:52 +04:00
|
|
|
mFeatureSettings == aFeatureSettings &&
|
|
|
|
mLanguageOverride == aLanguageOverride &&
|
2014-11-06 07:42:50 +03:00
|
|
|
mSrcList == aFontFaceSrcList &&
|
2016-01-07 08:03:05 +03:00
|
|
|
mFontDisplay == aFontDisplay &&
|
2014-11-06 07:42:50 +03:00
|
|
|
((!aUnicodeRanges && !mCharacterMap) ||
|
|
|
|
(aUnicodeRanges && mCharacterMap && mCharacterMap->Equals(aUnicodeRanges)));
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFont*
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::CreateFontInstance(const gfxFontStyle* aFontStyle, bool aNeedsBold)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
2014-09-08 11:23:20 +04:00
|
|
|
NS_NOTREACHED("should only be creating a gfxFont"
|
|
|
|
" with an actual platform font entry");
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// userfont entry is a container, can't create font from the container
|
2014-07-09 11:08:52 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-08-23 18:12:00 +04:00
|
|
|
class gfxOTSContext : public ots::OTSContext {
|
|
|
|
public:
|
2014-09-09 04:48:12 +04:00
|
|
|
explicit gfxOTSContext(gfxUserFontEntry* aUserFontEntry)
|
2017-02-16 20:16:09 +03:00
|
|
|
: mUserFontEntry(aUserFontEntry)
|
|
|
|
{
|
|
|
|
// Whether to apply OTS validation to OpenType Layout tables
|
|
|
|
mCheckOTLTables = gfxPrefs::ValidateOTLTables();
|
2017-02-20 21:00:54 +03:00
|
|
|
// Whether to preserve Variation tables in downloaded fonts
|
|
|
|
mKeepVariationTables = gfxPrefs::KeepVariationTables();
|
2017-02-16 20:16:09 +03:00
|
|
|
}
|
2014-08-23 18:12:00 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual ots::TableAction GetTableAction(uint32_t aTag) override {
|
2017-02-16 20:16:09 +03:00
|
|
|
// Preserve Graphite, color glyph and SVG tables,
|
2017-02-20 21:00:54 +03:00
|
|
|
// and possibly OTL and Variation tables (depending on prefs)
|
2017-02-16 20:16:09 +03:00
|
|
|
if ((!mCheckOTLTables &&
|
|
|
|
(aTag == TRUETYPE_TAG('G', 'D', 'E', 'F') ||
|
|
|
|
aTag == TRUETYPE_TAG('G', 'P', 'O', 'S') ||
|
|
|
|
aTag == TRUETYPE_TAG('G', 'S', 'U', 'B'))) ||
|
2017-02-20 21:00:54 +03:00
|
|
|
(mKeepVariationTables &&
|
|
|
|
(aTag == TRUETYPE_TAG('a', 'v', 'a', 'r') ||
|
|
|
|
aTag == TRUETYPE_TAG('c', 'v', 'a', 'r') ||
|
|
|
|
aTag == TRUETYPE_TAG('f', 'v', 'a', 'r') ||
|
|
|
|
aTag == TRUETYPE_TAG('g', 'v', 'a', 'r') ||
|
|
|
|
aTag == TRUETYPE_TAG('H', 'V', 'A', 'R') ||
|
|
|
|
aTag == TRUETYPE_TAG('M', 'V', 'A', 'R') ||
|
|
|
|
aTag == TRUETYPE_TAG('V', 'V', 'A', 'R'))) ||
|
2016-02-03 12:22:58 +03:00
|
|
|
aTag == TRUETYPE_TAG('S', 'i', 'l', 'f') ||
|
2014-08-23 18:12:00 +04:00
|
|
|
aTag == TRUETYPE_TAG('S', 'i', 'l', 'l') ||
|
|
|
|
aTag == TRUETYPE_TAG('G', 'l', 'o', 'c') ||
|
|
|
|
aTag == TRUETYPE_TAG('G', 'l', 'a', 't') ||
|
|
|
|
aTag == TRUETYPE_TAG('F', 'e', 'a', 't') ||
|
|
|
|
aTag == TRUETYPE_TAG('S', 'V', 'G', ' ') ||
|
|
|
|
aTag == TRUETYPE_TAG('C', 'O', 'L', 'R') ||
|
|
|
|
aTag == TRUETYPE_TAG('C', 'P', 'A', 'L')) {
|
|
|
|
return ots::TABLE_ACTION_PASSTHRU;
|
|
|
|
}
|
|
|
|
return ots::TABLE_ACTION_DEFAULT;
|
2014-01-31 19:09:20 +04:00
|
|
|
}
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-10-09 11:43:30 +04:00
|
|
|
virtual void Message(int level, const char* format,
|
2015-03-21 19:28:04 +03:00
|
|
|
...) MSGFUNC_FMT_ATTR override {
|
2014-08-23 18:12:00 +04:00
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-10-10 17:50:52 +04:00
|
|
|
nsCString msg;
|
|
|
|
msg.AppendPrintf(format, va);
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-08-23 18:12:00 +04:00
|
|
|
va_end(va);
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-10-10 17:50:52 +04:00
|
|
|
if (level > 0) {
|
|
|
|
// For warnings (rather than errors that cause the font to fail),
|
|
|
|
// we only report the first instance of any given message.
|
|
|
|
if (mWarningsIssued.Contains(msg)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mWarningsIssued.PutEntry(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
mUserFontEntry->mFontSet->LogMessage(mUserFontEntry, msg.get());
|
2014-08-23 18:12:00 +04:00
|
|
|
}
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-08-23 18:12:00 +04:00
|
|
|
private:
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry* mUserFontEntry;
|
2014-10-10 17:50:52 +04:00
|
|
|
nsTHashtable<nsCStringHashKey> mWarningsIssued;
|
2017-02-16 20:16:09 +03:00
|
|
|
bool mCheckOTLTables;
|
2017-02-20 21:00:54 +03:00
|
|
|
bool mKeepVariationTables;
|
2014-08-23 18:12:00 +04:00
|
|
|
};
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2010-10-07 11:59:19 +04:00
|
|
|
// Call the OTS library to sanitize an sfnt before attempting to use it.
|
2013-07-31 19:44:31 +04:00
|
|
|
// Returns a newly-allocated block, or nullptr in case of fatal errors.
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t*
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::SanitizeOpenTypeData(const uint8_t* aData,
|
2014-09-08 11:23:20 +04:00
|
|
|
uint32_t aLength,
|
|
|
|
uint32_t& aSaneLength,
|
2014-10-04 14:36:05 +04:00
|
|
|
gfxUserFontType aFontType)
|
2010-10-07 11:59:19 +04:00
|
|
|
{
|
2014-10-04 14:36:05 +04:00
|
|
|
if (aFontType == GFX_USERFONT_UNKNOWN) {
|
|
|
|
aSaneLength = 0;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t lengthHint = aLength;
|
|
|
|
if (aFontType == GFX_USERFONT_WOFF) {
|
|
|
|
lengthHint *= 2;
|
|
|
|
} else if (aFontType == GFX_USERFONT_WOFF2) {
|
|
|
|
lengthHint *= 3;
|
|
|
|
}
|
|
|
|
|
2010-10-07 11:59:19 +04:00
|
|
|
// limit output/expansion to 256MB
|
2014-10-04 14:36:05 +04:00
|
|
|
ExpandingMemoryStream output(lengthHint, 1024 * 1024 * 256);
|
2012-05-30 02:44:50 +04:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxOTSContext otsContext(this);
|
2016-05-03 14:14:34 +03:00
|
|
|
if (!otsContext.Process(&output, aData, aLength)) {
|
|
|
|
// Failed to decode/sanitize the font, so discard it.
|
2010-10-07 11:59:19 +04:00
|
|
|
aSaneLength = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-10-07 11:59:19 +04:00
|
|
|
}
|
2016-05-03 14:14:34 +03:00
|
|
|
|
|
|
|
aSaneLength = output.Tell();
|
|
|
|
return static_cast<const uint8_t*>(output.forget());
|
2010-10-07 11:59:19 +04:00
|
|
|
}
|
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
void
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry::StoreUserFontData(gfxFontEntry* aFontEntry,
|
|
|
|
bool aPrivate,
|
|
|
|
const nsAString& aOriginalName,
|
|
|
|
FallibleTArray<uint8_t>* aMetadata,
|
2014-10-04 14:46:54 +04:00
|
|
|
uint32_t aMetaOrigLen,
|
|
|
|
uint8_t aCompression)
|
2011-06-16 10:31:37 +04:00
|
|
|
{
|
|
|
|
if (!aFontEntry->mUserFontData) {
|
2016-04-15 22:45:37 +03:00
|
|
|
aFontEntry->mUserFontData = MakeUnique<gfxUserFontData>();
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2016-04-15 22:45:37 +03:00
|
|
|
gfxUserFontData* userFontData = aFontEntry->mUserFontData.get();
|
2014-07-09 11:08:52 +04:00
|
|
|
userFontData->mSrcIndex = mSrcIndex;
|
|
|
|
const gfxFontFaceSrc& src = mSrcList[mSrcIndex];
|
2014-10-02 06:32:09 +04:00
|
|
|
switch (src.mSourceType) {
|
|
|
|
case gfxFontFaceSrc::eSourceType_Local:
|
|
|
|
userFontData->mLocalName = src.mLocalName;
|
|
|
|
break;
|
|
|
|
case gfxFontFaceSrc::eSourceType_URL:
|
|
|
|
userFontData->mURI = src.mURI;
|
|
|
|
userFontData->mPrincipal = mPrincipal;
|
|
|
|
break;
|
|
|
|
case gfxFontFaceSrc::eSourceType_Buffer:
|
|
|
|
userFontData->mIsBuffer = true;
|
|
|
|
break;
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2013-05-22 10:42:30 +04:00
|
|
|
userFontData->mPrivate = aPrivate;
|
2011-06-16 10:31:37 +04:00
|
|
|
userFontData->mFormat = src.mFormatFlags;
|
2011-06-16 10:31:37 +04:00
|
|
|
userFontData->mRealName = aOriginalName;
|
2011-06-16 10:31:37 +04:00
|
|
|
if (aMetadata) {
|
|
|
|
userFontData->mMetadata.SwapElements(*aMetadata);
|
|
|
|
userFontData->mMetaOrigLen = aMetaOrigLen;
|
2014-10-04 14:46:54 +04:00
|
|
|
userFontData->mCompression = aCompression;
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 14:14:35 +03:00
|
|
|
size_t
|
|
|
|
gfxUserFontData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this)
|
|
|
|
+ mMetadata.ShallowSizeOfExcludingThis(aMallocSizeOf)
|
|
|
|
+ mLocalName.SizeOfExcludingThisIfUnshared(aMallocSizeOf)
|
|
|
|
+ mRealName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
// Not counting mURI and mPrincipal, as those will be shared.
|
|
|
|
}
|
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
/*virtual*/
|
|
|
|
gfxUserFontFamily::~gfxUserFontFamily()
|
|
|
|
{
|
|
|
|
// Should not be dropped by stylo
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::GetFamilyNameAndURIForLogging(nsACString& aFamilyName,
|
|
|
|
nsACString& aURI)
|
|
|
|
{
|
|
|
|
aFamilyName.Assign(NS_ConvertUTF16toUTF8(mFamilyName));
|
|
|
|
|
|
|
|
aURI.Truncate();
|
|
|
|
if (mSrcIndex == mSrcList.Length()) {
|
|
|
|
aURI.AppendLiteral("(end of source list)");
|
|
|
|
} else {
|
|
|
|
if (mSrcList[mSrcIndex].mURI) {
|
|
|
|
mSrcList[mSrcIndex].mURI->GetSpec(aURI);
|
2017-01-18 23:38:04 +03:00
|
|
|
// If the source URI was very long, elide the middle of it.
|
|
|
|
// In principle, the byte-oriented chopping here could leave us
|
|
|
|
// with partial UTF-8 characters at the point where we cut it,
|
|
|
|
// but it really doesn't matter as this is just for logging.
|
|
|
|
const uint32_t kMaxURILengthForLogging = 256;
|
|
|
|
// UTF-8 ellipsis, with spaces to allow additional wrap opportunities
|
|
|
|
// in the resulting log message
|
|
|
|
const char kEllipsis[] = { ' ', '\xE2', '\x80', '\xA6', ' ' };
|
|
|
|
if (aURI.Length() > kMaxURILengthForLogging) {
|
|
|
|
aURI.Replace(kMaxURILengthForLogging / 2,
|
|
|
|
aURI.Length() - kMaxURILengthForLogging,
|
|
|
|
kEllipsis, ArrayLength(kEllipsis));
|
|
|
|
}
|
2014-10-02 06:32:05 +04:00
|
|
|
} else {
|
|
|
|
aURI.AppendLiteral("(invalid URI)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-09 06:05:33 +04:00
|
|
|
struct WOFFHeader {
|
|
|
|
AutoSwap_PRUint32 signature;
|
|
|
|
AutoSwap_PRUint32 flavor;
|
|
|
|
AutoSwap_PRUint32 length;
|
|
|
|
AutoSwap_PRUint16 numTables;
|
|
|
|
AutoSwap_PRUint16 reserved;
|
|
|
|
AutoSwap_PRUint32 totalSfntSize;
|
|
|
|
AutoSwap_PRUint16 majorVersion;
|
|
|
|
AutoSwap_PRUint16 minorVersion;
|
|
|
|
AutoSwap_PRUint32 metaOffset;
|
|
|
|
AutoSwap_PRUint32 metaCompLen;
|
|
|
|
AutoSwap_PRUint32 metaOrigLen;
|
|
|
|
AutoSwap_PRUint32 privOffset;
|
|
|
|
AutoSwap_PRUint32 privLen;
|
|
|
|
};
|
|
|
|
|
2014-10-04 14:46:54 +04:00
|
|
|
struct WOFF2Header {
|
|
|
|
AutoSwap_PRUint32 signature;
|
|
|
|
AutoSwap_PRUint32 flavor;
|
|
|
|
AutoSwap_PRUint32 length;
|
|
|
|
AutoSwap_PRUint16 numTables;
|
|
|
|
AutoSwap_PRUint16 reserved;
|
|
|
|
AutoSwap_PRUint32 totalSfntSize;
|
|
|
|
AutoSwap_PRUint32 totalCompressedSize;
|
|
|
|
AutoSwap_PRUint16 majorVersion;
|
|
|
|
AutoSwap_PRUint16 minorVersion;
|
|
|
|
AutoSwap_PRUint32 metaOffset;
|
|
|
|
AutoSwap_PRUint32 metaCompLen;
|
|
|
|
AutoSwap_PRUint32 metaOrigLen;
|
|
|
|
AutoSwap_PRUint32 privOffset;
|
|
|
|
AutoSwap_PRUint32 privLen;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename HeaderT>
|
|
|
|
void
|
2014-07-09 11:08:52 +04:00
|
|
|
CopyWOFFMetadata(const uint8_t* aFontData,
|
|
|
|
uint32_t aLength,
|
|
|
|
FallibleTArray<uint8_t>* aMetadata,
|
|
|
|
uint32_t* aMetaOrigLen)
|
2011-06-16 10:31:37 +04:00
|
|
|
{
|
|
|
|
// This function may be called with arbitrary, unvalidated "font" data
|
|
|
|
// from @font-face, so it needs to be careful to bounds-check, etc.,
|
|
|
|
// before trying to read anything.
|
|
|
|
// This just saves a copy of the compressed data block; it does NOT check
|
|
|
|
// that the block can be successfully decompressed, or that it contains
|
|
|
|
// well-formed/valid XML metadata.
|
2014-10-04 14:46:54 +04:00
|
|
|
if (aLength < sizeof(HeaderT)) {
|
2011-06-16 10:31:37 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-10-04 14:46:54 +04:00
|
|
|
const HeaderT* woff =
|
|
|
|
reinterpret_cast<const HeaderT*>(aFontData);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t metaOffset = woff->metaOffset;
|
|
|
|
uint32_t metaCompLen = woff->metaCompLen;
|
2011-06-16 10:31:37 +04:00
|
|
|
if (!metaOffset || !metaCompLen || !woff->metaOrigLen) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-09 11:08:52 +04:00
|
|
|
if (metaOffset >= aLength || metaCompLen > aLength - metaOffset) {
|
|
|
|
return;
|
2014-07-09 15:03:19 +04:00
|
|
|
}
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!aMetadata->SetLength(woff->metaCompLen, fallible)) {
|
2014-07-09 11:08:52 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(aMetadata->Elements(), aFontData + metaOffset, metaCompLen);
|
|
|
|
*aMetaOrigLen = woff->metaOrigLen;
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::LoadNextSrc()
|
2008-10-01 07:04:10 +04:00
|
|
|
{
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
NS_ASSERTION(mSrcIndex < mSrcList.Length(),
|
2011-07-12 15:24:36 +04:00
|
|
|
"already at the end of the src list for user font");
|
2014-09-25 07:16:53 +04:00
|
|
|
NS_ASSERTION((mUserFontLoadState == STATUS_NOT_LOADED ||
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
mUserFontLoadState == STATUS_LOAD_PENDING ||
|
2014-09-25 07:16:53 +04:00
|
|
|
mUserFontLoadState == STATUS_LOADING) &&
|
|
|
|
mFontDataLoadingState < LOADING_FAILED,
|
|
|
|
"attempting to load a font that has either completed or failed");
|
|
|
|
|
|
|
|
if (mUserFontLoadState == STATUS_NOT_LOADED) {
|
|
|
|
SetLoadState(STATUS_LOADING);
|
|
|
|
mFontDataLoadingState = LOADING_STARTED;
|
2014-07-09 11:08:52 +04:00
|
|
|
mUnsupportedFormat = false;
|
2008-10-01 07:04:10 +04:00
|
|
|
} else {
|
2011-01-06 00:48:48 +03:00
|
|
|
// we were already loading; move to the next source,
|
|
|
|
// but don't reset state - if we've already timed out,
|
|
|
|
// that counts against the new download
|
2014-07-09 11:08:52 +04:00
|
|
|
mSrcIndex++;
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
DoLoadNextSrc(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontEntry::ContinueLoad()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mUserFontLoadState == STATUS_LOAD_PENDING);
|
|
|
|
MOZ_ASSERT(mSrcList[mSrcIndex].mSourceType == gfxFontFaceSrc::eSourceType_URL);
|
|
|
|
|
2017-06-28 21:14:18 +03:00
|
|
|
SetLoadState(STATUS_LOADING);
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
DoLoadNextSrc(true);
|
2017-06-28 21:14:18 +03:00
|
|
|
if (LoadState() != STATUS_LOADING) {
|
|
|
|
MOZ_ASSERT(mUserFontLoadState != STATUS_LOAD_PENDING,
|
|
|
|
"Not in parallel traversal, shouldn't get LOAD_PENDING again");
|
|
|
|
// Loading is synchronously finished (loaded from cache or failed). We
|
|
|
|
// need to increment the generation so that we flush the style data to
|
|
|
|
// use the new loaded font face.
|
|
|
|
// Without parallel traversal, we would simply get the right font data
|
|
|
|
// after the first call to DoLoadNextSrc() in this case, so we don't need
|
|
|
|
// to touch the generation to trigger another restyle.
|
|
|
|
// XXX We may want to return synchronously in parallel traversal in those
|
|
|
|
// cases as well if possible, so that we don't have an additional restyle.
|
|
|
|
// That doesn't work currently because nsIDocument::GetDocShell (called
|
|
|
|
// from FontFaceSet::CheckFontLoad) dereferences a weak pointer, which is
|
|
|
|
// not allowed in parallel traversal.
|
|
|
|
IncrementGeneration();
|
|
|
|
}
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
|
|
|
|
{
|
|
|
|
uint32_t numSrc = mSrcList.Length();
|
|
|
|
|
2011-07-12 15:24:36 +04:00
|
|
|
// load each src entry in turn, until a local face is found
|
|
|
|
// or a download begins successfully
|
2014-07-09 11:08:52 +04:00
|
|
|
while (mSrcIndex < numSrc) {
|
2014-10-02 06:32:09 +04:00
|
|
|
gfxFontFaceSrc& currSrc = mSrcList[mSrcIndex];
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2012-03-16 07:31:01 +04:00
|
|
|
// src local ==> lookup and load immediately
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_Local) {
|
2016-08-23 03:06:07 +03:00
|
|
|
// Don't look up local fonts if the font whitelist is being used.
|
2016-10-06 23:00:24 +03:00
|
|
|
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
|
|
|
|
gfxFontEntry* fe = pfl && pfl->IsFontFamilyWhitelistActive() ?
|
2016-08-23 03:06:07 +03:00
|
|
|
nullptr :
|
2014-09-08 11:23:19 +04:00
|
|
|
gfxPlatform::GetPlatform()->LookupLocalFont(currSrc.mLocalName,
|
|
|
|
mWeight,
|
|
|
|
mStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
mStyle);
|
2015-10-16 09:10:14 +03:00
|
|
|
nsTArray<gfxUserFontSet*> fontSets;
|
|
|
|
GetUserFontSets(fontSets);
|
|
|
|
for (gfxUserFontSet* fontSet : fontSets) {
|
|
|
|
// We need to note on each gfxUserFontSet that contains the user
|
|
|
|
// font entry that we used a local() rule.
|
|
|
|
fontSet->SetLocalRulesUsed();
|
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
if (fe) {
|
2014-10-17 04:15:29 +04:00
|
|
|
LOG(("userfonts (%p) [src %d] loaded local: (%s) for (%s) gen: %8.8x\n",
|
2014-07-09 11:08:52 +04:00
|
|
|
mFontSet, mSrcIndex,
|
2011-07-12 15:24:36 +04:00
|
|
|
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
|
2014-07-09 11:08:55 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get(),
|
2014-07-09 11:08:52 +04:00
|
|
|
uint32_t(mFontSet->mGeneration)));
|
|
|
|
fe->mFeatureSettings.AppendElements(mFeatureSettings);
|
|
|
|
fe->mLanguageOverride = mLanguageOverride;
|
2014-07-09 11:08:54 +04:00
|
|
|
fe->mFamilyName = mFamilyName;
|
2013-05-22 10:42:30 +04:00
|
|
|
// For src:local(), we don't care whether the request is from
|
|
|
|
// a private window as there's no issue of caching resources;
|
|
|
|
// local fonts are just available all the time.
|
2014-10-04 14:46:54 +04:00
|
|
|
StoreUserFontData(fe, false, nsString(), nullptr, 0,
|
|
|
|
gfxUserFontData::kUnknownCompression);
|
2014-09-08 11:23:20 +04:00
|
|
|
mPlatformFontEntry = fe;
|
2014-09-25 07:16:53 +04:00
|
|
|
SetLoadState(STATUS_LOADED);
|
2015-11-25 08:48:16 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::WEBFONT_SRCTYPE,
|
|
|
|
currSrc.mSourceType + 1);
|
2014-09-25 07:16:53 +04:00
|
|
|
return;
|
2008-10-01 07:04:10 +04:00
|
|
|
} else {
|
2014-10-17 04:15:29 +04:00
|
|
|
LOG(("userfonts (%p) [src %d] failed local: (%s) for (%s)\n",
|
2014-07-09 11:08:52 +04:00
|
|
|
mFontSet, mSrcIndex,
|
2011-07-12 15:24:36 +04:00
|
|
|
NS_ConvertUTF16toUTF8(currSrc.mLocalName).get(),
|
2014-07-09 11:08:55 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get()));
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
2011-07-12 15:24:36 +04:00
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
|
|
|
|
// src url ==> start the load process
|
2014-10-02 06:32:09 +04:00
|
|
|
else if (currSrc.mSourceType == gfxFontFaceSrc::eSourceType_URL) {
|
2017-07-08 09:10:05 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->IsFontFormatSupported(
|
2008-10-01 07:04:10 +04:00
|
|
|
currSrc.mFormatFlags)) {
|
2012-03-16 07:31:01 +04:00
|
|
|
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
if (ServoStyleSet* set = ServoStyleSet::Current()) {
|
2017-07-12 13:41:22 +03:00
|
|
|
set->AppendTask(PostTraversalTask::LoadFontEntry(this));
|
|
|
|
SetLoadState(STATUS_LOAD_PENDING);
|
|
|
|
return;
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
}
|
|
|
|
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* principal = nullptr;
|
2013-05-22 08:39:39 +04:00
|
|
|
bool bypassCache;
|
2014-07-09 11:08:52 +04:00
|
|
|
nsresult rv = mFontSet->CheckFontLoad(&currSrc, &principal,
|
|
|
|
&bypassCache);
|
2012-03-16 07:31:01 +04:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && principal != nullptr) {
|
2013-05-22 08:39:39 +04:00
|
|
|
if (!bypassCache) {
|
|
|
|
// see if we have an existing entry for this source
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxFontEntry* fe = gfxUserFontSet::
|
2014-07-09 11:08:52 +04:00
|
|
|
UserFontCache::GetFont(currSrc.mURI,
|
|
|
|
principal,
|
|
|
|
this,
|
|
|
|
mFontSet->GetPrivateBrowsing());
|
2013-05-22 08:39:39 +04:00
|
|
|
if (fe) {
|
2014-09-08 11:23:20 +04:00
|
|
|
mPlatformFontEntry = fe;
|
2014-09-25 07:16:53 +04:00
|
|
|
SetLoadState(STATUS_LOADED);
|
2015-11-25 08:48:16 +03:00
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
LOG(("userfonts (%p) [src %d] "
|
|
|
|
"loaded uri from cache: (%s) for (%s)\n",
|
2016-08-26 09:02:31 +03:00
|
|
|
mFontSet, mSrcIndex,
|
|
|
|
currSrc.mURI->GetSpecOrDefault().get(),
|
2015-11-25 08:48:16 +03:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get()));
|
|
|
|
}
|
2014-09-25 07:16:53 +04:00
|
|
|
return;
|
2013-05-22 08:39:39 +04:00
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
2012-03-16 07:31:01 +04:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
// record the principal returned by CheckFontLoad,
|
|
|
|
// for use when creating a channel
|
|
|
|
// and when caching the loaded entry
|
2014-07-09 11:08:52 +04:00
|
|
|
mPrincipal = principal;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
|
|
|
bool loadDoesntSpin = false;
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
if (!aForceAsync) {
|
2017-07-08 09:10:05 +03:00
|
|
|
loadDoesntSpin = currSrc.mURI->SyncLoadIsOK();
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
}
|
2014-07-09 11:08:52 +04:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && loadDoesntSpin) {
|
2014-09-08 11:23:20 +04:00
|
|
|
uint8_t* buffer = nullptr;
|
2012-12-10 13:31:07 +04:00
|
|
|
uint32_t bufferLength = 0;
|
|
|
|
|
|
|
|
// sync load font immediately
|
2014-07-09 11:08:52 +04:00
|
|
|
rv = mFontSet->SyncLoadFontData(this, &currSrc, buffer,
|
|
|
|
bufferLength);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) &&
|
2014-09-25 07:16:53 +04:00
|
|
|
LoadPlatformFont(buffer, bufferLength)) {
|
|
|
|
SetLoadState(STATUS_LOADED);
|
2015-11-25 08:48:16 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::WEBFONT_SRCTYPE,
|
|
|
|
currSrc.mSourceType + 1);
|
2014-09-25 07:16:53 +04:00
|
|
|
return;
|
2012-12-10 13:31:07 +04:00
|
|
|
} else {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this,
|
2014-07-09 11:08:52 +04:00
|
|
|
"font load failed",
|
|
|
|
nsIScriptError::errorFlag,
|
|
|
|
rv);
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
2014-07-09 11:08:52 +04:00
|
|
|
|
2012-03-16 07:31:01 +04:00
|
|
|
} else {
|
2012-12-10 13:31:07 +04:00
|
|
|
// otherwise load font async
|
2014-09-08 11:23:20 +04:00
|
|
|
rv = mFontSet->StartLoad(this, &currSrc);
|
2014-07-09 11:08:52 +04:00
|
|
|
bool loadOK = NS_SUCCEEDED(rv);
|
|
|
|
|
|
|
|
if (loadOK) {
|
2013-11-25 06:02:14 +04:00
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
LOG(("userfonts (%p) [src %d] loading uri: (%s) for (%s)\n",
|
2016-08-26 09:02:31 +03:00
|
|
|
mFontSet, mSrcIndex,
|
|
|
|
currSrc.mURI->GetSpecOrDefault().get(),
|
2014-07-09 11:08:55 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get()));
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
2014-09-25 07:16:53 +04:00
|
|
|
return;
|
2012-12-10 13:31:07 +04:00
|
|
|
} else {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this,
|
2014-07-09 11:08:52 +04:00
|
|
|
"download failed",
|
|
|
|
nsIScriptError::errorFlag,
|
|
|
|
rv);
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
2012-12-10 13:31:07 +04:00
|
|
|
} else {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this, "download not allowed",
|
2014-07-09 11:08:52 +04:00
|
|
|
nsIScriptError::errorFlag, rv);
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-01-05 14:14:11 +04:00
|
|
|
// We don't log a warning to the web console yet,
|
|
|
|
// as another source may load successfully
|
2014-07-09 11:08:52 +04:00
|
|
|
mUnsupportedFormat = true;
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
// FontFace buffer ==> load immediately
|
|
|
|
|
|
|
|
else {
|
|
|
|
MOZ_ASSERT(currSrc.mSourceType == gfxFontFaceSrc::eSourceType_Buffer);
|
|
|
|
|
|
|
|
uint8_t* buffer = nullptr;
|
|
|
|
uint32_t bufferLength = 0;
|
|
|
|
|
|
|
|
// sync load font immediately
|
|
|
|
currSrc.mBuffer->TakeBuffer(buffer, bufferLength);
|
|
|
|
if (buffer && LoadPlatformFont(buffer, bufferLength)) {
|
|
|
|
// LoadPlatformFont takes ownership of the buffer, so no need
|
|
|
|
// to free it here.
|
|
|
|
SetLoadState(STATUS_LOADED);
|
2015-11-25 08:48:16 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::WEBFONT_SRCTYPE,
|
|
|
|
currSrc.mSourceType + 1);
|
2014-10-02 06:32:09 +04:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
mFontSet->LogMessage(this,
|
|
|
|
"font load failed",
|
|
|
|
nsIScriptError::errorFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
mSrcIndex++;
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
if (mUnsupportedFormat) {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this, "no supported format found",
|
2014-07-09 11:08:52 +04:00
|
|
|
nsIScriptError::warningFlag);
|
2012-01-05 14:14:11 +04:00
|
|
|
}
|
|
|
|
|
2011-03-24 06:01:50 +03:00
|
|
|
// all src's failed; mark this entry as unusable (so fallback will occur)
|
2013-11-25 06:02:14 +04:00
|
|
|
LOG(("userfonts (%p) failed all src for (%s)\n",
|
2014-07-09 11:08:55 +04:00
|
|
|
mFontSet, NS_ConvertUTF16toUTF8(mFamilyName).get()));
|
2014-09-25 07:16:53 +04:00
|
|
|
mFontDataLoadingState = LOADING_FAILED;
|
|
|
|
SetLoadState(STATUS_FAILED);
|
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::SetLoadState(UserFontLoadState aLoadState)
|
|
|
|
{
|
|
|
|
mUserFontLoadState = aLoadState;
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 14:14:34 +03:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(UserFontMallocSizeOfOnAlloc)
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
bool
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
|
2012-03-16 07:31:01 +04:00
|
|
|
{
|
2014-09-25 07:16:53 +04:00
|
|
|
NS_ASSERTION((mUserFontLoadState == STATUS_NOT_LOADED ||
|
Bug 1356103 - Part 9: Use a PostTraversalTask to deal with downloadable fonts in gfxUserFontSet. r=bholley,jfkthame
Here we add a new UserFontLoadState value, STATUS_LOAD_PENDING, which
represents the state just after a gfxUserFontEntry's url()-valued source
would being loading, except that we can't start the load due to being
on a Servo style worker thread. In that case, we defer the work of
initiating the load until just after the Servo traversal is finished.
URLs that can normally be loaded synchronously, such as data: URLs
and script-implemented protocols marked as synchronous, must be
handled asynchronously when encountered during Servo traversal, since
various main-thread only work (in FontFaceSet::SyncLoadFontData) must
happen. This is a user visible change from stock Gecko, but should
only happen when font metrics for a data: URL font are requested
due to ch/ex unit resolution when layout hasn't previously requested
the font load. Hopefully nobody relies on synchronous resolution of
ch/ex units with data: URLs.
We unfortunately also can't pick gfxUserFontEntry objects out of the
UserFontCache during Servo traversal, since validating the cache
entry involves doing content policy checking, which is not thread-safe
(due in part to taking strong references to nsIPrincipals).
Platform fonts and ArrayBuffer-backed DOM FontFace objects continue
to be handled synchronously.
The PostTraversalTask does not take a strong reference to the
gfxUserFontEntry object, since it is held on to by the DOM FontFace
object, which itself won't go away before the PostTraversalTask
is run.
MozReview-Commit-ID: J9ODLsusrNV
--HG--
extra : rebase_source : d3e3d1dc187cb252750b57bcecd0b1ed77a15a7c
2017-04-30 09:57:25 +03:00
|
|
|
mUserFontLoadState == STATUS_LOAD_PENDING ||
|
2014-09-25 07:16:53 +04:00
|
|
|
mUserFontLoadState == STATUS_LOADING) &&
|
|
|
|
mFontDataLoadingState < LOADING_FAILED,
|
|
|
|
"attempting to load a font that has either completed or failed");
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxFontEntry* fe = nullptr;
|
2012-03-16 07:31:01 +04:00
|
|
|
|
|
|
|
gfxUserFontType fontType =
|
|
|
|
gfxFontUtils::DetermineFontDataType(aFontData, aLength);
|
2015-11-25 08:48:16 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::WEBFONT_FONTTYPE, uint32_t(fontType));
|
2012-03-16 07:31:01 +04:00
|
|
|
|
|
|
|
// Unwrap/decompress/sanitize or otherwise munge the downloaded data
|
|
|
|
// to make a usable sfnt structure.
|
|
|
|
|
|
|
|
// Because platform font activation code may replace the name table
|
|
|
|
// in the font with a synthetic one, we save the original name so that
|
|
|
|
// it can be reported via the nsIDOMFontFace API.
|
|
|
|
nsAutoString originalFullName;
|
|
|
|
|
2013-01-23 20:41:18 +04:00
|
|
|
// Call the OTS sanitizer; this will also decode WOFF to sfnt
|
|
|
|
// if necessary. The original data in aFontData is left unchanged.
|
|
|
|
uint32_t saneLen;
|
2015-11-25 08:48:16 +03:00
|
|
|
uint32_t fontCompressionRatio = 0;
|
2016-05-03 14:14:34 +03:00
|
|
|
size_t computedSize = 0;
|
2013-01-23 20:41:18 +04:00
|
|
|
const uint8_t* saneData =
|
2014-10-04 14:36:05 +04:00
|
|
|
SanitizeOpenTypeData(aFontData, aLength, saneLen, fontType);
|
2013-01-23 20:41:18 +04:00
|
|
|
if (!saneData) {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this, "rejected by sanitizer");
|
2016-11-14 17:54:23 +03:00
|
|
|
} else {
|
|
|
|
// Check whether saneData is a known OpenType format; it might be
|
|
|
|
// a TrueType Collection, which OTS would accept but we don't yet
|
|
|
|
// know how to handle. If so, discard.
|
|
|
|
if (gfxFontUtils::DetermineFontDataType(saneData, saneLen) !=
|
|
|
|
GFX_USERFONT_OPENTYPE) {
|
|
|
|
mFontSet->LogMessage(this, "not a supported OpenType format");
|
|
|
|
free((void*)saneData);
|
|
|
|
saneData = nullptr;
|
|
|
|
}
|
2013-01-23 20:41:18 +04:00
|
|
|
}
|
|
|
|
if (saneData) {
|
2015-11-25 08:48:16 +03:00
|
|
|
if (saneLen) {
|
|
|
|
fontCompressionRatio = uint32_t(100.0 * aLength / saneLen + 0.5);
|
|
|
|
if (fontType == GFX_USERFONT_WOFF ||
|
|
|
|
fontType == GFX_USERFONT_WOFF2) {
|
|
|
|
Telemetry::Accumulate(fontType == GFX_USERFONT_WOFF ?
|
|
|
|
Telemetry::WEBFONT_COMPRESSION_WOFF :
|
|
|
|
Telemetry::WEBFONT_COMPRESSION_WOFF2,
|
|
|
|
fontCompressionRatio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:41:18 +04:00
|
|
|
// The sanitizer ensures that we have a valid sfnt and a usable
|
|
|
|
// name table, so this should never fail unless we're out of
|
|
|
|
// memory, and GetFullNameFromSFNT is not directly exposed to
|
|
|
|
// arbitrary/malicious data from the web.
|
|
|
|
gfxFontUtils::GetFullNameFromSFNT(saneData, saneLen,
|
|
|
|
originalFullName);
|
2016-05-03 14:14:34 +03:00
|
|
|
|
|
|
|
// Record size for memory reporting purposes. We measure this now
|
|
|
|
// because by the time we potentially want to collect reports, this
|
|
|
|
// data block may have been handed off to opaque OS font APIs that
|
|
|
|
// don't allow us to retrieve or measure it directly.
|
|
|
|
// The *OnAlloc function will also tell DMD about this block, as the
|
|
|
|
// OS font code may hold on to it for an extended period.
|
|
|
|
computedSize = UserFontMallocSizeOfOnAlloc(saneData);
|
|
|
|
|
2013-01-23 20:41:18 +04:00
|
|
|
// Here ownership of saneData is passed to the platform,
|
|
|
|
// which will delete it when no longer required
|
2014-09-08 11:23:19 +04:00
|
|
|
fe = gfxPlatform::GetPlatform()->MakePlatformFont(mName,
|
|
|
|
mWeight,
|
|
|
|
mStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
mStyle,
|
2013-01-23 20:41:18 +04:00
|
|
|
saneData,
|
|
|
|
saneLen);
|
|
|
|
if (!fe) {
|
2014-09-08 11:23:20 +04:00
|
|
|
mFontSet->LogMessage(this, "not usable by platform");
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fe) {
|
2016-05-03 14:14:34 +03:00
|
|
|
fe->mComputedSizeOfUserFont = computedSize;
|
|
|
|
|
2013-01-23 20:41:18 +04:00
|
|
|
// Save a copy of the metadata block (if present) for nsIDOMFontFace
|
|
|
|
// to use if required. Ownership of the metadata block will be passed
|
|
|
|
// to the gfxUserFontData record below.
|
2014-02-08 22:10:07 +04:00
|
|
|
FallibleTArray<uint8_t> metadata;
|
2013-01-23 20:41:18 +04:00
|
|
|
uint32_t metaOrigLen = 0;
|
2014-10-04 14:46:54 +04:00
|
|
|
uint8_t compression = gfxUserFontData::kUnknownCompression;
|
2013-01-23 20:41:18 +04:00
|
|
|
if (fontType == GFX_USERFONT_WOFF) {
|
2014-10-04 14:46:54 +04:00
|
|
|
CopyWOFFMetadata<WOFFHeader>(aFontData, aLength,
|
|
|
|
&metadata, &metaOrigLen);
|
|
|
|
compression = gfxUserFontData::kZlibCompression;
|
|
|
|
} else if (fontType == GFX_USERFONT_WOFF2) {
|
|
|
|
CopyWOFFMetadata<WOFF2Header>(aFontData, aLength,
|
|
|
|
&metadata, &metaOrigLen);
|
|
|
|
compression = gfxUserFontData::kBrotliCompression;
|
2013-01-23 20:41:18 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// copy OpenType feature/language settings from the userfont entry to the
|
2012-03-16 07:31:01 +04:00
|
|
|
// newly-created font entry
|
2014-07-09 11:08:52 +04:00
|
|
|
fe->mFeatureSettings.AppendElements(mFeatureSettings);
|
|
|
|
fe->mLanguageOverride = mLanguageOverride;
|
2014-07-09 11:08:54 +04:00
|
|
|
fe->mFamilyName = mFamilyName;
|
2014-07-09 11:08:52 +04:00
|
|
|
StoreUserFontData(fe, mFontSet->GetPrivateBrowsing(), originalFullName,
|
2014-10-04 14:46:54 +04:00
|
|
|
&metadata, metaOrigLen, compression);
|
2013-11-25 06:02:14 +04:00
|
|
|
if (LOG_ENABLED()) {
|
2015-11-25 08:48:16 +03:00
|
|
|
LOG(("userfonts (%p) [src %d] loaded uri: (%s) for (%s) "
|
|
|
|
"(%p) gen: %8.8x compress: %d%%\n",
|
2016-08-26 09:02:31 +03:00
|
|
|
mFontSet, mSrcIndex,
|
|
|
|
mSrcList[mSrcIndex].mURI->GetSpecOrDefault().get(),
|
2014-07-09 11:08:55 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get(),
|
2015-11-25 08:48:16 +03:00
|
|
|
this, uint32_t(mFontSet->mGeneration), fontCompressionRatio));
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
2014-09-08 11:23:20 +04:00
|
|
|
mPlatformFontEntry = fe;
|
2014-09-25 07:16:53 +04:00
|
|
|
SetLoadState(STATUS_LOADED);
|
2014-07-09 11:08:52 +04:00
|
|
|
gfxUserFontSet::UserFontCache::CacheFont(fe);
|
2012-03-16 07:31:01 +04:00
|
|
|
} else {
|
2013-11-25 06:02:14 +04:00
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s)"
|
2012-03-16 07:31:01 +04:00
|
|
|
" error making platform font\n",
|
2016-08-26 09:02:31 +03:00
|
|
|
mFontSet, mSrcIndex,
|
|
|
|
mSrcList[mSrcIndex].mURI->GetSpecOrDefault().get(),
|
2014-07-09 11:08:55 +04:00
|
|
|
NS_ConvertUTF16toUTF8(mFamilyName).get()));
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 20:41:18 +04:00
|
|
|
// The downloaded data can now be discarded; the font entry is using the
|
|
|
|
// sanitized copy
|
2015-02-19 07:51:06 +03:00
|
|
|
free((void*)aFontData);
|
2013-01-23 20:41:18 +04:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
return fe != nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::Load()
|
|
|
|
{
|
|
|
|
if (mUserFontLoadState == STATUS_NOT_LOADED) {
|
|
|
|
LoadNextSrc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::IncrementGeneration()
|
|
|
|
{
|
|
|
|
nsTArray<gfxUserFontSet*> fontSets;
|
|
|
|
GetUserFontSets(fontSets);
|
|
|
|
for (gfxUserFontSet* fontSet : fontSets) {
|
|
|
|
fontSet->IncrementGeneration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// This is called when a font download finishes.
|
|
|
|
// Ownership of aFontData passes in here, and the font set must
|
2015-02-19 07:51:06 +03:00
|
|
|
// ensure that it is eventually deleted via free().
|
2014-09-08 11:23:20 +04:00
|
|
|
bool
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxUserFontEntry::FontDataDownloadComplete(const uint8_t* aFontData,
|
|
|
|
uint32_t aLength,
|
|
|
|
nsresult aDownloadStatus)
|
2014-09-08 11:23:20 +04:00
|
|
|
{
|
|
|
|
// forget about the loader, as we no longer potentially need to cancel it
|
|
|
|
// if the entry is obsoleted
|
|
|
|
mLoader = nullptr;
|
|
|
|
|
|
|
|
// download successful, make platform font using font data
|
2016-01-07 08:03:05 +03:00
|
|
|
if (NS_SUCCEEDED(aDownloadStatus) &&
|
|
|
|
mFontDataLoadingState != LOADING_TIMED_OUT) {
|
2014-09-25 07:16:53 +04:00
|
|
|
bool loaded = LoadPlatformFont(aFontData, aLength);
|
2014-09-08 11:23:20 +04:00
|
|
|
aFontData = nullptr;
|
|
|
|
|
|
|
|
if (loaded) {
|
2015-10-16 09:10:14 +03:00
|
|
|
IncrementGeneration();
|
2014-09-08 11:23:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// download failed
|
|
|
|
mFontSet->LogMessage(this,
|
2016-01-07 08:03:05 +03:00
|
|
|
(mFontDataLoadingState != LOADING_TIMED_OUT ?
|
|
|
|
"download failed" : "download timed out"),
|
|
|
|
nsIScriptError::errorFlag,
|
2014-09-08 11:23:20 +04:00
|
|
|
aDownloadStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFontData) {
|
2015-02-19 07:51:06 +03:00
|
|
|
free((void*)aFontData);
|
2014-09-08 11:23:20 +04:00
|
|
|
}
|
|
|
|
|
2016-01-07 08:03:05 +03:00
|
|
|
// error occurred, load next src if load not yet timed out
|
|
|
|
if (mFontDataLoadingState != LOADING_TIMED_OUT) {
|
|
|
|
LoadNextSrc();
|
|
|
|
}
|
2014-09-08 11:23:20 +04:00
|
|
|
|
|
|
|
// We ignore the status returned by LoadNext();
|
|
|
|
// even if loading failed, we need to bump the font-set generation
|
|
|
|
// and return true in order to trigger reflow, so that fallback
|
|
|
|
// will be used where the text was "masked" by the pending download
|
2015-10-16 09:10:14 +03:00
|
|
|
IncrementGeneration();
|
2014-09-08 11:23:20 +04:00
|
|
|
return true;
|
2012-03-16 07:31:01 +04:00
|
|
|
}
|
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
void
|
|
|
|
gfxUserFontEntry::GetUserFontSets(nsTArray<gfxUserFontSet*>& aResult)
|
|
|
|
{
|
|
|
|
aResult.Clear();
|
|
|
|
aResult.AppendElement(mFontSet);
|
|
|
|
}
|
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
gfxUserFontSet::gfxUserFontSet()
|
2015-11-25 08:48:16 +03:00
|
|
|
: mFontFamilies(4),
|
|
|
|
mLocalRulesUsed(false),
|
2016-02-08 04:11:39 +03:00
|
|
|
mRebuildLocalRules(false),
|
2015-11-25 08:48:16 +03:00
|
|
|
mDownloadCount(0),
|
|
|
|
mDownloadSize(0)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
2014-09-25 07:16:54 +04:00
|
|
|
IncrementGeneration(true);
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList();
|
2014-07-09 11:08:52 +04:00
|
|
|
if (fp) {
|
|
|
|
fp->AddUserFontSet(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxUserFontSet::~gfxUserFontSet()
|
|
|
|
{
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxPlatformFontList* fp = gfxPlatformFontList::PlatformFontList();
|
2014-07-09 11:08:52 +04:00
|
|
|
if (fp) {
|
|
|
|
fp->RemoveUserFontSet(this);
|
|
|
|
}
|
2017-07-07 08:35:28 +03:00
|
|
|
|
|
|
|
UserFontCache::ClearAllowedFontSets(this);
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
already_AddRefed<gfxUserFontEntry>
|
2014-10-02 06:32:07 +04:00
|
|
|
gfxUserFontSet::FindOrCreateUserFontEntry(
|
2014-07-23 09:05:50 +04:00
|
|
|
const nsAString& aFamilyName,
|
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-07-23 09:05:50 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2017-04-20 10:00:59 +03:00
|
|
|
gfxCharacterMap* aUnicodeRanges,
|
2016-01-07 08:03:05 +03:00
|
|
|
uint8_t aFontDisplay)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxUserFontEntry> entry;
|
2014-07-09 11:08:52 +04:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// If there's already a userfont entry in the family whose descriptors all match,
|
2014-07-09 11:08:52 +04:00
|
|
|
// we can just move it to the end of the list instead of adding a new
|
|
|
|
// face that will always "shadow" the old one.
|
2014-09-08 11:23:20 +04:00
|
|
|
// Note that we can't do this for platform font entries, even if the
|
2014-07-09 11:08:52 +04:00
|
|
|
// style descriptors match, as they might have had a different source list,
|
|
|
|
// but we no longer have the old source list available to check.
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily* family = LookupFamily(aFamilyName);
|
2014-07-23 09:05:50 +04:00
|
|
|
if (family) {
|
2014-09-08 11:23:20 +04:00
|
|
|
entry = FindExistingUserFontEntry(family, aFontFaceSrcList, aWeight,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStretch, aStyle,
|
2014-09-08 11:23:20 +04:00
|
|
|
aFeatureSettings, aLanguageOverride,
|
2016-01-07 08:03:05 +03:00
|
|
|
aUnicodeRanges, aFontDisplay);
|
2014-07-23 09:05:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!entry) {
|
2014-10-02 06:32:07 +04:00
|
|
|
entry = CreateUserFontEntry(aFontFaceSrcList, aWeight, aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStyle, aFeatureSettings,
|
2016-01-07 08:03:05 +03:00
|
|
|
aLanguageOverride, aUnicodeRanges,
|
|
|
|
aFontDisplay);
|
2014-07-23 09:05:50 +04:00
|
|
|
entry->mFamilyName = aFamilyName;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
already_AddRefed<gfxUserFontEntry>
|
2014-10-02 06:32:07 +04:00
|
|
|
gfxUserFontSet::CreateUserFontEntry(
|
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
2014-07-23 09:05:50 +04:00
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-07-23 09:05:50 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2017-04-20 10:00:59 +03:00
|
|
|
gfxCharacterMap* aUnicodeRanges,
|
2016-01-07 08:03:05 +03:00
|
|
|
uint8_t aFontDisplay)
|
2014-07-23 09:05:50 +04:00
|
|
|
{
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxUserFontEntry> userFontEntry =
|
2014-09-08 11:23:20 +04:00
|
|
|
new gfxUserFontEntry(this, aFontFaceSrcList, aWeight,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStretch, aStyle, aFeatureSettings,
|
2016-01-07 08:03:05 +03:00
|
|
|
aLanguageOverride, aUnicodeRanges, aFontDisplay);
|
2014-09-08 11:23:20 +04:00
|
|
|
return userFontEntry.forget();
|
2014-07-23 09:05:50 +04:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry*
|
|
|
|
gfxUserFontSet::FindExistingUserFontEntry(
|
|
|
|
gfxUserFontFamily* aFamily,
|
2014-07-23 09:05:50 +04:00
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
uint32_t aWeight,
|
|
|
|
int32_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-07-23 09:05:50 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
uint32_t aLanguageOverride,
|
2017-04-20 10:00:59 +03:00
|
|
|
gfxCharacterMap* aUnicodeRanges,
|
2016-01-07 08:03:05 +03:00
|
|
|
uint8_t aFontDisplay)
|
2014-07-23 09:05:50 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWeight != 0,
|
|
|
|
"aWeight must not be 0; use NS_FONT_WEIGHT_NORMAL instead");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<gfxFontEntry>>& fontList = aFamily->GetFontList();
|
2014-07-23 09:05:50 +04:00
|
|
|
|
|
|
|
for (size_t i = 0, count = fontList.Length(); i < count; i++) {
|
2014-09-08 11:23:20 +04:00
|
|
|
if (!fontList[i]->mIsUserFontContainer) {
|
2014-07-09 11:08:52 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry* existingUserFontEntry =
|
|
|
|
static_cast<gfxUserFontEntry*>(fontList[i].get());
|
|
|
|
if (!existingUserFontEntry->Matches(aFontFaceSrcList,
|
2015-10-19 05:16:43 +03:00
|
|
|
aWeight, aStretch, aStyle,
|
2014-09-08 11:23:20 +04:00
|
|
|
aFeatureSettings, aLanguageOverride,
|
2016-01-07 08:03:05 +03:00
|
|
|
aUnicodeRanges, aFontDisplay)) {
|
2014-07-09 11:08:52 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
return existingUserFontEntry;
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
2014-07-23 09:05:50 +04:00
|
|
|
return nullptr;
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-10-02 06:32:07 +04:00
|
|
|
gfxUserFontSet::AddUserFontEntry(const nsAString& aFamilyName,
|
|
|
|
gfxUserFontEntry* aUserFontEntry)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily* family = GetFamily(aFamilyName);
|
2014-09-08 11:23:20 +04:00
|
|
|
family->AddFontEntry(aUserFontEntry);
|
2014-07-23 09:05:50 +04:00
|
|
|
|
|
|
|
if (LOG_ENABLED()) {
|
2015-01-29 10:44:59 +03:00
|
|
|
LOG(("userfonts (%p) added to \"%s\" (%p) style: %s weight: %d "
|
2016-01-07 08:03:05 +03:00
|
|
|
"stretch: %d display: %d",
|
2015-01-29 10:44:59 +03:00
|
|
|
this, NS_ConvertUTF16toUTF8(aFamilyName).get(), aUserFontEntry,
|
2015-10-19 05:16:43 +03:00
|
|
|
(aUserFontEntry->IsItalic() ? "italic" :
|
|
|
|
(aUserFontEntry->IsOblique() ? "oblique" : "normal")),
|
2016-01-07 08:03:05 +03:00
|
|
|
aUserFontEntry->Weight(), aUserFontEntry->Stretch(),
|
|
|
|
aUserFontEntry->GetFontDisplay()));
|
2014-07-23 09:05:50 +04:00
|
|
|
}
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxUserFontSet::IncrementGeneration(bool aIsRebuild)
|
2014-07-09 11:08:52 +04:00
|
|
|
{
|
|
|
|
// add one, increment again if zero
|
|
|
|
++sFontSetGeneration;
|
|
|
|
if (sFontSetGeneration == 0)
|
|
|
|
++sFontSetGeneration;
|
|
|
|
mGeneration = sFontSetGeneration;
|
2014-09-25 07:16:54 +04:00
|
|
|
if (aIsRebuild) {
|
|
|
|
mRebuildGeneration = mGeneration;
|
|
|
|
}
|
2014-07-09 11:08:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontSet::RebuildLocalRules()
|
|
|
|
{
|
|
|
|
if (mLocalRulesUsed) {
|
2016-02-08 04:11:39 +03:00
|
|
|
mRebuildLocalRules = true;
|
2014-07-09 11:08:52 +04:00
|
|
|
DoRebuildUserFontSet();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily*
|
2014-07-09 11:08:55 +04:00
|
|
|
gfxUserFontSet::LookupFamily(const nsAString& aFamilyName) const
|
2008-12-06 02:19:27 +03:00
|
|
|
{
|
|
|
|
nsAutoString key(aFamilyName);
|
|
|
|
ToLowerCase(key);
|
|
|
|
|
|
|
|
return mFontFamilies.GetWeak(key);
|
|
|
|
}
|
2012-03-16 07:31:01 +04:00
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
bool
|
|
|
|
gfxUserFontSet::ContainsUserFontSetFonts(const FontFamilyList& aFontList) const
|
|
|
|
{
|
|
|
|
for (const FontFamilyName& name : aFontList.GetFontlist()) {
|
|
|
|
if (name.mType != eFamily_named &&
|
|
|
|
name.mType != eFamily_named_quoted) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (LookupFamily(name.mName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily*
|
2014-07-09 11:08:55 +04:00
|
|
|
gfxUserFontSet::GetFamily(const nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
nsAutoString key(aFamilyName);
|
|
|
|
ToLowerCase(key);
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily* family = mFontFamilies.GetWeak(key);
|
2014-07-09 11:08:55 +04:00
|
|
|
if (!family) {
|
2014-09-08 11:23:20 +04:00
|
|
|
family = new gfxUserFontFamily(aFamilyName);
|
2014-07-09 11:08:55 +04:00
|
|
|
mFontFamilies.Put(key, family);
|
|
|
|
}
|
|
|
|
return family;
|
|
|
|
}
|
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// gfxUserFontSet::UserFontCache - re-use platform font entries for user fonts
|
|
|
|
// across pages/fontsets rather than instantiating new platform fonts.
|
|
|
|
//
|
|
|
|
// Entries are added to this cache when a platform font is instantiated from
|
|
|
|
// downloaded data, and removed when the platform font entry is destroyed.
|
|
|
|
// We don't need to use a timed expiration scheme here because the gfxFontEntry
|
|
|
|
// for a downloaded font will be kept alive by its corresponding gfxFont
|
|
|
|
// instance(s) until they are deleted, and *that* happens using an expiration
|
|
|
|
// tracker (gfxFontCache). The result is that the downloaded font instances
|
|
|
|
// recorded here will persist between pages and can get reused (provided the
|
|
|
|
// source URI and principal match, of course).
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsTHashtable<gfxUserFontSet::UserFontCache::Entry>*
|
2017-07-06 11:00:34 +03:00
|
|
|
gfxUserFontSet::UserFontCache::sUserFonts = nullptr;
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
gfxUserFontSet::UserFontCache::sGeneration = 0;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(gfxUserFontSet::UserFontCache::Flusher, nsIObserver)
|
2013-05-22 08:39:47 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
gfxUserFontSet::UserFontCache::Flusher::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData)
|
2013-05-22 08:39:47 +04:00
|
|
|
{
|
2013-05-22 10:42:30 +04:00
|
|
|
if (!sUserFonts) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-05 22:14:07 +04:00
|
|
|
if (!strcmp(aTopic, "cacheservice:empty-cache")) {
|
2015-07-14 03:41:12 +03:00
|
|
|
for (auto i = sUserFonts->Iter(); !i.Done(); i.Next()) {
|
2017-07-06 17:06:53 +03:00
|
|
|
i.Remove();
|
2015-07-14 03:41:12 +03:00
|
|
|
}
|
2013-05-22 10:42:30 +04:00
|
|
|
} else if (!strcmp(aTopic, "last-pb-context-exited")) {
|
2015-07-14 03:41:12 +03:00
|
|
|
for (auto i = sUserFonts->Iter(); !i.Done(); i.Next()) {
|
|
|
|
if (i.Get()->IsPrivate()) {
|
|
|
|
i.Remove();
|
|
|
|
}
|
|
|
|
}
|
2013-05-22 19:48:55 +04:00
|
|
|
} else if (!strcmp(aTopic, "xpcom-shutdown")) {
|
2015-07-14 03:41:12 +03:00
|
|
|
for (auto i = sUserFonts->Iter(); !i.Done(); i.Next()) {
|
|
|
|
i.Get()->GetFontEntry()->DisconnectSVG();
|
|
|
|
}
|
2013-05-22 10:42:30 +04:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("unexpected topic");
|
2013-05-22 08:39:47 +04:00
|
|
|
}
|
2013-05-22 10:42:30 +04:00
|
|
|
|
2013-05-22 08:39:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-12 13:41:22 +03:00
|
|
|
static bool
|
2017-07-08 09:10:05 +03:00
|
|
|
IgnorePrincipal(gfxFontSrcURI* aURI)
|
2017-07-12 13:41:22 +03:00
|
|
|
{
|
2017-07-08 09:10:05 +03:00
|
|
|
return aURI->InheritsSecurityContext();
|
2017-07-12 13:41:22 +03:00
|
|
|
}
|
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
bool
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::KeyEquals(const KeyTypePointer aKey) const
|
|
|
|
{
|
2014-09-08 11:23:20 +04:00
|
|
|
const gfxFontEntry* fe = aKey->mFontEntry;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2017-07-08 09:10:05 +03:00
|
|
|
if (!mURI->Equals(aKey->mURI)) {
|
2017-07-06 17:06:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 20:26:55 +04:00
|
|
|
|
2017-07-06 17:06:53 +03:00
|
|
|
// For data: URIs, we don't care about the principal; otherwise, check it.
|
|
|
|
if (!IgnorePrincipal(mURI)) {
|
|
|
|
NS_ASSERTION(mPrincipal && aKey->mPrincipal,
|
|
|
|
"only data: URIs are allowed to omit the principal");
|
2017-07-08 13:00:24 +03:00
|
|
|
if (!mPrincipal->Equals(aKey->mPrincipal)) {
|
2014-08-04 20:26:55 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 10:42:30 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 17:06:53 +03:00
|
|
|
if (mPrivate != aKey->mPrivate) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:16:43 +03:00
|
|
|
if (mFontEntry->mStyle != fe->mStyle ||
|
2012-12-10 13:31:07 +04:00
|
|
|
mFontEntry->mWeight != fe->mWeight ||
|
|
|
|
mFontEntry->mStretch != fe->mStretch ||
|
|
|
|
mFontEntry->mFeatureSettings != fe->mFeatureSettings ||
|
2013-02-18 06:22:55 +04:00
|
|
|
mFontEntry->mLanguageOverride != fe->mLanguageOverride ||
|
|
|
|
mFontEntry->mFamilyName != fe->mFamilyName) {
|
2012-12-10 13:31:07 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-07-06 17:06:53 +03:00
|
|
|
gfxUserFontSet::UserFontCache::CacheFont(gfxFontEntry* aFontEntry)
|
2012-12-10 13:31:07 +04:00
|
|
|
{
|
2013-02-18 06:22:55 +04:00
|
|
|
NS_ASSERTION(aFontEntry->mFamilyName.Length() != 0,
|
|
|
|
"caching a font associated with no family yet");
|
2014-10-02 06:32:09 +04:00
|
|
|
|
2015-02-23 03:32:04 +03:00
|
|
|
// if caching is disabled, simply return
|
|
|
|
if (Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-15 22:45:37 +03:00
|
|
|
gfxUserFontData* data = aFontEntry->mUserFontData.get();
|
2014-10-02 06:32:09 +04:00
|
|
|
if (data->mIsBuffer) {
|
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
|
|
|
printf("userfontcache skipped fontentry with buffer source: %p\n",
|
|
|
|
aFontEntry);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
if (!sUserFonts) {
|
|
|
|
sUserFonts = new nsTHashtable<Entry>;
|
2013-05-22 08:39:47 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
2014-09-08 11:23:20 +04:00
|
|
|
Flusher* flusher = new Flusher;
|
2014-06-05 22:14:07 +04:00
|
|
|
obs->AddObserver(flusher, "cacheservice:empty-cache",
|
2013-05-22 08:39:47 +04:00
|
|
|
false);
|
2013-05-22 10:42:30 +04:00
|
|
|
obs->AddObserver(flusher, "last-pb-context-exited", false);
|
2013-05-22 19:48:55 +04:00
|
|
|
obs->AddObserver(flusher, "xpcom-shutdown", false);
|
2013-05-22 08:39:47 +04:00
|
|
|
}
|
2016-05-03 14:14:34 +03:00
|
|
|
|
|
|
|
// Create and register a memory reporter for sUserFonts.
|
|
|
|
// This reporter is never unregistered, but that's OK because
|
|
|
|
// the reporter checks whether sUserFonts is null, so it would
|
|
|
|
// be safe to call even after UserFontCache::Shutdown has deleted
|
|
|
|
// the cache.
|
|
|
|
RegisterStrongMemoryReporter(new MemoryReporter());
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 17:06:53 +03:00
|
|
|
// For data: URIs, the principal is ignored; anyone who has the same
|
|
|
|
// data: URI is able to load it and get an equivalent font.
|
|
|
|
// Otherwise, the principal is used as part of the cache key.
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* principal;
|
2017-07-06 17:06:53 +03:00
|
|
|
if (IgnorePrincipal(data->mURI)) {
|
|
|
|
principal = nullptr;
|
2014-06-27 19:19:28 +04:00
|
|
|
} else {
|
2017-07-06 17:06:53 +03:00
|
|
|
principal = data->mPrincipal;
|
2014-06-27 19:19:28 +04:00
|
|
|
}
|
2017-07-06 17:06:53 +03:00
|
|
|
sUserFonts->PutEntry(Key(data->mURI, principal, aFontEntry,
|
|
|
|
data->mPrivate));
|
2013-09-19 05:56:49 +04:00
|
|
|
|
2017-07-06 11:00:34 +03:00
|
|
|
++sGeneration;
|
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
|
|
|
printf("userfontcache added fontentry: %p\n", aFontEntry);
|
|
|
|
Dump();
|
|
|
|
#endif
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontSet::UserFontCache::ForgetFont(gfxFontEntry* aFontEntry)
|
2012-12-10 13:31:07 +04:00
|
|
|
{
|
|
|
|
if (!sUserFonts) {
|
|
|
|
// if we've already deleted the cache (i.e. during shutdown),
|
|
|
|
// just ignore this
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-18 14:48:38 +04:00
|
|
|
// We can't simply use RemoveEntry here because it's possible the principal
|
|
|
|
// may have changed since the font was cached, in which case the lookup
|
|
|
|
// would no longer find the entry (bug 838105).
|
2015-07-14 03:41:12 +03:00
|
|
|
for (auto i = sUserFonts->Iter(); !i.Done(); i.Next()) {
|
|
|
|
if (i.Get()->GetFontEntry() == aFontEntry) {
|
|
|
|
i.Remove();
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 05:56:49 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
|
|
|
printf("userfontcache removed fontentry: %p\n", aFontEntry);
|
|
|
|
Dump();
|
|
|
|
#endif
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2017-07-08 09:10:05 +03:00
|
|
|
gfxUserFontSet::UserFontCache::GetFont(gfxFontSrcURI* aSrcURI,
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* aPrincipal,
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry* aUserFontEntry,
|
|
|
|
bool aPrivate)
|
2012-12-10 13:31:07 +04:00
|
|
|
{
|
2015-02-23 03:32:04 +03:00
|
|
|
if (!sUserFonts ||
|
|
|
|
Preferences::GetBool("gfx.downloadable_fonts.disable_cache")) {
|
2012-12-10 13:31:07 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-27 19:19:28 +04:00
|
|
|
// Ignore principal when looking up a data: URI.
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* principal;
|
2014-06-27 19:19:28 +04:00
|
|
|
if (IgnorePrincipal(aSrcURI)) {
|
|
|
|
principal = nullptr;
|
|
|
|
} else {
|
|
|
|
principal = aPrincipal;
|
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
Entry* entry = sUserFonts->GetEntry(Key(aSrcURI, principal, aUserFontEntry,
|
2013-05-22 10:42:30 +04:00
|
|
|
aPrivate));
|
2017-07-07 08:35:28 +03:00
|
|
|
if (!entry) {
|
|
|
|
return nullptr;
|
2017-07-12 11:35:46 +03:00
|
|
|
}
|
|
|
|
|
2017-07-07 08:35:28 +03:00
|
|
|
// We have to perform another content policy check here to prevent
|
|
|
|
// cache poisoning. E.g. a.com loads a font into the cache but
|
|
|
|
// b.com has a CSP not allowing any fonts to be loaded.
|
|
|
|
bool allowed = false;
|
|
|
|
if (ServoStyleSet::IsInServoTraversal()) {
|
|
|
|
// Use the cached IsFontLoadAllowed results in mAllowedFontSets.
|
|
|
|
allowed = entry->IsFontSetAllowed(aUserFontEntry->mFontSet);
|
|
|
|
} else {
|
|
|
|
// Call IsFontLoadAllowed directly, since we are on the main thread.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-07-08 13:00:24 +03:00
|
|
|
nsIPrincipal* principal = aPrincipal ? aPrincipal->get() : nullptr;
|
2017-07-08 09:10:05 +03:00
|
|
|
allowed = aUserFontEntry->mFontSet->IsFontLoadAllowed(aSrcURI->get(),
|
2017-07-08 13:00:24 +03:00
|
|
|
principal);
|
2017-07-07 08:35:28 +03:00
|
|
|
MOZ_ASSERT(!entry->IsFontSetAllowedKnown(aUserFontEntry->mFontSet) ||
|
|
|
|
entry->IsFontSetAllowed(aUserFontEntry->mFontSet) == allowed,
|
|
|
|
"why does IsFontLoadAllowed return a different value from "
|
|
|
|
"the cached value in mAllowedFontSets?");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!allowed) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry->GetFontEntry();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxUserFontSet::UserFontCache::UpdateAllowedFontSets(
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!sUserFonts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto iter = sUserFonts->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Entry* entry = iter.Get();
|
|
|
|
if (!entry->IsFontSetAllowedKnown(aUserFontSet)) {
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* principal = entry->GetPrincipal();
|
2017-07-07 08:35:28 +03:00
|
|
|
if (!principal) {
|
|
|
|
// This is a data: URI. Just get the standard principal the
|
|
|
|
// font set uses. (For cases when mUseOriginPrincipal is true,
|
|
|
|
// we don't use the cached results of IsFontLoadAllowed, and
|
|
|
|
// instead just process the data: URI load async.)
|
|
|
|
principal = aUserFontSet->GetStandardFontLoadPrincipal();
|
|
|
|
}
|
|
|
|
bool allowed =
|
2017-07-08 09:10:05 +03:00
|
|
|
aUserFontSet->IsFontLoadAllowed(entry->GetURI()->get(),
|
2017-07-08 13:00:24 +03:00
|
|
|
principal->get());
|
2017-07-07 08:35:28 +03:00
|
|
|
entry->SetIsFontSetAllowed(aUserFontSet, allowed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxUserFontSet::UserFontCache::ClearAllowedFontSets(
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!sUserFonts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto iter = sUserFonts->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
Entry* entry = iter.Get();
|
|
|
|
entry->ClearIsFontSetAllowed(aUserFontSet);
|
|
|
|
}
|
2012-12-10 13:31:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Shutdown()
|
|
|
|
{
|
|
|
|
if (sUserFonts) {
|
|
|
|
delete sUserFonts;
|
|
|
|
sUserFonts = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2013-09-19 05:56:49 +04:00
|
|
|
|
2016-05-03 14:14:34 +03:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(UserFontsMallocSizeOf)
|
|
|
|
|
2017-07-07 08:35:28 +03:00
|
|
|
bool
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::IsFontSetAllowed(
|
|
|
|
gfxUserFontSet* aUserFontSet) const
|
|
|
|
{
|
|
|
|
bool allowed = false;
|
|
|
|
DebugOnly<bool> found = mAllowedFontSets.Get(aUserFontSet, &allowed);
|
|
|
|
MOZ_ASSERT(found, "UpdateAllowedFontSets should have been called and "
|
|
|
|
"added an entry to mAllowedFontSets");
|
|
|
|
return allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::IsFontSetAllowedKnown(
|
|
|
|
gfxUserFontSet* aUserFontSet) const
|
|
|
|
{
|
|
|
|
return mAllowedFontSets.Contains(aUserFontSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::SetIsFontSetAllowed(
|
|
|
|
gfxUserFontSet* aUserFontSet,
|
|
|
|
bool aAllowed)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!IsFontSetAllowedKnown(aUserFontSet));
|
|
|
|
mAllowedFontSets.Put(aUserFontSet, aAllowed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::ClearIsFontSetAllowed(
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
|
|
|
{
|
|
|
|
mAllowedFontSets.Remove(aUserFontSet);
|
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::ReportMemory(
|
|
|
|
nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize)
|
2016-05-03 14:14:34 +03:00
|
|
|
{
|
2016-05-17 12:05:23 +03:00
|
|
|
MOZ_ASSERT(mFontEntry);
|
2016-05-03 14:14:34 +03:00
|
|
|
nsAutoCString path("explicit/gfx/user-fonts/font(");
|
|
|
|
|
|
|
|
if (aAnonymize) {
|
|
|
|
path.AppendPrintf("<anonymized-%p>", this);
|
|
|
|
} else {
|
2016-05-17 12:05:23 +03:00
|
|
|
NS_ConvertUTF16toUTF8 familyName(mFontEntry->mFamilyName);
|
|
|
|
path.AppendPrintf("family=%s", familyName.get());
|
2016-05-03 14:14:34 +03:00
|
|
|
if (mURI) {
|
2016-08-26 09:02:31 +03:00
|
|
|
nsCString spec = mURI->GetSpecOrDefault();
|
2016-05-03 14:14:34 +03:00
|
|
|
spec.ReplaceChar('/', '\\');
|
|
|
|
// Some fonts are loaded using horrendously-long data: URIs;
|
|
|
|
// truncate those before reporting them.
|
|
|
|
bool isData;
|
2017-07-08 09:10:05 +03:00
|
|
|
if (NS_SUCCEEDED(mURI->get()->SchemeIs("data", &isData)) && isData &&
|
2016-05-03 14:14:34 +03:00
|
|
|
spec.Length() > 255) {
|
|
|
|
spec.Truncate(252);
|
|
|
|
spec.Append("...");
|
|
|
|
}
|
|
|
|
path.AppendPrintf(", url=%s", spec.get());
|
|
|
|
}
|
|
|
|
if (mPrincipal) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-07-08 13:00:24 +03:00
|
|
|
mPrincipal->get()->GetURI(getter_AddRefs(uri));
|
2016-05-09 04:57:44 +03:00
|
|
|
if (uri) {
|
2016-08-26 09:02:31 +03:00
|
|
|
nsCString spec = uri->GetSpecOrDefault();
|
2016-05-09 04:57:44 +03:00
|
|
|
if (!spec.IsEmpty()) {
|
|
|
|
// Include a clue as to who loaded this resource. (Note
|
|
|
|
// that because of font entry sharing, other pages may now
|
|
|
|
// be using this resource, and the original page may not
|
|
|
|
// even be loaded any longer.)
|
|
|
|
spec.ReplaceChar('/', '\\');
|
|
|
|
path.AppendPrintf(", principal=%s", spec.get());
|
|
|
|
}
|
2016-05-03 14:14:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path.Append(')');
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
aHandleReport->Callback(
|
|
|
|
EmptyCString(), path,
|
|
|
|
nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
|
|
|
|
mFontEntry->ComputedSizeOfExcludingThis(UserFontsMallocSizeOf),
|
|
|
|
NS_LITERAL_CSTRING("Memory used by @font-face resource."),
|
|
|
|
aData);
|
2016-05-03 14:14:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(gfxUserFontSet::UserFontCache::MemoryReporter,
|
|
|
|
nsIMemoryReporter)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
gfxUserFontSet::UserFontCache::MemoryReporter::CollectReports(
|
2016-08-24 08:23:45 +03:00
|
|
|
nsIHandleReportCallback* aHandleReport, nsISupports* aData, bool aAnonymize)
|
2016-05-03 14:14:34 +03:00
|
|
|
{
|
|
|
|
if (!sUserFonts) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = sUserFonts->Iter(); !it.Done(); it.Next()) {
|
2016-08-24 08:23:45 +03:00
|
|
|
it.Get()->ReportMemory(aHandleReport, aData, aAnonymize);
|
2016-05-03 14:14:34 +03:00
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/gfx/user-fonts/cache-overhead", KIND_HEAP, UNITS_BYTES,
|
|
|
|
sUserFonts->ShallowSizeOfIncludingThis(UserFontsMallocSizeOf),
|
|
|
|
"Memory used by the @font-face cache, not counting the actual font "
|
|
|
|
"resources.");
|
|
|
|
|
|
|
|
return NS_OK;
|
2016-05-03 14:14:34 +03:00
|
|
|
}
|
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
|
|
|
|
2015-07-14 03:41:12 +03:00
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Entry::Dump()
|
2013-09-19 05:56:49 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2014-06-27 19:19:28 +04:00
|
|
|
nsAutoCString principalURISpec("(null)");
|
2013-09-19 05:56:49 +04:00
|
|
|
bool setDomain = false;
|
|
|
|
|
2015-07-14 03:41:12 +03:00
|
|
|
if (mPrincipal) {
|
2014-06-27 19:19:28 +04:00
|
|
|
nsCOMPtr<nsIURI> principalURI;
|
2017-07-08 13:00:24 +03:00
|
|
|
rv = mPrincipal->get()->GetURI(getter_AddRefs(principalURI));
|
2014-06-27 19:19:28 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
principalURI->GetSpec(principalURISpec);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> domainURI;
|
2017-07-08 13:00:24 +03:00
|
|
|
mPrincipal->get()->GetDomain(getter_AddRefs(domainURI));
|
2014-06-27 19:19:28 +04:00
|
|
|
if (domainURI) {
|
|
|
|
setDomain = true;
|
|
|
|
}
|
2013-09-19 05:56:49 +04:00
|
|
|
}
|
|
|
|
|
2015-07-14 03:41:12 +03:00
|
|
|
NS_ASSERTION(mURI, "null URI in userfont cache entry");
|
2013-09-19 05:56:49 +04:00
|
|
|
|
2015-07-14 03:41:12 +03:00
|
|
|
printf("userfontcache fontEntry: %p fonturihash: %8.8x "
|
|
|
|
"family: %s domainset: %s principal: [%s]\n",
|
|
|
|
mFontEntry,
|
2017-07-08 09:10:05 +03:00
|
|
|
mURI->Hash(),
|
2015-07-14 03:41:12 +03:00
|
|
|
NS_ConvertUTF16toUTF8(mFontEntry->FamilyName()).get(),
|
|
|
|
setDomain ? "true" : "false",
|
|
|
|
principalURISpec.get());
|
2013-09-19 05:56:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUserFontSet::UserFontCache::Dump()
|
|
|
|
{
|
|
|
|
if (!sUserFonts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("userfontcache dump count: %d ========\n", sUserFonts->Count());
|
2015-07-14 03:41:12 +03:00
|
|
|
for (auto it = sUserFonts->Iter(); !it.Done(); it.Next()) {
|
|
|
|
it.Get()->Dump();
|
|
|
|
}
|
2013-09-19 05:56:49 +04:00
|
|
|
printf("userfontcache dump ==================\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2016-07-26 23:19:48 +03:00
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#undef LOG_ENABLED
|