⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243758 in webkit


Ignore:
Timestamp:
Apr 2, 2019, 2:06:49 PM (7 years ago)
Author:
timothy@apple.com
Message:

NSAttributedString crashes when encoding text attachment cell for missing image.
https://bugs.webkit.org/show_bug.cgi?id=196504
rdar://problem/49161281

Reviewed by Tim Horton.

Clean up and fix a couple of errors and crashes in the missing image path of our
attributed string converter.

Fixes include:

  • Removed manual call to release on a RetainPtr, leading to autorelease pool crash.
  • No longer try to load an image that is missing on disk and has long been renamed.
  • No longer use a NSTextAttachmentCell in the Mac code path which can't be encoded for sending to the UIProcess, so it was pretty useless in the web content process.
  • Stopped using NSFileWrapper for the missing image so the attachment can contain the retina versions of the missing image.
  • Simplified bundle finding code, since WebCore is assumed to be loaded.
  • Fix leak of attachment by adding missing adoptNS().
  • editing/cocoa/HTMLConverter.mm:

(HTMLConverter::_addAttachmentForElement): Unify and simplify missing image path.
(_NSFirstPathForDirectoriesInDomains): Deleted.
(_NSSystemLibraryPath): Deleted.
(_webKitBundle): Deleted.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243757 r243758  
     12019-04-02  Timothy Hatcher  <timothy@apple.com>
     2
     3        NSAttributedString crashes when encoding text attachment cell for missing image.
     4        https://bugs.webkit.org/show_bug.cgi?id=196504
     5        rdar://problem/49161281
     6
     7        Reviewed by Tim Horton.
     8
     9        Clean up and fix a couple of errors and crashes in the missing image path of our
     10        attributed string converter.
     11
     12        Fixes include:
     13        * Removed manual call to release on a RetainPtr, leading to autorelease pool crash.
     14        * No longer try to load an image that is missing on disk and has long been renamed.
     15        * No longer use a NSTextAttachmentCell in the Mac code path which can't be encoded
     16          for sending to the UIProcess, so it was pretty useless in the web content process.
     17        * Stopped using NSFileWrapper for the missing image so the attachment can contain the
     18          retina versions of the missing image.
     19        * Simplified bundle finding code, since WebCore is assumed to be loaded.
     20        * Fix leak of attachment by adding missing adoptNS().
     21
     22        * editing/cocoa/HTMLConverter.mm:
     23        (HTMLConverter::_addAttachmentForElement): Unify and simplify missing image path.
     24        (_NSFirstPathForDirectoriesInDomains): Deleted.
     25        (_NSSystemLibraryPath): Deleted.
     26        (_webKitBundle): Deleted.
     27
    1282019-04-02  Chris Dumez  <cdumez@apple.com>
    229
  • trunk/Source/WebCore/editing/cocoa/HTMLConverter.mm

    r242831 r243758  
    9999#define PlatformFont                UIFont
    100100#define PlatformFontClass           PAL::getUIFontClass()
     101#define PlatformImageClass          PAL::getUIImageClass()
    101102
    102103#else
     
    114115#define PlatformFont                NSFont
    115116#define PlatformFontClass           NSFont
     117#define PlatformImageClass          NSImage
    116118
    117119#endif
     
    773775}
    774776
    775 #if PLATFORM(IOS_FAMILY)
    776 static NSString *_NSFirstPathForDirectoriesInDomains(NSSearchPathDirectory directory, NSSearchPathDomainMask domainMask, BOOL expandTilde)
    777 {
    778     NSArray *array = NSSearchPathForDirectoriesInDomains(directory, domainMask, expandTilde);
    779     return [array count] >= 1 ? [array objectAtIndex:0] : nil;
    780 }
    781 
    782 static NSString *_NSSystemLibraryPath(void)
    783 {
    784     return _NSFirstPathForDirectoriesInDomains(NSLibraryDirectory, NSSystemDomainMask, YES);
    785 }
    786 
    787 static NSBundle *_webKitBundle()
    788 {
    789     // FIXME: This should probably use the WebCore bundle to avoid the layering violation.
    790     NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
    791     if (!bundle)
    792         bundle = [NSBundle bundleWithPath:[_NSSystemLibraryPath() stringByAppendingPathComponent:@"Frameworks/WebKit.framework"]];
    793     return bundle;
    794 }
    795 #endif
    796 
    797777static inline NSShadow *_shadowForShadowStyle(NSString *shadowStyle)
    798778{
     
    13601340#endif
    13611341        } else {
     1342            NSBundle *webCoreBundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"];
    13621343#if PLATFORM(IOS_FAMILY)
    1363             [attachment release];
    1364             NSURL *missingImageURL = [_webKitBundle() URLForResource:@"missing_image" withExtension:@"tiff"];
    1365             ASSERT_WITH_MESSAGE(missingImageURL != nil, "Unable to find missing_image.tiff!");
    1366             NSFileWrapper *missingImageFileWrapper = [[[NSFileWrapper alloc] initWithURL:missingImageURL options:0 error:NULL] autorelease];
    1367             attachment = [[PlatformNSTextAttachment alloc] initWithFileWrapper:missingImageFileWrapper];
     1344            UIImage *missingImage = [PlatformImageClass imageNamed:@"missingImage" inBundle:webCoreBundle compatibleWithTraitCollection:nil];
    13681345#else
    1369             static NSImage *missingImage = nil;
    1370             NSTextAttachmentCell *cell;
    1371             cell = [[NSTextAttachmentCell alloc] initImageCell:missingImage];
    1372             [attachment setAttachmentCell:cell];
    1373             [cell release];
     1346            NSImage *missingImage = [webCoreBundle imageForResource:@"missingImage"];
    13741347#endif
     1348            ASSERT_WITH_MESSAGE(missingImage != nil, "Unable to find missingImage.");
     1349            attachment = adoptNS([[PlatformNSTextAttachment alloc] initWithData:nil ofType:nil]);
     1350            attachment.get().image = missingImage;
    13751351        }
    13761352        [_attrStr replaceCharactersInRange:rangeToReplace withString:string.get()];
Note: See TracChangeset for help on using the changeset viewer.