Diff
Modified: trunk/LayoutTests/ChangeLog (200529 => 200530)
--- trunk/LayoutTests/ChangeLog 2016-05-06 22:39:07 UTC (rev 200529)
+++ trunk/LayoutTests/ChangeLog 2016-05-06 22:47:16 UTC (rev 200530)
@@ -1,3 +1,15 @@
+2016-05-06 Tim Horton <timothy_hor...@apple.com>
+
+ <attachment> element should understand UTIs
+ https://bugs.webkit.org/show_bug.cgi?id=157425
+ <rdar://problem/25585401>
+
+ 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.
+
2016-05-06 Chris Dumez <cdu...@apple.com>
Clean up converting from JSValue to float / double in the bindings generator
Added: trunk/LayoutTests/fast/attachment/attachment-uti-expected.html (0 => 200530)
--- 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)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<script>
+ if (window.internals)
+ window.internals.settings.setAttachmentElementEnabled(true)
+</script>
+<body>
+<attachment title=" " type="image/jpeg"></attachment>
+<attachment title=" " type="text/plain"></attachment>
+</body>
+</html>
Added: trunk/LayoutTests/fast/attachment/attachment-uti.html (0 => 200530)
--- 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)
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<script>
+ if (window.internals)
+ window.internals.settings.setAttachmentElementEnabled(true)
+</script>
+<body>
+<attachment title=" " type="public.jpeg"></attachment>
+<attachment title=" " type="public.plain-text"></attachment>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (200529 => 200530)
--- 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)
@@ -1,3 +1,33 @@
+2016-05-06 Tim Horton <timothy_hor...@apple.com>
+
+ <attachment> element should understand UTIs
+ https://bugs.webkit.org/show_bug.cgi?id=157425
+ <rdar://problem/25585401>
+
+ Reviewed by Anders Carlsson.
+
+ UTIs are often much more specific than MIME types, so we should allow
+ clients of <attachment> 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.
+
2016-05-06 Chris Dumez <cdu...@apple.com>
Clean up converting from JSValue to float / double in the bindings generator
Modified: trunk/Source/WebCore/platform/graphics/Icon.h (200529 => 200530)
--- 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)
@@ -62,7 +62,6 @@
#if PLATFORM(MAC)
static RefPtr<Icon> createIconForUTI(const String&);
- static RefPtr<Icon> createIconForMIMEType(const String&);
static RefPtr<Icon> createIconForFileExtension(const String&);
#endif
Modified: trunk/Source/WebCore/platform/graphics/mac/IconMac.mm (200529 => 200530)
--- 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)
@@ -91,11 +91,6 @@
return adoptRef(new Icon(image));
}
-RefPtr<Icon> Icon::createIconForMIMEType(const String& MIMEType)
-{
- return createIconForUTI(UTIFromMIMEType(MIMEType.createCFString().get()).get());
-}
-
void Icon::paint(GraphicsContext& context, const FloatRect& rect)
{
if (context.paintingDisabled())
Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.h (200529 => 200530)
--- 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)
@@ -31,6 +31,7 @@
namespace WebCore {
RetainPtr<CFStringRef> mimeTypeFromUTITree(CFStringRef uti);
RetainPtr<CFStringRef> UTIFromMIMEType(CFStringRef mime);
+bool isDeclaredUTI(CFStringRef UTI);
}
#endif // UTIUtilities_h
Modified: trunk/Source/WebCore/platform/network/mac/UTIUtilities.mm (200529 => 200530)
--- 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)
@@ -32,6 +32,7 @@
SOFT_LINK_FRAMEWORK(MobileCoreServices)
+SOFT_LINK(MobileCoreServices, UTTypeIsDeclared, Boolean, (CFStringRef inUTI), (inUTI))
SOFT_LINK(MobileCoreServices, UTTypeCopyDeclaration, CFDictionaryRef, (CFStringRef inUTI), (inUTI))
SOFT_LINK(MobileCoreServices, UTTypeCopyPreferredTagWithClass, CFStringRef, (CFStringRef inUTI, CFStringRef inTagClass), (inUTI, inTagClass))
SOFT_LINK(MobileCoreServices, UTTypeCreatePreferredIdentifierForTag, CFStringRef, (CFStringRef inTagClass, CFStringRef inTag, CFStringRef inConformingToUTI), (inTagClass, inTag, inConformingToUTI))
@@ -86,4 +87,9 @@
return uti;
}
+bool isDeclaredUTI(CFStringRef UTI)
+{
+ return UTTypeIsDeclared(UTI);
}
+
+}
Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (200529 => 200530)
--- 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)
@@ -1497,7 +1497,7 @@
static RetainPtr<UIImage> iconForAttachment(const RenderAttachment& attachment, FloatSize& size)
{
- String MIMEType = attachment.attachmentElement().attachmentType();
+ auto documentInteractionController = adoptNS([[getUIDocumentInteractionControllerClass() alloc] init]);
String fileName;
if (File* file = attachment.attachmentElement().file())
@@ -1505,18 +1505,25 @@
if (fileName.isEmpty())
fileName = attachment.attachmentElement().attachmentTitle();
+ [documentInteractionController setName:fileName];
- RetainPtr<UIImage> result;
+ String attachmentType = attachment.attachmentElement().attachmentType();
+ if (!attachmentType.isEmpty()) {
+ auto attachmentTypeCF = attachmentType.createCFString();
+ RetainPtr<CFStringRef> UTI;
+ if (isDeclaredUTI(attachmentTypeCF.get()))
+ UTI = attachmentTypeCF;
+ else
+ UTI = UTIFromMIMEType(attachmentTypeCF.get());
- RetainPtr<UIDocumentInteractionController> documentInteractionController = adoptNS([[getUIDocumentInteractionControllerClass() alloc] init]);
- [documentInteractionController setName:fileName];
- [documentInteractionController setUTI:static_cast<NSString *>(mimeTypeFromUTITree(MIMEType.createCFString().get()).get())];
+ [documentInteractionController setUTI:static_cast<NSString *>(UTI.get())];
+ }
NSArray *icons = [documentInteractionController icons];
if (!icons.count)
return nil;
- result = icons.lastObject;
+ RetainPtr<UIImage> result = icons.lastObject;
BOOL useHeightForClosestMatch = [result size].height > [result size].width;
CGFloat bestMatchRatio = -1;
Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (200529 => 200530)
--- 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)
@@ -68,6 +68,7 @@
#import "StyleResolver.h"
#import "ThemeMac.h"
#import "TimeRanges.h"
+#import "UTIUtilities.h"
#import "UserAgentScripts.h"
#import "UserAgentStyleSheets.h"
#import "WebCoreSystemInterface.h"
@@ -2403,13 +2404,23 @@
static RefPtr<Icon> iconForAttachment(const RenderAttachment& attachment)
{
- String MIMEType = attachment.attachmentElement().attachmentType();
- if (!MIMEType.isEmpty()) {
- if (equalIgnoringASCIICase(MIMEType, "multipart/x-folder") || equalIgnoringASCIICase(MIMEType, "application/vnd.apple.folder")) {
+ String attachmentType = attachment.attachmentElement().attachmentType();
+
+ if (!attachmentType.isEmpty()) {
+ if (equalIgnoringASCIICase(attachmentType, "multipart/x-folder") || equalIgnoringASCIICase(attachmentType, "application/vnd.apple.folder")) {
if (auto icon = Icon::createIconForUTI("public.directory"))
return icon;
- } else if (auto icon = Icon::createIconForMIMEType(MIMEType))
- return icon;
+ } else {
+ auto attachmentTypeCF = attachmentType.createCFString();
+ RetainPtr<CFStringRef> UTI;
+ if (isDeclaredUTI(attachmentTypeCF.get()))
+ UTI = attachmentTypeCF;
+ else
+ UTI = UTIFromMIMEType(attachmentTypeCF.get());
+
+ if (auto icon = Icon::createIconForUTI(UTI.get()))
+ return icon;
+ }
}
if (File* file = attachment.attachmentElement().file()) {