gecko-dev/layout/style/PostTraversalTask.cpp
Cameron McCormack 756d5f5a9a 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 14:57:25 +08:00

46 lines
1.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PostTraversalTask.h"
#include "mozilla/dom/FontFace.h"
#include "mozilla/dom/FontFaceSet.h"
#include "gfxUserFontSet.h"
namespace mozilla {
using namespace dom;
void
PostTraversalTask::Run()
{
switch (mType) {
case Type::ResolveFontFaceLoadedPromise:
static_cast<FontFace*>(mTarget)->DoResolve();
break;
case Type::RejectFontFaceLoadedPromise:
static_cast<FontFace*>(mTarget)->DoReject(mResult);
break;
case Type::DispatchLoadingEventAndReplaceReadyPromise:
static_cast<FontFaceSet*>(mTarget)->
DispatchLoadingEventAndReplaceReadyPromise();
break;
case Type::DispatchFontFaceSetCheckLoadingFinishedAfterDelay:
static_cast<FontFaceSet*>(mTarget)->
DispatchCheckLoadingFinishedAfterDelay();
break;
case Type::LoadFontEntry:
static_cast<gfxUserFontEntry*>(mTarget)->ContinueLoad();
break;
}
}
} // namespace mozilla