[CG] Enable setAdditionalSupportedImageTypes for WK1
authorsaid@apple.com <said@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 00:47:17 +0000 (00:47 +0000)
committersaid@apple.com <said@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Feb 2019 00:47:17 +0000 (00:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=194190

Reviewed by Tim Horton.

Source/WebCore:

Move the function webCoreStringVectorFromNSStringArray from WebKit to
WebCore so it can be used by both WebKit and WebKitLegacy.

* platform/mac/StringUtilities.h:
* platform/mac/StringUtilities.mm:
(WebCore::webCoreStringVectorFromNSStringArray):

Source/WebKit:

Move the function webCoreStringVectorFromNSStringArray from WebKit to
WebCore so it can be used by both WebKit and WebKitLegacy.

* Platform/mac/StringUtilities.h:
* Platform/mac/StringUtilities.mm:
(WebKit::webCoreStringVectorFromNSStringArray): Deleted.
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):

Source/WebKitLegacy/mac:

1. Define the preferences key AdditionalSupportedImageTypes.
2. Add additionalSupportedImageTypes as a private preference property.
3. Define the setter and the getter of the property.
4. Add function to convert from an id to an array of strings.
5. Call WebCore::setAdditionalSupportedImageTypes when preferences change.

* WebView/WebPreferenceKeysPrivate.h:
* WebView/WebPreferences.mm:
(-[WebPreferences _stringArrayValueForKey:]):
(-[WebPreferences _setStringArrayValueForKey:forKey:]):
(-[WebPreferences setAdditionalSupportedImageTypes:]):
(-[WebPreferences additionalSupportedImageTypes]):
* WebView/WebPreferencesPrivate.h:
* WebView/WebView.mm:
(-[WebView _preferencesChanged:]):

Tools:

Add a test similar to the one under WebKit Cocoa but make it create a
WebView instead of a WKWebView.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/mac/100x100-red.tga: Added.
* TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.html: Added.
* TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.mm: Added.
(-[AdditionalSupportedImageTypesTest webView:didFinishLoadForFrame:]):
(TestWebKitAPI::runTest):
(TestWebKitAPI::TEST):

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/mac/StringUtilities.h
Source/WebCore/platform/mac/StringUtilities.mm
Source/WebKit/ChangeLog
Source/WebKit/Platform/mac/StringUtilities.h
Source/WebKit/Platform/mac/StringUtilities.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebView/WebPreferenceKeysPrivate.h
Source/WebKitLegacy/mac/WebView/WebPreferences.mm
Source/WebKitLegacy/mac/WebView/WebPreferencesPrivate.h
Source/WebKitLegacy/mac/WebView/WebView.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/mac/100x100-red.tga [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.mm [new file with mode: 0644]

index 0cf299f..0d7d1b8 100644 (file)
@@ -1,3 +1,17 @@
+2019-02-04  Said Abou-Hallawa  <said@apple.com>
+
+        [CG] Enable setAdditionalSupportedImageTypes for WK1
+        https://bugs.webkit.org/show_bug.cgi?id=194190
+
+        Reviewed by Tim Horton.
+
+        Move the function webCoreStringVectorFromNSStringArray from WebKit to
+        WebCore so it can be used by both WebKit and WebKitLegacy.
+
+        * platform/mac/StringUtilities.h:
+        * platform/mac/StringUtilities.mm:
+        (WebCore::webCoreStringVectorFromNSStringArray):
+
 2019-02-04  Justin Fan  <justin_fan@apple.com>
 
         [Web GPU] Code clean-up for RenderPipeline backend
index 0011bfc..abf2bf1 100644 (file)
 #import <wtf/Forward.h>
 
 namespace WebCore {
+
 WEBCORE_EXPORT bool stringMatchesWildcardString(const String& stringToBeMatched, const String& wildcardString);
+
+#ifdef __OBJC__
+WEBCORE_EXPORT Vector<String> webCoreStringVectorFromNSStringArray(NSArray<NSString *> *);
+#endif // defined(__OBJC__)
+
 }
index 7cd1bd8..f1f56b3 100644 (file)
@@ -59,4 +59,15 @@ bool stringMatchesWildcardString(const String& string, const String& wildcardStr
     return JSC::Yarr::RegularExpression(wildcardRegexPatternString(wildcardString), JSC::Yarr::TextCaseInsensitive).match(string) != -1;
 }
 
+Vector<String> webCoreStringVectorFromNSStringArray(NSArray<NSString *> *nsStringArray)
+{
+    Vector<String> stringVector;
+    stringVector.reserveInitialCapacity([nsStringArray count]);
+
+    for (NSString *nsString in nsStringArray)
+        stringVector.uncheckedAppend(nsString);
+
+    return stringVector;
+}
+
 }
