2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
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
|
|
|
|
|
|
|
#ifndef GFX_USER_FONT_SET_H
|
|
|
|
#define GFX_USER_FONT_SET_H
|
|
|
|
|
|
|
|
#include "gfxFont.h"
|
2015-03-06 11:44:18 +03:00
|
|
|
#include "gfxFontFamilyList.h"
|
2017-07-08 13:00:24 +03:00
|
|
|
#include "gfxFontSrcPrincipal.h"
|
2017-07-08 09:10:05 +03:00
|
|
|
#include "gfxFontSrcURI.h"
|
2008-10-01 07:04:10 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIURI.h"
|
2012-12-10 13:31:07 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2011-07-12 15:24:36 +04:00
|
|
|
#include "nsIScriptError.h"
|
2012-12-10 13:31:07 +04:00
|
|
|
#include "nsURIHashKey.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2018-10-04 00:50:21 +03:00
|
|
|
#include "mozilla/ServoStyleConsts.h"
|
2014-11-18 16:46:47 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2015-10-19 05:16:43 +03:00
|
|
|
#include "gfxFontConstants.h"
|
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
|
|
|
namespace mozilla {
|
|
|
|
class PostTraversalTask;
|
|
|
|
} // namespace mozilla
|
2012-04-26 21:50:41 +04:00
|
|
|
class nsFontFaceLoader;
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
//#define DEBUG_USERFONT_CACHE
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
class gfxFontFaceBufferSource {
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxFontFaceBufferSource)
|
|
|
|
public:
|
|
|
|
virtual void TakeBuffer(uint8_t*& aBuffer, uint32_t& aLength) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~gfxFontFaceBufferSource() {}
|
|
|
|
};
|
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
// parsed CSS @font-face rule information
|
|
|
|
// lifetime: from when @font-face rule processed until font is loaded
|
|
|
|
struct gfxFontFaceSrc {
|
2014-10-02 06:32:09 +04:00
|
|
|
enum SourceType { eSourceType_Local, eSourceType_URL, eSourceType_Buffer };
|
|
|
|
|
|
|
|
SourceType mSourceType;
|
2008-11-27 06:50:16 +03:00
|
|
|
|
|
|
|
// if url, whether to use the origin principal or not
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUseOriginPrincipal;
|
2008-10-01 07:04:10 +04:00
|
|
|
|
|
|
|
// format hint flags, union of all possible formats
|
|
|
|
// (e.g. TrueType, EOT, SVG, etc.)
|
|
|
|
// see FLAG_FORMAT_* enum values below
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mFormatFlags;
|
2008-11-27 06:50:16 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mLocalName; // full font name if local
|
2017-07-08 09:10:05 +03:00
|
|
|
RefPtr<gfxFontSrcURI> mURI; // uri if url
|
2008-11-27 06:50:16 +03:00
|
|
|
nsCOMPtr<nsIURI> mReferrer; // referrer url if url
|
2014-11-18 16:46:47 +03:00
|
|
|
mozilla::net::ReferrerPolicy mReferrerPolicy;
|
2017-07-08 13:00:24 +03:00
|
|
|
RefPtr<gfxFontSrcPrincipal> mOriginPrincipal; // principal if url
|
2014-10-02 06:32:09 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontFaceBufferSource> mBuffer;
|
2018-03-23 18:06:56 +03:00
|
|
|
|
|
|
|
// The principal that should be used for the load. Should only be used for
|
|
|
|
// URL sources.
|
|
|
|
gfxFontSrcPrincipal* LoadPrincipal(const gfxUserFontSet&) const;
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
2013-08-12 13:07:55 +04:00
|
|
|
inline bool operator==(const gfxFontFaceSrc& a, const gfxFontFaceSrc& b) {
|
2017-07-08 09:10:05 +03:00
|
|
|
// The mReferrer and mOriginPrincipal comparisons aren't safe OMT.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2014-10-02 06:32:09 +04:00
|
|
|
if (a.mSourceType != b.mSourceType) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-02 06:32:09 +04:00
|
|
|
switch (a.mSourceType) {
|
|
|
|
case gfxFontFaceSrc::eSourceType_Local:
|
|
|
|
return a.mLocalName == b.mLocalName;
|
|
|
|
case gfxFontFaceSrc::eSourceType_URL: {
|
|
|
|
bool equals;
|
|
|
|
return a.mUseOriginPrincipal == b.mUseOriginPrincipal &&
|
|
|
|
a.mFormatFlags == b.mFormatFlags &&
|
2017-07-08 09:10:05 +03:00
|
|
|
(a.mURI == b.mURI || a.mURI->Equals(b.mURI)) &&
|
2014-10-02 06:32:09 +04:00
|
|
|
NS_SUCCEEDED(a.mReferrer->Equals(b.mReferrer, &equals)) &&
|
2014-11-18 16:46:47 +03:00
|
|
|
equals && a.mReferrerPolicy == b.mReferrerPolicy &&
|
2014-10-02 06:32:09 +04:00
|
|
|
a.mOriginPrincipal->Equals(b.mOriginPrincipal);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-02 06:32:09 +04:00
|
|
|
case gfxFontFaceSrc::eSourceType_Buffer:
|
|
|
|
return a.mBuffer == b.mBuffer;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-10-02 06:32:09 +04:00
|
|
|
NS_WARNING("unexpected mSourceType");
|
|
|
|
return false;
|
2013-08-12 13:07:55 +04:00
|
|
|
}
|
|
|
|
|
2011-06-16 10:31:37 +04:00
|
|
|
// Subclassed to store platform-specific code cleaned out when font entry is
|
|
|
|
// deleted.
|
|
|
|
// Lifetime: from when platform font is created until it is deactivated.
|
|
|
|
// If the platform does not need to add any platform-specific code/data here,
|
|
|
|
// then the gfxUserFontSet will allocate a base gfxUserFontData and attach
|
|
|
|
// to the entry to track the basic user font info fields here.
|
2008-10-01 07:04:10 +04:00
|
|
|
class gfxUserFontData {
|
|
|
|
public:
|
2011-06-16 10:31:37 +04:00
|
|
|
gfxUserFontData()
|
2014-08-04 20:26:55 +04:00
|
|
|
: mSrcIndex(0),
|
|
|
|
mFormat(0),
|
|
|
|
mMetaOrigLen(0),
|
2017-07-06 17:06:53 +03:00
|
|
|
mCompression(kUnknownCompression),
|
2014-10-04 14:46:54 +04:00
|
|
|
mPrivate(false),
|
|
|
|
mIsBuffer(false) {}
|
2008-10-01 07:04:10 +04:00
|
|
|
virtual ~gfxUserFontData() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-03 14:14:35 +03:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsTArray<uint8_t> mMetadata; // woff metadata block (compressed), if any
|
2017-07-08 09:10:05 +03:00
|
|
|
RefPtr<gfxFontSrcURI> mURI; // URI of the source, if it was url()
|
2017-07-08 13:00:24 +03:00
|
|
|
RefPtr<gfxFontSrcPrincipal>
|
|
|
|
mPrincipal; // principal for the download, if url()
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mLocalName; // font name used for the source, if local()
|
|
|
|
nsCString mRealName; // original fullname from the font resource
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSrcIndex; // index in the rule's source list
|
|
|
|
uint32_t mFormat; // format hint for the source used, if any
|
|
|
|
uint32_t mMetaOrigLen; // length needed to decompress metadata
|
2014-10-04 14:46:54 +04:00
|
|
|
uint8_t mCompression; // compression type
|
2013-05-22 10:42:30 +04:00
|
|
|
bool mPrivate; // whether font belongs to a private window
|
2014-10-02 06:32:09 +04:00
|
|
|
bool mIsBuffer; // whether the font source was a buffer
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-04 14:46:54 +04:00
|
|
|
enum {
|
|
|
|
kUnknownCompression = 0,
|
|
|
|
kZlibCompression = 1,
|
|
|
|
kBrotliCompression = 2
|
|
|
|
};
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// initially contains a set of userfont font entry objects, replaced with
|
2008-10-01 07:04:10 +04:00
|
|
|
// platform/user fonts as downloaded
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
class gfxUserFontFamily : public gfxFontFamily {
|
2008-10-01 07:04:10 +04:00
|
|
|
public:
|
2009-08-16 17:52:12 +04:00
|
|
|
friend class gfxUserFontSet;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
explicit gfxUserFontFamily(const nsACString& aName) : gfxFontFamily(aName) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
virtual ~gfxUserFontFamily();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// add the given font entry to the end of the family's list
|
|
|
|
void AddFontEntry(gfxFontEntry* aFontEntry) {
|
|
|
|
// keep ref while removing existing entry
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontEntry> fe = aFontEntry;
|
2014-09-08 11:23:20 +04:00
|
|
|
// remove existing entry, if already present
|
|
|
|
mAvailableFonts.RemoveElement(aFontEntry);
|
2015-09-02 06:24:30 +03:00
|
|
|
// insert at the beginning so that the last-defined font is the first
|
|
|
|
// one in the fontlist used for matching, as per CSS Fonts spec
|
|
|
|
mAvailableFonts.InsertElementAt(0, aFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-09 11:08:54 +04:00
|
|
|
if (aFontEntry->mFamilyName.IsEmpty()) {
|
|
|
|
aFontEntry->mFamilyName = Name();
|
|
|
|
} else {
|
2014-07-23 10:09:56 +04:00
|
|
|
#ifdef DEBUG
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString thisName = Name();
|
|
|
|
nsCString entryName = aFontEntry->mFamilyName;
|
2014-07-23 10:09:56 +04:00
|
|
|
ToLowerCase(thisName);
|
|
|
|
ToLowerCase(entryName);
|
|
|
|
MOZ_ASSERT(thisName.Equals(entryName));
|
|
|
|
#endif
|
2008-10-01 07:04:10 +04:00
|
|
|
}
|
2011-08-09 12:06:01 +04:00
|
|
|
ResetCharacterMap();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2013-08-12 13:07:55 +04:00
|
|
|
// Remove all font entries from the family
|
2012-02-02 15:24:22 +04:00
|
|
|
void DetachFontEntries() { mAvailableFonts.Clear(); }
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
class gfxUserFontEntry;
|
2014-08-23 18:12:00 +04:00
|
|
|
class gfxOTSContext;
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxUserFontSet {
|
2014-09-08 11:23:20 +04:00
|
|
|
friend class gfxUserFontEntry;
|
2014-08-23 18:12:00 +04:00
|
|
|
friend class gfxOTSContext;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
public:
|
2018-04-23 17:52:20 +03:00
|
|
|
typedef mozilla::FontStretch FontStretch;
|
2018-04-25 09:18:23 +03:00
|
|
|
typedef mozilla::StretchRange StretchRange;
|
2018-04-23 17:52:20 +03:00
|
|
|
typedef mozilla::FontSlantStyle FontSlantStyle;
|
2018-04-25 09:18:23 +03:00
|
|
|
typedef mozilla::SlantStyleRange SlantStyleRange;
|
2018-04-13 22:34:37 +03:00
|
|
|
typedef mozilla::FontWeight FontWeight;
|
2018-04-25 09:18:23 +03:00
|
|
|
typedef mozilla::WeightRange WeightRange;
|
2018-04-26 17:32:36 +03:00
|
|
|
typedef gfxFontEntry::RangeFlags RangeFlags;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-30 09:48:17 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxUserFontSet)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-12-12 10:31:51 +03:00
|
|
|
gfxUserFontSet();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
enum {
|
2009-01-13 08:16:58 +03:00
|
|
|
// no flags ==> no hint set
|
|
|
|
// unknown ==> unknown format hint set
|
2014-10-04 14:36:05 +04:00
|
|
|
FLAG_FORMAT_UNKNOWN = 1,
|
2008-10-01 07:04:10 +04:00
|
|
|
FLAG_FORMAT_OPENTYPE = 1 << 1,
|
2018-02-15 13:56:42 +03:00
|
|
|
FLAG_FORMAT_TRUETYPE = 1 << 2,
|
|
|
|
FLAG_FORMAT_TRUETYPE_AAT = 1 << 3,
|
2009-01-13 08:16:58 +03:00
|
|
|
FLAG_FORMAT_EOT = 1 << 4,
|
2014-10-04 14:36:05 +04:00
|
|
|
FLAG_FORMAT_SVG = 1 << 5,
|
|
|
|
FLAG_FORMAT_WOFF = 1 << 6,
|
|
|
|
FLAG_FORMAT_WOFF2 = 1 << 7,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
FLAG_FORMAT_OPENTYPE_VARIATIONS = 1 << 8,
|
|
|
|
FLAG_FORMAT_TRUETYPE_VARIATIONS = 1 << 9,
|
2018-02-15 13:56:42 +03:00
|
|
|
FLAG_FORMAT_WOFF_VARIATIONS = 1 << 10,
|
2009-01-13 08:16:58 +03:00
|
|
|
FLAG_FORMAT_WOFF2_VARIATIONS = 1 << 11,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// the common formats that we support everywhere
|
|
|
|
FLAG_FORMATS_COMMON =
|
|
|
|
FLAG_FORMAT_OPENTYPE | FLAG_FORMAT_TRUETYPE | FLAG_FORMAT_WOFF |
|
2018-02-15 13:56:42 +03:00
|
|
|
FLAG_FORMAT_WOFF2 | FLAG_FORMAT_OPENTYPE_VARIATIONS |
|
2009-01-13 08:16:58 +03:00
|
|
|
FLAG_FORMAT_TRUETYPE_VARIATIONS | FLAG_FORMAT_WOFF_VARIATIONS |
|
2018-02-15 13:56:42 +03:00
|
|
|
FLAG_FORMAT_WOFF2_VARIATIONS,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// mask of all unused bits, update when adding new formats
|
|
|
|
FLAG_FORMAT_NOT_USED = ~((1 << 12) - 1)
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// creates a font face without adding it to a particular family
|
|
|
|
// weight - [100, 900] (multiples of 100)
|
|
|
|
// stretch = [FontStretch::UltraCondensed(), FontStretch::UltraExpanded()]
|
|
|
|
// italic style = constants in gfxFontConstants.h, e.g. NS_FONT_STYLE_NORMAL
|
|
|
|
// language override = result of calling
|
2018-09-12 10:37:37 +03:00
|
|
|
// nsLayoutUtils::ParseFontLanguageOverride
|
2009-09-17 15:03:12 +04:00
|
|
|
// TODO: support for unicode ranges not yet implemented
|
2014-10-02 06:32:07 +04:00
|
|
|
virtual already_AddRefed<gfxUserFontEntry> CreateUserFontEntry(
|
2011-04-12 14:53:20 +04:00
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
2018-04-25 09:18:23 +03:00
|
|
|
StretchRange aStretch, SlantStyleRange aStyle,
|
2012-04-26 10:24:26 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
2009-09-17 15:03:12 +04:00
|
|
|
const nsTArray<gfxFontVariation>& aVariationSettings,
|
|
|
|
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
|
|
|
mozilla::StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-15 13:56:42 +03:00
|
|
|
// creates a font face for the specified family, or returns an existing
|
|
|
|
// matching entry on the family if there is one
|
2014-10-02 06:32:07 +04:00
|
|
|
already_AddRefed<gfxUserFontEntry> FindOrCreateUserFontEntry(
|
2018-02-15 13:56:42 +03:00
|
|
|
const nsACString& aFamilyName,
|
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
|
|
|
StretchRange aStretch, SlantStyleRange aStyle,
|
2012-04-26 10:24:26 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
2018-02-15 13:56:42 +03:00
|
|
|
const nsTArray<gfxFontVariation>& aVariationSettings,
|
|
|
|
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
|
|
|
mozilla::StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-15 13:56:42 +03:00
|
|
|
// add in a font face for which we have the gfxUserFontEntry already
|
2018-09-12 22:34:57 +03:00
|
|
|
void AddUserFontEntry(const nsCString& aFamilyName,
|
2014-10-02 06:32:07 +04:00
|
|
|
gfxUserFontEntry* aUserFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-12-06 02:19:27 +03:00
|
|
|
// Whether there is a face with this family name
|
2018-09-12 22:34:57 +03:00
|
|
|
bool HasFamily(const nsACString& aFamilyName) const {
|
2014-07-09 11:08:55 +04:00
|
|
|
return LookupFamily(aFamilyName) != nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// Look up and return the gfxUserFontFamily in mFontFamilies with
|
2014-07-09 11:08:55 +04:00
|
|
|
// the given name
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxUserFontFamily* LookupFamily(const nsACString& aName) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
// Look up names in a fontlist and return true if any are in the set
|
|
|
|
bool ContainsUserFontSetFonts(const mozilla::FontFamilyList& aFontList) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-15 13:56:42 +03:00
|
|
|
virtual gfxFontSrcPrincipal* GetStandardFontLoadPrincipal() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-04 14:36:05 +04:00
|
|
|
// check whether content policies allow the given URI to load.
|
|
|
|
virtual bool IsFontLoadAllowed(const gfxFontFaceSrc&) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-04 14:36:05 +04:00
|
|
|
// Dispatches all of the specified runnables to the font face set's
|
|
|
|
// document's event queue.
|
2017-08-07 05:12:12 +03:00
|
|
|
virtual void DispatchFontLoadViolations(
|
2014-10-04 14:36:05 +04:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable>>& aViolations) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-04 14:36:05 +04:00
|
|
|
// initialize the process that loads external font data, which upon
|
|
|
|
// completion will call FontDataDownloadComplete method
|
2014-09-08 11:23:20 +04:00
|
|
|
virtual nsresult StartLoad(gfxUserFontEntry* aUserFontEntry,
|
|
|
|
const gfxFontFaceSrc* aFontFaceSrc) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
// generation - each time a face is loaded, generation is
|
2014-09-25 07:16:53 +04:00
|
|
|
// incremented so that the change can be recognized
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t GetGeneration() { return mGeneration; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-04 14:36:05 +04:00
|
|
|
// increment the generation on font load
|
|
|
|
void IncrementGeneration(bool aIsRebuild = false);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-15 13:56:42 +03:00
|
|
|
// Generation is bumped on font loads but that doesn't affect name-style
|
|
|
|
// mappings. Rebuilds do however affect name-style mappings so need to
|
|
|
|
// lookup fontlists again when that happens.
|
|
|
|
uint64_t GetRebuildGeneration() { return mRebuildGeneration; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-17 18:17:22 +04:00
|
|
|
// rebuild if local rules have been used
|
2018-02-15 13:56:42 +03:00
|
|
|
void RebuildLocalRules();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-15 13:56:42 +03:00
|
|
|
class UserFontCache {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2018-02-15 13:56:42 +03:00
|
|
|
// Record a loaded user-font in the cache. This requires that the
|
2009-01-13 08:16:58 +03:00
|
|
|
// font-entry's userFontData has been set up already, as it relies
|
|
|
|
// on the URI and Principal recorded there.
|
2017-07-06 17:06:53 +03:00
|
|
|
static void CacheFont(gfxFontEntry* aFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
// The given gfxFontEntry is being destroyed, so remove any record that
|
|
|
|
// refers to it.
|
2014-09-08 11:23:20 +04:00
|
|
|
static void ForgetFont(gfxFontEntry* aFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// Return the gfxFontEntry corresponding to a given URI and principal,
|
|
|
|
// and the features of the given userfont entry, or nullptr if none is
|
2018-02-15 13:56:42 +03:00
|
|
|
// available. The aPrivate flag is set for requests coming from private
|
|
|
|
// windows, so we can avoid leaking fonts cached in private windows mode out
|
|
|
|
// to normal windows.
|
2018-03-23 18:06:56 +03:00
|
|
|
static gfxFontEntry* GetFont(const gfxFontFaceSrc&,
|
2018-02-15 13:56:42 +03:00
|
|
|
const gfxUserFontEntry&);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
// Clear everything so that we don't leak URIs and Principals.
|
|
|
|
static void Shutdown();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-03 14:14:34 +03:00
|
|
|
// Memory-reporting support.
|
|
|
|
class MemoryReporter final : public nsIMemoryReporter {
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2018-02-15 13:56:42 +03:00
|
|
|
~MemoryReporter() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2016-05-03 14:14:34 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
2018-02-15 13:56:42 +03:00
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
|
|
|
// dump contents
|
|
|
|
static void Dump();
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2014-07-23 09:05:50 +04:00
|
|
|
private:
|
|
|
|
// Helper that we use to observe the empty-cache notification
|
2014-09-08 11:23:20 +04:00
|
|
|
// from nsICacheService.
|
2008-12-06 02:19:27 +03:00
|
|
|
class Flusher : public nsIObserver {
|
2018-03-23 18:06:56 +03:00
|
|
|
virtual ~Flusher() {}
|
2017-07-07 08:35:28 +03:00
|
|
|
|
2016-03-02 00:06:13 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
2018-03-23 18:06:56 +03:00
|
|
|
Flusher() {}
|
|
|
|
};
|
2017-08-07 05:12:12 +03:00
|
|
|
|
|
|
|
// Key used to look up entries in the user-font cache.
|
|
|
|
// Note that key comparison does *not* use the mFontEntry field
|
|
|
|
// as a whole; it only compares specific fields within the entry
|
|
|
|
// (weight/width/style/features) that could affect font selection
|
|
|
|
// or rendering, and that must match between a font-set's userfont
|
|
|
|
// entry and the corresponding "real" font entry.
|
|
|
|
struct Key {
|
|
|
|
RefPtr<gfxFontSrcURI> mURI;
|
2017-07-08 13:00:24 +03:00
|
|
|
RefPtr<gfxFontSrcPrincipal> mPrincipal; // use nullptr with data: URLs
|
2017-08-07 05:12:12 +03:00
|
|
|
// The font entry MUST notify the cache when it is destroyed
|
|
|
|
// (by calling ForgetFont()).
|
2015-05-22 18:47:00 +03:00
|
|
|
gfxFontEntry* MOZ_NON_OWNING_REF mFontEntry;
|
2017-08-07 05:12:12 +03:00
|
|
|
bool mPrivate;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-07 05:12:12 +03:00
|
|
|
Key(gfxFontSrcURI* aURI, gfxFontSrcPrincipal* aPrincipal,
|
|
|
|
gfxFontEntry* aFontEntry, bool aPrivate)
|
2012-12-10 13:31:07 +04:00
|
|
|
: mURI(aURI),
|
2017-08-07 05:12:12 +03:00
|
|
|
mPrincipal(aPrincipal),
|
2013-05-22 10:42:30 +04:00
|
|
|
mFontEntry(aFontEntry),
|
2017-07-06 17:06:53 +03:00
|
|
|
mPrivate(aPrivate) {}
|
2017-08-07 05:12:12 +03:00
|
|
|
};
|
2016-03-02 00:06:13 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
class Entry : public PLDHashEntryHdr {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-25 07:16:53 +04:00
|
|
|
typedef const Key& KeyType;
|
|
|
|
typedef const Key* KeyTypePointer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
explicit Entry(KeyTypePointer aKey)
|
2012-12-10 13:31:07 +04:00
|
|
|
: mURI(aKey->mURI),
|
|
|
|
mPrincipal(aKey->mPrincipal),
|
2014-09-25 07:16:53 +04:00
|
|
|
mFontEntry(aKey->mFontEntry),
|
|
|
|
mPrivate(aKey->mPrivate) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
Entry(Entry&& aOther)
|
Bug 1415980 - make hash keys movable and not copyable; r=erahm
Everything that goes in a PLDHashtable (and its derivatives, like
nsTHashtable) needs to inherit from PLDHashEntryHdr. But through a lack
of enforcement, copy constructors for these derived classes didn't
explicitly invoke the copy constructor for PLDHashEntryHdr (and the
compiler didn't invoke the copy constructor for us). Instead,
PLDHashTable explicitly copied around the bits that the copy constructor
would have.
The current setup has two problems:
1) Derived classes should be using move construction, not copy
construction, since anything that's shuffling hash table keys/entries
around will be using move construction.
2) Derived classes should take responsibility for transferring bits of
superclass state around, and not rely on something else to handle that.
The second point is not a huge problem for PLDHashTable (PLDHashTable
only has to copy PLDHashEntryHdr's bits in a single place), but future
hash table implementations that might move entries around more
aggressively would have to insert compensation code all over the
place. Additionally, if moving entries is implemented via memcpy (which
is quite common), PLDHashTable copying around bits *again* is
inefficient.
Let's fix all these problems in one go, by:
1) Explicitly declaring the set of constructors that PLDHashEntryHdr
implements (and does not implement). In particular, the copy
constructor is deleted, so any derived classes that attempt to make
themselves copyable will be detected at compile time: the compiler
will complain that the superclass type is not copyable.
This change on its own will result in many compiler errors, so...
2) Change any derived classes to implement move constructors instead of
copy constructors. Note that some of these move constructors are,
strictly speaking, unnecessary, since the relevant classes are moved
via memcpy in nsTHashtable and its derivatives.
2018-09-20 18:20:36 +03:00
|
|
|
: PLDHashEntryHdr(std::move(aOther)),
|
|
|
|
mURI(std::move(aOther.mURI)),
|
2014-09-25 07:16:53 +04:00
|
|
|
mPrincipal(std::move(aOther.mPrincipal)),
|
2018-05-30 22:15:35 +03:00
|
|
|
mFontEntry(std::move(aOther.mFontEntry)),
|
|
|
|
mPrivate(std::move(aOther.mPrivate)) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
~Entry() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
|
|
|
PLDHashNumber principalHash =
|
|
|
|
aKey->mPrincipal ? aKey->mPrincipal->Hash() : 0;
|
|
|
|
return mozilla::HashGeneric(
|
2013-05-22 10:42:30 +04:00
|
|
|
principalHash + int(aKey->mPrivate), aKey->mURI->Hash(),
|
2012-12-10 13:31:07 +04:00
|
|
|
HashFeatures(aKey->mFontEntry->mFeatureSettings),
|
2014-09-25 07:16:53 +04:00
|
|
|
HashVariations(aKey->mFontEntry->mVariationSettings),
|
2013-02-18 06:22:55 +04:00
|
|
|
mozilla::HashString(aKey->mFontEntry->mFamilyName),
|
2018-04-25 09:18:23 +03:00
|
|
|
aKey->mFontEntry->Weight().AsScalar(),
|
2014-09-25 07:16:53 +04:00
|
|
|
aKey->mFontEntry->SlantStyle().AsScalar(),
|
2018-04-25 09:18:23 +03:00
|
|
|
aKey->mFontEntry->Stretch().AsScalar(),
|
2018-04-23 17:52:20 +03:00
|
|
|
aKey->mFontEntry->mLanguageOverride);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
gfxFontSrcURI* GetURI() const { return mURI; }
|
|
|
|
gfxFontSrcPrincipal* GetPrincipal() const { return mPrincipal; }
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxFontEntry* GetFontEntry() const { return mFontEntry; }
|
|
|
|
bool IsPrivate() const { return mPrivate; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
void ReportMemory(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize);
|
2011-04-12 14:53:20 +04:00
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
#ifdef DEBUG_USERFONT_CACHE
|
2012-08-22 19:56:38 +04:00
|
|
|
void Dump();
|
|
|
|
#endif
|
2008-10-01 07:04:10 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2011-01-06 00:48:48 +03:00
|
|
|
static uint32_t HashFeatures(const nsTArray<gfxFontFeature>& aFeatures) {
|
|
|
|
return mozilla::HashBytes(aFeatures.Elements(),
|
2012-12-10 13:31:07 +04:00
|
|
|
aFeatures.Length() * sizeof(gfxFontFeature));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-14 14:02:05 +03:00
|
|
|
static uint32_t HashVariations(
|
|
|
|
const nsTArray<gfxFontVariation>& aVariations) {
|
2011-01-06 00:48:48 +03:00
|
|
|
return mozilla::HashBytes(
|
|
|
|
aVariations.Elements(),
|
2018-02-14 14:02:05 +03:00
|
|
|
aVariations.Length() * sizeof(gfxFontVariation));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-07-08 09:10:05 +03:00
|
|
|
RefPtr<gfxFontSrcURI> mURI;
|
2011-01-06 00:48:48 +03:00
|
|
|
RefPtr<gfxFontSrcPrincipal> mPrincipal; // or nullptr for data: URLs
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-01-06 00:48:48 +03:00
|
|
|
// The "real" font entry corresponding to this downloaded font.
|
2014-09-25 07:16:54 +04:00
|
|
|
// The font entry MUST notify the cache when it is destroyed
|
|
|
|
// (by calling ForgetFont()).
|
|
|
|
gfxFontEntry* MOZ_NON_OWNING_REF mFontEntry;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
// Whether this font was loaded from a private window.
|
|
|
|
bool mPrivate;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-25 07:16:54 +04:00
|
|
|
|
|
|
|
static nsTHashtable<Entry>* sUserFonts;
|
|
|
|
};
|
2011-01-06 00:48:48 +03:00
|
|
|
|
2014-04-17 18:17:22 +04:00
|
|
|
void SetLocalRulesUsed() { mLocalRulesUsed = true; }
|
|
|
|
|
2017-07-06 17:06:53 +03:00
|
|
|
static mozilla::LogModule* GetUserFontsLog();
|
2012-12-10 13:31:07 +04:00
|
|
|
|
|
|
|
// record statistics about font completion
|
2014-09-08 11:23:20 +04:00
|
|
|
virtual void RecordFontLoadDone(uint32_t aFontSize,
|
|
|
|
mozilla::TimeStamp aDoneTime) {}
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2018-03-23 18:06:56 +03:00
|
|
|
void GetLoadStatistics(uint32_t& aLoadCount, uint64_t& aLoadSize) const {
|
|
|
|
aLoadCount = mDownloadCount;
|
2015-11-25 08:48:16 +03:00
|
|
|
aLoadSize = mDownloadSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
protected:
|
2012-12-10 13:31:07 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~gfxUserFontSet();
|
|
|
|
|
2016-05-03 14:14:34 +03:00
|
|
|
// Return whether the font set is associated with a private-browsing tab.
|
|
|
|
virtual bool GetPrivateBrowsing() = 0;
|
|
|
|
|
|
|
|
// Return whether the font set is associated with a document that was
|
|
|
|
// shift-reloaded, for example, and thus should bypass the font cache.
|
|
|
|
virtual bool BypassCache() = 0;
|
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
// parse data for a data URL
|
|
|
|
virtual nsresult SyncLoadFontData(gfxUserFontEntry* aFontToLoad,
|
|
|
|
const gfxFontFaceSrc* aFontFaceSrc,
|
2014-10-02 06:32:09 +04:00
|
|
|
uint8_t*& aBuffer,
|
2013-09-19 05:56:49 +04:00
|
|
|
uint32_t& aBufferLength) = 0;
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// report a problem of some kind (implemented in nsUserFontSet)
|
2017-07-06 17:06:53 +03:00
|
|
|
virtual nsresult LogMessage(gfxUserFontEntry* aUserFontEntry,
|
2012-12-10 13:31:07 +04:00
|
|
|
const char* aMessage,
|
2013-05-22 10:42:30 +04:00
|
|
|
uint32_t aFlags = nsIScriptError::errorFlag,
|
2017-07-08 09:10:05 +03:00
|
|
|
nsresult aStatus = NS_OK) = 0;
|
2016-05-03 14:14:34 +03:00
|
|
|
|
2013-09-19 05:56:49 +04:00
|
|
|
// helper method for performing the actual userfont set rebuild
|
2015-07-14 03:41:12 +03:00
|
|
|
virtual void DoRebuildUserFontSet() = 0;
|
2013-09-19 05:56:49 +04:00
|
|
|
|
2012-12-10 13:31:07 +04:00
|
|
|
// helper method for FindOrCreateUserFontEntry
|
|
|
|
gfxUserFontEntry* FindExistingUserFontEntry(
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontFamily* aFamily,
|
2012-12-10 13:31:07 +04:00
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList, WeightRange aWeight,
|
|
|
|
StretchRange aStretch, SlantStyleRange aStyle,
|
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
|
|
|
const nsTArray<gfxFontVariation>& aVariationSettings,
|
|
|
|
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
|
|
|
mozilla::StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags);
|
|
|
|
|
2018-02-14 14:02:05 +03:00
|
|
|
// creates a new gfxUserFontFamily in mFontFamilies, or returns an existing
|
|
|
|
// family if there is one
|
|
|
|
gfxUserFontFamily* GetFamily(const nsACString& aFamilyName);
|
|
|
|
|
2017-07-08 13:00:24 +03:00
|
|
|
// font families defined by @font-face rules
|
|
|
|
nsRefPtrHashtable<nsCStringHashKey, gfxUserFontFamily> mFontFamilies;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
|
|
|
uint64_t mGeneration; // bumped on any font load change
|
|
|
|
uint64_t mRebuildGeneration; // only bumped on rebuilds
|
2013-05-22 10:42:30 +04:00
|
|
|
|
|
|
|
// true when local names have been looked up, false otherwise
|
|
|
|
bool mLocalRulesUsed;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
// true when rules using local names need to be redone
|
|
|
|
bool mRebuildLocalRules;
|
2012-12-10 13:31:07 +04:00
|
|
|
|
2013-05-22 10:42:30 +04:00
|
|
|
// performance stats
|
2012-12-10 13:31:07 +04:00
|
|
|
uint32_t mDownloadCount;
|
2014-09-25 07:16:54 +04:00
|
|
|
uint64_t mDownloadSize;
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// acts a placeholder until the real font is downloaded
|
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
class gfxUserFontEntry : public gfxFontEntry {
|
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
|
|
|
friend class mozilla::PostTraversalTask;
|
2009-08-16 17:52:12 +04:00
|
|
|
friend class gfxUserFontSet;
|
2014-07-09 11:08:52 +04:00
|
|
|
friend class nsUserFontSet;
|
|
|
|
friend class nsFontFaceLoader;
|
2014-08-23 18:12:00 +04:00
|
|
|
friend class gfxOTSContext;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2008-10-01 07:04:10 +04:00
|
|
|
public:
|
2014-09-25 07:16:53 +04:00
|
|
|
enum UserFontLoadState {
|
|
|
|
STATUS_NOT_LOADED = 0,
|
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
|
|
|
STATUS_LOAD_PENDING,
|
2014-09-25 07:16:53 +04:00
|
|
|
STATUS_LOADING,
|
2014-07-09 11:08:52 +04:00
|
|
|
STATUS_LOADED,
|
2014-09-25 07:16:53 +04:00
|
|
|
STATUS_FAILED
|
2014-07-09 11:08:52 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
gfxUserFontEntry(gfxUserFontSet* aFontSet,
|
2014-09-08 11:23:20 +04:00
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight, StretchRange aStretch,
|
|
|
|
SlantStyleRange aStyle,
|
2014-09-08 11:23:20 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
2018-02-14 14:02:05 +03:00
|
|
|
const nsTArray<gfxFontVariation>& aVariationSettings,
|
2017-04-20 10:00:59 +03:00
|
|
|
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
2018-10-04 00:50:21 +03:00
|
|
|
mozilla::StyleFontDisplay aFontDisplay,
|
2018-04-26 17:32:36 +03:00
|
|
|
RangeFlags aRangeFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-08 11:23:20 +04:00
|
|
|
virtual ~gfxUserFontEntry();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-12 13:07:55 +04:00
|
|
|
// Return whether the entry matches the given list of attributes
|
|
|
|
bool Matches(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight, StretchRange aStretch,
|
|
|
|
SlantStyleRange aStyle,
|
2013-08-12 13:07:55 +04:00
|
|
|
const nsTArray<gfxFontFeature>& aFeatureSettings,
|
2018-02-14 14:02:05 +03:00
|
|
|
const nsTArray<gfxFontVariation>& aVariationSettings,
|
2017-04-20 10:00:59 +03:00
|
|
|
uint32_t aLanguageOverride, gfxCharacterMap* aUnicodeRanges,
|
2018-10-04 00:50:21 +03:00
|
|
|
mozilla::StyleFontDisplay aFontDisplay, RangeFlags aRangeFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
gfxFontEntry* GetPlatformFontEntry() const { return mPlatformFontEntry; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// is the font loading or loaded, or did it fail?
|
|
|
|
UserFontLoadState LoadState() const { return mUserFontLoadState; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-10 17:08:12 +03:00
|
|
|
void LoadCanceled() {
|
|
|
|
mUserFontLoadState = STATUS_NOT_LOADED;
|
|
|
|
mFontDataLoadingState = NOT_LOADING;
|
|
|
|
mLoader = nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// whether to wait before using fallback font or not
|
|
|
|
bool WaitForUserFont() const {
|
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
|
|
|
return (mUserFontLoadState == STATUS_LOAD_PENDING ||
|
|
|
|
mUserFontLoadState == STATUS_LOADING) &&
|
2014-09-25 07:16:53 +04:00
|
|
|
mFontDataLoadingState < LOADING_SLOWLY;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
// for userfonts, cmap is used to store the unicode range data
|
|
|
|
// no cmap ==> all codepoints permitted
|
|
|
|
bool CharacterInUnicodeRange(uint32_t ch) const {
|
|
|
|
if (mCharacterMap) {
|
|
|
|
return mCharacterMap->test(ch);
|
|
|
|
}
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-11-06 07:42:50 +03:00
|
|
|
|
|
|
|
gfxCharacterMap* GetUnicodeRangeMap() const { return mCharacterMap.get(); }
|
|
|
|
|
2018-10-04 00:50:21 +03:00
|
|
|
mozilla::StyleFontDisplay GetFontDisplay() const { return mFontDisplay; }
|
2016-01-07 08:03:05 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// load the font - starts the loading of sources which continues until
|
|
|
|
// a valid font resource is found or all sources fail
|
|
|
|
void Load();
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2014-10-02 06:32:05 +04:00
|
|
|
// methods to expose some information to FontFaceSet::UserFontSet
|
|
|
|
// since we can't make that class a friend
|
|
|
|
void SetLoader(nsFontFaceLoader* aLoader) { mLoader = aLoader; }
|
|
|
|
nsFontFaceLoader* GetLoader() { return mLoader; }
|
2017-07-08 13:00:24 +03:00
|
|
|
gfxFontSrcPrincipal* GetPrincipal() { return mPrincipal; }
|
2014-10-02 06:32:05 +04:00
|
|
|
uint32_t GetSrcIndex() { return mSrcIndex; }
|
|
|
|
void GetFamilyNameAndURIForLogging(nsACString& aFamilyName, nsACString& aURI);
|
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
gfxFontEntry* Clone() const override {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("cannot Clone user fonts");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-21 22:07:31 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
gfxUserFontSet* GetUserFontSet() const { return mFontSet; }
|
|
|
|
#endif
|
|
|
|
|
2018-03-23 18:06:56 +03:00
|
|
|
const nsTArray<gfxFontFaceSrc>& SourceList() const { return mSrcList; }
|
|
|
|
|
2018-04-26 19:08:18 +03:00
|
|
|
// The variation-query APIs should not be called on placeholders.
|
|
|
|
bool HasVariations() override {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void GetVariationAxes(nsTArray<gfxFontVariationAxis>&) override {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
|
|
|
|
}
|
|
|
|
void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
protected:
|
2014-09-08 11:23:20 +04:00
|
|
|
const uint8_t* SanitizeOpenTypeData(const uint8_t* aData, uint32_t aLength,
|
2014-07-09 11:08:52 +04:00
|
|
|
uint32_t& aSaneLength,
|
2014-10-04 14:36:05 +04:00
|
|
|
gfxUserFontType aFontType);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// attempt to load the next resource in the src list.
|
|
|
|
void LoadNextSrc();
|
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 ContinueLoad();
|
|
|
|
void DoLoadNextSrc(bool aForceAsync);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// change the load state
|
2014-10-02 06:32:06 +04:00
|
|
|
virtual void SetLoadState(UserFontLoadState aLoadState);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// when download has been completed, pass back data here
|
|
|
|
// aDownloadStatus == NS_OK ==> download succeeded, error otherwise
|
|
|
|
// returns true if platform font creation sucessful (or local()
|
|
|
|
// reference was next in line)
|
|
|
|
// Ownership of aFontData is passed in here; the font set must
|
2015-04-01 08:29:55 +03:00
|
|
|
// ensure that it is eventually deleted with free().
|
2014-09-25 07:16:53 +04:00
|
|
|
bool FontDataDownloadComplete(const uint8_t* aFontData, uint32_t aLength,
|
|
|
|
nsresult aDownloadStatus);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
// helper method for creating a platform font
|
2014-09-08 11:23:20 +04:00
|
|
|
// returns true if platform font creation successful
|
2014-07-09 11:08:52 +04:00
|
|
|
// Ownership of aFontData is passed in here; the font must
|
2015-04-01 08:29:55 +03:00
|
|
|
// ensure that it is eventually deleted with free().
|
2014-09-25 07:16:53 +04:00
|
|
|
bool LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-09 11:08:52 +04:00
|
|
|
// store metadata and src details for current src into aFontEntry
|
|
|
|
void StoreUserFontData(gfxFontEntry* aFontEntry, bool aPrivate,
|
2018-09-12 22:34:57 +03:00
|
|
|
const nsACString& aOriginalName,
|
2014-07-09 11:08:52 +04:00
|
|
|
FallibleTArray<uint8_t>* aMetadata,
|
2014-10-04 14:46:54 +04:00
|
|
|
uint32_t aMetaOrigLen, uint8_t aCompression);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
// Clears and then adds to aResult all of the user font sets that this user
|
|
|
|
// font entry has been added to. This will at least include mFontSet, the
|
|
|
|
// owner of this user font entry.
|
|
|
|
virtual void GetUserFontSets(nsTArray<gfxUserFontSet*>& aResult);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-16 09:10:14 +03:00
|
|
|
// Calls IncrementGeneration() on all user font sets that contain this
|
|
|
|
// user font entry.
|
|
|
|
void IncrementGeneration();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// general load state
|
|
|
|
UserFontLoadState mUserFontLoadState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:53 +04:00
|
|
|
// detailed load state while font data is loading
|
|
|
|
// used to determine whether to use fallback font or not
|
2011-01-06 00:48:48 +03:00
|
|
|
// note that code depends on the ordering of these values!
|
2014-09-25 07:16:53 +04:00
|
|
|
enum FontDataLoadingState {
|
2011-01-06 00:48:48 +03:00
|
|
|
NOT_LOADING = 0, // not started to load any font resources yet
|
|
|
|
LOADING_STARTED, // loading has started; hide fallback font
|
|
|
|
LOADING_ALMOST_DONE, // timeout happened but we're nearly done,
|
|
|
|
// so keep hiding fallback font
|
2011-03-24 06:01:50 +03:00
|
|
|
LOADING_SLOWLY, // timeout happened and we're not nearly done,
|
2011-01-06 00:48:48 +03:00
|
|
|
// so use the fallback font
|
2016-01-07 08:03:05 +03:00
|
|
|
LOADING_TIMED_OUT, // font load took too long
|
2011-03-24 06:01:50 +03:00
|
|
|
LOADING_FAILED // failed to load any source: use fallback
|
2011-01-06 00:48:48 +03:00
|
|
|
};
|
2014-09-25 07:16:53 +04:00
|
|
|
FontDataLoadingState mFontDataLoadingState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-10-04 00:50:21 +03:00
|
|
|
bool mUnsupportedFormat;
|
|
|
|
mozilla::StyleFontDisplay mFontDisplay; // timing of userfont fallback
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontEntry> mPlatformFontEntry;
|
2011-01-06 00:48:48 +03:00
|
|
|
nsTArray<gfxFontFaceSrc> mSrcList;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mSrcIndex; // index of loading src item
|
2015-05-25 18:30:00 +03:00
|
|
|
// This field is managed by the nsFontFaceLoader. In the destructor and
|
|
|
|
// Cancel() methods of nsFontFaceLoader this reference is nulled out.
|
|
|
|
nsFontFaceLoader* MOZ_NON_OWNING_REF
|
|
|
|
mLoader; // current loader for this entry, if any
|
2017-06-30 03:52:43 +03:00
|
|
|
gfxUserFontSet* MOZ_NON_OWNING_REF
|
|
|
|
mFontSet; // font-set which owns this userfont entry
|
2017-07-08 13:00:24 +03:00
|
|
|
RefPtr<gfxFontSrcPrincipal> mPrincipal;
|
2008-10-01 07:04:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFX_USER_FONT_SET_H */
|