Source/WebCore:
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 03:23:17 +0000 (03:23 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Nov 2018 03:23:17 +0000 (03:23 +0000)
Add an SPI to allow WebView clients to add additional supported image formats
https://bugs.webkit.org/show_bug.cgi?id=190454

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2018-11-08
Reviewed by Simon Fraser.

Add an SPI to allow additional supported image formats in WebView. These
additional formats can be set in the WKWebViewConfiguration as an NSArray
of NStrings. Each string represents an image source type aka UTI.

The ImageSourceType in the functions' names will be replaced by ImageType.
ImageType in this context is the image UTI (Uniform Type Identifier).

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::supportedImageMIMETypes):
(WebCore::MIMETypeRegistry::additionalSupportedImageMIMETypes):
(WebCore::supportedImageMIMETypesForEncoding):
(WebCore::MIMETypeRegistry::isSupportedImageMIMEType):
* platform/MIMETypeRegistry.h:
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoderCG::filenameExtension const):
(WebCore::ImageDecoderCG::encodedDataStatus const):
* platform/graphics/cg/ImageSourceCG.h:
* platform/graphics/cg/ImageSourceCGMac.mm:
(WebCore::MIMETypeForImageType):
(WebCore::preferredExtensionForImageType):
(WebCore::MIMETypeForImageSourceType): Deleted.
(WebCore::preferredExtensionForImageSourceType): Deleted.
* platform/graphics/cg/ImageSourceCGWin.cpp:
(WebCore::MIMETypeForImageType):
(WebCore::preferredExtensionForImageType):
(WebCore::MIMETypeForImageSourceType): Deleted.
(WebCore::preferredExtensionForImageSourceType): Deleted.
* platform/graphics/cg/UTIRegistry.cpp:
(WebCore::defaultSupportedImageTypes):
(WebCore::additionalSupportedImageTypes):
(WebCore::setAdditionalSupportedImageTypes):
(WebCore::isSupportedImageType):
(WebCore::supportedDefaultImageSourceTypes): Deleted.
(WebCore::isSupportImageSourceType): Deleted.
* platform/graphics/cg/UTIRegistry.h:

Source/WebKit:
Add an SPI to allow WebView clients to add additional supported image formats
https://bugs.webkit.org/show_bug.cgi?id=190454

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2018-11-08
Reviewed by Simon Fraser.

* Platform/mac/StringUtilities.h:
* Platform/mac/StringUtilities.mm:
(WebKit::webCoreStringVectorFromNSStringArray):
A helper function which converts an NSArray of NSStrings to a Vector of
WTFString.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
Handle encoding and decoding the AdditionalSupportedImageTypes which will
allow transferring it from the UI process to the web process.

