Changeset 263832 in webkit
- Timestamp:
- Jul 1, 2020, 10:02:18 PM (6 years ago)
- Location:
- trunk/Source
- Files:
-
- 8 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/platform/MIMETypeRegistry.h (modified) (1 diff)
-
WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm (modified) (2 diffs)
-
WebCore/platform/playstation/MIMETypeRegistryPlayStation.cpp (modified) (1 diff)
-
WebCore/platform/win/MIMETypeRegistryWin.cpp (modified) (1 diff)
-
WebCore/platform/xdg/MIMETypeRegistryXdg.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/API/Cocoa/WKOpenPanelParameters.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r263830 r263832 1 2020-07-01 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 MIMETypeRegistry::getExtensionsForMIMEType() needs to handle wildcard MIME types 4 https://bugs.webkit.org/show_bug.cgi?id=213826 5 6 Reviewed by Darin Adler. 7 8 Working towards webkit.org/b/213347, it needs to be possible for WebCore 9 to get the file extensions for wildcard MIME types, e.g. "image/*" or "video/*". 10 11 For Cocoa platforms, we will enumerate the UTIs of the system. Get the 12 MIMEType and the extensions of each UTI. Add the following pairs to a 13 singleton HashMap: 14 15 { MIMEType, extension } 16 { Type(MIMEType)/*, extension } 17 18 Change MIMETypeRegistry::getExtensionsForMIMEType() such that it calls 19 extensionsForWildcardMIMEType() if the MIMEType ends with "*". 20 21 * platform/MIMETypeRegistry.h: 22 * platform/cocoa/MIMETypeRegistryCocoa.mm: 23 (WebCore::extensionsForMIMETypeMap): 24 (WebCore::extensionsForWildcardMIMEType): 25 (WebCore::MIMETypeRegistry::getExtensionsForMIMEType): 26 * platform/playstation/MIMETypeRegistryPlayStation.cpp: 27 (WebCore::MIMETypeRegistry::getExtensionsForMIMEType): 28 * platform/win/MIMETypeRegistryWin.cpp: 29 (WebCore::MIMETypeRegistry::getExtensionsForMIMEType): 30 * platform/xdg/MIMETypeRegistryXdg.cpp: 31 (WebCore::MIMETypeRegistry::getExtensionsForMIMEType): 32 1 33 2020-07-01 Said Abou-Hallawa <sabouhallawa@apple.com> 2 34 -
trunk/Source/WebCore/platform/MIMETypeRegistry.h
r261479 r263832 58 58 59 59 // FIXME: WebKit coding style says we should not have the word "get" in the names of these functions. 60 static Vector<String> getExtensionsForMIMEType(const String& type);60 WEBCORE_EXPORT static Vector<String> getExtensionsForMIMEType(const String& type); 61 61 WEBCORE_EXPORT static String getPreferredExtensionForMIMEType(const String& type); 62 62 WEBCORE_EXPORT static String getMediaMIMETypeForExtension(const String& extension); -
trunk/Source/WebCore/platform/cocoa/MIMETypeRegistryCocoa.mm
r259843 r263832 28 28 #import "MIMETypeRegistry.h" 29 29 30 #import <pal/spi/cocoa/CoreServicesSPI.h> 30 31 #import <pal/spi/cocoa/NSURLFileTypeMappingsSPI.h> 31 32 #import <wtf/cocoa/VectorCocoa.h> 32 33 33 34 namespace WebCore { 35 36 static HashMap<String, HashSet<String>>& extensionsForMIMETypeMap() 37 { 38 static auto extensionsForMIMETypeMap = makeNeverDestroyed([] { 39 HashMap<String, HashSet<String>> map; 40 41 auto addExtension = [&](const String& type, const String& extension) { 42 map.add(type, HashSet<String>()).iterator->value.add(extension); 43 }; 44 45 auto addExtensions = [&](const String& type, NSArray<NSString *> *extensions) { 46 size_t pos = type.reverseFind('/'); 47 48 ASSERT(pos != notFound); 49 auto wildcardMIMEType = makeString(type.left(pos), "/*"_s); 50 51 for (NSString *extension in extensions) { 52 if (!extension) 53 continue; 54 55 // Add extension to wildcardMIMEType, for example add "png" to "image/*" 56 addExtension(wildcardMIMEType, extension); 57 // Add extension to its mimeType, for example add "png" to "image/png" 58 addExtension(type, extension); 59 } 60 }; 61 62 auto allUTIs = adoptNS((__bridge NSArray<NSString *> *)_UTCopyDeclaredTypeIdentifiers()); 63 64 for (NSString *uti in allUTIs.get()) { 65 auto type = adoptCF(UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)uti, kUTTagClassMIMEType)); 66 if (!type) 67 continue; 68 auto extensions = adoptCF(UTTypeCopyAllTagsWithClass((__bridge CFStringRef)uti, kUTTagClassFilenameExtension)); 69 if (!extensions || !CFArrayGetCount(extensions.get())) 70 continue; 71 addExtensions(type.get(), (__bridge NSArray<NSString *> *)extensions.get()); 72 } 73 74 return map; 75 }()); 76 77 return extensionsForMIMETypeMap; 78 } 79 80 static Vector<String> extensionsForWildcardMIMEType(const String& type) 81 { 82 Vector<String> extensions; 83 84 auto iterator = extensionsForMIMETypeMap().find(type); 85 if (iterator != extensionsForMIMETypeMap().end()) 86 extensions.appendRange(iterator->value.begin(), iterator->value.end()); 87 88 return extensions; 89 } 34 90 35 91 String MIMETypeRegistry::getMIMETypeForExtension(const String& extension) … … 40 96 Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String& type) 41 97 { 98 if (type.endsWith('*')) 99 return extensionsForWildcardMIMEType(type); 42 100 return makeVector<String>([[NSURLFileTypeMappings sharedMappings] extensionsForMIMEType:type]); 43 101 } -
trunk/Source/WebCore/platform/playstation/MIMETypeRegistryPlayStation.cpp
r255391 r263832 81 81 } 82 82 83 Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String&) 84 { 85 ASSERT_NOT_IMPLEMENTED_YET(); 86 return { }; 87 } 88 83 89 } // namespace WebCore -
trunk/Source/WebCore/platform/win/MIMETypeRegistryWin.cpp
r242592 r263832 115 115 } 116 116 117 Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String&) 118 { 119 ASSERT_NOT_IMPLEMENTED_YET(); 120 return { }; 117 121 } 122 123 } -
trunk/Source/WebCore/platform/xdg/MIMETypeRegistryXdg.cpp
r214397 r263832 67 67 } 68 68 69 Vector<String> MIMETypeRegistry::getExtensionsForMIMEType(const String&) 70 { 71 ASSERT_NOT_IMPLEMENTED_YET(); 72 return { }; 69 73 } 74 75 } -
trunk/Source/WebKit/ChangeLog
r263831 r263832 1 2020-07-01 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 MIMETypeRegistry::getExtensionsForMIMEType() needs to handle wildcard MIME types 4 https://bugs.webkit.org/show_bug.cgi?id=213826 5 6 Reviewed by Darin Adler. 7 8 Replace extensionsForMIMEType() with MIMETypeRegistry::getExtensionsForMIMEType(). 9 10 * UIProcess/API/Cocoa/WKOpenPanelParameters.mm: 11 (-[WKOpenPanelParameters _allowedFileExtensions]): 12 1 13 2020-07-01 Lauro Moura <lmoura@igalia.com> 2 14 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKOpenPanelParameters.mm
r262895 r263832 26 26 #import "config.h" 27 27 #import "WKOpenPanelParametersInternal.h" 28 #import < pal/spi/cocoa/CoreServicesSPI.h>28 #import <WebCore/MIMETypeRegistry.h> 29 29 30 30 #if PLATFORM(MAC) 31 31 32 32 #import "WKNSArray.h" 33 34 static NSDictionary<NSString *, NSSet<NSString *> *> *extensionsForMIMETypeMap()35 {36 static auto extensionsForMIMETypeMap = makeNeverDestroyed([] {37 auto extensionsForMIMETypeMap = adoptNS([[NSMutableDictionary alloc] init]);38 auto allUTIs = adoptCF(_UTCopyDeclaredTypeIdentifiers());39 40 auto addExtensionForMIMEType = ^(NSString *mimeType, NSString *extension) {41 if (!extensionsForMIMETypeMap.get()[mimeType])42 extensionsForMIMETypeMap.get()[mimeType] = [NSMutableSet set];43 [extensionsForMIMETypeMap.get()[mimeType] addObject:extension];44 };45 46 auto addExtensionsForMIMEType = ^(NSString *mimeType, NSArray<NSString *> *extensions) {47 auto wildcardMIMEType = [[mimeType componentsSeparatedByString:@"/"][0] stringByAppendingString:@"/*"];48 49 for (NSString *extension in extensions) {50 if (!extension)51 continue;52 // Add extension to wildcardMIMEType, for example add "png" to "image/*"53 addExtensionForMIMEType(wildcardMIMEType, extension);54 // Add extension to itsmimeType, for example add "png" to "image/png"55 addExtensionForMIMEType(mimeType, extension);56 }57 };58 59 for (CFIndex i = 0, count = CFArrayGetCount(allUTIs.get()); i < count; ++i) {60 auto uti = static_cast<CFStringRef>(CFArrayGetValueAtIndex(allUTIs.get(), i));61 auto mimeType = adoptCF(UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType));62 if (!mimeType)63 continue;64 auto extensions = adoptCF(UTTypeCopyAllTagsWithClass(uti, kUTTagClassFilenameExtension));65 addExtensionsForMIMEType((__bridge NSString *)mimeType.get(), (__bridge NSArray<NSString *> *)extensions.get());66 }67 68 // Add additional mime types which _UTCopyDeclaredTypeIdentifiers() may not return.69 addExtensionForMIMEType(@"image/webp", @"webp");70 71 return extensionsForMIMETypeMap;72 }());73 74 return extensionsForMIMETypeMap.get().get();75 }76 77 static NSSet<NSString *> *extensionsForMIMEType(NSString *mimetype)78 {79 return [extensionsForMIMETypeMap() objectForKey:mimetype];80 }81 33 82 34 @implementation WKOpenPanelParameters … … 123 75 [acceptedMIMETypes enumerateObjectsUsingBlock:^(NSString *mimeType, NSUInteger index, BOOL* stop) { 124 76 ASSERT([mimeType containsString:@"/"]); 125 [allowedFileExtensions unionSet:extensionsForMIMEType(mimeType)]; 77 auto extensions = API::Array::createStringArray(WebCore::MIMETypeRegistry::getExtensionsForMIMEType(mimeType)); 78 [allowedFileExtensions addObjectsFromArray:wrapper(extensions)]; 126 79 }]; 127 80
Note:
See TracChangeset
for help on using the changeset viewer.