index 7815f29..8c3f6f8 100644 (file)
@@ -1,3 +1,19 @@
+2019-02-04  Said Abou-Hallawa  <said@apple.com>
+
+        [CG] Enable setAdditionalSupportedImageTypes for WK1
+        https://bugs.webkit.org/show_bug.cgi?id=194190
+
+        Reviewed by Tim Horton.
+
+        Move the function webCoreStringVectorFromNSStringArray from WebKit to
+        WebCore so it can be used by both WebKit and WebKitLegacy.
+
+        * Platform/mac/StringUtilities.h:
+        * Platform/mac/StringUtilities.mm:
+        (WebKit::webCoreStringVectorFromNSStringArray): Deleted.
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+
 2019-02-04  Benjamin Poulain  <benjamin@webkit.org>
 
         Use deferrable timer to restart the Responsiveness Timer on each wheel event
index 4257c8c..29a76cd 100644 (file)
@@ -37,8 +37,6 @@ namespace WebKit {
 NSString *nsStringFromWebCoreString(const String&);
 NSString *formattedPhoneNumberString(NSString *originalPhoneNumber);
 
-Vector<String> webCoreStringVectorFromNSStringArray(NSArray<NSString *> *);
-
 #endif // defined(__OBJC__)
 
 }
index bcd2fb6..ecbb797 100644 (file)
@@ -82,15 +82,4 @@ NSString *formattedPhoneNumberString(NSString *)
 
 #endif // ENABLE(TELEPHONE_NUMBER_DETECTION) && PLATFORM(MAC)
 
-Vector<String> webCoreStringVectorFromNSStringArray(NSArray<NSString *> *nsStringArray)
-{
-    Vector<String> stringVector;
-    stringVector.reserveInitialCapacity([nsStringArray count]);
-
-    for (NSString *nsString in nsStringArray)
-        stringVector.uncheckedAppend(nsString);
-
-    return stringVector;
-}
-
 }
index 9a73a36..757c958 100644 (file)
@@ -51,7 +51,6 @@
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
 #import "SafeBrowsingWarning.h"
-#import "StringUtilities.h"
 #import "UIDelegate.h"
 #import "UserMediaProcessManager.h"
 #import "VersionChecks.h"
 #import <WebCore/SchemeRegistry.h>
 #import <WebCore/Settings.h>
 #import <WebCore/SharedBuffer.h>
+#import <WebCore/StringUtilities.h>
 #import <WebCore/ValidationBubble.h>
 #import <WebCore/ViewportArguments.h>
 #import <WebCore/WritingMode.h>
@@ -583,7 +583,7 @@ static void validate(WKWebViewConfiguration *configuration)
             pageConfiguration->setPageGroup(WebKit::WebPageGroup::create(configuration._groupIdentifier).ptr());
     }
 
-    pageConfiguration->setAdditionalSupportedImageTypes(WebKit::webCoreStringVectorFromNSStringArray([_configuration _additionalSupportedImageTypes]));
+    pageConfiguration->setAdditionalSupportedImageTypes(WebCore::webCoreStringVectorFromNSStringArray([_configuration _additionalSupportedImageTypes]));
 
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::suppressesIncrementalRenderingKey(), WebKit::WebPreferencesStore::Value(!![_configuration suppressesIncrementalRendering]));
 
