Code refactoring: move mimeTypeFromUTITree to a separate file.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 20:19:08 +0000 (20:19 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Jul 2012 20:19:08 +0000 (20:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90619

We should move UTI handling related code to a separate file.

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2012-07-05
Reviewed by David Kilzer.

* WebCore.xcodeproj/project.pbxproj: Add UTIUtilities.h/UTIUtilities.mm to xcode project, and drive-by fix
    that happened when editing the Xcode project file.
* platform/network/mac/UTIUtilities.h: Added.
(WebCore):
* platform/network/mac/UTIUtilities.mm: Added.  move mimeTypeFromUTITree to UTIUtilities.mm.
(WebCore):
(WebCore::mimeTypeFromUTITree):
* platform/network/mac/WebCoreURLResponse.mm: include UTIUtilities.h to use mimeTypeFromUTITree.
(WebCore):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121923 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/network/mac/UTIUtilities.h [new file with mode: 0644]
Source/WebCore/platform/network/mac/UTIUtilities.mm [new file with mode: 0644]
Source/WebCore/platform/network/mac/WebCoreURLResponse.mm

index 3e2ecfa..b0cb4bd 100644 (file)
@@ -1,3 +1,22 @@
+2012-07-05  Yongjun Zhang  <yongjun_zhang@apple.com>
+
+        Code refactoring: move mimeTypeFromUTITree to a separate file.
+        https://bugs.webkit.org/show_bug.cgi?id=90619
+
+        We should move UTI handling related code to a separate file.
+
+        Reviewed by David Kilzer.
+
+        * WebCore.xcodeproj/project.pbxproj: Add UTIUtilities.h/UTIUtilities.mm to xcode project, and drive-by fix
+            that happened when editing the Xcode project file.
+        * platform/network/mac/UTIUtilities.h: Added.
+        (WebCore):
+        * platform/network/mac/UTIUtilities.mm: Added.  move mimeTypeFromUTITree to UTIUtilities.mm.
+        (WebCore):
+        (WebCore::mimeTypeFromUTITree):
+        * platform/network/mac/WebCoreURLResponse.mm: include UTIUtilities.h to use mimeTypeFromUTITree.
+        (WebCore):
+
 2012-07-05  Leandro Gracia Gil  <leandrogracia@chromium.org>
 
         Character iterators should not advance if they are at end
index 5141077..b66d7f2 100644 (file)
                1F3C3BEA135CAF3C00B8C1AC /* MediaControls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */; };
                1F3C3BEB135CAF3C00B8C1AC /* MediaControls.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */; };
                1F3F19531499CA7600A5AEA7 /* PODFreeListArena.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F3F19521499CA7600A5AEA7 /* PODFreeListArena.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */; };
+               1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */; };
                20D629261253690B00081543 /* InspectorInstrumentation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20D629241253690B00081543 /* InspectorInstrumentation.cpp */; };
                20D629271253690B00081543 /* InspectorInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = 20D629251253690B00081543 /* InspectorInstrumentation.h */; };
                227777601345DEA9008EA455 /* InspectorFrontendChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 2277775F1345DEA9008EA455 /* InspectorFrontendChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1F3C3BE8135CAF3C00B8C1AC /* MediaControls.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaControls.cpp; sourceTree = "<group>"; };
                1F3C3BE9135CAF3C00B8C1AC /* MediaControls.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaControls.h; sourceTree = "<group>"; };
                1F3F19521499CA7600A5AEA7 /* PODFreeListArena.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PODFreeListArena.h; sourceTree = "<group>"; };
+               1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTIUtilities.h; sourceTree = "<group>"; };
+               1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIUtilities.mm; sourceTree = "<group>"; };
                20D629241253690B00081543 /* InspectorInstrumentation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorInstrumentation.cpp; sourceTree = "<group>"; };
                20D629251253690B00081543 /* InspectorInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorInstrumentation.h; sourceTree = "<group>"; };
                2277775F1345DEA9008EA455 /* InspectorFrontendChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorFrontendChannel.h; sourceTree = "<group>"; };
                3314ACE910892086000F0E56 /* JSExceptionBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSExceptionBase.cpp; sourceTree = "<group>"; };
                3314ACEA10892086000F0E56 /* JSExceptionBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSExceptionBase.h; sourceTree = "<group>"; };
                333F704E0FB49CA2008E12A6 /* Notification.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Notification.idl; path = Modules/notifications/Notification.idl; sourceTree = "<group>"; };
-               333F704F0FB49CA2008E12A6 /* Notification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Notification.h; path =Modules/notifications/Notification.h; sourceTree = "<group>"; };
+               333F704F0FB49CA2008E12A6 /* Notification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Notification.h; path = Modules/notifications/Notification.h; sourceTree = "<group>"; };
                33503C9910179A74003B47E1 /* NotificationClient.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 4; name = NotificationClient.h; path = Modules/notifications/NotificationClient.h; sourceTree = "<group>"; };
                33503C9F10179AD7003B47E1 /* JSNotification.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSNotification.cpp; sourceTree = "<group>"; };
                33503CA010179AD7003B47E1 /* JSNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSNotification.h; sourceTree = "<group>"; };
                                514C76470CE9234E007EF3CD /* ResourceHandleMac.mm */,
                                514C76490CE9234E007EF3CD /* ResourceRequestMac.mm */,
                                514C764B0CE9234E007EF3CD /* ResourceResponseMac.mm */,