* UIProcess/API/APIPageConfiguration.h:
(API::PageConfiguration::additionalSupportedImageTypes const):
(API::PageConfiguration::setAdditionalSupportedImageTypes):
Store the AdditionalSupportedImageTypes in the APIPageConfiguration
which is used when creating the WebPageProxy in the UIPorcess.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _additionalSupportedImageTypes]):
(-[WKWebViewConfiguration _setAdditionalSupportedImageTypes:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
Setter/Getter for the AdditionalSupportedImageTypes.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
Copy the AdditionalSupportedImageTypes from APIPageConfiguration to
WebPageCreationParameters.

* UIProcess/WebPageProxy.h:
Delete unimplemented function.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_shouldAttachDrawingAreaOnPageTransition):
Copy the AdditionalSupportedImageTypes from WebPageCreationParameters to
WebCore.

Tools:
onal supported image formats
https://bugs.webkit.org/show_bug.cgi?id=190454

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2018-11-08
Reviewed by Simon Fraser.

Test opening a TGA image in WebView which is not allowed by default. The
TGA format will be allowed through WKWebViewConfiguration.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/100x100-red.tga: Added.
* TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png: Added.
* TestWebKitAPI/Tests/WebKitCocoa/AdditionalSupportedImageTypes.mm: Added.
(runTest):
(TEST):

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

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp
Source/WebCore/platform/graphics/cg/ImageSourceCG.h
Source/WebCore/platform/graphics/cg/ImageSourceCGMac.mm
Source/WebCore/platform/graphics/cg/ImageSourceCGWin.cpp
Source/WebCore/platform/graphics/cg/UTIRegistry.cpp
Source/WebCore/platform/graphics/cg/UTIRegistry.h
Source/WebKit/ChangeLog
Source/WebKit/Platform/mac/StringUtilities.h
Source/WebKit/Platform/mac/StringUtilities.mm
Source/WebKit/Shared/WebPageCreationParameters.cpp
Source/WebKit/Shared/WebPageCreationParameters.h
Source/WebKit/UIProcess/API/APIPageConfiguration.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/100x100-red.tga [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/AdditionalSupportedImageTypes.mm [new file with mode: 0644]

index 0ac0eb5..1506cc3 100644 (file)
@@ -1,3 +1,46 @@
+2018-11-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Add an SPI to allow WebView clients to add additional supported image formats
+        https://bugs.webkit.org/show_bug.cgi?id=190454
+
+        Reviewed by Simon Fraser.
+
+        Add an SPI to allow additional supported image formats in WebView. These
+        additional formats can be set in the WKWebViewConfiguration as an NSArray
+        of NStrings. Each string represents an image source type aka UTI.
+
+        The ImageSourceType in the functions' names will be replaced by ImageType.
+        ImageType in this context is the image UTI (Uniform Type Identifier).
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::supportedImageMIMETypes):
+        (WebCore::MIMETypeRegistry::additionalSupportedImageMIMETypes):
+        (WebCore::supportedImageMIMETypesForEncoding):
+        (WebCore::MIMETypeRegistry::isSupportedImageMIMEType):
+        * platform/MIMETypeRegistry.h:
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoderCG::filenameExtension const):
+        (WebCore::ImageDecoderCG::encodedDataStatus const):
+        * platform/graphics/cg/ImageSourceCG.h:
+        * platform/graphics/cg/ImageSourceCGMac.mm:
+        (WebCore::MIMETypeForImageType):
+        (WebCore::preferredExtensionForImageType):
+        (WebCore::MIMETypeForImageSourceType): Deleted.
+        (WebCore::preferredExtensionForImageSourceType): Deleted.
+        * platform/graphics/cg/ImageSourceCGWin.cpp:
+        (WebCore::MIMETypeForImageType):
+        (WebCore::preferredExtensionForImageType):
+        (WebCore::MIMETypeForImageSourceType): Deleted.
+        (WebCore::preferredExtensionForImageSourceType): Deleted.
+        * platform/graphics/cg/UTIRegistry.cpp:
+        (WebCore::defaultSupportedImageTypes):
+        (WebCore::additionalSupportedImageTypes):
+        (WebCore::setAdditionalSupportedImageTypes):
+        (WebCore::isSupportedImageType):
+        (WebCore::supportedDefaultImageSourceTypes): Deleted.
+        (WebCore::isSupportImageSourceType): Deleted.
+        * platform/graphics/cg/UTIRegistry.h:
+
 2018-11-08  Megan Gardner  <megan_gardner@apple.com>
 
         Adopt Reveal Framework to replace Lookup
index 3e98d83..c6bb703 100644 (file)
@@ -133,11 +133,11 @@ const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedImag
 
 #if USE(CG)
 #ifndef NDEBUG
-    // Esnure supportedImageMIMETypes() is in sync with supportedDefaultImageSourceTypes().
+    // Esnure supportedImageMIMETypes() is in sync with defaultSupportedImageTypes().
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
-        for (auto& imageSourceType : supportedDefaultImageSourceTypes()) {
-            auto mimeType = MIMETypeForImageSourceType(imageSourceType);
+        for (auto& imageType : defaultSupportedImageTypes()) {
+            auto mimeType = MIMETypeForImageType(imageType);
             ASSERT_IMPLIES(!mimeType.isEmpty(), supportedImageMIMETypes.get().contains(mimeType));
         }
     });
