Title: [185775] trunk/Source/WebKit2
Revision
185775
Author
[email protected]
Date
2015-06-19 16:33:36 -0700 (Fri, 19 Jun 2015)

Log Message

REGRESSION(r185475): [Mac] ASSERT() when clicking on text using web fonts with force touch trackpad
https://bugs.webkit.org/show_bug.cgi?id=145890
<rdar://problem/21390877>

Reviewed by Darin Adler and Tim Horton.

The best place to stop the serialization of unserializable fonts is inside WebKit2's IPC code. We want
this logic to occur when encoding an NSAttributedString, rather than when encoding an NSDictionary,
because changing the shape of an NSAttributedString is less likely to result in problems rather than
changing the shape of an NSDictionary.

* Shared/mac/ArgumentCodersMac.mm:
(IPC::fontIsSerializable):
(IPC::filterUnserializableValues):
(IPC::encode):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (185774 => 185775)


--- trunk/Source/WebKit2/ChangeLog	2015-06-19 23:25:51 UTC (rev 185774)
+++ trunk/Source/WebKit2/ChangeLog	2015-06-19 23:33:36 UTC (rev 185775)
@@ -1,3 +1,21 @@
+2015-06-18  Myles C. Maxfield  <[email protected]>
+
+        REGRESSION(r185475): [Mac] ASSERT() when clicking on text using web fonts with force touch trackpad
+        https://bugs.webkit.org/show_bug.cgi?id=145890
+        <rdar://problem/21390877>
+
+        Reviewed by Darin Adler and Tim Horton.
+
+        The best place to stop the serialization of unserializable fonts is inside WebKit2's IPC code. We want
+        this logic to occur when encoding an NSAttributedString, rather than when encoding an NSDictionary,
+        because changing the shape of an NSAttributedString is less likely to result in problems rather than
+        changing the shape of an NSDictionary.
+
+        * Shared/mac/ArgumentCodersMac.mm:
+        (IPC::fontIsSerializable):
+        (IPC::filterUnserializableValues):
+        (IPC::encode):
+
 2015-06-19  Michael Catanzaro  <[email protected]>
 
         [SOUP] Fix return-type-c-linkage warning after r185553

Modified: trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm (185774 => 185775)


--- trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm	2015-06-19 23:25:51 UTC (rev 185774)
+++ trunk/Source/WebKit2/Shared/mac/ArgumentCodersMac.mm	2015-06-19 23:33:36 UTC (rev 185775)
@@ -26,6 +26,11 @@
 #import "config.h"
 #import "ArgumentCodersMac.h"
 
+#import <CoreText/CoreText.h>
+#if PLATFORM(IOS)
+#import <UIKit/UIKit.h>
+#endif
+
 #import "ArgumentCodersCF.h"
 #import "ArgumentDecoder.h"
 #import "ArgumentEncoder.h"
@@ -210,6 +215,41 @@
     return false;
 }
 
+static inline bool isSerializableFont(CTFontRef font)
+{
+    return adoptCF(CTFontCopyAttribute(font, kCTFontURLAttribute));
+}
+
+static inline bool isSerializableValue(id value)
+{
+#if USE(APPKIT)
+    auto fontClass = [NSFont class];
+#else
+    auto fontClass = [UIFont class];
+#endif
+    return ![value isKindOfClass:fontClass] || isSerializableFont(reinterpret_cast<CTFontRef>(value));
+}
+
+static inline RetainPtr<NSDictionary> filterUnserializableValues(NSDictionary *dictionary)
+{
+    __block bool modificationNecessary = false;
+    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
+        if (!isSerializableValue(object)) {
+            modificationNecessary = true;
+            *stop = YES;
+        }
+    }];
+    if (!modificationNecessary)
+        return dictionary;
+
+    auto result = adoptNS([[NSMutableDictionary alloc] init]);
+    [dictionary enumerateKeysAndObjectsUsingBlock:^(id key, id object, BOOL *stop) {
+        if (isSerializableValue(object))
+            [result setObject:object forKey:key];
+    }];
+    return result;
+}
+
 void encode(ArgumentEncoder& encoder, NSAttributedString *string)
 {
     // Even though NSAttributedString is toll free bridged with CFAttributedStringRef, attributes' values may be not, so we should stay within this file's code.
@@ -229,7 +269,7 @@
         ASSERT(effectiveRange.length);
         ASSERT(NSMaxRange(effectiveRange) <= length);
 
-        ranges.append(std::make_pair(effectiveRange, attributesAtIndex));
+        ranges.append(std::make_pair(effectiveRange, filterUnserializableValues(attributesAtIndex.get())));
 
         position = NSMaxRange(effectiveRange);
     }
@@ -313,6 +353,7 @@
         ASSERT(key);
         ASSERT([key isKindOfClass:[NSString class]]);
         ASSERT(value);
+        ASSERT(isSerializableValue(value));
 
         // Ignore values we don't recognize.
         if (typeFromObject(value) == Unknown)
@@ -409,6 +450,8 @@
         if (typeFromObject(value) == Unknown)
             continue;
 
+        ASSERT(isSerializableValue(value));
+
         encode(encoder, value);
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to