index 088dac1..6ea34d3 100644 (file)
@@ -1,3 +1,26 @@
+2019-02-04  Said Abou-Hallawa  <said@apple.com>
+
+        [CG] Enable setAdditionalSupportedImageTypes for WK1
+        https://bugs.webkit.org/show_bug.cgi?id=194190
+
+        Reviewed by Tim Horton.
+
+        1. Define the preferences key AdditionalSupportedImageTypes.
+        2. Add additionalSupportedImageTypes as a private preference property.
+        3. Define the setter and the getter of the property.
+        4. Add function to convert from an id to an array of strings.
+        5. Call WebCore::setAdditionalSupportedImageTypes when preferences change.
+
+        * WebView/WebPreferenceKeysPrivate.h:
+        * WebView/WebPreferences.mm:
+        (-[WebPreferences _stringArrayValueForKey:]):
+        (-[WebPreferences _setStringArrayValueForKey:forKey:]):
+        (-[WebPreferences setAdditionalSupportedImageTypes:]):
+        (-[WebPreferences additionalSupportedImageTypes]):
+        * WebView/WebPreferencesPrivate.h:
+        * WebView/WebView.mm:
+        (-[WebView _preferencesChanged:]):
+
 2019-02-04  Timothy Hatcher  <timothy@apple.com>
 
         Add WebView SPI to temporarily force light or dark appearance on a page.
index 49d342f..da4d627 100644 (file)
@@ -66,6 +66,7 @@
 #define WebKitAllowAnimatedImagesPreferenceKey @"WebKitAllowAnimatedImagesPreferenceKey"
 #define WebKitAllowAnimatedImageLoopingPreferenceKey @"WebKitAllowAnimatedImageLoopingPreferenceKey"
 #define WebKitDisplayImagesKey @"WebKitDisplayImagesKey"
+#define WebKitAdditionalSupportedImageTypesKey  @"WebKitAdditionalSupportedImageTypesKey"
 #define WebKitLoadSiteIconsKey @"WebKitLoadSiteIconsKey"
 #define WebKitBackForwardCacheExpirationIntervalKey @"WebKitBackForwardCacheExpirationIntervalKey"
 #if !TARGET_OS_IPHONE
index e802c0a..261ff17 100644 (file)
@@ -757,6 +757,36 @@ public:
     [self _postPreferencesChangedNotification];
 }
 
+- (NSArray<NSString *> *)_stringArrayValueForKey:(NSString *)key
+{
+    id value = [self _valueForKey:key];
+    if (![value isKindOfClass:[NSArray class]])
+        return nil;
+
+    NSArray *array = (NSArray *)value;
+    for (id object in array) {
+        if (![object isKindOfClass:[NSString class]])
+            return nil;
+    }
+
+    return (NSArray<NSString *> *)array;
+}
+
+- (void)_setStringArrayValueForKey:(NSArray<NSString *> *)value forKey:(NSString *)key
+{
+    NSString *_key = KEY(key);
+#if PLATFORM(IOS_FAMILY)
+    dispatch_barrier_sync(_private->readWriteQueue, ^{
+#endif
+        [_private->values.get() setObject:value forKey:_key];
+#if PLATFORM(IOS_FAMILY)
+    });
+#endif
+    if (_private->autosaves)
+        [[NSUserDefaults standardUserDefaults] setObject:value forKey:_key];
+    [self _postPreferencesChangedNotification];
+}
+
 - (int)_integerValueForKey:(NSString *)key
 {
     id o = [self _valueForKey:key];
@@ -1159,6 +1189,16 @@ public:
     return [self _boolValueForKey: WebKitDisplayImagesKey];
 }
 
