Bug 1092570 - Avoid exposing FontFace(Set) constructors when the Font Loading API pref is not set. r=bzbarsky

This commit is contained in:
Cameron McCormack 2014-11-11 14:53:55 +11:00
Родитель c5b1ff4bcb
Коммит 3fe0848250
3 изменённых файлов: 28 добавлений и 3 удалений

Просмотреть файл

@ -226,7 +226,10 @@ FontFace::FontFace(nsISupports* aParent, nsPresContext* aPresContext)
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aParent);
if (global) {
// If the pref is not set, don't create the Promise (which the page wouldn't
// be able to get to anyway) as it causes the window.FontFace constructor
// to be created.
if (global && FontFaceSet::PrefEnabled()) {
ErrorResult rv;
mLoaded = Promise::Create(global, rv);
}

Просмотреть файл

@ -39,6 +39,8 @@ using namespace mozilla::dom;
#define LOG_ENABLED() PR_LOG_TEST(gfxUserFontSet::GetUserFontsLog(), \
PR_LOG_DEBUG)
#define FONT_LOADING_API_ENABLED_PREF "layout.css.font-loading-api.enabled"
NS_IMPL_CYCLE_COLLECTION_CLASS(FontFaceSet)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FontFaceSet, DOMEventTargetHelper)
@ -83,7 +85,10 @@ FontFaceSet::FontFaceSet(nsPIDOMWindow* aWindow, nsPresContext* aPresContext)
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aWindow);
if (global) {
// If the pref is not set, don't create the Promise (which the page wouldn't
// be able to get to anyway) as it causes the window.FontFaceSet constructor
// to be created.
if (global && PrefEnabled()) {
ErrorResult rv;
mReady = Promise::Create(global, rv);
}
@ -1337,7 +1342,7 @@ FontFaceSet::CheckLoadingStarted()
false))->RunDOMEventWhenSafe();
}
if (mReadyIsResolved) {
if (mReadyIsResolved && PrefEnabled()) {
nsRefPtr<Promise> ready;
if (GetParentObject()) {
ErrorResult rv;
@ -1496,6 +1501,18 @@ FontFaceSet::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK;
}
/* static */ bool
FontFaceSet::PrefEnabled()
{
static bool initialized = false;
static bool enabled;
if (!initialized) {
initialized = true;
Preferences::AddBoolVarCache(&enabled, FONT_LOADING_API_ENABLED_PREF);
}
return enabled;
}
// nsICSSLoaderObserver
NS_IMETHODIMP

Просмотреть файл

@ -157,6 +157,11 @@ public:
*/
void DidRefresh();
/**
* Returns whether the "layout.css.font-loading-api.enabled" pref is true.
*/
static bool PrefEnabled();
// nsICSSLoaderObserver
NS_IMETHOD StyleSheetLoaded(mozilla::CSSStyleSheet* aSheet,
bool aWasAlternate,