| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/base/platform_mime_util.h" | 5 #include "net/base/platform_mime_util.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension)); | 66 UTTypeCopyPreferredTagWithClass(uti, kUTTagClassFilenameExtension)); |
| 67 if (!ext_ref) | 67 if (!ext_ref) |
| 68 return false; | 68 return false; |
| 69 | 69 |
| 70 *ext = base::SysCFStringRefToUTF8(ext_ref); | 70 *ext = base::SysCFStringRefToUTF8(ext_ref); |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void PlatformMimeUtil::GetPlatformExtensionsForMimeType( | 74 void PlatformMimeUtil::GetPlatformExtensionsForMimeType( |
| 75 const std::string& mime_type, | 75 const std::string& mime_type, |
| 76 base::hash_set<base::FilePath::StringType>* extensions) const { | 76 std::unordered_set<base::FilePath::StringType>* extensions) const { |
| 77 #if defined(OS_IOS) | 77 #if defined(OS_IOS) |
| 78 NSArray* extensions_list = nil; | 78 NSArray* extensions_list = nil; |
| 79 #else | 79 #else |
| 80 // There is no API for this that uses UTIs. The WebKitSystemInterface call | 80 // There is no API for this that uses UTIs. The WebKitSystemInterface call |
| 81 // WKGetExtensionsForMIMEType() is a thin wrapper around | 81 // WKGetExtensionsForMIMEType() is a thin wrapper around |
| 82 // [[NSURLFileTypeMappings sharedMappings] extensionsForMIMEType:], which is | 82 // [[NSURLFileTypeMappings sharedMappings] extensionsForMIMEType:], which is |
| 83 // used by Firefox as well. | 83 // used by Firefox as well. |
| 84 // | 84 // |
| 85 // See: | 85 // See: |
| 86 // http://mxr.mozilla.org/mozilla-central/search?string=extensionsForMIMEType | 86 // http://mxr.mozilla.org/mozilla-central/search?string=extensionsForMIMEType |
| 87 // http://www.openradar.me/11384153 | 87 // http://www.openradar.me/11384153 |
| 88 // rdar://11384153 | 88 // rdar://11384153 |
| 89 NSArray* extensions_list = | 89 NSArray* extensions_list = |
| 90 [[NSURLFileTypeMappings sharedMappings] | 90 [[NSURLFileTypeMappings sharedMappings] |
| 91 extensionsForMIMEType:base::SysUTF8ToNSString(mime_type)]; | 91 extensionsForMIMEType:base::SysUTF8ToNSString(mime_type)]; |
| 92 #endif // defined(OS_IOS) | 92 #endif // defined(OS_IOS) |
| 93 | 93 |
| 94 if (extensions_list) { | 94 if (extensions_list) { |
| 95 for (NSString* extension in extensions_list) | 95 for (NSString* extension in extensions_list) |
| 96 extensions->insert(base::SysNSStringToUTF8(extension)); | 96 extensions->insert(base::SysNSStringToUTF8(extension)); |
| 97 } else { | 97 } else { |
| 98 // Huh? Give up. | 98 // Huh? Give up. |
| 99 base::FilePath::StringType ext; | 99 base::FilePath::StringType ext; |
| 100 if (GetPreferredExtensionForMimeType(mime_type, &ext)) | 100 if (GetPreferredExtensionForMimeType(mime_type, &ext)) |
| 101 extensions->insert(ext); | 101 extensions->insert(ext); |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace net | 105 } // namespace net |
| OLD | NEW |