+                               1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */,
+                               1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */,
                                37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */,
                                37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */,
                        );
                                50987C27157D676D00BDA835 /* CustomFilterGlobalContext.h in Headers */,
                                4F32BB1B14FA85E800F6C1A3 /* MemoryInstrumentation.h in Headers */,
                                A882DA231593848D000115ED /* CSSToStyleMap.h in Headers */,
+                               1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                2E4346480F546A8200B0F1BA /* WorkerContext.cpp in Sources */,
                                9712A611150090CE0048AF10 /* WorkerContextIndexedDatabase.cpp in Sources */,
                                97F8E665151D4A4B00D2D181 /* WorkerContextNotifications.cpp in Sources */,
-                               A8CCBB4C151F833B00AB7CE9 /* WorkerContextWebDatabase.cpp in Sources */, F34742E01343631F00531BC2 /* WorkerDebuggerAgent.cpp in Sources */,
+                               A8CCBB4C151F833B00AB7CE9 /* WorkerContextWebDatabase.cpp in Sources */,
+                               F34742E01343631F00531BC2 /* WorkerDebuggerAgent.cpp in Sources */,
                                A3E2643014748991005A8588 /* WorkerEventQueue.cpp in Sources */,
                                F36E07A41358A8BE00AACBC9 /* WorkerInspectorController.cpp in Sources */,
                                2E43464C0F546A8200B0F1BA /* WorkerLocation.cpp in Sources */,
                                CE7B2DB61586ABAD0098B3FA /* TextAlternativeWithRange.mm in Sources */,
                                50987C26157D676D00BDA835 /* CustomFilterGlobalContext.cpp in Sources */,
                                A882DA201593846A000115ED /* CSSToStyleMap.cpp in Sources */,
