<!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>[170091] trunk/Source</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/170091">170091</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2014-06-17 18:35:32 -0700 (Tue, 17 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS][wk2] Use ImageDocument to display subframe PDFs
https://bugs.webkit.org/show_bug.cgi?id=133944
&lt;rdar://problem/17205983&gt;

Reviewed by Dan Bates.

* dom/DOMImplementation.cpp:
(WebCore::DOMImplementation::createDocument):
Make a ImageDocument to show our subframe PDF, if the setting is enabled.

* html/ImageDocument.cpp:
(WebCore::ImageDocument::finishedParsing):
(WebCore::ImageDocument::createDocumentStructure):
Set the ResourceResponse on the ImageElement upon creation, instead of
when the load finishes. This way, when the internal CachedImage creates
its Image, it can have the correct MIME type for the response, and can
make a PDFDocumentImage if necessary.

We never noticed this before because CachedImage falls back to making a
BitmapImage, and that was the only case that was normally used.

Throw an explicit white background behind PDF ImageDocuments; PDFDocumentImage
paints with a transparent background, but when used as an ImageDocument
it seems reasonable to assume that there should be a white page background
(similar to what PDFPlugin and friends do).

* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::createDocument):
Don't make a PDFDocument if we want to use an ImageDocument for this subframe PDF.