@@ -146,6 +146,12 @@ const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedImag
     return supportedImageMIMETypes;
 }
 
+HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::additionalSupportedImageMIMETypes()
+{
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> additionalSupportedImageMIMETypes;
+    return additionalSupportedImageMIMETypes;
+}
+
 static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypesForEncoding()
 {
 #if PLATFORM(COCOA)
@@ -155,7 +161,7 @@ static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypesF
         CFIndex count = CFArrayGetCount(supportedTypes.get());
         for (CFIndex i = 0; i < count; i++) {
             CFStringRef supportedType = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i));
-            String mimeType = MIMETypeForImageSourceType(supportedType);
+            String mimeType = MIMETypeForImageType(supportedType);
             if (!mimeType.isEmpty())
                 supportedImageMIMETypesForEncoding.add(mimeType);
         }
@@ -433,7 +439,8 @@ bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    return supportedImageMIMETypes().contains(getNormalizedMIMEType(mimeType));
+    String normalizedMIMEType = getNormalizedMIMEType(mimeType);
+    return supportedImageMIMETypes().contains(normalizedMIMEType) || additionalSupportedImageMIMETypes().contains(normalizedMIMEType);
 }
 
 bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType)
index 7185df4..7c929be 100644 (file)
@@ -106,6 +106,7 @@ public:
 
     // FIXME: Would be nice to find a way to avoid exposing these sets, even worse exposing non-const references.
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypes();
+    static HashSet<String, ASCIICaseInsensitiveHash>& additionalSupportedImageMIMETypes();
     WEBCORE_EXPORT static HashSet<String, ASCIICaseInsensitiveHash>& supportedNonImageMIMETypes();
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedMediaMIMETypes();
     WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& pdfMIMETypes();
index 852dd06..e18e63f 100644 (file)
@@ -176,7 +176,7 @@ String ImageDecoderCG::uti() const
 
 String ImageDecoderCG::filenameExtension() const
 {
-    return WebCore::preferredExtensionForImageSourceType(uti());
+    return WebCore::preferredExtensionForImageType(uti());
 }
 
 EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
@@ -199,7 +199,7 @@ EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
         return EncodedDataStatus::Error;
 
     case kCGImageStatusIncomplete: {
-        if (!isSupportImageSourceType(uti))
+        if (!isSupportedImageType(uti))
             return EncodedDataStatus::Error;
 
         RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
@@ -213,7 +213,7 @@ EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
     }
 
     case kCGImageStatusComplete:
-        if (!isSupportImageSourceType(uti))
+        if (!isSupportedImageType(uti))
             return EncodedDataStatus::Error;
 
         return EncodedDataStatus::Complete;
