Title: [91699] trunk/Source/WebCore
Revision
91699
Author
m...@apple.com
Date
2011-07-25 13:00:49 -0700 (Mon, 25 Jul 2011)

Log 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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (91698 => 91699)


--- trunk/Source/WebCore/ChangeLog	2011-07-25 19:55:13 UTC (rev 91698)
+++ trunk/Source/WebCore/ChangeLog	2011-07-25 20:00:49 UTC (rev 91699)
@@ -1,3 +1,21 @@
+2011-07-25  Dan Bernstein  <m...@apple.com>
+
+        <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:
+
 2011-07-25  Andrew Wason  <rectalo...@rectalogic.com>
 
         [Qt] Adopt GraphicsContext3DOpenGL.cpp and ANGLE (part 2)

Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (91698 => 91699)


--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2011-07-25 19:55:13 UTC (rev 91698)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp	2011-07-25 20:00:49 UTC (rev 91699)
@@ -50,6 +50,7 @@
     : m_string(str)
     , m_font(font)
     , m_face(0)
+    , m_startLoadingTimer(this, &CSSFontFaceSource::startLoadingTimerFired)
 #if ENABLE(SVG_FONTS)
     , m_hasExternalSVGFont(false)
 #endif
@@ -60,6 +61,7 @@
 
 CSSFontFaceSource::~CSSFontFaceSource()
 {
+    m_startLoadingTimer.stop();
     if (m_font)
         m_font->removeClient(this);
     pruneTable();
@@ -172,9 +174,12 @@
 #endif
         }
     } else {
-        // Kick off the load now.
-        if (CachedResourceLoader* cachedResourceLoader = fontSelector->cachedResourceLoader())
-            m_font->beginLoadIfNeeded(cachedResourceLoader);
+        // Kick off the load now. Do it on a zero-delay timer rather than synchronously, because we may be in
+        // the middle of layout, and the loader may invoke aribtrary delegate or event handler code.
+        m_fontSelector = fontSelector;
+        if (!m_startLoadingTimer.isActive())
+            m_startLoadingTimer.startOneShot(0);
+
         // FIXME: m_string is a URL so it makes no sense to pass it as a family name.
         SimpleFontData* tempData = fontCache()->getCachedFontData(fontDescription, m_string);
         if (!tempData)
@@ -189,6 +194,17 @@
     return fontDataRawPtr;
 }
 
+void CSSFontFaceSource::startLoadingTimerFired(Timer<WebCore::CSSFontFaceSource>*)
+{
+    ASSERT(m_font);
+    ASSERT(m_fontSelector);
+
+    if (CachedResourceLoader* cachedResourceLoader = m_fontSelector->cachedResourceLoader())
+        m_font->beginLoadIfNeeded(cachedResourceLoader);
+
+    m_fontSelector = nullptr;
+}
+
 #if ENABLE(SVG_FONTS)
 SVGFontFaceElement* CSSFontFaceSource::svgFontFaceElement() const
 {

Modified: trunk/Source/WebCore/css/CSSFontFaceSource.h (91698 => 91699)


--- trunk/Source/WebCore/css/CSSFontFaceSource.h	2011-07-25 19:55:13 UTC (rev 91698)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.h	2011-07-25 20:00:49 UTC (rev 91699)
@@ -28,6 +28,7 @@
 
 #include "CachedResourceClient.h"
 #include "CachedResourceHandle.h"
+#include "Timer.h"
 #include <wtf/HashMap.h>
 #include <wtf/text/AtomicString.h>
 
@@ -70,11 +71,16 @@
 #endif
 
 private:
+    void startLoadingTimerFired(Timer<CSSFontFaceSource>*);
+
     AtomicString m_string; // URI for remote, built-in font name for local.
     CachedResourceHandle<CachedFont> m_font; // For remote fonts, a pointer to our cached resource.
     CSSFontFace* m_face; // Our owning font face.
     HashMap<unsigned, SimpleFontData*> m_fontDataTable; // The hash key is composed of size synthetic styles.
 
+    Timer<CSSFontFaceSource> m_startLoadingTimer;
+    RefPtr<CSSFontSelector> m_fontSelector;
+
 #if ENABLE(SVG_FONTS)
     RefPtr<SVGFontFaceElement> m_svgFontFaceElement;
     RefPtr<SVGFontElement> m_externalSVGFontElement;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to