+- (void)setAdditionalSupportedImageTypes:(NSArray<NSString*> *)imageTypes
+{
+    [self _setStringArrayValueForKey:imageTypes forKey:WebKitAdditionalSupportedImageTypesKey];
+}
+
+- (NSArray<NSString *> *)additionalSupportedImageTypes
+{
+    return [self _stringArrayValueForKey:WebKitAdditionalSupportedImageTypesKey];
+}
+
 - (void)setAutosaves:(BOOL)flag
 {
     _private->autosaves = flag;
index 8820db2..ffaf05a 100644 (file)
@@ -626,4 +626,7 @@ extern NSString *WebPreferencesCacheModelChangedInternalNotification WEBKIT_DEPR
 
 @property (nonatomic) NSString *mediaContentTypesRequiringHardwareSupport;
 
+// additionalSupportedImageTypes is an array of image UTIs.
+@property (nonatomic, retain) NSArray<NSString *> *additionalSupportedImageTypes;
+
 @end
index e6c482b..480f885 100644 (file)
 #import <WebCore/Settings.h>
 #import <WebCore/ShouldTreatAsContinuingLoad.h>
 #import <WebCore/SocketProvider.h>
+#import <WebCore/StringUtilities.h>
 #import <WebCore/StyleProperties.h>
 #import <WebCore/TextResourceDecoder.h>
 #import <WebCore/ThreadCheck.h>
+#import <WebCore/UTIRegistry.h>
 #import <WebCore/UserAgent.h>
 #import <WebCore/UserContentController.h>
 #import <WebCore/UserGestureIndicator.h>
@@ -2879,6 +2881,9 @@ static bool needsSelfRetainWhileLoadingQuirk()
     settings.setStandardFontFamily([preferences standardFontFamily]);
     settings.setLoadsImagesAutomatically([preferences loadsImagesAutomatically]);
     settings.setLoadsSiteIconsIgnoringImageLoadingSetting([preferences loadsSiteIconsIgnoringImageLoadingPreference]);
+
+    WebCore::setAdditionalSupportedImageTypes(WebCore::webCoreStringVectorFromNSStringArray([preferences additionalSupportedImageTypes]));
+
 #if PLATFORM(IOS_FAMILY)
     settings.setShouldPrintBackgrounds(true);
 #else
index 2a1dd5f..b6c833c 100644 (file)
@@ -1,3 +1,21 @@
+2019-02-04  Said Abou-Hallawa  <said@apple.com>
+
+        [CG] Enable setAdditionalSupportedImageTypes for WK1
+        https://bugs.webkit.org/show_bug.cgi?id=194190
+
+        Reviewed by Tim Horton.
+
+        Add a test similar to the one under WebKit Cocoa but make it create a
+        WebView instead of a WKWebView.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/100x100-red.tga: Added.
+        * TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.html: Added.
+        * TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.mm: Added.
+        (-[AdditionalSupportedImageTypesTest webView:didFinishLoadForFrame:]):
+        (TestWebKitAPI::runTest):
+        (TestWebKitAPI::TEST):
+
 2019-02-04  Zalan Bujtas  <zalan@apple.com>
 
         [First paint] Adjust "finishedParsingMainDocument" flag by taking deferred and async scripts into account.
index 1ee3a0d..95dc51d 100644 (file)
                55A817FC218100E00004A39A /* AdditionalSupportedImageTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55A817FB218100E00004A39A /* AdditionalSupportedImageTypes.mm */; };
                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55A817FE218101DF0004A39A /* 100x100-red.tga */; };
                55A81800218102210004A39A /* 400x400-green.png in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55A817FD218101DF0004A39A /* 400x400-green.png */; };
+               55F9D2E52205031800A9AB38 /* AdditionalSupportedImageTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 55F9D2E42205031800A9AB38 /* AdditionalSupportedImageTypes.mm */; };
                5714ECB91CA8B5B000051AC8 /* DownloadRequestOriginalURL.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */; };
                5714ECBB1CA8BFE400051AC8 /* DownloadRequestOriginalURLFrame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */; };
                5714ECBD1CA8C22A00051AC8 /* DownloadRequestOriginalURL2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */; };
                6B306106218A372900F5A802 /* ClosingWebView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6B306105218A372900F5A802 /* ClosingWebView.mm */; };
                6B9ABE122086952F00D75DE6 /* HTTPParsers.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */; };
                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A38D7E51C752D5F004F157D /* HashCountedSet.cpp */; };