index 933ef62..6bb81e6 100644 (file)
@@ -30,9 +30,9 @@
 
 namespace WebCore {
 
-String preferredExtensionForImageSourceType(const String& type);
+String preferredExtensionForImageType(const String& type);
 
-String MIMETypeForImageSourceType(const String& type);
+String MIMETypeForImageType(const String& type);
 
 #if !PLATFORM(COCOA)
 size_t sharedBufferGetBytesAtPosition(void* info, void* buffer, off_t position, size_t count);
index f9402ba..a258d28 100644 (file)
 
 namespace WebCore {
 
-String MIMETypeForImageSourceType(const String& uti)
+String MIMETypeForImageType(const String& uti)
 {
     return MIMETypeFromUTI(uti);
 }
 
-String preferredExtensionForImageSourceType(const String& uti)
+String preferredExtensionForImageType(const String& uti)
 {
     return adoptCF(UTTypeCopyPreferredTagWithClass(uti.createCFString().get(), kUTTagClassFilenameExtension)).get();
 }
index 6d53737..f0206ea 100644 (file)
@@ -32,7 +32,7 @@
 
 namespace WebCore {
 
-String MIMETypeForImageSourceType(const String& type)
+String MIMETypeForImageType(const String& type)
 {
     String mimeType;
     // FIXME: This approach of taking a UTI like public.type and giving back 
@@ -44,7 +44,7 @@ String MIMETypeForImageSourceType(const String& type)
     return mimeType;
 }
 
-String preferredExtensionForImageSourceType(const String& type)
+String preferredExtensionForImageType(const String& type)
 {
     if (type.isNull())
         return String();
index ec9c879..c78158f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc.  All rights reserved.
+ * Copyright (C) 2017-2018 Apple Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,6 +28,9 @@
 
 #if USE(CG)
 
+#include "ImageSourceCG.h"
+#include "MIMETypeRegistry.h"
+
 #include <wtf/HashSet.h>
 #include <wtf/NeverDestroyed.h>
 #include <ImageIO/ImageIO.h>
 
 namespace WebCore {
 
-const HashSet<String>& supportedDefaultImageSourceTypes()
+const HashSet<String>& defaultSupportedImageTypes()
 {
     // CG at least supports the following standard image types:
-    static NeverDestroyed<HashSet<String>> supportedDefaultImageSourceTypes = std::initializer_list<String> {
+    static NeverDestroyed<HashSet<String>> defaultSupportedImageTypes = std::initializer_list<String> {
         "com.compuserve.gif",
         "com.microsoft.bmp",
         "com.microsoft.cur",
@@ -57,21 +60,40 @@ const HashSet<String>& supportedDefaultImageSourceTypes()
     // Make sure that CG supports them.
     static std::once_flag onceFlag;
     std::call_once(onceFlag, [] {
-        RetainPtr<CFArrayRef> systemImageSourceTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());
-        CFIndex count = CFArrayGetCount(systemImageSourceTypes.get());
-        for (auto& imageSourceType : supportedDefaultImageSourceTypes.get()) {
-            RetainPtr<CFStringRef> string = imageSourceType.createCFString();
-            ASSERT(CFArrayContainsValue(systemImageSourceTypes.get(), CFRangeMake(0, count), string.get()));
+        RetainPtr<CFArrayRef> systemImageTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());
+        CFIndex count = CFArrayGetCount(systemImageTypes.get());
+        for (auto& imageType : defaultSupportedImageTypes.get()) {
+            RetainPtr<CFStringRef> string = imageType.createCFString();
+            ASSERT(CFArrayContainsValue(systemImageTypes.get(), CFRangeMake(0, count), string.get()));
         }
     });
 #endif
 
-    return supportedDefaultImageSourceTypes;
+    return defaultSupportedImageTypes;
+}
+
+HashSet<String>& additionalSupportedImageTypes()
+{
+    static NeverDestroyed<HashSet<String>> additionalSupportedImageTypes;
+    return additionalSupportedImageTypes;
+}
+
+void setAdditionalSupportedImageTypes(const Vector<String>& imageTypes)
+{
+    MIMETypeRegistry::additionalSupportedImageMIMETypes().clear();
+    for (const auto& imageType : imageTypes) {
+        additionalSupportedImageTypes().add(imageType);
+        auto mimeType = MIMETypeForImageType(imageType);
+        if (!mimeType.isEmpty())
+            MIMETypeRegistry::additionalSupportedImageMIMETypes().add(mimeType);
+    }
 }
 
-bool isSupportImageSourceType(const String& imageSourceType)
+bool isSupportedImageType(const String& imageType)
 {
-    return !imageSourceType.isEmpty() && supportedDefaultImageSourceTypes().contains(imageSourceType);
+    if (imageType.isEmpty())
+        return false;
+    return defaultSupportedImageTypes().contains(imageType) || additionalSupportedImageTypes().contains(imageType);
 }
 
 }
index 56f3f47..3c84de3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,7 +30,9 @@
 
 namespace WebCore {
 
-const HashSet<String>& supportedDefaultImageSourceTypes();
-bool isSupportImageSourceType(const String&);
+const HashSet<String>& defaultSupportedImageTypes();
+HashSet<String>& additionalSupportedImageTypes();
+WEBCORE_EXPORT void setAdditionalSupportedImageTypes(const Vector<String>&);
+bool isSupportedImageType(const String&);
 
 }
index a4329df..904f26e 100644 (file)
@@ -1,3 +1,51 @@
+2018-11-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Add an SPI to allow WebView clients to add additional supported image formats
+        https://bugs.webkit.org/show_bug.cgi?id=190454
+
+        Reviewed by Simon Fraser.
+
+        * Platform/mac/StringUtilities.h:
+        * Platform/mac/StringUtilities.mm:
+        (WebKit::webCoreStringVectorFromNSStringArray):
+        A helper function which converts an NSArray of NSStrings to a Vector of
+        WTFString.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        Handle encoding and decoding the AdditionalSupportedImageTypes which will
+        allow transferring it from the UI process to the web process.
+
+        * UIProcess/API/APIPageConfiguration.h:
+        (API::PageConfiguration::additionalSupportedImageTypes const):
+        (API::PageConfiguration::setAdditionalSupportedImageTypes):
+        Store the AdditionalSupportedImageTypes in the APIPageConfiguration
+        which is used when creating the WebPageProxy in the UIPorcess.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _additionalSupportedImageTypes]):
+        (-[WKWebViewConfiguration _setAdditionalSupportedImageTypes:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        Setter/Getter for the AdditionalSupportedImageTypes.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        Copy the AdditionalSupportedImageTypes from APIPageConfiguration to 
+        WebPageCreationParameters.
+
+        * UIProcess/WebPageProxy.h:
+        Delete unimplemented function.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_shouldAttachDrawingAreaOnPageTransition):
+        Copy the AdditionalSupportedImageTypes from WebPageCreationParameters to
+        WebCore.
+
 2018-11-08  Megan Gardner  <megan_gardner@apple.com>
 
         Adopt Reveal Framework to replace Lookup
index 29a76cd..4257c8c 100644 (file)
@@ -37,6 +37,8 @@ namespace WebKit {
 NSString *nsStringFromWebCoreString(const String&);
 NSString *formattedPhoneNumberString(NSString *originalPhoneNumber);
 
+Vector<String> webCoreStringVectorFromNSStringArray(NSArray<NSString *> *);
+
 #endif // defined(__OBJC__)
 
 }
index 5c96793..6b8fe74 100644 (file)
@@ -82,4 +82,15 @@ 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 cf9a1b0..a777439 100644 (file)
@@ -97,6 +97,7 @@ void WebPageCreationParameters::encode(IPC::Encoder& encoder) const
 #endif
 #if PLATFORM(COCOA)
     encoder << smartInsertDeleteEnabled;
+    encoder << additionalSupportedImageTypes;
 #endif
     encoder << appleMailPaginationQuirkEnabled;
     encoder << appleMailLinesClampEnabled;
@@ -272,6 +273,8 @@ std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::
 #if PLATFORM(COCOA)
     if (!decoder.decode(parameters.smartInsertDeleteEnabled))
         return std::nullopt;
+    if (!decoder.decode(parameters.additionalSupportedImageTypes))
+        return std::nullopt;
 #endif
 
     if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled))
index ffaf778..205b19a 100644 (file)
@@ -154,6 +154,7 @@ struct WebPageCreationParameters {
 #endif
 #if PLATFORM(COCOA)
     bool smartInsertDeleteEnabled;
+    Vector<String> additionalSupportedImageTypes;
 #endif
     bool appleMailPaginationQuirkEnabled;
     bool appleMailLinesClampEnabled;
index 4981b95..67ac5c6 100644 (file)
@@ -110,6 +110,11 @@ public:
     const WTF::String& overrideContentSecurityPolicy() const { return m_overrideContentSecurityPolicy; }
     void setOverrideContentSecurityPolicy(const WTF::String& overrideContentSecurityPolicy) { m_overrideContentSecurityPolicy = overrideContentSecurityPolicy; }
 
+#if PLATFORM(COCOA)
+    const WTF::Vector<WTF::String>& additionalSupportedImageTypes() const { return m_additionalSupportedImageTypes; }
+    void setAdditionalSupportedImageTypes(WTF::Vector<WTF::String>&& additionalSupportedImageTypes) { m_additionalSupportedImageTypes = WTFMove(additionalSupportedImageTypes); }
+#endif
+
 #if ENABLE(APPLICATION_MANIFEST)
     ApplicationManifest* applicationManifest() const;
     void setApplicationManifest(ApplicationManifest*);
@@ -146,6 +151,10 @@ private:
 
     WTF::String m_overrideContentSecurityPolicy;
 
+#if PLATFORM(COCOA)
+    WTF::Vector<WTF::String> m_additionalSupportedImageTypes;
+#endif
+
 #if ENABLE(APPLICATION_MANIFEST)
     RefPtr<ApplicationManifest> m_applicationManifest;
 #endif
index 9ec6598..448f932 100644 (file)
@@ -46,6 +46,7 @@
 #import "RemoteLayerTreeTransaction.h"
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
+#import "StringUtilities.h"
 #import "UIDelegate.h"
 #import "UserMediaProcessManager.h"
 #import "VersionChecks.h"
@@ -569,6 +570,8 @@ static void validate(WKWebViewConfiguration *configuration)
             pageConfiguration->setPageGroup(WebKit::WebPageGroup::create(configuration._groupIdentifier).ptr());
     }
 
+    pageConfiguration->setAdditionalSupportedImageTypes(WebKit::webCoreStringVectorFromNSStringArray([_configuration _additionalSupportedImageTypes]));
+
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::suppressesIncrementalRenderingKey(), WebKit::WebPreferencesStore::Value(!![_configuration suppressesIncrementalRendering]));
 
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::shouldRespectImageOrientationKey(), WebKit::WebPreferencesStore::Value(!![_configuration _respectsImageOrientation]));
index 7feb0b5..82eabfd 100644 (file)
@@ -161,6 +161,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     BOOL _drawsBackground;
 
     RetainPtr<NSString> _mediaContentTypesRequiringHardwareSupport;
