Commit f947670c authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Switch to UTTypeCopyAllTagsWithClass.

This allows us to remove the use of a private API.

Bug: 1027401
Change-Id: I1cd0e236fdb4ded2093a4120a0af326b57d9efd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929848
Auto-Submit: Avi Drissman <avi@chromium.org>
Commit-Queue: Matt Mueller <mattm@chromium.org>
Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718877}
parent 190c0e45
......@@ -18,16 +18,6 @@
#include <CoreServices/CoreServices.h>
#endif // defined(OS_IOS)
#if !defined(OS_IOS)
// SPI declaration; see the commentary in GetPlatformExtensionsForMimeType.
// iOS must not use any private API, per Apple guideline.
@interface NSURLFileTypeMappings : NSObject
+ (NSURLFileTypeMappings*)sharedMappings;
- (NSArray*)extensionsForMIMEType:(NSString*)mimeType;
@end
#endif // !defined(OS_IOS)
namespace net {
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
......@@ -40,7 +30,7 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
if (!ext_ref)
return false;
base::ScopedCFTypeRef<CFStringRef> uti(UTTypeCreatePreferredIdentifierForTag(
kUTTagClassFilenameExtension, ext_ref, NULL));
kUTTagClassFilenameExtension, ext_ref, nullptr));
if (!uti)
return false;
base::ScopedCFTypeRef<CFStringRef> mime_ref(
......@@ -60,7 +50,7 @@ bool PlatformMimeUtil::GetPlatformPreferredExtensionForMimeType(
if (!mime_ref)
return false;
base::ScopedCFTypeRef<CFStringRef> uti(UTTypeCreatePreferredIdentifierForTag(
kUTTagClassMIMEType, mime_ref, NULL));
kUTTagClassMIMEType, mime_ref, nullptr));
if (!uti)
return false;
base::ScopedCFTypeRef<CFStringRef> ext_ref(
......@@ -75,22 +65,21 @@ bool PlatformMimeUtil::GetPlatformPreferredExtensionForMimeType(
void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
const std::string& mime_type,
std::unordered_set<base::FilePath::StringType>* extensions) const {
#if defined(OS_IOS)
NSArray* extensions_list = nil;
#else
// There is no API for this that uses UTIs. The WebKitSystemInterface call
// WKGetExtensionsForMIMEType() is a thin wrapper around
// [[NSURLFileTypeMappings sharedMappings] extensionsForMIMEType:], which is
// used by Firefox as well.
//
// See:
// http://mxr.mozilla.org/mozilla-central/search?string=extensionsForMIMEType
// http://www.openradar.me/11384153
// rdar://11384153
NSArray* extensions_list =
[[NSURLFileTypeMappings sharedMappings]
extensionsForMIMEType:base::SysUTF8ToNSString(mime_type)];
#endif // defined(OS_IOS)
base::ScopedCFTypeRef<CFArrayRef> exts_ref;
base::ScopedCFTypeRef<CFStringRef> mime_ref(
base::SysUTF8ToCFStringRef(mime_type));
if (mime_ref) {
base::ScopedCFTypeRef<CFStringRef> uti(
UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mime_ref,
nullptr));
if (uti) {
exts_ref.reset(
UTTypeCopyAllTagsWithClass(uti, kUTTagClassFilenameExtension));
}
}
NSArray* extensions_list = base::mac::CFToNSCast(exts_ref);
if (extensions_list) {
for (NSString* extension in extensions_list)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment