WKWebView.GetContentsShouldReturnAttributedString is crashing on iOS Simulator.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2019 23:54:38 +0000 (23:54 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Mar 2019 23:54:38 +0000 (23:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=195916

Reviewed by Tim Horton.

Source/WebCore:

* WebCore.xcodeproj/project.pbxproj: Make ColorIOS.h a private header.
* platform/ios/ColorIOS.h: Export colorFromUIColor.

Source/WebKit:

Add direct support for UIColor so it does not try to use the NSSecureCoding path.
This avoids needs to list the classes when decoding the attributes NSDictionary
and matches the macOS NSColor encoder/decoder.

* Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::typeFromObject):
(IPC::encodeColorInternal):
(IPC::decodeColorInternal):
(IPC::encodeObject):
(IPC::decodeObject):

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm:
(TEST(WKWebView, GetContentsShouldReturnAttributedString): Fix iOS code path to pass.

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/ios/ColorIOS.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/Cocoa/ArgumentCodersCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm

index b37aa3c..3453d6c 100644 (file)
@@ -1,3 +1,13 @@
+2019-03-18  Timothy Hatcher  <timothy@apple.com>
+
+        WKWebView.GetContentsShouldReturnAttributedString is crashing on iOS Simulator.
+        https://bugs.webkit.org/show_bug.cgi?id=195916
+
+        Reviewed by Tim Horton.
+
+        * WebCore.xcodeproj/project.pbxproj: Make ColorIOS.h a private header.
+        * platform/ios/ColorIOS.h: Export colorFromUIColor.
+
 2019-03-18  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Define the type of SVGPropertyOwnerRegistry for all SVG elements
index c701f80..519dbda 100644 (file)
                CE08C3D2152B599A0021B8C2 /* AlternativeTextController.h in Headers */ = {isa = PBXBuildFile; fileRef = CE08C3D0152B599A0021B8C2 /* AlternativeTextController.h */; settings = {ATTRIBUTES = (); }; };
                CE1866451F72E5B400A0CAB6 /* MarkedText.h in Headers */ = {isa = PBXBuildFile; fileRef = CE1866431F72E5B400A0CAB6 /* MarkedText.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE2849871CA360DF00B4A57F /* ContentSecurityPolicyDirectiveNames.h in Headers */ = {isa = PBXBuildFile; fileRef = CE2849861CA360DF00B4A57F /* ContentSecurityPolicyDirectiveNames.h */; };
-               CE5169E721F1B84700EA4F78 /* ColorIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5169E521F1B84700EA4F78 /* ColorIOS.h */; };
+               CE5169E721F1B84700EA4F78 /* ColorIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5169E521F1B84700EA4F78 /* ColorIOS.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE5FA255209E48C50051D700 /* ContentSecurityPolicyClient.h in Headers */ = {isa = PBXBuildFile; fileRef = CE5FA253209E48C50051D700 /* ContentSecurityPolicyClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE6DADFA1C591E6A003F6A88 /* ContentSecurityPolicyResponseHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = CE6DADF81C591E6A003F6A88 /* ContentSecurityPolicyResponseHeaders.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CE799F981C6A46BC0097B518 /* ContentSecurityPolicySourceList.h in Headers */ = {isa = PBXBuildFile; fileRef = CE799F961C6A46BC0097B518 /* ContentSecurityPolicySourceList.h */; };
index ef07785..0e44c1d 100644 (file)
@@ -33,7 +33,7 @@ OBJC_CLASS UIColor;
 
 namespace WebCore {
 
-Color colorFromUIColor(UIColor *);
+WEBCORE_EXPORT Color colorFromUIColor(UIColor *);
 
 } // namespace WebCore
 
index e3fec73..52f715e 100644 (file)
@@ -1,5 +1,23 @@
 2019-03-18  Timothy Hatcher  <timothy@apple.com>
 
+        WKWebView.GetContentsShouldReturnAttributedString is crashing on iOS Simulator.
+        https://bugs.webkit.org/show_bug.cgi?id=195916
+
+        Reviewed by Tim Horton.
+
+        Add direct support for UIColor so it does not try to use the NSSecureCoding path.
+        This avoids needs to list the classes when decoding the attributes NSDictionary
+        and matches the macOS NSColor encoder/decoder.
+
+        * Shared/Cocoa/ArgumentCodersCocoa.mm:
+        (IPC::typeFromObject):
+        (IPC::encodeColorInternal):
+        (IPC::decodeColorInternal):
+        (IPC::encodeObject):
+        (IPC::decodeObject):
+
+2019-03-18  Timothy Hatcher  <timothy@apple.com>
+
         Add new NSAttributedString API for converting HTML.
         https://bugs.webkit.org/show_bug.cgi?id=195636
         rdar://problem/45055697
index 80e8e55..221737d 100644 (file)
 
 #if USE(APPKIT)
 #import <WebCore/ColorMac.h>
+#else
+#import <WebCore/ColorIOS.h>
 #endif
 
 #if PLATFORM(IOS_FAMILY)
+#import <UIKit/UIColor.h>
 #import <UIKit/UIFont.h>
 #import <UIKit/UIFontDescriptor.h>
 #endif
 
 #if USE(APPKIT)
+using PlatformColor = NSColor;
 using PlatformFont = NSFont;
 using PlatformFontDescriptor = NSFontDescriptor;
 #else
+using PlatformColor = UIColor;
 using PlatformFont = UIFont;
 using PlatformFontDescriptor = UIFontDescriptor;
 #endif
@@ -58,9 +63,7 @@ using namespace WebCore;
 
 enum class NSType {
     Array,
-#if USE(APPKIT)
     Color,
-#endif
     Data,
     Date,
     Dictionary,
@@ -81,10 +84,8 @@ static NSType typeFromObject(id object)
     // Specific classes handled.
     if ([object isKindOfClass:[NSArray class]])
         return NSType::Array;
-#if USE(APPKIT)
-    if ([object isKindOfClass:[NSColor class]])
+    if ([object isKindOfClass:[PlatformColor class]])
         return NSType::Color;
-#endif
     if ([object isKindOfClass:[NSData class]])
         return NSType::Data;
     if ([object isKindOfClass:[NSDate class]])
@@ -170,7 +171,7 @@ static Optional<RetainPtr<id>> decodeArrayInternal(Decoder& decoder, NSArray<Cla
     return { array };
 }
 
-#pragma mark - NSColor
+#pragma mark - NSColor / UIColor
 
 #if USE(APPKIT)
 static inline void encodeColorInternal(Encoder& encoder, NSColor *color)
@@ -185,6 +186,19 @@ static inline Optional<RetainPtr<id>> decodeColorInternal(Decoder& decoder)
         return WTF::nullopt;
     return { nsColor(color) };
 }
+#else
+static inline void encodeColorInternal(Encoder& encoder, UIColor *color)
+{
+    encoder << colorFromUIColor(color);
+}
+
+static inline Optional<RetainPtr<id>> decodeColorInternal(Decoder& decoder)
+{
+    Color color;
+    if (!decoder.decode(color))
+        return WTF::nullopt;
+    return { adoptNS([[UIColor alloc] initWithCGColor:cachedCGColor(color)]) };
+}
 #endif
 
 #pragma mark - NSData
@@ -384,11 +398,9 @@ void encodeObject(Encoder& encoder, id object)
     case NSType::Array:
         encodeArrayInternal(encoder, static_cast<NSArray *>(object));
         return;
-#if USE(APPKIT)
     case NSType::Color:
-        encodeColorInternal(encoder, static_cast<NSColor *>(object));
+        encodeColorInternal(encoder, static_cast<PlatformColor *>(object));
         return;
-#endif
     case NSType::Dictionary:
         encodeDictionaryInternal(encoder, static_cast<NSDictionary *>(object));
         return;
@@ -435,10 +447,8 @@ Optional<RetainPtr<id>> decodeObject(Decoder& decoder, NSArray<Class> *allowedCl
     switch (type) {
     case NSType::Array:
         return decodeArrayInternal(decoder, allowedClasses);
-#if USE(APPKIT)
     case NSType::Color:
         return decodeColorInternal(decoder);
-#endif
     case NSType::Dictionary:
         return decodeDictionaryInternal(decoder, allowedClasses);
     case NSType::Font:
@@ -470,9 +480,7 @@ template<> struct EnumTraits<IPC::NSType> {
     using values = EnumValues<
         IPC::NSType,
         IPC::NSType::Array,
-#if USE(APPKIT)
         IPC::NSType::Color,
-#endif
         IPC::NSType::Data,
         IPC::NSType::Date,
         IPC::NSType::Dictionary,
index ef68ca7..7a6a91d 100644 (file)
@@ -1,3 +1,13 @@
+2019-03-18  Timothy Hatcher  <timothy@apple.com>
+
+        WKWebView.GetContentsShouldReturnAttributedString is crashing on iOS Simulator.
+        https://bugs.webkit.org/show_bug.cgi?id=195916
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewGetContents.mm:
+        (TEST(WKWebView, GetContentsShouldReturnAttributedString): Fix iOS code path to pass.
+
 2019-03-18  Alexey Proskuryakov  <ap@apple.com>
 
         Add a secondary e-mail address for Fujii Hironori to make tools happier.
index 4337bda..6afa645 100644 (file)
@@ -57,14 +57,6 @@ TEST(WKWebView, GetContentsShouldReturnAttributedString)
 
     __block bool finished = false;
 
-#if USE(APPKIT)
-    using PlatformFont = NSFont;
-    using PlatformColor = NSColor;
-#else
-    using PlatformFont = UIFont;
-    using PlatformColor = UIColor;
-#endif
-
     [webView _getContentsAsAttributedStringWithCompletionHandler:^(NSAttributedString *attributedString, NSDictionary<NSAttributedStringDocumentAttributeKey, id> *documentAttributes, NSError *error) {
         EXPECT_NOT_NULL(attributedString);
         EXPECT_NOT_NULL(documentAttributes);
@@ -76,17 +68,29 @@ TEST(WKWebView, GetContentsShouldReturnAttributedString)
 
             if (!i) {
                 EXPECT_WK_STREQ(@"Hello ", substring.string);
-                EXPECT_WK_STREQ(@"Times-Roman", dynamic_objc_cast<PlatformFont>(attributes[NSFontAttributeName]).fontName);
+#if USE(APPKIT)
+                EXPECT_WK_STREQ(@"Times-Roman", dynamic_objc_cast<NSFont>(attributes[NSFontAttributeName]).fontName);
+#else
+                EXPECT_WK_STREQ(@"TimesNewRomanPSMT", dynamic_objc_cast<UIFont>(attributes[NSFontAttributeName]).fontName);
+#endif
             } else if (i == 1) {
                 EXPECT_WK_STREQ(@"World!", substring.string);
-                EXPECT_WK_STREQ(@"Times-Bold", dynamic_objc_cast<PlatformFont>(attributes[NSFontAttributeName]).fontName);
+#if USE(APPKIT)
+                EXPECT_WK_STREQ(@"Times-Bold", dynamic_objc_cast<NSFont>(attributes[NSFontAttributeName]).fontName);
+#else
+                EXPECT_WK_STREQ(@"TimesNewRomanPS-BoldMT", dynamic_objc_cast<UIFont>(attributes[NSFontAttributeName]).fontName);
+#endif
             } else
                 ASSERT_NOT_REACHED();
 
             ++i;
         }];
 
-        EXPECT_WK_STREQ(@"sRGB IEC61966-2.1 colorspace 1 0 0 1", dynamic_objc_cast<PlatformColor>(documentAttributes[NSBackgroundColorDocumentAttribute]).description);
+#if USE(APPKIT)
+        EXPECT_WK_STREQ(@"sRGB IEC61966-2.1 colorspace 1 0 0 1", dynamic_objc_cast<NSColor>(documentAttributes[NSBackgroundColorDocumentAttribute]).description);
+#else
+        EXPECT_WK_STREQ(@"kCGColorSpaceModelRGB 1 0 0 1 ", dynamic_objc_cast<UIColor>(documentAttributes[NSBackgroundColorDocumentAttribute]).description);
+#endif
 
         finished = true;
     }];