+    RetainPtr<NSArray<NSString *>> _additionalSupportedImageTypes;
 }
 
 - (instancetype)init
@@ -394,6 +395,7 @@ static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
     configuration->_needsStorageAccessFromFileURLsQuirk = self->_needsStorageAccessFromFileURLsQuirk;
 
     configuration->_mediaContentTypesRequiringHardwareSupport = adoptNS([self._mediaContentTypesRequiringHardwareSupport copyWithZone:zone]);
+    configuration->_additionalSupportedImageTypes = adoptNS([self->_additionalSupportedImageTypes copyWithZone:zone]);
     configuration->_legacyEncryptedMediaAPIEnabled = self->_legacyEncryptedMediaAPIEnabled;
     configuration->_allowMediaContentTypesRequiringHardwareSupportAsFallback = self->_allowMediaContentTypesRequiringHardwareSupportAsFallback;
 
@@ -990,6 +992,16 @@ ALLOW_DEPRECATED_DECLARATIONS_END
     _mediaContentTypesRequiringHardwareSupport = adoptNS([mediaContentTypesRequiringHardwareSupport copy]);
 }
 
+- (NSArray<NSString *> *)_additionalSupportedImageTypes
+{
+    return _additionalSupportedImageTypes.get();
+}
+
+- (void)_setAdditionalSupportedImageTypes:(NSArray<NSString *> *)additionalSupportedImageTypes
+{
+    _additionalSupportedImageTypes = adoptNS([additionalSupportedImageTypes copy]);
+}
+
 - (void)_setLegacyEncryptedMediaAPIEnabled:(BOOL)enabled
 {
     _legacyEncryptedMediaAPIEnabled = enabled;
index f105a1a..905e13d 100644 (file)
@@ -102,6 +102,9 @@ typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
 @property (nonatomic, setter=_setLegacyEncryptedMediaAPIEnabled:) BOOL _legacyEncryptedMediaAPIEnabled WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 @property (nonatomic, setter=_setAllowMediaContentTypesRequiringHardwareSupportAsFallback:) BOOL _allowMediaContentTypesRequiringHardwareSupportAsFallback WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
+// The input of this SPI is an array of image UTI (Uniform Type Identifier).
+@property (nonatomic, copy, setter=_setAdditionalSupportedImageTypes:) NSArray<NSString *> *_additionalSupportedImageTypes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 #endif
index c8f86de..35cece5 100644 (file)
@@ -6415,6 +6415,7 @@ WebPageCreationParameters WebPageProxy::creationParameters()
 
 #if PLATFORM(COCOA)
     parameters.smartInsertDeleteEnabled = m_isSmartInsertDeleteEnabled;
+    parameters.additionalSupportedImageTypes = m_configuration->additionalSupportedImageTypes();
 #endif
     parameters.shouldScaleViewToFitDocument = m_shouldScaleViewToFitDocument;
     parameters.userInterfaceLayoutDirection = pageClient().userInterfaceLayoutDirection();
index 4682d74..29bddcb 100644 (file)
@@ -1360,10 +1360,6 @@ public:
 
     WebCore::IntRect syncRootViewToScreen(const WebCore::IntRect& viewRect);
 
-#if PLATFORM(COCOA)
-    Vector<String> mediaMIMETypes();
-#endif
-
 #if ENABLE(DATALIST_ELEMENT)
     void didSelectOption(const String&);
     void didCloseSuggestions();
index 2f54d5d..62dba3f 100644 (file)
 #include "VideoFullscreenManager.h"
 #include "WKStringCF.h"
 #include <WebCore/LegacyWebArchive.h>
+#include <WebCore/UTIRegistry.h>
 #include <wtf/MachSendRight.h>
 #endif
 
@@ -595,6 +596,7 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
 #if PLATFORM(COCOA)
     m_page->settings().setContentDispositionAttachmentSandboxEnabled(true);
     setSmartInsertDeleteEnabled(parameters.smartInsertDeleteEnabled);
+    WebCore::setAdditionalSupportedImageTypes(parameters.additionalSupportedImageTypes);
 #endif
 
 #if ENABLE(SERVICE_WORKER)
index 0ee8b2b..7e47792 100644 (file)
@@ -1,3 +1,20 @@
+2018-11-08  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+onal supported image formats
+        https://bugs.webkit.org/show_bug.cgi?id=190454
+
+        Reviewed by Simon Fraser.
+
+        Test opening a TGA image in WebView which is not allowed by default. The
+        TGA format will be allowed through WKWebViewConfiguration.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/100x100-red.tga: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png: Added.
+        * TestWebKitAPI/Tests/WebKitCocoa/AdditionalSupportedImageTypes.mm: Added.
+        (runTest):
+        (TEST):
+
 2018-11-08  Jiewen Tan  <jiewen_tan@apple.com>
 
         Unreviewed, a proper build fix for r237983
index 7ef0314..6eef735 100644 (file)
                53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */; };
                55226A2F1EBA44B900C36AD0 /* large-red-square-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 55226A2E1EB969B600C36AD0 /* large-red-square-image.html */; };
                5597F8361D9596C80066BC21 /* SynchronizedFixedQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */; };
