Changeset 91699 in webkit


Ignore:
Timestamp:
Jul 25, 2011 1:00:49 PM (13 years ago)
Author:
mitz@apple.com
Message:

<rdar://problem/9835028> Font loading during layout can cause layout code to be re-entered via resource load delegate
https://bugs.webkit.org/show_bug.cgi?id=65123

Reviewed by Anders Carlsson.

Since CSSFontFaceSource::getFontData() can get called during layout, avoid calling out to loader
code from under it, and instead defer that work using a zero-delay timer.

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::CSSFontFaceSource):
(WebCore::CSSFontFaceSource::~CSSFontFaceSource):
(WebCore::CSSFontFaceSource::getFontData): Rather than starting the font load here, schedule
a zero-delay timer to do it.
(WebCore::CSSFontFaceSource::startLoadingTimerFired): Added. Starts loading the font if needed.

  • css/CSSFontFaceSource.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r91694 r91699  
     12011-07-25  Dan Bernstein  <mitz@apple.com>
     2
     3        <rdar://problem/9835028> Font loading during layout can cause layout code to be re-entered via resource load delegate
     4        https://bugs.webkit.org/show_bug.cgi?id=65123
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Since CSSFontFaceSource::getFontData() can get called during layout, avoid calling out to loader
     9        code from under it, and instead defer that work using a zero-delay timer.
     10
     11        * css/CSSFontFaceSource.cpp:
     12        (WebCore::CSSFontFaceSource::CSSFontFaceSource):
     13        (WebCore::CSSFontFaceSource::~CSSFontFaceSource):
     14        (WebCore::CSSFontFaceSource::getFontData): Rather than starting the font load here, schedule
     15        a zero-delay timer to do it.
     16        (WebCore::CSSFontFaceSource::startLoadingTimerFired): Added. Starts loading the font if needed.
     17        * css/CSSFontFaceSource.h:
     18
    1192011-07-25  Andrew Wason  <rectalogic@rectalogic.com>
    220
  • trunk/Source/WebCore/css/CSSFontFaceSource.cpp

    r89340 r91699  
    5151    , m_font(font)
    5252    , m_face(0)
     53    , m_startLoadingTimer(this, &CSSFontFaceSource::startLoadingTimerFired)
    5354#if ENABLE(SVG_FONTS)
    5455    , m_hasExternalSVGFont(false)
     
    6162CSSFontFaceSource::~CSSFontFaceSource()
    6263{
     64    m_startLoadingTimer.stop();
    6365    if (m_font)
    6466        m_font->removeClient(this);
     
    173175        }
    174176    } else {
    175         // Kick off the load now.
    176         if (CachedResourceLoader* cachedResourceLoader = fontSelector->cachedResourceLoader())
    177             m_font->beginLoadIfNeeded(cachedResourceLoader);
     177        // Kick off the load now. Do it on a zero-delay timer rather than synchronously, because we may be in
     178        // the middle of layout, and the loader may invoke aribtrary delegate or event handler code.
     179        m_fontSelector = fontSelector;
     180        if (!m_startLoadingTimer.isActive())
     181            m_startLoadingTimer.startOneShot(0);
     182
    178183        // FIXME: m_string is a URL so it makes no sense to pass it as a family name.
    179184        SimpleFontData* tempData = fontCache()->getCachedFontData(fontDescription, m_string);
     
    190195}
    191196
     197void CSSFontFaceSource::startLoadingTimerFired(Timer<WebCore::CSSFontFaceSource>*)
     198{
     199    ASSERT(m_font);
     200    ASSERT(m_fontSelector);
     201
     202    if (CachedResourceLoader* cachedResourceLoader = m_fontSelector->cachedResourceLoader())
     203        m_font->beginLoadIfNeeded(cachedResourceLoader);
     204
     205    m_fontSelector = nullptr;
     206}
     207
    192208#if ENABLE(SVG_FONTS)
    193209SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const
  • trunk/Source/WebCore/css/CSSFontFaceSource.h

    r83896 r91699  
    2929#include "CachedResourceClient.h"
    3030#include "CachedResourceHandle.h"
     31#include "Timer.h"
    3132#include <wtf/HashMap.h>
    3233#include <wtf/text/AtomicString.h>
     
    7172
    7273private:
     74    void startLoadingTimerFired(Timer<CSSFontFaceSource>*);
     75
    7376    AtomicString m_string; // URI for remote, built-in font name for local.
    7477    CachedResourceHandle<CachedFont> m_font; // For remote fonts, a pointer to our cached resource.
    7578    CSSFontFace* m_face; // Our owning font face.
    7679    HashMap<unsigned, SimpleFontData*> m_fontDataTable; // The hash key is composed of size synthetic styles.
     80
     81    Timer<CSSFontFaceSource> m_startLoadingTimer;
     82    RefPtr<CSSFontSelector> m_fontSelector;
    7783
    7884#if ENABLE(SVG_FONTS)
Note: See TracChangeset for help on using the changeset viewer.