+                               1FAFBF1815A5FA6E00083A20 /* UTIUtilities.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebCore/platform/network/mac/UTIUtilities.h b/Source/WebCore/platform/network/mac/UTIUtilities.h
new file mode 100644 (file)
index 0000000..b3787ed
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UTIUtilities_h
+#define UTIUtilities_h
+
+#import <wtf/RetainPtr.h>
+
+namespace WebCore {
+RetainPtr<CFStringRef> mimeTypeFromUTITree(CFStringRef uti);
+}
+
+#endif // UTIUtilities_h
diff --git a/Source/WebCore/platform/network/mac/UTIUtilities.mm b/Source/WebCore/platform/network/mac/UTIUtilities.mm
new file mode 100644 (file)
index 0000000..9cdc0d6
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer. 
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution. 
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "UTIUtilities.h"
+
+#if PLATFORM(IOS)
+#import "SoftLinking.h"
+#import <MobileCoreServices/MobileCoreServices.h>
+
+SOFT_LINK_FRAMEWORK(MobileCoreServices)
+
+SOFT_LINK(MobileCoreServices, UTTypeCopyDeclaration, CFDictionaryRef, (CFStringRef inUTI), (inUTI))
+SOFT_LINK(MobileCoreServices, UTTypeCopyPreferredTagWithClass, CFStringRef, (CFStringRef inUTI, CFStringRef inTagClass), (inUTI, inTagClass))
+
+SOFT_LINK_CONSTANT(MobileCoreServices, kUTTypeConformsToKey, CFStringRef)
+SOFT_LINK_CONSTANT(MobileCoreServices, kUTTagClassMIMEType, CFStringRef)
+
+#define kUTTagClassMIMEType getkUTTagClassMIMEType()
+#define kUTTypeConformsToKey getkUTTypeConformsToKey()
+#endif
+
+namespace WebCore {
+
+RetainPtr<CFStringRef> mimeTypeFromUTITree(CFStringRef uti)
+{
+    // Check if this UTI has a MIME type.
+    RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
+    if (mimeType)
+        return mimeType.get();
+
+    // If not, walk the ancestory of this UTI via its "ConformsTo" tags and return the first MIME type we find.
+    RetainPtr<CFDictionaryRef> decl(AdoptCF, UTTypeCopyDeclaration(uti));
+    if (!decl)
+        return nil;
+    CFTypeRef value = CFDictionaryGetValue(decl.get(), kUTTypeConformsToKey);
+    if (!value)
+        return nil;
+    CFTypeID typeID = CFGetTypeID(value);
+
+    if (typeID == CFStringGetTypeID())
+        return mimeTypeFromUTITree((CFStringRef)value);
+
+    if (typeID == CFArrayGetTypeID()) {
+        CFArrayRef newTypes = (CFArrayRef)value;
+        CFIndex count = CFArrayGetCount(newTypes);
+        for (CFIndex i = 0; i < count; ++i) {
+        CFTypeRef object = CFArrayGetValueAtIndex(newTypes, i);
+        if (CFGetTypeID(object) != CFStringGetTypeID())
+            continue;
+
+        if (RetainPtr<CFStringRef> mimeType = mimeTypeFromUTITree((CFStringRef)object))
+            return mimeType;
+        }
+    }
+
+    return nil;
+}
+
+}
index 0960492..be2e276 100644 (file)
@@ -30,6 +30,7 @@
 #import "WebCoreURLResponse.h"
 
 #import "MIMETypeRegistry.h"
+#import "UTIUtilities.h"
 #import "WebCoreSystemInterface.h"
 #import <wtf/Assertions.h>
 #import <wtf/RetainPtr.h>
@@ -447,41 +448,6 @@ static CFDictionaryRef createExtensionToMIMETypeMap()
     return CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys, (const void**)&values, sizeof(keys)/sizeof(CFStringRef), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 }
 
-static RetainPtr<CFStringRef> mimeTypeFromUTITree(CFStringRef uti)
-{
-    // Check if this UTI has a MIME type.
-    RetainPtr<CFStringRef> mimeType(AdoptCF, UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));
-    if (mimeType)
-        return mimeType.get();
-    
-    // If not, walk the ancestory of this UTI via its "ConformsTo" tags and return the first MIME type we find.
-    RetainPtr<CFDictionaryRef> decl(AdoptCF, UTTypeCopyDeclaration(uti));
-    if (!decl)
-        return nil;
-    CFTypeRef value = CFDictionaryGetValue(decl.get(), kUTTypeConformsToKey);
-    if (!value)
-        return nil;
-    CFTypeID typeID = CFGetTypeID(value);
-    
-    if (typeID == CFStringGetTypeID())
-        return mimeTypeFromUTITree((CFStringRef)value);
-
-    if (typeID == CFArrayGetTypeID()) {
-        CFArrayRef newTypes = (CFArrayRef)value;
-        CFIndex count = CFArrayGetCount(newTypes);
-        for (CFIndex i = 0; i < count; ++i) {
-            CFTypeRef object = CFArrayGetValueAtIndex(newTypes, i);
-            if (CFGetTypeID(object) != CFStringGetTypeID())
-                continue;
-
-            if (RetainPtr<CFStringRef> mimeType = mimeTypeFromUTITree((CFStringRef)object))
-                return mimeType;
-        }
-    }
-    
-    return nil;
-}
-
 void adjustMIMETypeIfNecessary(CFURLResponseRef cfResponse)
 {
     RetainPtr<CFStringRef> result = wkGetCFURLResponseMIMEType(cfResponse);