+               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 */; };
                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 */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               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 */,
                                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
                                1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */,
                53EC253F1E96BC80000831B9 /* PriorityQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PriorityQueue.cpp; sourceTree = "<group>"; };
                55226A2E1EB969B600C36AD0 /* large-red-square-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-red-square-image.html"; sourceTree = "<group>"; };
                5597F8341D9596C80066BC21 /* SynchronizedFixedQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronizedFixedQueue.cpp; sourceTree = "<group>"; };
+               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>"; };
                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>"; };
                                37E7DD631EA06FF2009B396D /* AdditionalReadAccessAllowedURLs.mm */,
                                37E7DD661EA071F3009B396D /* AdditionalReadAccessAllowedURLsPlugin.mm */,
                                37E7DD651EA0715B009B396D /* AdditionalReadAccessAllowedURLsProtocol.h */,
+                               55A817FB218100E00004A39A /* AdditionalSupportedImageTypes.mm */,
                                A1DF74301C41B65800A2F4D0 /* AlwaysRevalidatedURLSchemes.mm */,
                                2DE71AFD1D49C0BD00904094 /* AnimatedResize.mm */,
                                63F668201F97C3AA0032EE51 /* ApplicationManifest.mm */,
                A16F66B81C40E9E100BD4D24 /* Resources */ = {
                        isa = PBXGroup;
                        children = (
+                               55A817FE218101DF0004A39A /* 100x100-red.tga */,
+                               55A817FD218101DF0004A39A /* 400x400-green.png */,
                                C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
                                F4A9202E1FEE34C800F59590 /* apple-data-url.html */,
                                F47D30EB1ED28619000482E1 /* apple.gif */,
                        };
                        buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "TestWebKitAPI" */;
                        compatibilityVersion = "Xcode 3.2";
-                       developmentRegion = English;
+                       developmentRegion = en;
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                                9BD5111C1FE8E11600D2B630 /* AccessingPastedImage.mm in Sources */,
                                F45B63FE1F19D410009D38B9 /* ActionSheetTests.mm in Sources */,
                                37E7DD641EA06FF2009B396D /* AdditionalReadAccessAllowedURLs.mm in Sources */,
+                               55A817FC218100E00004A39A /* 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/WebKitCocoa/100x100-red.tga b/Tools/TestWebKitAPI/Tests/WebKitCocoa/100x100-red.tga
new file mode 100644 (file)
index 0000000..06958ba
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKitCocoa/100x100-red.tga differ
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png b/Tools/TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png
new file mode 100644 (file)
index 0000000..5284982
Binary files /dev/null and b/Tools/TestWebKitAPI/Tests/WebKitCocoa/400x400-green.png differ
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/AdditionalSupportedImageTypes.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/AdditionalSupportedImageTypes.mm
new file mode 100644 (file)
index 0000000..51aa8b6
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#import "config.h"
+#import <WebKit/WKFoundation.h>
+
+#if WK_API_ENABLED && PLATFORM(COCOA)
+
+#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <wtf/RetainPtr.h>
+
+static void runTest(NSArray<NSString *> *additionalSupportedImageTypes, NSString *imageURL, NSString *imageExtension, CGFloat imageWidth)
+{
+    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration _setAdditionalSupportedImageTypes:additionalSupportedImageTypes];
+
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:imageURL withExtension:imageExtension subdirectory:@"TestWebKitAPI.resources"];
+    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
+    [webView _test_waitForDidFinishNavigation];
+
+    __block bool isDone = false;
+    [webView _doAfterNextPresentationUpdate:^{
+        [webView evaluateJavaScript:@"[document.querySelector('img').width]" completionHandler:^(id value, NSError *error) {
+            CGFloat width = [[value objectAtIndex:0] floatValue];
+            EXPECT_EQ(width, imageWidth);
+            isDone = true;
+        }];
+    }];
+    TestWebKitAPI::Util::run(&isDone);
+}
+
+TEST(WebKit, AddSupportedImageType)
+{
+    runTest(@[@"public.png"], @"400x400-green", @"png", 400);
+}
+
+TEST(WebKit, AddSupportedAndBogusImageTypes)
+{
+    runTest(@[@"public.png", @"public.bogus"], @"400x400-green", @"png", 400);
+}
+
+TEST(WebKit, AddSupportedAndBogusImageTypesTwice)
+{
+    runTest(@[@"public.png", @"public.bogus", @"public.png", @"public.bogus"], @"400x400-green", @"png", 400);
+}
+
+TEST(WebKit, AddUnsupportedImageType)
+{
+    runTest(@[@"com.truevision.tga-image"], @"100x100-red", @"tga", 100);
+}
+
+TEST(WebKit, AddUnsupportedAndBogusImageTypes)
+{
+    runTest(@[@"com.truevision.tga-image", @"public.bogus"], @"100x100-red", @"tga", 100);
+}
+
+TEST(WebKit, AddUnsupportedAndBogusImageTypesTwice)
+{
+    runTest(@[@"com.truevision.tga-image", @"public.bogus", @"com.truevision.tga-image", @"public.bogus"], @"100x100-red", @"tga", 100);
+}
+
+#endif