<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[173028] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/173028">173028</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2014-08-27 15:56:06 -0700 (Wed, 27 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Drawing text in an SVG font causes load events to be fired.
&lt;https://webkit.org/b/136269&gt;
&lt;rdar://problem/15724915&gt;

Source/WebCore:

Don't flush pending load events in Document::implicitClose() for frameless documents.
This is a targeted fix for an issue where parsing SVG fonts during layout would cause
event dispatch to happen in the main document, leading to arbitrary JS execution.

Note that the testcase only works in DRT/WTR, since once the SVG font is in cached
by WebCore, we won't reparse it again. Caches are cleared between tests, so it will
correctly fail if this should regress.

Longer-term, we should clean this up and get rid of the global dispatch entirely.

Reviewed by Simon Fraser.

Test: fast/text/svg-font-trigger-load-event.html

* dom/Document.cpp:
(WebCore::Document::implicitClose):

LayoutTests:

Reviewed by Simon Fraser.

* fast/text/svg-font-trigger-load-event-expected.txt: Added.
* fast/text/svg-font-trigger-load-event.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfasttextsvgfonttriggerloadeventexpectedtxt">trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfasttextsvgfonttriggerloadeventhtml">trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (173027 => 173028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/LayoutTests/ChangeLog        2014-08-27 22:56:06 UTC (rev 173028)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2014-08-27  Andreas Kling  &lt;akling@apple.com&gt;
+
+        Drawing text in an SVG font causes load events to be fired.
+        &lt;https://webkit.org/b/136269&gt;
+        &lt;rdar://problem/15724915&gt;
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/svg-font-trigger-load-event-expected.txt: Added.
+        * fast/text/svg-font-trigger-load-event.html: Added.
+
</ins><span class="cx"> 2014-08-27  Benjamin Poulain  &lt;bpoulain@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Updating attributes on HTML elements do not invalidate the style correctly unless the attribute name is lowercase in the stylesheet
</span></span></pre></div>
<a id="trunkLayoutTestsfasttextsvgfonttriggerloadeventexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt (0 => 173028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/text/svg-font-trigger-load-event-expected.txt        2014-08-27 22:56:06 UTC (rev 173028)
</span><span class="lines">@@ -0,0 +1,5 @@
</span><ins>+This test makes sure that drawing text in an SVG font that resides in another document doesn't cause load events to be fired. The test is successful if the image load hander line blow occurs after the line that says it should be before the image load handler.
+This line should occur before the image load handler.
+Image load handler occurred.
+
+This is some dummy text
</ins></span></pre></div>
<a id="trunkLayoutTestsfasttextsvgfonttriggerloadeventhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html (0 => 173028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html                                (rev 0)
+++ trunk/LayoutTests/fast/text/svg-font-trigger-load-event.html        2014-08-27 22:56:06 UTC (rev 173028)
</span><span class="lines">@@ -0,0 +1,30 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;style&gt;
+@font-face {
+    font-family: 'SVGraffiti';
+    src: url(&quot;../../svg/custom/resources/graffiti.svg&quot;) format(svg)
+}
+&lt;/style&gt;
+&lt;/head&gt;
+&lt;body&gt;
+This test makes sure that drawing text in an SVG font that resides in another document doesn't cause load events to be fired. The test is successful if the image load hander line blow occurs after the line that says it should be before the image load handler.
+&lt;pre id=&quot;log&quot;&gt;&lt;/pre&gt;
+&lt;script&gt;
+function log(line) {
+    document.querySelector(&quot;#log&quot;).innerText += line + '\n';
+}
+function imageLoadHandler() {
+    log(&quot;Image load handler occurred.&quot;);
+}
+if (window.testRunner)
+    testRunner.dumpAsText();
+&lt;/script&gt;
+&lt;img src=&quot;data:image/png;charset=binary;base64,iVBORw0KGgoAAAANSUhEUgAAAEIAAAAaCAYAAAF0jrrkAAACmWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNS4xLjIiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iPgogICAgICAgICA8ZGM6cmlnaHRzPgogICAgICAgICAgICA8cmRmOkFsdD4KICAgICAgICAgICAgICAgPHJkZjpsaSB4bWw6bGFuZz0ieC1kZWZhdWx0Ij5Db3B5cmlnaHQgwqkgMjAxMyBBcHBsZSBJbmMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuPC9yZGY6bGk+CiAgICAgICAgICAgIDwvcmRmOkFsdD4KICAgICAgICAgPC9kYzpyaWdodHM+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iPgogICAgICAgICA8eG1wOkNyZWF0b3JUb29sPkFkb2JlIEltYWdlUmVhZHk8L3htcDpDcmVhdG9yVG9vbD4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+ClkMcMUAAAGcSURBVFgJ7ZkxTgMxEEV3EamgCqKFFgnECYAjwB2gpwwdPdSUELhCuAJwAsQBQguIiioS4T8jrywU7URYMJGckSZ2Yq//n++xvdmtL/s346rd6oX29u/WaTp1puk0qg1OJp+xCWN1qC0OliL36rBroViD7KiDHYs1itqzwjnQALc5oQxgmDMA13/mDmBmDSit5srgGWq5WdkantFYx/ZcGeI4vynZqla40JME+K/ynjcJiJx6k7gWieVFqDjZtnAfwfZaHc3KgITXdJwBHs2LRE8EGjW8SCDCi7cS4LNRcYS75QTY2B0fntMBPjaYBRLH3iSepMTQm8QW8+FJ4ggCmBeJkbD7gYEjiW4kQOl1gKUc/qs+FNCm/GMSoFdKTOLy17+tC+BdHhbkT7CShCD2jpx7uUO+pFaaEDH2K1XwxkoVAgHICrKDLHE7NsCeBWO/YN9YKzkj4kQsqXIxF6KqTiTEvue/8TgjXiVPiPbkPICtShXiTbFvyHlKFazEpfGgyFfljQgoUZoQ54o5vEYg+NRKWhrhDUYafFr/At4ROug1jBe0AAAAAElFTkSuQmCC&quot; onload=&quot;imageLoadHandler();&quot;&gt;
+&lt;div style=&quot;font-family: SVGraffiti;&quot;&gt;This is some dummy text&lt;/div&gt;
+&lt;script&gt;
+log(&quot;This line should occur before the image load handler.&quot;);
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (173027 => 173028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/Source/WebCore/ChangeLog        2014-08-27 22:56:06 UTC (rev 173028)
</span><span class="lines">@@ -1,3 +1,26 @@
</span><ins>+2014-08-27  Andreas Kling  &lt;akling@apple.com&gt;
+
+        Drawing text in an SVG font causes load events to be fired.
+        &lt;https://webkit.org/b/136269&gt;
+        &lt;rdar://problem/15724915&gt;
+
+        Don't flush pending load events in Document::implicitClose() for frameless documents.
+        This is a targeted fix for an issue where parsing SVG fonts during layout would cause
+        event dispatch to happen in the main document, leading to arbitrary JS execution.
+
+        Note that the testcase only works in DRT/WTR, since once the SVG font is in cached
+        by WebCore, we won't reparse it again. Caches are cleared between tests, so it will
+        correctly fail if this should regress.
+
+        Longer-term, we should clean this up and get rid of the global dispatch entirely.
+
+        Reviewed by Simon Fraser.
+
+        Test: fast/text/svg-font-trigger-load-event.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::implicitClose):
+
</ins><span class="cx"> 2014-08-27  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Some EventHandler naming cleanup
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (173027 => 173028)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2014-08-27 22:35:18 UTC (rev 173027)
+++ trunk/Source/WebCore/dom/Document.cpp        2014-08-27 22:56:06 UTC (rev 173028)
</span><span class="lines">@@ -2380,15 +2380,17 @@
</span><span class="cx">     if (f) {
</span><span class="cx">         f-&gt;loader().icon().startLoader();
</span><span class="cx">         f-&gt;animation().startAnimationsIfNotSuspended(this);
</span><ins>+
+        // FIXME: We shouldn't be dispatching pending events globally on all Documents here.
+        // For now, only do this when there is a Frame, otherwise this could cause JS reentrancy
+        // below SVG font parsing, for example. &lt;https://webkit.org/b/136269&gt;
+        ImageLoader::dispatchPendingBeforeLoadEvents();
+        ImageLoader::dispatchPendingLoadEvents();
+        ImageLoader::dispatchPendingErrorEvents();
+        HTMLLinkElement::dispatchPendingLoadEvents();
+        HTMLStyleElement::dispatchPendingLoadEvents();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ImageLoader::dispatchPendingBeforeLoadEvents();
-    ImageLoader::dispatchPendingLoadEvents();
-    ImageLoader::dispatchPendingErrorEvents();
-
-    HTMLLinkElement::dispatchPendingLoadEvents();
-    HTMLStyleElement::dispatchPendingLoadEvents();
-
</del><span class="cx">     // To align the HTML load event and the SVGLoad event for the outermost &lt;svg&gt; element, fire it from
</span><span class="cx">     // here, instead of doing it from SVGElement::finishedParsingChildren (if externalResourcesRequired=&quot;false&quot;,
</span><span class="cx">     // which is the default, for ='true' its fired at a later time, once all external resources finished loading).
</span></span></pre>
</div>
</div>

</body>
</html>