* page/Settings.in:

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isPDFMIMEType):
* platform/MIMETypeRegistry.h:
Expose the already implemented pdfMIMETypes table just like all the rest.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
Always use ImageDocument for subframe PDFs in WebKit2 on iOS.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDOMImplementationcpp">trunk/Source/WebCore/dom/DOMImplementation.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlImageDocumentcpp">trunk/Source/WebCore/html/ImageDocument.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentWritercpp">trunk/Source/WebCore/loader/DocumentWriter.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsin">trunk/Source/WebCore/page/Settings.in</a></li>
<li><a href="#trunkSourceWebCoreplatformMIMETypeRegistrycpp">trunk/Source/WebCore/platform/MIMETypeRegistry.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformMIMETypeRegistryh">trunk/Source/WebCore/platform/MIMETypeRegistry.h</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/ChangeLog        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2014-06-17  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        [iOS][wk2] Use ImageDocument to display subframe PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=133944
+        &lt;rdar://problem/17205983&gt;
+
+        Reviewed by Dan Bates.
+
+        * dom/DOMImplementation.cpp:
+        (WebCore::DOMImplementation::createDocument):
+        Make a ImageDocument to show our subframe PDF, if the setting is enabled.
+
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::finishedParsing):
+        (WebCore::ImageDocument::createDocumentStructure):
+        Set the ResourceResponse on the ImageElement upon creation, instead of
+        when the load finishes. This way, when the internal CachedImage creates
+        its Image, it can have the correct MIME type for the response, and can
+        make a PDFDocumentImage if necessary.
+
+        We never noticed this before because CachedImage falls back to making a
+        BitmapImage, and that was the only case that was normally used.
+
+        Throw an explicit white background behind PDF ImageDocuments; PDFDocumentImage
+        paints with a transparent background, but when used as an ImageDocument
+        it seems reasonable to assume that there should be a white page background
+        (similar to what PDFPlugin and friends do).
+
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::createDocument):
+        Don't make a PDFDocument if we want to use an ImageDocument for this subframe PDF.
+
+        * page/Settings.in:
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isPDFMIMEType):
+        * platform/MIMETypeRegistry.h:
+        Expose the already implemented pdfMIMETypes table just like all the rest.
+
</ins><span class="cx"> 2014-06-17  Ryuan Choi  &lt;ryuan.choi@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed build fix with ENABLE_NOSNIFF after r170021
</span></span></pre></div>
<a id="trunkSourceWebCoredomDOMImplementationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/DOMImplementation.cpp (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/DOMImplementation.cpp        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/dom/DOMImplementation.cpp        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx"> #include &quot;HTMLDocument.h&quot;
</span><span class="cx"> #include &quot;Image.h&quot;
</span><span class="cx"> #include &quot;ImageDocument.h&quot;
</span><ins>+#include &quot;MainFrame.h&quot;
</ins><span class="cx"> #include &quot;MediaDocument.h&quot;
</span><span class="cx"> #include &quot;MediaList.h&quot;
</span><span class="cx"> #include &quot;MIMETypeRegistry.h&quot;
</span><span class="lines">@@ -314,6 +315,10 @@
</span><span class="cx">         return FTPDirectoryDocument::create(frame, url);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    // If we want to useImageDocumentForSubframePDF, we'll let that override plugin support.
+    if (frame &amp;&amp; !frame-&gt;isMainFrame() &amp;&amp; MIMETypeRegistry::isPDFMIMEType(type) &amp;&amp; frame-&gt;settings().useImageDocumentForSubframePDF())
+        return ImageDocument::create(*frame, url);
+
</ins><span class="cx">     PluginData* pluginData = 0;
</span><span class="cx">     PluginData::AllowedPluginTypes allowedPluginTypes = PluginData::OnlyApplicationPlugins;
</span><span class="cx">     if (frame &amp;&amp; frame-&gt;page()) {
</span><span class="lines">@@ -325,7 +330,7 @@
</span><span class="cx"> 
</span><span class="cx">     // PDF is one image type for which a plugin can override built-in support.
</span><span class="cx">     // We do not want QuickTime to take over all image types, obviously.
</span><del>-    if ((MIMETypeRegistry::isPDFOrPostScriptMIMEType(type)) &amp;&amp; pluginData &amp;&amp; pluginData-&gt;supportsMimeType(type, allowedPluginTypes))
</del><ins>+    if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(type) &amp;&amp; pluginData &amp;&amp; pluginData-&gt;supportsMimeType(type, allowedPluginTypes))
</ins><span class="cx">         return PluginDocument::create(frame, url);
</span><span class="cx">     if (Image::supportsType(type))
</span><span class="cx">         return ImageDocument::create(*frame, url);
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlImageDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/ImageDocument.cpp (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/ImageDocument.cpp        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/html/ImageDocument.cpp        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -34,10 +34,12 @@
</span><span class="cx"> #include &quot;FrameLoader.h&quot;
</span><span class="cx"> #include &quot;FrameLoaderClient.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><ins>+#include &quot;HTMLBodyElement.h&quot;
</ins><span class="cx"> #include &quot;HTMLHtmlElement.h&quot;
</span><span class="cx"> #include &quot;HTMLImageElement.h&quot;
</span><span class="cx"> #include &quot;HTMLNames.h&quot;
</span><span class="cx"> #include &quot;LocalizedStrings.h&quot;
</span><ins>+#include &quot;MIMETypeRegistry.h&quot;
</ins><span class="cx"> #include &quot;MainFrame.h&quot;
</span><span class="cx"> #include &quot;MouseEvent.h&quot;
</span><span class="cx"> #include &quot;Page.h&quot;
</span><span class="lines">@@ -151,8 +153,6 @@
</span><span class="cx">         cachedImage.finishLoading(data.get());
</span><span class="cx">         cachedImage.finish();
</span><span class="cx"> 
</span><del>-        cachedImage.setResponse(loader()-&gt;response());
-
</del><span class="cx">         // Report the natural image size in the page title, regardless of zoom level.
</span><span class="cx">         // At a zoom level of 1 the image is guaranteed to have an integer size.
</span><span class="cx">         updateStyleIfNeeded();
</span><span class="lines">@@ -217,6 +217,8 @@
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;Element&gt; body = Document::createElement(bodyTag, false);
</span><span class="cx">     body-&gt;setAttribute(styleAttr, &quot;margin: 0px&quot;);
</span><ins>+    if (MIMETypeRegistry::isPDFMIMEType(document().loader()-&gt;responseMIMEType()))
+        toHTMLBodyElement(body.get())-&gt;setInlineStyleProperty(CSSPropertyBackgroundColor, &quot;white&quot;, CSSPrimitiveValue::CSS_IDENT);
</ins><span class="cx">     rootElement-&gt;appendChild(body);
</span><span class="cx">     
</span><span class="cx">     RefPtr&lt;ImageDocumentElement&gt; imageElement = ImageDocumentElement::create(*this);
</span><span class="lines">@@ -226,6 +228,7 @@
</span><span class="cx">         imageElement-&gt;setAttribute(styleAttr, &quot;-webkit-user-select:none;&quot;);
</span><span class="cx">     imageElement-&gt;setLoadManually(true);
</span><span class="cx">     imageElement-&gt;setSrc(url().string());
</span><ins>+    imageElement-&gt;cachedImage()-&gt;setResponse(loader()-&gt;response());
</ins><span class="cx">     body-&gt;appendChild(imageElement);
</span><span class="cx">     
</span><span class="cx">     if (m_shouldShrinkImage) {
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentWritercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentWriter.cpp (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentWriter.cpp        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/loader/DocumentWriter.cpp        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -36,6 +36,8 @@
</span><span class="cx"> #include &quot;FrameLoaderClient.h&quot;
</span><span class="cx"> #include &quot;FrameLoaderStateMachine.h&quot;
</span><span class="cx"> #include &quot;FrameView.h&quot;
</span><ins>+#include &quot;MIMETypeRegistry.h&quot;
+#include &quot;MainFrame.h&quot;
</ins><span class="cx"> #include &quot;PluginDocument.h&quot;
</span><span class="cx"> #include &quot;RawDataDocumentParser.h&quot;
</span><span class="cx"> #include &quot;ScriptController.h&quot;
</span><span class="lines">@@ -107,7 +109,7 @@
</span><span class="cx">     if (!m_frame-&gt;loader().stateMachine().isDisplayingInitialEmptyDocument() &amp;&amp; m_frame-&gt;loader().client().shouldAlwaysUsePluginDocument(m_mimeType))
</span><span class="cx">         return PluginDocument::create(m_frame, url);
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    if (equalIgnoringCase(m_mimeType, &quot;application/pdf&quot;))
</del><ins>+    if (MIMETypeRegistry::isPDFMIMEType(m_mimeType) &amp;&amp; (m_frame-&gt;isMainFrame() || !m_frame-&gt;settings().useImageDocumentForSubframePDF()))
</ins><span class="cx">         return PDFDocument::create(m_frame, url);
</span><span class="cx"> #endif
</span><span class="cx">     if (!m_frame-&gt;loader().client().hasHTMLView())
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.in (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.in        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/page/Settings.in        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -221,3 +221,5 @@
</span><span class="cx"> 
</span><span class="cx"> aggressiveTileRetentionEnabled initial=false
</span><span class="cx"> temporaryTileCohortRetentionEnabled initial=true
</span><ins>+
+useImageDocumentForSubframePDF initial=false
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformMIMETypeRegistrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -561,6 +561,15 @@
</span><span class="cx">     return pdfAndPostScriptMIMETypes-&gt;contains(mimeType);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool MIMETypeRegistry::isPDFMIMEType(const String&amp; mimeType)
+{
+    if (mimeType.isEmpty())
+        return false;
+    if (!pdfMIMETypes)
+        initializeMIMETypeRegistry();
+    return pdfMIMETypes-&gt;contains(mimeType);
+}
+
</ins><span class="cx"> bool MIMETypeRegistry::canShowMIMEType(const String&amp; mimeType)
</span><span class="cx"> {
</span><span class="cx">     if (isSupportedImageMIMEType(mimeType) || isSupportedNonImageMIMEType(mimeType) || isSupportedMediaMIMEType(mimeType))
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformMIMETypeRegistryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/MIMETypeRegistry.h        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -79,6 +79,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Check to see if a mime type is one of the common PDF/PS types.
</span><span class="cx">     static bool isPDFOrPostScriptMIMEType(const String&amp; mimeType);
</span><ins>+    static bool isPDFMIMEType(const String&amp; mimeType);
</ins><span class="cx"> 
</span><span class="cx">     // Check to see if a mime type is suitable for being shown inside a page.
</span><span class="cx">     // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(), isSupportedMediaMIMEType() returns true
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-06-17  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        [iOS][wk2] Use ImageDocument to display subframe PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=133944
+        &lt;rdar://problem/17205983&gt;
+
+        Reviewed by Dan Bates.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+        Always use ImageDocument for subframe PDFs in WebKit2 on iOS.
+
</ins><span class="cx"> 2014-06-17  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Make it possible to use -[NSBundle classNamed:] to find WebKitLegacy classes
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (170090 => 170091)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-06-18 01:16:17 UTC (rev 170090)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-06-18 01:35:32 UTC (rev 170091)
</span><span class="lines">@@ -2766,6 +2766,10 @@
</span><span class="cx"> 
</span><span class="cx">     settings.setShouldDispatchJavaScriptWindowOnErrorEvents(true);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+    settings.setUseImageDocumentForSubframePDF(true);
+#endif
+
</ins><span class="cx">     if (store.getBoolValueForKey(WebPreferencesKey::pageVisibilityBasedProcessSuppressionEnabledKey()))
</span><span class="cx">         m_processSuppressionDisabledByWebPreference.stop();
</span><span class="cx">     else
</span></span></pre>
</div>
</div>

</body>
</html>