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

Changeset 294830 in webkit


Ignore:
Timestamp:
May 25, 2022, 3:36:19 PM (4 years ago)
Author:
Kate Cheney
Message:

Directories showing up as terminal icons in mail compose
​https://bugs.webkit.org/show_bug.cgi?id=240882
rdar://45111300

Reviewed by Wenson Hsieh.

  • Source/WebCore/rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::iconForAttachment):
We should not try to fetch an icon if all three provided strings are
null. This was causing issues by attempting to fetch an icon after
already rendering a valid icon using the filewrapper.

  • Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::requestThumbnailWithOperation):
(WebKit::WebPageProxy::requestThumbnailWithPath):
Remove some extra spaces and unnecessary WebCore:: prefix.

(WebKit::WebPageProxy::updateIconForDirectory):
New function to update the icon for directories to use the filewrapper
icon instead of the iconForFileType API. This method flips the icon so
it is right-side-up and converts it to a bitmap to pass to the web
process.

  • Source/WebKit/UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::requestAttachmentIcon):

  • Source/WebKit/UIProcess/WebPageProxy.h:
  • Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:

(testDirectoryAttachmentFileURL):
(-[TestWKWebView waitForAttachmentElementSizeToBecome:]):
(TestWebKitAPI::_icon):
(TestWebKitAPI::TEST):
Add a test to make sure we hit the new NSFileWrapper icon path to fetch
the correct icon for the bundle.

