Bug 236386 - Send icons to the WebContent process for rendering of the attachment element
Summary: Send icons to the WebContent process for rendering of the attachment element
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Per Arne Vollan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-02-09 11:27 PST by Per Arne Vollan
Modified: 2022-02-16 19:48 PST (History)
18 users (show)

See Also:


Attachments
Patch (17.63 KB, patch)
2022-02-09 12:43 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (21.82 KB, patch)
2022-02-09 13:38 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (24.48 KB, patch)
2022-02-10 08:59 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (23.73 KB, patch)
2022-02-10 11:07 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (27.69 KB, patch)
2022-02-11 08:45 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (55.90 KB, patch)
2022-02-11 16:58 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (58.16 KB, patch)
2022-02-11 19:05 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (50.85 KB, patch)
2022-02-14 09:41 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (51.19 KB, patch)
2022-02-15 07:39 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff
Patch (51.45 KB, patch)
2022-02-15 15:19 PST, Per Arne Vollan
darin: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.14 KB, patch)
2022-02-16 10:03 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.16 KB, patch)
2022-02-16 10:08 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.14 KB, patch)
2022-02-16 10:14 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.29 KB, patch)
2022-02-16 10:35 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.28 KB, patch)
2022-02-16 11:11 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.29 KB, patch)
2022-02-16 11:31 PST, Per Arne Vollan
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (52.25 KB, patch)
2022-02-16 15:39 PST, Per Arne Vollan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Per Arne Vollan 2022-02-09 11:27:12 PST
In order to avoid connecting to the Icon Services daemon in the WebContent process, we should send the icons for the attachment element to the WebContent process from the UI process.
Comment 1 Per Arne Vollan 2022-02-09 12:43:38 PST
Created attachment 451428 [details]
Patch
Comment 2 Per Arne Vollan 2022-02-09 12:44:16 PST
(In reply to Per Arne Vollan from comment #1)
> Created attachment 451428 [details]
> Patch

WIP patch.
Comment 3 Per Arne Vollan 2022-02-09 13:38:23 PST
Created attachment 451438 [details]
Patch
Comment 4 Per Arne Vollan 2022-02-10 08:59:14 PST
Created attachment 451545 [details]
Patch
Comment 5 Per Arne Vollan 2022-02-10 11:07:48 PST
Created attachment 451576 [details]
Patch
Comment 6 Per Arne Vollan 2022-02-11 08:45:35 PST
Created attachment 451701 [details]
Patch
Comment 7 Geoffrey Garen 2022-02-11 11:27:32 PST
Comment on attachment 451701 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451701&action=review

Patch looks good to me; probably want a graphics expert to double-check too.

> Source/WebCore/html/HTMLAttachmentElement.cpp:267
> +void HTMLAttachmentElement::updateIcon(const RefPtr<Image>& icon, const WebCore::FloatSize& size)

icon => iconSize
Comment 8 Tim Horton 2022-02-11 11:51:27 PST
Comment on attachment 451701 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451701&action=review

> Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:328
> +    return convertPlatformImageToBitmap(image.get(), WebCore::IntSize(400, 400));

I guess this is your solution to not knowing destination resolution; is the icon any blurrier than it used to be, now that you're using a big representation and scaling it down instead of letting the multi-representation platform image do the right thing?
Comment 9 Per Arne Vollan 2022-02-11 16:58:16 PST
Created attachment 451758 [details]
Patch
Comment 10 Per Arne Vollan 2022-02-11 16:58:48 PST
(In reply to Geoffrey Garen from comment #7)
> Comment on attachment 451701 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451701&action=review
> 
> Patch looks good to me; probably want a graphics expert to double-check too.
> 
> > Source/WebCore/html/HTMLAttachmentElement.cpp:267
> > +void HTMLAttachmentElement::updateIcon(const RefPtr<Image>& icon, const WebCore::FloatSize& size)
> 
> icon => iconSize

Fixed.

Thanks for reviewing!
Comment 11 Per Arne Vollan 2022-02-11 17:00:01 PST
(In reply to Tim Horton from comment #8)
> Comment on attachment 451701 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451701&action=review
> 
> > Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:328
> > +    return convertPlatformImageToBitmap(image.get(), WebCore::IntSize(400, 400));
> 
> I guess this is your solution to not knowing destination resolution; is the
> icon any blurrier than it used to be, now that you're using a big
> representation and scaling it down instead of letting the
> multi-representation platform image do the right thing?

I have not noticed the icons being blurry when rendered on iOS or macOS.

Thanks for reviewing!
Comment 12 Per Arne Vollan 2022-02-11 19:05:32 PST
Created attachment 451769 [details]
Patch
Comment 13 Per Arne Vollan 2022-02-14 09:41:33 PST
Created attachment 451915 [details]
Patch
Comment 14 Geoffrey Garen 2022-02-14 09:47:08 PST
Comment on attachment 451701 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=451701&action=review

>>> Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:328
>>> +    return convertPlatformImageToBitmap(image.get(), WebCore::IntSize(400, 400));
>> 
>> I guess this is your solution to not knowing destination resolution; is the icon any blurrier than it used to be, now that you're using a big representation and scaling it down instead of letting the multi-representation platform image do the right thing?
> 
> I have not noticed the icons being blurry when rendered on iOS or macOS.
> 
> Thanks for reviewing!

Should we consider trying to send the destination resolution from the WebContent process, or is that something that WebKit just doesn't know?
Comment 15 Per Arne Vollan 2022-02-14 10:35:57 PST
(In reply to Geoffrey Garen from comment #14)
> Comment on attachment 451701 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=451701&action=review
> 
> >>> Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm:328
> >>> +    return convertPlatformImageToBitmap(image.get(), WebCore::IntSize(400, 400));
> >> 
> >> I guess this is your solution to not knowing destination resolution; is the icon any blurrier than it used to be, now that you're using a big representation and scaling it down instead of letting the multi-representation platform image do the right thing?
> > 
> > I have not noticed the icons being blurry when rendered on iOS or macOS.
> > 
> > Thanks for reviewing!
> 
> Should we consider trying to send the destination resolution from the
> WebContent process, or is that something that WebKit just doesn't know?

Yes, that is a good point. I think we actually know the destination rect. I will look into this!

Thanks for reviewing!
Comment 16 Per Arne Vollan 2022-02-15 07:39:00 PST
Created attachment 452024 [details]
Patch
Comment 17 Per Arne Vollan 2022-02-15 15:19:34 PST
Created attachment 452100 [details]
Patch
Comment 18 Darin Adler 2022-02-15 15:35:10 PST
Comment on attachment 452100 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=452100&action=review

> Source/WebCore/html/HTMLAttachmentElement.cpp:283
> +    return;

Don’t need this at the end of a function.

> Source/WebCore/html/HTMLAttachmentElement.cpp:289
> +FloatSize HTMLAttachmentElement::iconSize() const
> +{
> +    return m_iconSize;
> +}

Consider putting this in the header.

> Source/WebCore/page/EmptyAttachmentElementClient.h:40
> +    virtual void requestAttachmentIcon(const String&, const FloatSize&) { }

Should be marked "final", not "virtual".

> Source/WebCore/rendering/RenderThemeIOS.h:71
> +    WEBCORE_EXPORT static RetainPtr<UIImage> iconForAttachment(const String& fileName, const String& attachmentType, const String& title, FloatSize&);

I suggest returning a structure containing both the UIImage and FloatSize rather than using an out argument for that.

> Source/WebCore/rendering/RenderThemeIOS.mm:1805
> +    auto name = fileName;
> +    if (name.isEmpty())
> +        name = title;
> +
> +    [documentInteractionController setName:name];

I would have written:

    [documentInteractionController setName:fileName.isEmpty() ? title : fileName];

Rather than the 4 line version.

> Source/WebCore/rendering/RenderThemeMac.mm:2567
> +RetainPtr<NSImage> RenderThemeMac::iconForAttachment(const String& fileName, const String& attachmentType, const String& title)

Seems a shame that we need all those different nsImage() lines rather than a function returning an Icon and another that returns the NSImage *.

> Source/WebCore/rendering/RenderThemeMac.mm:2574
> +ALLOW_DEPRECATED_DECLARATIONS_BEGIN
> +            if (auto icon = Icon::createIconForUTI(kUTTypeFolder))
> +                return icon->nsImage();
> +ALLOW_DEPRECATED_DECLARATIONS_END

Just moved code, but I have some ideas for refinement. Would have been nice to wrap this around just a single line:

ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    auto type = kUTTypeFolder;
ALLOW_DEPRECATED_DECLARATIONS_END

> Source/WebCore/rendering/RenderThemeMac.mm:2576
> +            String UTI;

I would have just named this "type".

> Source/WebCore/rendering/RenderThemeMac.mm:2592
> +    NSString *fileExtension = [static_cast<NSString *>(title) pathExtension];

I recommend using a local variable instead of a static_cast, and auto instead of writing out the type.

    NSString *cocoaTitle = title;
    if (auto fileExtension = cocoaTitle.pathExtension; fileExtension.length) {

> Source/WebCore/rendering/RenderThemeMac.mm:2601
> +    return nullptr;

Should be nil instead of nullptr.

> Source/WebCore/rendering/RenderThemeMac.mm:2641
> +    String attachmentType = attachment.attachmentElement().attachmentType();

This looks unused. Why compute it if we aren’t using it?

> Source/WebCore/rendering/RenderThemeMac.mm:2649
> +    if (context.paintingDisabled())
> +        return;

Do we want to request the icon if painting is disabled?

> Source/WebCore/rendering/RenderThemeMac.mm:2651
> +    auto nsImage = icon->nsImage();

Can just call this "image", no need to say "nsImage".

> Source/WebKit/UIProcess/WebPageProxy.cpp:10207
> +    auto icon = iconForAttachment(fileName, contentType, title, size);
> +    if (icon)

if (auto icon = ...)

> Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:39
> +    WebAttachmentElementClient(WebPage&);

This should be marked explicit.

> Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:40
> +    virtual ~WebAttachmentElementClient() { }

This is not needed or helpful.

> Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:42
> +    virtual void requestAttachmentIcon(const String& identifier, const WebCore::FloatSize&);

This should be marked "final", not "virtual". Also could probably be private.

> Source/WebKit/WebProcess/WebPage/WebPage.cpp:7330
> +        if (RefPtr<ShareableBitmap> icon = !iconHandle.isNull() ? ShareableBitmap::create(iconHandle) : nullptr)

This can be RefPtr or auto, I think, doesn’t need to be RefPtr<ShareableBitmap>.
Comment 19 Per Arne Vollan 2022-02-15 15:43:13 PST
(In reply to Darin Adler from comment #18)
> Comment on attachment 452100 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=452100&action=review
> 
> > Source/WebCore/html/HTMLAttachmentElement.cpp:283
> > +    return;
> 
> Don’t need this at the end of a function.
> 
> > Source/WebCore/html/HTMLAttachmentElement.cpp:289
> > +FloatSize HTMLAttachmentElement::iconSize() const
> > +{
> > +    return m_iconSize;
> > +}
> 
> Consider putting this in the header.
> 
> > Source/WebCore/page/EmptyAttachmentElementClient.h:40
> > +    virtual void requestAttachmentIcon(const String&, const FloatSize&) { }
> 
> Should be marked "final", not "virtual".
> 
> > Source/WebCore/rendering/RenderThemeIOS.h:71
> > +    WEBCORE_EXPORT static RetainPtr<UIImage> iconForAttachment(const String& fileName, const String& attachmentType, const String& title, FloatSize&);
> 
> I suggest returning a structure containing both the UIImage and FloatSize
> rather than using an out argument for that.
> 
> > Source/WebCore/rendering/RenderThemeIOS.mm:1805
> > +    auto name = fileName;
> > +    if (name.isEmpty())
> > +        name = title;
> > +
> > +    [documentInteractionController setName:name];
> 
> I would have written:
> 
>     [documentInteractionController setName:fileName.isEmpty() ? title :
> fileName];
> 
> Rather than the 4 line version.
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2567
> > +RetainPtr<NSImage> RenderThemeMac::iconForAttachment(const String& fileName, const String& attachmentType, const String& title)
> 
> Seems a shame that we need all those different nsImage() lines rather than a
> function returning an Icon and another that returns the NSImage *.
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2574
> > +ALLOW_DEPRECATED_DECLARATIONS_BEGIN
> > +            if (auto icon = Icon::createIconForUTI(kUTTypeFolder))
> > +                return icon->nsImage();
> > +ALLOW_DEPRECATED_DECLARATIONS_END
> 
> Just moved code, but I have some ideas for refinement. Would have been nice
> to wrap this around just a single line:
> 
> ALLOW_DEPRECATED_DECLARATIONS_BEGIN
>     auto type = kUTTypeFolder;
> ALLOW_DEPRECATED_DECLARATIONS_END
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2576
> > +            String UTI;
> 
> I would have just named this "type".
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2592
> > +    NSString *fileExtension = [static_cast<NSString *>(title) pathExtension];
> 
> I recommend using a local variable instead of a static_cast, and auto
> instead of writing out the type.
> 
>     NSString *cocoaTitle = title;
>     if (auto fileExtension = cocoaTitle.pathExtension; fileExtension.length)
> {
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2601
> > +    return nullptr;
> 
> Should be nil instead of nullptr.
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2641
> > +    String attachmentType = attachment.attachmentElement().attachmentType();
> 
> This looks unused. Why compute it if we aren’t using it?
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2649
> > +    if (context.paintingDisabled())
> > +        return;
> 
> Do we want to request the icon if painting is disabled?
> 
> > Source/WebCore/rendering/RenderThemeMac.mm:2651
> > +    auto nsImage = icon->nsImage();
> 
> Can just call this "image", no need to say "nsImage".
> 
> > Source/WebKit/UIProcess/WebPageProxy.cpp:10207
> > +    auto icon = iconForAttachment(fileName, contentType, title, size);
> > +    if (icon)
> 
> if (auto icon = ...)
> 
> > Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:39
> > +    WebAttachmentElementClient(WebPage&);
> 
> This should be marked explicit.
> 
> > Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:40
> > +    virtual ~WebAttachmentElementClient() { }
> 
> This is not needed or helpful.
> 
> > Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h:42
> > +    virtual void requestAttachmentIcon(const String& identifier, const WebCore::FloatSize&);
> 
> This should be marked "final", not "virtual". Also could probably be private.
> 
> > Source/WebKit/WebProcess/WebPage/WebPage.cpp:7330
> > +        if (RefPtr<ShareableBitmap> icon = !iconHandle.isNull() ? ShareableBitmap::create(iconHandle) : nullptr)
> 
> This can be RefPtr or auto, I think, doesn’t need to be
> RefPtr<ShareableBitmap>.

Thanks for reviewing! I will address the comments in the upcoming patch.
Comment 20 Per Arne Vollan 2022-02-16 10:03:25 PST
Created attachment 452204 [details]
Patch
Comment 21 Per Arne Vollan 2022-02-16 10:08:07 PST
Created attachment 452205 [details]
Patch
Comment 22 Per Arne Vollan 2022-02-16 10:14:54 PST
Created attachment 452207 [details]
Patch
Comment 23 Per Arne Vollan 2022-02-16 10:35:27 PST
Created attachment 452209 [details]
Patch
Comment 24 Per Arne Vollan 2022-02-16 11:11:24 PST
Created attachment 452215 [details]
Patch
Comment 25 Radar WebKit Bug Importer 2022-02-16 11:28:18 PST
<rdar://problem/89038014>
Comment 26 Per Arne Vollan 2022-02-16 11:31:09 PST
Created attachment 452216 [details]
Patch
Comment 27 EWS 2022-02-16 15:30:40 PST
Tools/Scripts/svn-apply failed to apply attachment 452216 [details] to trunk.
Please resolve the conflicts and upload a new patch.
Comment 28 Per Arne Vollan 2022-02-16 15:39:56 PST
Created attachment 452260 [details]
Patch
Comment 29 EWS 2022-02-16 19:48:01 PST
Committed r289994 (247380@main): <https://commits.webkit.org/247380@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 452260 [details].