<!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>[200530] 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/200530">200530</a></dd>
<dt>Author</dt> <dd>timothy_horton@apple.com</dd>
<dt>Date</dt> <dd>2016-05-06 15:47:16 -0700 (Fri, 06 May 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>&lt;attachment&gt; element should understand UTIs
https://bugs.webkit.org/show_bug.cgi?id=157425
&lt;rdar://problem/25585401&gt;

Reviewed by Anders Carlsson.

UTIs are often much more specific than MIME types, so we should allow
clients of &lt;attachment&gt; to use them to get more accurate icons.

Test: fast/attachment/attachment-uti.html

* platform/graphics/Icon.h:
* platform/graphics/mac/IconMac.mm:
(WebCore::Icon::createIconForMIMEType): Deleted.
Remove the now-unused createIconForMIMEType.

* platform/network/mac/UTIUtilities.h:
* platform/network/mac/UTIUtilities.mm:
(WebCore::isDeclaredUTI):
Expose UTTypeIsDeclared as isDeclaredUTI.

* rendering/RenderThemeIOS.mm:
(WebCore::iconForAttachment):
* rendering/RenderThemeMac.mm:
(WebCore::iconForAttachment):
If the attachment's type is a UTI, request the icon for it directly.
If it's a MIME type, convert to a UTI before requesting.

* fast/attachment/attachment-uti-expected.html: Added.
* fast/attachment/attachment-uti.html: Added.
Add a test that UTIs render the same as their corresponding MIME types.</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="#trunkSourceWebCoreplatformgraphicsIconh">trunk/Source/WebCore/platform/graphics/Icon.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsmacIconMacmm">trunk/Source/WebCore/platform/graphics/mac/IconMac.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkmacUTIUtilitiesh">trunk/Source/WebCore/platform/network/mac/UTIUtilities.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkmacUTIUtilitiesmm">trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemeIOSmm">trunk/Source/WebCore/rendering/RenderThemeIOS.mm</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderThemeMacmm">trunk/Source/WebCore/rendering/RenderThemeMac.mm</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastattachmentattachmentutiexpectedhtml">trunk/LayoutTests/fast/attachment/attachment-uti-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastattachmentattachmentutihtml">trunk/LayoutTests/fast/attachment/attachment-uti.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/LayoutTests/ChangeLog        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-05-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        &lt;attachment&gt; element should understand UTIs
+        https://bugs.webkit.org/show_bug.cgi?id=157425
+        &lt;rdar://problem/25585401&gt;
+
+        Reviewed by Anders Carlsson.
+
+        * fast/attachment/attachment-uti-expected.html: Added.
+        * fast/attachment/attachment-uti.html: Added.
+        Add a test that UTIs render the same as their corresponding MIME types.
+
</ins><span class="cx"> 2016-05-06  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Clean up converting from JSValue to float / double in the bindings generator
</span></span></pre></div>
<a id="trunkLayoutTestsfastattachmentattachmentutiexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/attachment/attachment-uti-expected.html (0 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/attachment/attachment-uti-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-uti-expected.html        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.settings.setAttachmentElementEnabled(true)
+&lt;/script&gt;
+&lt;body&gt;
+&lt;attachment title=&quot; &quot; type=&quot;image/jpeg&quot;&gt;&lt;/attachment&gt;
+&lt;attachment title=&quot; &quot; type=&quot;text/plain&quot;&gt;&lt;/attachment&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastattachmentattachmentutihtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/attachment/attachment-uti.html (0 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/attachment/attachment-uti.html                                (rev 0)
+++ trunk/LayoutTests/fast/attachment/attachment-uti.html        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;script&gt;
+    if (window.internals)
+        window.internals.settings.setAttachmentElementEnabled(true)
+&lt;/script&gt;
+&lt;body&gt;
+&lt;attachment title=&quot; &quot; type=&quot;public.jpeg&quot;&gt;&lt;/attachment&gt;
+&lt;attachment title=&quot; &quot; type=&quot;public.plain-text&quot;&gt;&lt;/attachment&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/ChangeLog        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-05-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+
+        &lt;attachment&gt; element should understand UTIs
+        https://bugs.webkit.org/show_bug.cgi?id=157425
+        &lt;rdar://problem/25585401&gt;
+
+        Reviewed by Anders Carlsson.
+
+        UTIs are often much more specific than MIME types, so we should allow
+        clients of &lt;attachment&gt; to use them to get more accurate icons.
+
+        Test: fast/attachment/attachment-uti.html
+
+        * platform/graphics/Icon.h:
+        * platform/graphics/mac/IconMac.mm:
+        (WebCore::Icon::createIconForMIMEType): Deleted.
+        Remove the now-unused createIconForMIMEType.
+
+        * platform/network/mac/UTIUtilities.h:
+        * platform/network/mac/UTIUtilities.mm:
+        (WebCore::isDeclaredUTI):
+        Expose UTTypeIsDeclared as isDeclaredUTI.
+
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::iconForAttachment):
+        * rendering/RenderThemeMac.mm:
+        (WebCore::iconForAttachment):
+        If the attachment's type is a UTI, request the icon for it directly.
+        If it's a MIME type, convert to a UTI before requesting.
+
</ins><span class="cx"> 2016-05-06  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Clean up converting from JSValue to float / double in the bindings generator
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsIconh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Icon.h (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Icon.h        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/platform/graphics/Icon.h        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -62,7 +62,6 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">     static RefPtr&lt;Icon&gt; createIconForUTI(const String&amp;);
</span><del>-    static RefPtr&lt;Icon&gt; createIconForMIMEType(const String&amp;);
</del><span class="cx">     static RefPtr&lt;Icon&gt; createIconForFileExtension(const String&amp;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsmacIconMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/mac/IconMac.mm (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/mac/IconMac.mm        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/platform/graphics/mac/IconMac.mm        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -91,11 +91,6 @@
</span><span class="cx">     return adoptRef(new Icon(image));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-RefPtr&lt;Icon&gt; Icon::createIconForMIMEType(const String&amp; MIMEType)
-{
-    return createIconForUTI(UTIFromMIMEType(MIMEType.createCFString().get()).get());
-}
-
</del><span class="cx"> void Icon::paint(GraphicsContext&amp; context, const FloatRect&amp; rect)
</span><span class="cx"> {
</span><span class="cx">     if (context.paintingDisabled())
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkmacUTIUtilitiesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.h (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/mac/UTIUtilities.h        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/platform/network/mac/UTIUtilities.h        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> RetainPtr&lt;CFStringRef&gt; mimeTypeFromUTITree(CFStringRef uti);
</span><span class="cx"> RetainPtr&lt;CFStringRef&gt; UTIFromMIMEType(CFStringRef mime);
</span><ins>+bool isDeclaredUTI(CFStringRef UTI);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif // UTIUtilities_h
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkmacUTIUtilitiesmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(MobileCoreServices)
</span><span class="cx"> 
</span><ins>+SOFT_LINK(MobileCoreServices, UTTypeIsDeclared, Boolean, (CFStringRef inUTI), (inUTI))
</ins><span class="cx"> SOFT_LINK(MobileCoreServices, UTTypeCopyDeclaration, CFDictionaryRef, (CFStringRef inUTI), (inUTI))
</span><span class="cx"> SOFT_LINK(MobileCoreServices, UTTypeCopyPreferredTagWithClass, CFStringRef, (CFStringRef inUTI, CFStringRef inTagClass), (inUTI, inTagClass))
</span><span class="cx"> SOFT_LINK(MobileCoreServices, UTTypeCreatePreferredIdentifierForTag, CFStringRef, (CFStringRef inTagClass, CFStringRef inTag, CFStringRef inConformingToUTI), (inTagClass, inTag, inConformingToUTI))
</span><span class="lines">@@ -86,4 +87,9 @@
</span><span class="cx">     return uti;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool isDeclaredUTI(CFStringRef UTI)
+{
+    return UTTypeIsDeclared(UTI);
</ins><span class="cx"> }
</span><ins>+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemeIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -1497,7 +1497,7 @@
</span><span class="cx"> 
</span><span class="cx"> static RetainPtr&lt;UIImage&gt; iconForAttachment(const RenderAttachment&amp; attachment, FloatSize&amp; size)
</span><span class="cx"> {
</span><del>-    String MIMEType = attachment.attachmentElement().attachmentType();
</del><ins>+    auto documentInteractionController = adoptNS([[getUIDocumentInteractionControllerClass() alloc] init]);
</ins><span class="cx"> 
</span><span class="cx">     String fileName;
</span><span class="cx">     if (File* file = attachment.attachmentElement().file())
</span><span class="lines">@@ -1505,18 +1505,25 @@
</span><span class="cx"> 
</span><span class="cx">     if (fileName.isEmpty())
</span><span class="cx">         fileName = attachment.attachmentElement().attachmentTitle();
</span><ins>+    [documentInteractionController setName:fileName];
</ins><span class="cx"> 
</span><del>-    RetainPtr&lt;UIImage&gt; result;
</del><ins>+    String attachmentType = attachment.attachmentElement().attachmentType();
+    if (!attachmentType.isEmpty()) {
+        auto attachmentTypeCF = attachmentType.createCFString();
+        RetainPtr&lt;CFStringRef&gt; UTI;
+        if (isDeclaredUTI(attachmentTypeCF.get()))
+            UTI = attachmentTypeCF;
+        else
+            UTI = UTIFromMIMEType(attachmentTypeCF.get());
</ins><span class="cx"> 
</span><del>-    RetainPtr&lt;UIDocumentInteractionController&gt; documentInteractionController = adoptNS([[getUIDocumentInteractionControllerClass() alloc] init]);
-    [documentInteractionController setName:fileName];
-    [documentInteractionController setUTI:static_cast&lt;NSString *&gt;(mimeTypeFromUTITree(MIMEType.createCFString().get()).get())];
</del><ins>+        [documentInteractionController setUTI:static_cast&lt;NSString *&gt;(UTI.get())];
+    }
</ins><span class="cx"> 
</span><span class="cx">     NSArray *icons = [documentInteractionController icons];
</span><span class="cx">     if (!icons.count)
</span><span class="cx">         return nil;
</span><span class="cx"> 
</span><del>-    result = icons.lastObject;
</del><ins>+    RetainPtr&lt;UIImage&gt; result = icons.lastObject;
</ins><span class="cx"> 
</span><span class="cx">     BOOL useHeightForClosestMatch = [result size].height &gt; [result size].width;
</span><span class="cx">     CGFloat bestMatchRatio = -1;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderThemeMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (200529 => 200530)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderThemeMac.mm        2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm        2016-05-06 22:47:16 UTC (rev 200530)
</span><span class="lines">@@ -68,6 +68,7 @@
</span><span class="cx"> #import &quot;StyleResolver.h&quot;
</span><span class="cx"> #import &quot;ThemeMac.h&quot;
</span><span class="cx"> #import &quot;TimeRanges.h&quot;
</span><ins>+#import &quot;UTIUtilities.h&quot;
</ins><span class="cx"> #import &quot;UserAgentScripts.h&quot;
</span><span class="cx"> #import &quot;UserAgentStyleSheets.h&quot;
</span><span class="cx"> #import &quot;WebCoreSystemInterface.h&quot;
</span><span class="lines">@@ -2403,13 +2404,23 @@
</span><span class="cx"> 
</span><span class="cx"> static RefPtr&lt;Icon&gt; iconForAttachment(const RenderAttachment&amp; attachment)
</span><span class="cx"> {
</span><del>-    String MIMEType = attachment.attachmentElement().attachmentType();
-    if (!MIMEType.isEmpty()) {
-        if (equalIgnoringASCIICase(MIMEType, &quot;multipart/x-folder&quot;) || equalIgnoringASCIICase(MIMEType, &quot;application/vnd.apple.folder&quot;)) {
</del><ins>+    String attachmentType = attachment.attachmentElement().attachmentType();
+    
+    if (!attachmentType.isEmpty()) {
+        if (equalIgnoringASCIICase(attachmentType, &quot;multipart/x-folder&quot;) || equalIgnoringASCIICase(attachmentType, &quot;application/vnd.apple.folder&quot;)) {
</ins><span class="cx">             if (auto icon = Icon::createIconForUTI(&quot;public.directory&quot;))
</span><span class="cx">                 return icon;
</span><del>-        } else if (auto icon = Icon::createIconForMIMEType(MIMEType))
-            return icon;
</del><ins>+        } else {
+            auto attachmentTypeCF = attachmentType.createCFString();
+            RetainPtr&lt;CFStringRef&gt; UTI;
+            if (isDeclaredUTI(attachmentTypeCF.get()))
+                UTI = attachmentTypeCF;
+            else
+                UTI = UTIFromMIMEType(attachmentTypeCF.get());
+
+            if (auto icon = Icon::createIconForUTI(UTI.get()))
+                return icon;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (File* file = attachment.attachmentElement().file()) {
</span></span></pre>
</div>
</div>

</body>
</html>