Canonical link: ​https://commits.webkit.org/250979@main

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r294680 r294830  
    26002600RetainPtr<NSImage> RenderThemeMac::iconForAttachment(const String& fileName, const String& attachmentType, const String& title)
    26012601{
     2602    if (fileName.isNull() && attachmentType.isNull() && title.isNull())
     2603        return nil;
     2604
    26022605    if (auto icon = WebCore::iconForAttachment(fileName, attachmentType, title))
    26032606        return icon->nsImage();
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r294790 r294830  
    119119using namespace WebCore;
    120120
     121constexpr IntSize iconSize = IntSize(400, 400);
     122
    121123#if ENABLE(DATA_DETECTION)
    122124
    … …  
    603605        RunLoop::main().dispatch([this, operation = retainPtr(operation)] {
    604606            auto identifier = [operation identifier];
    605             auto convertedImage = convertPlatformImageToBitmap([operation thumbnail], WebCore::IntSize(400, 400));
     607            auto convertedImage = convertPlatformImageToBitmap([operation thumbnail], iconSize);
    606608            if (!convertedImage)
    607609                return;
    … …  
    613615}
    614616
    615 
    616 void WebPageProxy::requestThumbnailWithFileWrapper(NSFileWrapper* fileWrapper, const String& identifier)
     617void WebPageProxy::requestThumbnailWithFileWrapper(NSFileWrapper *fileWrapper, const String& identifier)
    617618{
    618619    auto operation = adoptNS([[WKQLThumbnailLoadOperation alloc] initWithAttachment:fileWrapper identifier:identifier]);
    … …  
    624625    auto operation = adoptNS([[WKQLThumbnailLoadOperation alloc] initWithURL:filePath identifier:identifier]);
    625626    requestThumbnailWithOperation(operation.get());
    626    
    627627}
    628628
    629629#endif // HAVE(QUICKLOOK_THUMBNAILING)
     630
     631#if PLATFORM(MAC)
     632
     633void WebPageProxy::updateIconForDirectory(NSFileWrapper *fileWrapper, const String& identifier)
     634{
     635    auto image = [fileWrapper icon];
     636    if (!image)
     637        return;
     638
     639    auto flippedIcon = [NSImage imageWithSize:iconSize flipped:YES drawingHandler:^BOOL(NSRect destinationRect) {
     640        [image drawInRect:destinationRect fromRect:NSMakeRect(0, 0, [image size].width, [image size].height) operation:NSCompositingOperationSourceOver fraction:1.0f];
     641        return YES;
     642    }];
     643
     644    auto convertedImage = convertPlatformImageToBitmap(flippedIcon, iconSize);
     645    if (!convertedImage)
     646        return;
     647
     648    ShareableBitmap::Handle handle;
     649    convertedImage->createHandle(handle);
     650    send(Messages::WebPage::UpdateAttachmentIcon(identifier, handle, iconSize));
     651}
     652
     653#endif
    630654
    631655void WebPageProxy::scheduleActivityStateUpdate()
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r294790 r294830  
    1030410304    FloatSize size = requestedSize;
    1030510305    ShareableBitmap::Handle handle;
     10306#if PLATFORM(MAC)
     10307    auto attachment = attachmentForIdentifier(identifier);
     10308    if (attachment && attachment->contentType() == "public.directory") {
     10309        updateIconForDirectory(attachment->fileWrapper(), attachment->identifier());
     10310        return;
     10311    }
     10312#endif
     10313
    1030610314#if PLATFORM(COCOA)
    1030710315    if (auto icon = iconForAttachment(fileName, contentType, title, size))
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r294790 r294830  
    21102110#endif
    21112111
     2112#if PLATFORM(MAC)
     2113    void updateIconForDirectory(NSFileWrapper *, const String&);
     2114#endif
     2115
    21122116private:
    21132117    WebPageProxy(PageClient&, WebProcessProxy&, Ref<API::PageConfiguration>&&);
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

    r294515 r294830  
    157157}
    158158
     159#if PLATFORM(MAC)
     160
     161static NSURL *testDirectoryAttachmentFileURL()
     162{
     163    NSString *folderName = [NSString stringWithFormat:@"some.directory-%@", [NSUUID UUID].UUIDString];
     164    auto temporaryFolder = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:folderName] isDirectory:YES];
     165    NSError *error = nil;
     166    [[NSFileManager defaultManager] createDirectoryAtURL:temporaryFolder withIntermediateDirectories:NO attributes:nil error:&error];
     167
     168    return temporaryFolder;
     169}
     170
     171#endif
     172
    159173@interface AttachmentUIDelegate : NSObject<WKUIDelegatePrivate>
    160174@end
    … …  
    20632077}
    20642078
     2079static bool didLoadIcon;
     2080static NSImage *_icon(id, SEL)
     2081{
     2082    didLoadIcon = true;
     2083    return nil;
     2084}
     2085
     2086TEST(WKAttachmentTestsMac, DragDirectoryAttachment)
     2087{
     2088    didLoadIcon = false;
     2089    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     2090    [configuration _setAttachmentElementEnabled:YES];
     2091    auto simulator = adoptNS([[DragAndDropSimulator alloc] initWithWebViewFrame:NSMakeRect(0, 0, 400, 400) configuration:configuration.get()]);
     2092    TestWKWebView *webView = [simulator webView];
     2093    [webView synchronouslyLoadHTMLString:attachmentEditingTestMarkup];
     2094
     2095    InstanceMethodSwizzler fileWrapperSwizzler {
     2096        [NSFileWrapper class],
     2097        @selector(icon),
     2098        reinterpret_cast<IMP>(_icon)
     2099    };
     2100
     2101    auto fileWrapper = adoptNS([[NSFileWrapper alloc] initWithURL:testDirectoryAttachmentFileURL() options:0 error:nil]);
     2102    auto attachment = retainPtr([webView synchronouslyInsertAttachmentWithFileWrapper:fileWrapper.get() contentType:nil]);
     2103    [simulator runFrom:[webView attachmentElementMidPoint] to:CGPointMake(300, 300)];
     2104    TestWebKitAPI::Util::run(&didLoadIcon);
     2105}
     2106
    20652107#endif // PLATFORM(MAC)
    20662108
Note: See TracChangeset for help on using the changeset viewer.