+               725C3EEF220570BE007C36FC /* 100x100-red.tga in Copy Resources */ = {isa = PBXBuildFile; fileRef = 725C3EEE22057005007C36FC /* 100x100-red.tga */; };
+               725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */; };
                751B05D61F8EAC410028A09E /* DatabaseTrackerTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */; };
                754CEC811F6722F200D0039A /* AutoFillAvailable.mm in Sources */ = {isa = PBXBuildFile; fileRef = 754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */; };
                7673499D1930C5BB00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7673499A1930182E00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               725C3EEF220570BE007C36FC /* 100x100-red.tga in Copy Resources */,
                                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
                                55A81800218102210004A39A /* 400x400-green.png in Copy Resources */,
                                379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */,
+                               725C3EF322058A5B007C36FC /* AdditionalSupportedImageTypes.html in Copy Resources */,
                                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
                                1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */,
                                C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
                55A817FB218100E00004A39A /* AdditionalSupportedImageTypes.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AdditionalSupportedImageTypes.mm; sourceTree = "<group>"; };
                55A817FD218101DF0004A39A /* 400x400-green.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "400x400-green.png"; sourceTree = "<group>"; };
                55A817FE218101DF0004A39A /* 100x100-red.tga */ = {isa = PBXFileReference; lastKnownFileType = file; path = "100x100-red.tga"; sourceTree = "<group>"; };
+               55F9D2E42205031800A9AB38 /* AdditionalSupportedImageTypes.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = AdditionalSupportedImageTypes.mm; sourceTree = "<group>"; };
                5714ECB81CA8B58800051AC8 /* DownloadRequestOriginalURL.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL.html; sourceTree = "<group>"; };
                5714ECBA1CA8BFD100051AC8 /* DownloadRequestOriginalURLFrame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURLFrame.html; sourceTree = "<group>"; };
                5714ECBC1CA8C21800051AC8 /* DownloadRequestOriginalURL2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DownloadRequestOriginalURL2.html; sourceTree = "<group>"; };
                6B0A07F621FA9C2B00D57391 /* AdClickAttribution.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AdClickAttribution.cpp; sourceTree = "<group>"; };
                6B306105218A372900F5A802 /* ClosingWebView.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ClosingWebView.mm; sourceTree = "<group>"; };
                6B9ABE112086952F00D75DE6 /* HTTPParsers.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPParsers.cpp; sourceTree = "<group>"; };
+               725C3EEE22057005007C36FC /* 100x100-red.tga */ = {isa = PBXFileReference; lastKnownFileType = file; path = "100x100-red.tga"; sourceTree = "<group>"; };
+               725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = AdditionalSupportedImageTypes.html; sourceTree = "<group>"; };
                751B05D51F8EAC1A0028A09E /* DatabaseTrackerTest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseTrackerTest.mm; sourceTree = "<group>"; };
                754CEC801F6722DC00D0039A /* AutoFillAvailable.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AutoFillAvailable.mm; sourceTree = "<group>"; };
                7560917719259C59009EF06E /* MemoryCacheAddImageToCacheIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheAddImageToCacheIOS.mm; sourceTree = "<group>"; };
                        children = (
                                C07E6CB013FD737C0038B22B /* Resources */,
                                379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */,
+                               55F9D2E42205031800A9AB38 /* AdditionalSupportedImageTypes.mm */,
                                B55F119F1516834F00915916 /* AttributedString.mm */,
                                00CD9F6215BE312C002DA2CE /* BackForwardList.mm */,
                                1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */,
                C07E6CB013FD737C0038B22B /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               725C3EEE22057005007C36FC /* 100x100-red.tga */,
                                379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
+                               725C3EF2220584BA007C36FC /* AdditionalSupportedImageTypes.html */,
                                B55F11B01517A2C400915916 /* attributedStringCustomFont.html */,
                                7C9ED98A17A19D0600E4DC33 /* attributedStringStrikethrough.html */,
                                26DF5A6115A2A22B003689C2 /* CancelLoadFromResourceLoadDelegate.html */,
                                6B0A07F721FA9C2B00D57391 /* AdClickAttribution.cpp in Sources */,
                                37E7DD641EA06FF2009B396D /* AdditionalReadAccessAllowedURLs.mm in Sources */,
                                55A817FC218100E00004A39A /* AdditionalSupportedImageTypes.mm in Sources */,
+                               55F9D2E52205031800A9AB38 /* AdditionalSupportedImageTypes.mm in Sources */,
                                7A909A7D1D877480007E10F8 /* AffineTransform.cpp in Sources */,
                                A1DF74321C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm in Sources */,
                                2DE71AFE1D49C0BD00904094 /* AnimatedResize.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/mac/100x100-red.tga b/Tools/TestWebKitAPI/Tests/mac/100x100-red.tga
new file mode 100644 (file)
index 0000000..06958ba
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/mac/100x100-red.tga differ
diff --git a/Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.html b/Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.html
new file mode 100644 (file)
index 0000000..5fe0ede
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+    <img src="100x100-red.tga" onerror="imgError(this);">
+    <script>
+        function imgError(image) {
+            image.parentNode. removeChild(image);
+            return true;
+        }
+    </script>
+</body>
+</html>
diff --git a/Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.mm b/Tools/TestWebKitAPI/Tests/mac/AdditionalSupportedImageTypes.mm
new file mode 100644 (file)
index 0000000..2a1900e
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2019 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 INC. 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 INC. 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.
+ */
+
+#include "config.h"
+
+#import "PlatformUtilities.h"
+#import "PlatformWebView.h"
+
+#import <WebKit/DOM.h>
+#import <WebKit/WebPreferencesPrivate.h>
+#import <WebKit/WebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+@interface AdditionalSupportedImageTypesTest : NSObject <WebFrameLoadDelegate> {
+}
+@end
+
+static bool didFinishLoad;
+
+@implementation AdditionalSupportedImageTypesTest
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+@end
+
+namespace TestWebKitAPI {
+
+static void runTest(NSArray *additionalSupportedImageTypes, Boolean expectedToLoad)
+{
+    RetainPtr<WebPreferences> preferences = adoptNS([[WebPreferences alloc] initWithIdentifier:nil]);
+    [preferences setAdditionalSupportedImageTypes:additionalSupportedImageTypes];
+
+    RetainPtr<WebView> webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
+    [webView setPreferences:preferences.get()];
+
+    RetainPtr<AdditionalSupportedImageTypesTest> testController = adoptNS([AdditionalSupportedImageTypesTest new]);
+    webView.get().frameLoadDelegate = testController.get();
+
+    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"AdditionalSupportedImageTypes" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
+
+    Util::run(&didFinishLoad);
+    didFinishLoad = false;
+
+    DOMDocument *document = webView.get().mainFrameDocument;
+    DOMElement *documentElement = [document documentElement];
+
+    DOMHTMLImageElement *image = (DOMHTMLImageElement *)[documentElement querySelector:@"img"];
+    EXPECT_EQ(image != nullptr, expectedToLoad);
+    if (image)
+        EXPECT_EQ([image width], 100);
+}
+
+TEST(WebKitLegacy, AdditionalSupportedStringImageType)
+{
+    runTest(@[@"com.truevision.tga-image"], true);
+}
+
+TEST(WebKitLegacy, AdditionalBogusStringImageType)
+{
+    runTest(@[@"public.bogus"], false);
+}
+
+TEST(WebKitLegacy, AdditionalEmptyArrayImageType)
+{
+    runTest(@[], false);
+}
+
+TEST(WebKitLegacy, AdditionalArryOfNullImageType)
+{
+    runTest(@[[NSNull null]], false);
+}
+
+TEST(WebKitLegacy, AdditionalArrayOfArrayImageType)
+{
+    runTest(@[@[@"com.truevision.tga-image"]], false);
+}
+
+} // namespace TestWebKitAPI