Title: [289994] trunk/Source
Revision
289994
Author
pvol...@apple.com
Date
2022-02-16 19:46:45 -0800 (Wed, 16 Feb 2022)

Log Message

Send icons to the WebContent process for rendering of the attachment element
https://bugs.webkit.org/show_bug.cgi?id=236386

Reviewed by Darin Adler.

In order to avoid connecting to the Icon Services daemon in the WebContent process, we should send the icons for the attachment
Source/WebCore:

element to the WebContent process from the UI process. When the icon is being painted in the WebContent process, it is getting
the icon from the HTML attachment element, instead of creating it by connecting to Icon Services. The icon in the attachment
element is received from the UI process. A new AttachmentElementClient class is created to forward the messages to the UI
process.

* WebCore.xcodeproj/project.pbxproj:
* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::updateIcon):
(WebCore::HTMLAttachmentElement::icon const):
(WebCore::HTMLAttachmentElement::iconSize const):
* html/HTMLAttachmentElement.h:
* loader/EmptyClients.cpp:
(WebCore::pageConfigurationWithEmptyClients):
* page/AttachmentElementClient.h: Added.
(WebCore::AttachmentElementClient::~AttachmentElementClient):
* page/EmptyAttachmentElementClient.h: Added.
* page/Page.cpp:
(WebCore::m_attachmentElementClient):
(WebCore::m_modelPlayerProvider): Deleted.
* page/Page.h:
(WebCore::Page::attachmentElementClient):
* page/PageConfiguration.cpp:
(WebCore::PageConfiguration::PageConfiguration):
* page/PageConfiguration.h:
* platform/graphics/Icon.h:
(WebCore::Icon::nsImage const):
* rendering/RenderThemeIOS.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::iconForAttachment):
(WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
(WebCore::paintAttachmentIcon):
(WebCore::iconForAttachment): Deleted.
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::iconForAttachment):
(WebCore::paintAttachmentIcon):
(WebCore::iconForAttachment): Deleted.

Source/WebKit:

element to the WebContent process from the UI process. The icon will be sent to the WebContent process when the attachment
attributes are updated, or the WebContent process has requested the icon. The new client class WebAttachmentElementClient is
responsible for requesting icons from the UI process.

* Sources.txt:
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::convertPlatformImageToBitmap):
(WebKit::WebPageProxy::iconForAttachment):
(WebKit::WebPageProxy::requestThumbnailWithOperation):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::requestAttachmentIcon):
(WebKit::WebPageProxy::updateAttachmentAttributes):
(WebKit::WebPageProxy::updateAttachmentThumbnail):
(WebKit::WebPageProxy::updateAttachmentIcon): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp: Added.
(WebKit::WebAttachmentElementClient::WebAttachmentElementClient):
(WebKit::WebAttachmentElementClient::requestAttachmentIcon):
* WebProcess/WebCoreSupport/WebAttachmentElementClient.h: Added.
* WebProcess/WebCoreSupport/WebEditorClient.cpp:
(WebKit::WebEditorClient::didInsertAttachmentWithIdentifier):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::m_appHighlightsVisible):
(WebKit::WebPage::updateAttachmentThumbnail):
(WebKit::WebPage::updateAttachmentIcon):
(WebKit::WebPage::requestAttachmentIcon):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289993 => 289994)


--- trunk/Source/WebCore/ChangeLog	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/ChangeLog	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1,3 +1,49 @@
+2022-02-16  Per Arne Vollan  <pvol...@apple.com>
+
+        Send icons to the WebContent process for rendering of the attachment element
+        https://bugs.webkit.org/show_bug.cgi?id=236386
+
+        Reviewed by Darin Adler.
+
+        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. When the icon is being painted in the WebContent process, it is getting
+        the icon from the HTML attachment element, instead of creating it by connecting to Icon Services. The icon in the attachment
+        element is received from the UI process. A new AttachmentElementClient class is created to forward the messages to the UI
+        process.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::updateIcon):
+        (WebCore::HTMLAttachmentElement::icon const):
+        (WebCore::HTMLAttachmentElement::iconSize const):
+        * html/HTMLAttachmentElement.h:
+        * loader/EmptyClients.cpp:
+        (WebCore::pageConfigurationWithEmptyClients):
+        * page/AttachmentElementClient.h: Added.
+        (WebCore::AttachmentElementClient::~AttachmentElementClient):
+        * page/EmptyAttachmentElementClient.h: Added.
+        * page/Page.cpp:
+        (WebCore::m_attachmentElementClient):
+        (WebCore::m_modelPlayerProvider): Deleted.
+        * page/Page.h:
+        (WebCore::Page::attachmentElementClient):
+        * page/PageConfiguration.cpp:
+        (WebCore::PageConfiguration::PageConfiguration):
+        * page/PageConfiguration.h:
+        * platform/graphics/Icon.h:
+        (WebCore::Icon::nsImage const):
+        * rendering/RenderThemeIOS.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::iconForAttachment):
+        (WebCore::RenderAttachmentInfo::RenderAttachmentInfo):
+        (WebCore::paintAttachmentIcon):
+        (WebCore::iconForAttachment): Deleted.
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::iconForAttachment):
+        (WebCore::paintAttachmentIcon):
+        (WebCore::iconForAttachment): Deleted.
+
 2022-02-16  Matt Woodrow  <mattwood...@apple.com>
 
         Implement getComputedStyle for subgrids

Modified: trunk/Source/WebCore/Headers.cmake (289993 => 289994)


--- trunk/Source/WebCore/Headers.cmake	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/Headers.cmake	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1069,6 +1069,7 @@
     page/ActivityStateChangeObserver.h
     page/AdjustViewSizeOrNot.h
     page/AlternativeTextClient.h
+    page/AttachmentElementClient.h
     page/AutoplayEvent.h
     page/Base64Utilities.h
     page/CacheStorageProvider.h

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (289993 => 289994)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-17 03:46:45 UTC (rev 289994)
@@ -4310,7 +4310,7 @@
 		BCEA4878097D93020094C9E4 /* RenderInline.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4839097D93020094C9E4 /* RenderInline.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCEA487A097D93020094C9E4 /* RenderLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA483B097D93020094C9E4 /* RenderLayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCEA4880097D93020094C9E4 /* RenderObject.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4841097D93020094C9E4 /* RenderObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
-		BCEA4887097D93020094C9E4 /* RenderThemeMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4848097D93020094C9E4 /* RenderThemeMac.h */; };
+		BCEA4887097D93020094C9E4 /* RenderThemeMac.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4848097D93020094C9E4 /* RenderThemeMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCEA488A097D93020094C9E4 /* RenderTheme.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA484B097D93020094C9E4 /* RenderTheme.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCEA488C097D93020094C9E4 /* RenderText.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA484D097D93020094C9E4 /* RenderText.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		BCEA488E097D93020094C9E4 /* RenderTextFragment.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA484F097D93020094C9E4 /* RenderTextFragment.h */; };
@@ -5286,6 +5286,8 @@
 		E3582C282527F66900D1B790 /* WebCoreJITOperations.h in Headers */ = {isa = PBXBuildFile; fileRef = E3582C262527F66800D1B790 /* WebCoreJITOperations.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E35B907F23F60A50000011FF /* LocalizedDeviceModel.h in Headers */ = {isa = PBXBuildFile; fileRef = E35B907C23F60677000011FF /* LocalizedDeviceModel.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E364321C25D37A6700F90E2A /* ModuleScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = E364321A25D37A6600F90E2A /* ModuleScriptLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E36D701F27B7200C006531B7 /* AttachmentElementClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E36D701B27B70B23006531B7 /* AttachmentElementClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E36D702027B72013006531B7 /* EmptyAttachmentElementClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E36D701E27B71F04006531B7 /* EmptyAttachmentElementClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E377FE4D1DADE16500CDD025 /* NodeConstants.h in Headers */ = {isa = PBXBuildFile; fileRef = E3D049931DADC04500718F3C /* NodeConstants.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E37C86501EB63E3F0087C6CA /* JSDOMPromise.h in Headers */ = {isa = PBXBuildFile; fileRef = E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E39628BF2395728F00658ECD /* DeviceOrientationUpdateProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = E39628BD2395728E00658ECD /* DeviceOrientationUpdateProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -17343,6 +17345,8 @@
 		E35B907C23F60677000011FF /* LocalizedDeviceModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizedDeviceModel.h; sourceTree = "<group>"; };
 		E35B907E23F60677000011FF /* LocalizedDeviceModel.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalizedDeviceModel.mm; sourceTree = "<group>"; };
 		E364321A25D37A6600F90E2A /* ModuleScriptLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModuleScriptLoader.h; sourceTree = "<group>"; };
+		E36D701B27B70B23006531B7 /* AttachmentElementClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AttachmentElementClient.h; sourceTree = "<group>"; };
+		E36D701E27B71F04006531B7 /* EmptyAttachmentElementClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EmptyAttachmentElementClient.h; sourceTree = "<group>"; };
 		E37C864F1EB63E2D0087C6CA /* JSDOMPromise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMPromise.h; sourceTree = "<group>"; };
 		E38838941BAD145F00D62EE3 /* ScriptModuleLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptModuleLoader.cpp; sourceTree = "<group>"; };
 		E38838951BAD145F00D62EE3 /* ScriptModuleLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptModuleLoader.h; sourceTree = "<group>"; };
@@ -24057,6 +24061,7 @@
 				724EE54F1DC7F25B00A91FFB /* ActivityStateChangeObserver.h */,
 				BCF48CE61370D114004E87D6 /* AdjustViewSizeOrNot.h */,
 				CEDA12D6152CA1CB00D9E08D /* AlternativeTextClient.h */,
+				E36D701B27B70B23006531B7 /* AttachmentElementClient.h */,
 				C9D467041E60C3EB008195FB /* AutoplayEvent.h */,
 				45830D4B1679B4F800ACF8C3 /* AutoscrollController.cpp */,
 				45830D4C1679B4F800ACF8C3 /* AutoscrollController.h */,
@@ -24128,6 +24133,7 @@
 				81F65FF513788FAA00FF6F2D /* DragState.h */,
 				93D6B7A62551D3ED0058DD3A /* DummySpeechRecognitionProvider.h */,
 				1AF326770D78B9440068F0C4 /* EditorClient.h */,
+				E36D701E27B71F04006531B7 /* EmptyAttachmentElementClient.h */,
 				93C09A800B064F00005ABD4D /* EventHandler.cpp */,
 				93C09A520B064DB3005ABD4D /* EventHandler.h */,
 				E0FEF371B27C53EAC1C1FBEE /* EventSource.cpp */,
@@ -33528,6 +33534,7 @@
 				FD5686CA13AC180200B69C68 /* AsyncAudioDecoder.h in Headers */,
 				E1CDE9221501916900862CC5 /* AsyncFileStream.h in Headers */,
 				0FFD4D6118651FA300512F6E /* AsyncScrollingCoordinator.h in Headers */,
+				E36D701F27B7200C006531B7 /* AttachmentElementClient.h in Headers */,
 				57D135252294A33C00827401 /* AttestationConveyancePreference.h in Headers */,
 				A8C4A80D09D563270003AC8D /* Attr.h in Headers */,
 				A8C4A80B09D563270003AC8D /* Attribute.h in Headers */,
@@ -34452,6 +34459,7 @@
 				FBDB619F16D6036500BB3394 /* ElementRuleCollector.h in Headers */,
 				E4D58EBB17B8F12800CBDCA8 /* ElementTraversal.h in Headers */,
 				F55B3DBC1251F12D003EF269 /* EmailInputType.h in Headers */,
+				E36D702027B72013006531B7 /* EmptyAttachmentElementClient.h in Headers */,
 				B25599A50D00D8BA00BB825C /* EmptyClients.h in Headers */,
 				414DEDE71F9FE91E0047C40D /* EmptyFrameLoaderClient.h in Headers */,
 				515BE1901D54F5FB00DD7C68 /* EmptyGamepadProvider.h in Headers */,

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (289993 => 289994)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -28,6 +28,7 @@
 
 #if ENABLE(ATTACHMENT_ELEMENT)
 
+#include "AttachmentElementClient.h"
 #include "DOMURL.h"
 #include "Document.h"
 #include "Editor.h"
@@ -264,6 +265,23 @@
         renderer->invalidate();
 }
 
+void HTMLAttachmentElement::updateIcon(const RefPtr<Image>& icon, const WebCore::FloatSize& iconSize)
+{
+    m_icon = icon;
+    m_iconSize = iconSize;
+
+    if (auto* renderer = this->renderer())
+        renderer->invalidate();
+}
+
+void HTMLAttachmentElement::requestIconWithSize(const FloatSize& size) const
+{
+    if (!document().page() || !document().page()->attachmentElementClient())
+        return;
+
+    document().page()->attachmentElementClient()->requestAttachmentIcon(uniqueIdentifier(), size);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (289993 => 289994)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -59,6 +59,7 @@
     WEBCORE_EXPORT void updateAttributes(std::optional<uint64_t>&& newFileSize, const String& newContentType, const String& newFilename);
     WEBCORE_EXPORT void updateEnclosingImageWithData(const String& contentType, Ref<FragmentedSharedBuffer>&& data);
     WEBCORE_EXPORT void updateThumbnail(const RefPtr<Image>& thumbnail);
+    WEBCORE_EXPORT void updateIcon(const RefPtr<Image>& icon, const WebCore::FloatSize&);
 
     InsertedIntoAncestorResult insertedIntoAncestor(InsertionType, ContainerNode&) final;
     void removedFromAncestor(RemovalType, ContainerNode&) final;
@@ -68,9 +69,12 @@
 
     WEBCORE_EXPORT String attachmentTitle() const;
     String attachmentTitleForDisplay() const;
-    String attachmentType() const;
+    WEBCORE_EXPORT String attachmentType() const;
     String attachmentPath() const;
     RefPtr<Image> thumbnail() const { return m_thumbnail; }
+    RefPtr<Image> icon() const { return m_icon; }
+    void requestIconWithSize(const FloatSize&) const;
+    FloatSize iconSize() const { return m_iconSize; }
     RenderAttachment* renderer() const;
 
 private:
@@ -91,6 +95,8 @@
     RefPtr<File> m_file;
     String m_uniqueIdentifier;
     RefPtr<Image> m_thumbnail;
+    RefPtr<Image> m_icon;
+    FloatSize m_iconSize;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/loader/EmptyClients.cpp (289993 => 289994)


--- trunk/Source/WebCore/loader/EmptyClients.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/loader/EmptyClients.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -49,6 +49,7 @@
 #include "DummySpeechRecognitionProvider.h"
 #include "DummyStorageProvider.h"
 #include "EditorClient.h"
+#include "EmptyAttachmentElementClient.h"
 #include "EmptyFrameLoaderClient.h"
 #include "FileChooser.h"
 #include "FormState.h"
@@ -1255,6 +1256,10 @@
     pageConfiguration.storageNamespaceProvider = adoptRef(*new EmptyStorageNamespaceProvider);
     pageConfiguration.visitedLinkStore = adoptRef(*new EmptyVisitedLinkStore);
     
+#if ENABLE(ATTACHMENT_ELEMENT)
+    pageConfiguration.attachmentElementClient = makeUnique<EmptyAttachmentElementClient>();
+#endif
+
     return pageConfiguration;
 }
 

Added: trunk/Source/WebCore/page/AttachmentElementClient.h (0 => 289994)


--- trunk/Source/WebCore/page/AttachmentElementClient.h	                        (rev 0)
+++ trunk/Source/WebCore/page/AttachmentElementClient.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+class FloatSize;
+
+class AttachmentElementClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    virtual ~AttachmentElementClient() { }
+    virtual void requestAttachmentIcon(const String& identifier, const FloatSize&) = 0;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)

Added: trunk/Source/WebCore/page/EmptyAttachmentElementClient.h (0 => 289994)


--- trunk/Source/WebCore/page/EmptyAttachmentElementClient.h	                        (rev 0)
+++ trunk/Source/WebCore/page/EmptyAttachmentElementClient.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+#include "AttachmentElementClient.h"
+
+namespace WebCore {
+
+class EmptyAttachmentElementClient final : public AttachmentElementClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    EmptyAttachmentElementClient() = default;
+
+private:
+    void requestAttachmentIcon(const String&, const FloatSize&) final { }
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebCore/page/Page.cpp (289993 => 289994)


--- trunk/Source/WebCore/page/Page.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/page/Page.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -25,6 +25,7 @@
 #include "AnimationFrameRate.h"
 #include "AppHighlightStorage.h"
 #include "ApplicationCacheStorage.h"
+#include "AttachmentElementClient.h"
 #include "AuthenticatorCoordinator.h"
 #include "AuthenticatorCoordinatorClient.h"
 #include "BackForwardCache.h"
@@ -343,6 +344,9 @@
     , m_permissionController(WTFMove(pageConfiguration.permissionController))
     , m_storageProvider(WTFMove(pageConfiguration.storageProvider))
     , m_modelPlayerProvider(WTFMove(pageConfiguration.modelPlayerProvider))
+#if ENABLE(ATTACHMENT_ELEMENT)
+    , m_attachmentElementClient(WTFMove(pageConfiguration.attachmentElementClient))
+#endif
 {
     updateTimerThrottlingState();
 

Modified: trunk/Source/WebCore/page/Page.h (289993 => 289994)


--- trunk/Source/WebCore/page/Page.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/page/Page.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -96,6 +96,7 @@
 class ActivityStateChangeObserver;
 class AlternativeTextClient;
 class ApplicationCacheStorage;
+class AttachmentElementClient;
 class AuthenticatorCoordinator;
 class BackForwardController;
 class BroadcastChannelRegistry;
@@ -930,6 +931,10 @@
 
     ModelPlayerProvider& modelPlayerProvider();
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+    AttachmentElementClient* attachmentElementClient() { return m_attachmentElementClient.get(); }
+#endif
+
 #if USE(ATSPI)
     AccessibilityRootAtspi* accessibilityRootObject() const { return m_accessibilityRootObject; }
     void setAccessibilityRootObject(AccessibilityRootAtspi* rootObject) { m_accessibilityRootObject = rootObject; }
@@ -1286,6 +1291,10 @@
     UniqueRef<StorageProvider> m_storageProvider;
     UniqueRef<ModelPlayerProvider> m_modelPlayerProvider;
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+    std::unique_ptr<AttachmentElementClient> m_attachmentElementClient;
+#endif
+
 #if ENABLE(IMAGE_ANALYSIS)
     using CachedTextRecognitionResult = std::pair<TextRecognitionResult, IntRect>;
     WeakHashMap<HTMLElement, CachedTextRecognitionResult> m_textRecognitionResults;

Modified: trunk/Source/WebCore/page/PageConfiguration.cpp (289993 => 289994)


--- trunk/Source/WebCore/page/PageConfiguration.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/page/PageConfiguration.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -28,6 +28,7 @@
 
 #include "AlternativeTextClient.h"
 #include "ApplicationCacheStorage.h"
+#include "AttachmentElementClient.h"
 #include "BackForwardClient.h"
 #include "BroadcastChannelRegistry.h"
 #include "CacheStorageProvider.h"

Modified: trunk/Source/WebCore/page/PageConfiguration.h (289993 => 289994)


--- trunk/Source/WebCore/page/PageConfiguration.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/page/PageConfiguration.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -46,6 +46,7 @@
 
 class AlternativeTextClient;
 class ApplicationCacheStorage;
+class AttachmentElementClient;
 class AuthenticatorCoordinatorClient;
 class BackForwardClient;
 class BroadcastChannelRegistry;
@@ -152,6 +153,9 @@
     UniqueRef<StorageProvider> storageProvider;
 
     UniqueRef<ModelPlayerProvider> modelPlayerProvider;
+#if ENABLE(ATTACHMENT_ELEMENT)
+    std::unique_ptr<AttachmentElementClient> attachmentElementClient;
+#endif
 };
 
 }

Modified: trunk/Source/WebCore/platform/graphics/Icon.h (289993 => 289994)


--- trunk/Source/WebCore/platform/graphics/Icon.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/platform/graphics/Icon.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -61,6 +61,8 @@
 #if PLATFORM(MAC)
     static RefPtr<Icon> createIconForUTI(const String&);
     static RefPtr<Icon> createIconForFileExtension(const String&);
+
+    RetainPtr<NSImage> nsImage() const { return m_nsImage; }
 #endif
 
 private:

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.h (289993 => 289994)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -36,6 +36,7 @@
 #endif
 
 OBJC_CLASS CIContext;
+OBJC_CLASS UIImage;
 
 namespace WebCore {
     
@@ -67,6 +68,13 @@
 
     WEBCORE_EXPORT static Color systemFocusRingColor();
 
+    struct IconAndSize {
+        RetainPtr<UIImage> icon;
+        FloatSize size;
+    };
+
+    WEBCORE_EXPORT static IconAndSize iconForAttachment(const String& fileName, const String& attachmentType, const String& title);
+
 private:
     bool canPaint(const PaintInfo&, const Settings&) const final;
 

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (289993 => 289994)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1681,7 +1681,7 @@
     BOOL hasProgress { NO };
     float progress;
 
-    RetainPtr<UIImage> icon;
+    RefPtr<Image> icon;
     RefPtr<Image> thumbnailIcon;
 
     int baseline { 0 };
@@ -1793,21 +1793,14 @@
     return validProgress;
 }
 
-static RetainPtr<UIImage> iconForAttachment(const RenderAttachment& attachment, FloatSize& size)
+RenderThemeIOS::IconAndSize RenderThemeIOS::iconForAttachment(const String& fileName, const String& attachmentType, const String& title)
 {
     ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     auto documentInteractionController = adoptNS([PAL::allocUIDocumentInteractionControllerInstance() init]);
     ALLOW_DEPRECATED_DECLARATIONS_END
 
-    String fileName;
-    if (File* file = attachment.attachmentElement().file())
-        fileName = file->name();
+    [documentInteractionController setName:fileName.isEmpty() ? title : fileName];
 
-    if (fileName.isEmpty())
-        fileName = attachment.attachmentElement().attachmentTitle();
-    [documentInteractionController setName:fileName];
-
-    String attachmentType = attachment.attachmentElement().attachmentType();
     if (!attachmentType.isEmpty()) {
         String UTI;
         if (isDeclaredUTI(attachmentType))
@@ -1824,7 +1817,7 @@
 #if PLATFORM(IOS)
     NSArray *icons = [documentInteractionController icons];
     if (!icons.count)
-        return nil;
+        return IconAndSize { nil, FloatSize() };
 
     result = icons.lastObject;
 
@@ -1845,9 +1838,9 @@
     }
 #endif
     CGFloat iconAspect = [result size].width / [result size].height;
-    size = largestRectWithAspectRatioInsideRect(iconAspect, FloatRect(0, 0, attachmentIconSize, attachmentIconSize)).size();
+    auto size = largestRectWithAspectRatioInsideRect(iconAspect, FloatRect(0, 0, attachmentIconSize, attachmentIconSize)).size();
 
-    return result;
+    return IconAndSize { result, size };
 }
 
 RenderAttachmentInfo::RenderAttachmentInfo(const RenderAttachment& attachment)
@@ -1868,8 +1861,10 @@
     }
 
     if (action.isEmpty() && !hasProgress) {
-        FloatSize iconSize;
-        icon = iconForAttachment(attachment, iconSize);
+        FloatSize iconSize = attachment.attachmentElement().iconSize();
+        icon = attachment.attachmentElement().icon();
+        if (!icon)
+            attachment.attachmentElement().requestIconWithSize(FloatSize());
         thumbnailIcon = attachment.attachmentElement().thumbnail();
         if (thumbnailIcon)
             iconSize = largestRectWithAspectRatioInsideRect(thumbnailIcon->size().aspectRatio(), FloatRect(0, 0, attachmentIconSize, attachmentIconSize)).size();
@@ -1914,7 +1909,7 @@
     if (info.thumbnailIcon)
         iconImage = info.thumbnailIcon;
     else if (info.icon)
-        iconImage = BitmapImage::create([info.icon CGImage]);
+        iconImage = info.icon;
     
     context.drawImage(*iconImage, info.iconRect);
 }

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (289993 => 289994)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -100,6 +100,8 @@
     // A view associated to the contained document.
     NSView* documentViewFor(const RenderObject&) const;
 
+    WEBCORE_EXPORT static RetainPtr<NSImage> iconForAttachment(const String& fileName, const String& attachmentType, const String& title);
+
 private:
     RenderThemeMac();
 

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (289993 => 289994)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2022-02-17 03:46:45 UTC (rev 289994)
@@ -2564,6 +2564,48 @@
     return layout.baseline;
 }
 
+static RefPtr<Icon> iconForAttachment(const String& fileName, const String& attachmentType, const String& title)
+{
+    if (!attachmentType.isEmpty()) {
+        if (equalIgnoringASCIICase(attachmentType, "multipart/x-folder") || equalIgnoringASCIICase(attachmentType, "application/vnd.apple.folder")) {
+ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+            auto type = kUTTypeFolder;
+ALLOW_DEPRECATED_DECLARATIONS_END
+            if (auto icon = Icon::createIconForUTI(type))
+                return icon;
+        } else {
+            String type;
+            if (isDeclaredUTI(attachmentType))
+                type = attachmentType;
+            else
+                type = UTIFromMIMEType(attachmentType);
+
+            if (auto icon = Icon::createIconForUTI(type))
+                return icon;
+        }
+    }
+
+    if (!fileName.isEmpty()) {
+        if (auto icon = Icon::createIconForFiles({ fileName }))
+            return icon;
+    }
+
+    NSString *cocoaTitle = title;
+    if (auto fileExtension = cocoaTitle.pathExtension; fileExtension.length) {
+        if (auto icon = Icon::createIconForFileExtension(fileExtension))
+            return icon;
+    }
+
+    return Icon::createIconForUTI("public.data");
+}
+
+RetainPtr<NSImage> RenderThemeMac::iconForAttachment(const String& fileName, const String& attachmentType, const String& title)
+{
+    if (auto icon = WebCore::iconForAttachment(fileName, attachmentType, title))
+        return icon->nsImage();
+    return nil;
+}
+
 static void paintAttachmentIconBackground(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
 {
     if (layout.style == AttachmentLayoutStyle::NonSelected)
@@ -2595,52 +2637,29 @@
     }
 }
 
-static RefPtr<Icon> iconForAttachment(const RenderAttachment& attachment)
+static void paintAttachmentIcon(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
 {
-    String attachmentType = attachment.attachmentElement().attachmentType();
-    
-    if (!attachmentType.isEmpty()) {
-        if (equalIgnoringASCIICase(attachmentType, "multipart/x-folder") || equalIgnoringASCIICase(attachmentType, "application/vnd.apple.folder")) {
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-            if (auto icon = Icon::createIconForUTI(kUTTypeFolder))
-                return icon;
-ALLOW_DEPRECATED_DECLARATIONS_END
-        } else {
-            String UTI;
-            if (isDeclaredUTI(attachmentType))
-                UTI = attachmentType;
-            else
-                UTI = UTIFromMIMEType(attachmentType);
-
-            if (auto icon = Icon::createIconForUTI(UTI))
-                return icon;
-        }
+    if (auto thumbnailIcon = attachment.attachmentElement().thumbnail()) {
+        context.drawImage(*thumbnailIcon, layout.iconRect);
+        return;
     }
 
-    if (File* file = attachment.attachmentElement().file()) {
-        if (auto icon = Icon::createIconForFiles({ file->path() }))
-            return icon;
-    }
+    if (context.paintingDisabled())
+        return;
 
-    NSString *fileExtension = [static_cast<NSString *>(attachment.attachmentElement().attachmentTitle()) pathExtension];
-    if (fileExtension.length) {
-        if (auto icon = Icon::createIconForFileExtension(fileExtension))
-            return icon;
+    auto icon = attachment.attachmentElement().icon();
+    if (!icon) {
+        attachment.attachmentElement().requestIconWithSize(layout.iconRect.size());
+        return;
     }
 
-    return Icon::createIconForUTI("public.data");
-}
+    auto image = icon->nsImage();
+    if (!image)
+        return;
+    
+    LocalCurrentGraphicsContext localCurrentGC(context);
 
-static void paintAttachmentIcon(const RenderAttachment& attachment, GraphicsContext& context, AttachmentLayout& layout)
-{
-    if (auto thumbnailIcon = attachment.attachmentElement().thumbnail()) {
-        context.drawImage(*thumbnailIcon, layout.iconRect);
-        return;
-    }
-    auto icon = iconForAttachment(attachment);
-    if (!icon)
-        return;
-    icon->paint(context, layout.iconRect);
+    [image drawInRect:layout.iconRect fromRect:NSMakeRect(0, 0, [image size].width, [image size].height) operation:NSCompositingOperationSourceOver fraction:1.0f];
 }
 
 static std::pair<RefPtr<Image>, float> createAttachmentPlaceholderImage(float deviceScaleFactor, const AttachmentLayout& layout)

Modified: trunk/Source/WebKit/ChangeLog (289993 => 289994)


--- trunk/Source/WebKit/ChangeLog	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/ChangeLog	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1,3 +1,42 @@
+2022-02-16  Per Arne Vollan  <pvol...@apple.com>
+
+        Send icons to the WebContent process for rendering of the attachment element
+        https://bugs.webkit.org/show_bug.cgi?id=236386
+
+        Reviewed by Darin Adler.
+
+        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. The icon will be sent to the WebContent process when the attachment
+        attributes are updated, or the WebContent process has requested the icon. The new client class WebAttachmentElementClient is
+        responsible for requesting icons from the UI process.
+
+        * Sources.txt:
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::convertPlatformImageToBitmap):
+        (WebKit::WebPageProxy::iconForAttachment):
+        (WebKit::WebPageProxy::requestThumbnailWithOperation):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::requestAttachmentIcon):
+        (WebKit::WebPageProxy::updateAttachmentAttributes):
+        (WebKit::WebPageProxy::updateAttachmentThumbnail):
+        (WebKit::WebPageProxy::updateAttachmentIcon): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp: Added.
+        (WebKit::WebAttachmentElementClient::WebAttachmentElementClient):
+        (WebKit::WebAttachmentElementClient::requestAttachmentIcon):
+        * WebProcess/WebCoreSupport/WebAttachmentElementClient.h: Added.
+        * WebProcess/WebCoreSupport/WebEditorClient.cpp:
+        (WebKit::WebEditorClient::didInsertAttachmentWithIdentifier):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::m_appHighlightsVisible):
+        (WebKit::WebPage::updateAttachmentThumbnail):
+        (WebKit::WebPage::updateAttachmentIcon):
+        (WebKit::WebPage::requestAttachmentIcon):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2022-02-15  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [WebGPU] Update IDLs and stubs to latest version of the spec

Modified: trunk/Source/WebKit/Sources.txt (289993 => 289994)


--- trunk/Source/WebKit/Sources.txt	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/Sources.txt	2022-02-17 03:46:45 UTC (rev 289994)
@@ -810,6 +810,7 @@
 WebProcess/WebCoreSupport/RemoteWebLockRegistry.cpp
 WebProcess/WebCoreSupport/SessionStateConversion.cpp
 WebProcess/WebCoreSupport/ShareableBitmapUtilities.cpp
+WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp
 WebProcess/WebCoreSupport/WebBroadcastChannelRegistry.cpp
 WebProcess/WebCoreSupport/WebChromeClient.cpp
 WebProcess/WebCoreSupport/WebColorChooser.cpp

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (289993 => 289994)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2022-02-17 03:46:45 UTC (rev 289994)
@@ -85,6 +85,12 @@
 #import <UIKit/UIImage.h>
 #endif
 
+#if PLATFORM(IOS_FAMILY)
+#import <WebCore/RenderThemeIOS.h>
+#else
+#import <WebCore/RenderThemeMac.h>
+#endif
+
 #if PLATFORM(IOS)
 #import <pal/spi/cocoa/WebFilterEvaluatorSPI.h>
 
@@ -289,6 +295,43 @@
     toAttachment->setFileWrapper(fromAttachment->fileWrapper());
 }
 
+static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::FloatSize& fittingSize)
+{
+    FloatSize originalThumbnailSize([image size]);
+    auto resultRect = roundedIntRect(largestRectWithAspectRatioInsideRect(originalThumbnailSize.aspectRatio(), { { }, fittingSize }));
+    resultRect.setLocation({ });
+
+    WebKit::ShareableBitmap::Configuration bitmapConfiguration;
+    auto bitmap = WebKit::ShareableBitmap::createShareable(resultRect.size(), bitmapConfiguration);
+    if (!bitmap)
+        return nullptr;
+
+    auto graphicsContext = bitmap->createGraphicsContext();
+    if (!graphicsContext)
+        return nullptr;
+
+    LocalCurrentGraphicsContext savedContext(*graphicsContext);
+#if PLATFORM(IOS_FAMILY)
+    [image drawInRect:resultRect];
+#elif USE(APPKIT)
+    [image drawInRect:resultRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
+#endif
+
+    return bitmap;
+}
+
+RefPtr<WebKit::ShareableBitmap> WebPageProxy::iconForAttachment(const String& fileName, const String& contentType, const String& title, FloatSize& size)
+{
+#if PLATFORM(IOS_FAMILY)
+    auto imageAndSize = RenderThemeIOS::iconForAttachment(fileName, contentType, title);
+    auto image = imageAndSize.icon;
+    size = imageAndSize.size;
+#else
+    auto image = RenderThemeMac::iconForAttachment(fileName, contentType, title);
+#endif
+    return convertPlatformImageToBitmap(image.get(), size);
+}
+
 #endif // ENABLE(ATTACHMENT_ELEMENT)
     
 void WebPageProxy::performDictionaryLookupAtLocation(const WebCore::FloatPoint& point)
@@ -524,31 +567,6 @@
 
 #if HAVE(QUICKLOOK_THUMBNAILING)
 
-static RefPtr<WebKit::ShareableBitmap> convertPlatformImageToBitmap(CocoaImage *image, const WebCore::IntSize& fittingSize)
-{
-    FloatSize originalThumbnailSize([image size]);
-    auto resultRect = roundedIntRect(largestRectWithAspectRatioInsideRect(originalThumbnailSize.aspectRatio(), { { }, fittingSize }));
-    resultRect.setLocation({ });
-
-    WebKit::ShareableBitmap::Configuration bitmapConfiguration;
-    auto bitmap = WebKit::ShareableBitmap::createShareable(resultRect.size(), bitmapConfiguration);
-    if (!bitmap)
-        return nullptr;
-
-    auto graphicsContext = bitmap->createGraphicsContext();
-    if (!graphicsContext)
-        return nullptr;
-
-    LocalCurrentGraphicsContext savedContext(*graphicsContext);
-#if PLATFORM(IOS_FAMILY)
-    [image drawInRect:resultRect];
-#elif USE(APPKIT)
-    [image drawInRect:resultRect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:nil];
-#endif
-
-    return bitmap;
-}
-
 void WebPageProxy::requestThumbnailWithOperation(WKQLThumbnailLoadOperation *operation)
 {
     [operation setCompletionBlock:^{
@@ -557,7 +575,7 @@
             auto convertedImage = convertPlatformImageToBitmap([operation thumbnail], WebCore::IntSize(400, 400));
             if (!convertedImage)
                 return;
-            this->updateAttachmentIcon(identifier, convertedImage);
+            this->updateAttachmentThumbnail(identifier, convertedImage);
         });
     }];
         

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (289993 => 289994)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -10230,6 +10230,17 @@
     pageClient().writePromisedAttachmentToPasteboard(WTFMove(info));
 }
 
+void WebPageProxy::requestAttachmentIcon(const String& identifier, const String& contentType, const String& fileName, const String& title, const FloatSize& requestedSize)
+{
+    FloatSize size = requestedSize;
+    ShareableBitmap::Handle handle;
+#if PLATFORM(COCOA)
+    if (auto icon = iconForAttachment(fileName, contentType, title, size))
+        icon->createHandle(handle);
+#endif
+    send(Messages::WebPage::UpdateAttachmentIcon(identifier, handle, size));
+}
+
 RefPtr<API::Attachment> WebPageProxy::attachmentForIdentifier(const String& identifier) const
 {
     if (identifier.isEmpty())
@@ -10251,7 +10262,7 @@
 }
 
 #if HAVE(QUICKLOOK_THUMBNAILING)
-void WebPageProxy::updateAttachmentIcon(const String& identifier, const RefPtr<ShareableBitmap>& bitmap)
+void WebPageProxy::updateAttachmentThumbnail(const String& identifier, const RefPtr<ShareableBitmap>& bitmap)
 {
     if (!hasRunningProcess())
         return;
@@ -10260,7 +10271,7 @@
     if (bitmap)
         bitmap->createHandle(handle);
 
-    send(Messages::WebPage::UpdateAttachmentIcon(identifier, handle));
+    send(Messages::WebPage::UpdateAttachmentThumbnail(identifier, handle));
 }
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (289993 => 289994)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1755,7 +1755,7 @@
     void registerAttachmentIdentifier(const String&);
     void didInvalidateDataForAttachment(API::Attachment&);
 #if HAVE(QUICKLOOK_THUMBNAILING)
-    void updateAttachmentIcon(const String&, const RefPtr<ShareableBitmap>&);
+    void updateAttachmentThumbnail(const String&, const RefPtr<ShareableBitmap>&);
     void requestThumbnailWithPath(const String&, const String&);
     void requestThumbnailWithFileWrapper(NSFileWrapper *, const String&);
     void requestThumbnailWithOperation(WKQLThumbnailLoadOperation *);
@@ -2536,6 +2536,10 @@
     void invalidateAllAttachments();
 
     void writePromisedAttachmentToPasteboard(WebCore::PromisedAttachmentInfo&&);
+
+    void requestAttachmentIcon(const String& identifier, const String& type, const String& path, const String& title, const WebCore::FloatSize&);
+
+    RefPtr<WebKit::ShareableBitmap> iconForAttachment(const String& fileName, const String& contentType, const String& title, WebCore::FloatSize&);
 #endif
 
     void reportPageLoadResult(const WebCore::ResourceError& = { });

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (289993 => 289994)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2022-02-17 03:46:45 UTC (rev 289994)
@@ -526,6 +526,7 @@
     DidRemoveAttachmentWithIdentifier(String identifier)
     SerializedAttachmentDataForIdentifiers(Vector<String> identifiers) -> (Vector<WebCore::SerializedAttachmentData> seralizedData) Synchronous
     WritePromisedAttachmentToPasteboard(struct WebCore::PromisedAttachmentInfo info)
+    RequestAttachmentIcon(String identifier, String contentType, String path, String title, WebCore::FloatSize size)
 #endif
 
 #if ENABLE(APP_HIGHLIGHTS)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (289993 => 289994)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-02-17 03:46:45 UTC (rev 289994)
@@ -6449,6 +6449,8 @@
 		E313664D265EE5AF0051084F /* com.apple.WebKit.WebContent.sb.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = com.apple.WebKit.WebContent.sb.in; sourceTree = "<group>"; };
 		E3439B632345463A0011DE0B /* NetworkProcessConnectionInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NetworkProcessConnectionInfo.h; path = Network/NetworkProcessConnectionInfo.h; sourceTree = "<group>"; };
 		E3612FF026F90862007B1175 /* Sandbox */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Sandbox; sourceTree = "<group>"; };
+		E36D701A27B709ED006531B7 /* WebAttachmentElementClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAttachmentElementClient.h; sourceTree = "<group>"; };
+		E36D701D27B718EF006531B7 /* WebAttachmentElementClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebAttachmentElementClient.cpp; sourceTree = "<group>"; };
 		E3866AE42397400400F88FE9 /* WebDeviceOrientationUpdateProviderProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebDeviceOrientationUpdateProviderProxy.mm; path = ios/WebDeviceOrientationUpdateProviderProxy.mm; sourceTree = "<group>"; };
 		E3866AE62397405300F88FE9 /* WebDeviceOrientationUpdateProviderProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebDeviceOrientationUpdateProviderProxy.h; path = ios/WebDeviceOrientationUpdateProviderProxy.h; sourceTree = "<group>"; };
 		E3866AED2398471A00F88FE9 /* WebDeviceOrientationUpdateProviderProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = WebDeviceOrientationUpdateProviderProxy.messages.in; path = ios/WebDeviceOrientationUpdateProviderProxy.messages.in; sourceTree = "<group>"; };
@@ -10900,6 +10902,8 @@
 				F43A9CDE25D72E2D00990E26 /* ShareableBitmapUtilities.cpp */,
 				F43A9CDD25D72E0C00990E26 /* ShareableBitmapUtilities.h */,
 				CEDA12DE152CCAE800D9E08D /* WebAlternativeTextClient.h */,
+				E36D701D27B718EF006531B7 /* WebAttachmentElementClient.cpp */,
+				E36D701A27B709ED006531B7 /* WebAttachmentElementClient.h */,
 				46EE2847269E049B00DD48AB /* WebBroadcastChannelRegistry.cpp */,
 				46EE2848269E049B00DD48AB /* WebBroadcastChannelRegistry.h */,
 				46E9760A2757F6C900ACDD37 /* WebBroadcastChannelRegistry.messages.in */,

Added: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp (0 => 289994)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebAttachmentElementClient.h"
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+#include "WebPage.h"
+
+namespace WebKit {
+
+WebAttachmentElementClient::WebAttachmentElementClient(WebPage& page)
+    : m_page(page)
+{
+}
+
+void WebAttachmentElementClient::requestAttachmentIcon(const String& identifier, const WebCore::FloatSize& size)
+{
+    m_page.requestAttachmentIcon(identifier, size);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)

Added: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h (0 => 289994)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h	                        (rev 0)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebAttachmentElementClient.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(ATTACHMENT_ELEMENT)
+
+#include <WebCore/AttachmentElementClient.h>
+
+namespace WebKit {
+
+class WebPage;
+
+class WebAttachmentElementClient final : public WebCore::AttachmentElementClient {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    explicit WebAttachmentElementClient(WebPage&);
+
+    void requestAttachmentIcon(const String& identifier, const WebCore::FloatSize&) final;
+
+private:
+    WebPage& m_page;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (289993 => 289994)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2022-02-17 03:46:45 UTC (rev 289994)
@@ -72,6 +72,7 @@
 #include "WKRetainPtr.h"
 #include "WKSharedAPICast.h"
 #include "WebAlternativeTextClient.h"
+#include "WebAttachmentElementClient.h"
 #include "WebBackForwardListItem.h"
 #include "WebBackForwardListProxy.h"
 #include "WebBroadcastChannelRegistry.h"
@@ -651,6 +652,10 @@
     if (!parameters.crossOriginAccessControlCheckEnabled)
         CrossOriginAccessControlCheckDisabler::singleton().setCrossOriginAccessControlCheckEnabled(false);
 
+#if ENABLE(ATTACHMENT_ELEMENT)
+    pageConfiguration.attachmentElementClient = makeUnique<WebAttachmentElementClient>(*this);
+#endif
+
 #if PLATFORM(COCOA)
     // FIXME(207716): The following should be removed when the GPU process is complete.
     static bool hasConsumedMediaExtensionHandles = false;
@@ -7352,7 +7357,7 @@
     callback();
 }
 
-void WebPage::updateAttachmentIcon(const String& identifier, const ShareableBitmap::Handle& qlThumbnailHandle)
+void WebPage::updateAttachmentThumbnail(const String& identifier, const ShareableBitmap::Handle& qlThumbnailHandle)
 {
     if (auto attachment = attachmentElementWithIdentifier(identifier)) {
         if (RefPtr<ShareableBitmap> thumbnail = !qlThumbnailHandle.isNull() ? ShareableBitmap::create(qlThumbnailHandle) : nullptr)
@@ -7360,6 +7365,24 @@
     }
 }
 
+void WebPage::updateAttachmentIcon(const String& identifier, const ShareableBitmap::Handle& iconHandle, const WebCore::FloatSize& size)
+{
+    if (auto attachment = attachmentElementWithIdentifier(identifier)) {
+        if (auto icon = !iconHandle.isNull() ? ShareableBitmap::create(iconHandle) : nullptr)
+            attachment->updateIcon(icon->createImage(), size);
+    }
+}
+
+void WebPage::requestAttachmentIcon(const String& identifier, const WebCore::FloatSize& size)
+{
+    if (auto attachment = attachmentElementWithIdentifier(identifier)) {
+        String fileName;
+        if (File* file = attachment->file())
+            fileName = file->path();
+        send(Messages::WebPageProxy::RequestAttachmentIcon(identifier, attachment->attachmentType(), fileName, attachment->attachmentTitle(), size));
+    }
+}
+
 RefPtr<HTMLAttachmentElement> WebPage::attachmentElementWithIdentifier(const String& identifier) const
 {
     // FIXME: Handle attachment elements in subframes too as well.

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (289993 => 289994)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-02-17 03:46:45 UTC (rev 289994)
@@ -1319,7 +1319,9 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
     void insertAttachment(const String& identifier, std::optional<uint64_t>&& fileSize, const String& fileName, const String& contentType, CompletionHandler<void()>&&);
     void updateAttachmentAttributes(const String& identifier, std::optional<uint64_t>&& fileSize, const String& contentType, const String& fileName, const IPC::SharedBufferCopy& enclosingImageData, CompletionHandler<void()>&&);
-    void updateAttachmentIcon(const String& identifier, const ShareableBitmap::Handle& qlThumbnailHandle);
+    void updateAttachmentThumbnail(const String& identifier, const ShareableBitmap::Handle& qlThumbnailHandle);
+    void updateAttachmentIcon(const String& identifier, const ShareableBitmap::Handle& icon, const WebCore::FloatSize&);
+    void requestAttachmentIcon(const String& identifier, const WebCore::FloatSize&);
 #endif
 
 #if ENABLE(APPLICATION_MANIFEST)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (289993 => 289994)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-17 03:40:20 UTC (rev 289993)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-02-17 03:46:45 UTC (rev 289994)
@@ -584,7 +584,8 @@
 #if ENABLE(ATTACHMENT_ELEMENT)
     InsertAttachment(String identifier, std::optional<uint64_t> fileSize, String fileName, String contentType) -> () Async
     UpdateAttachmentAttributes(String identifier, std::optional<uint64_t> fileSize, String contentType, String fileName, IPC::SharedBufferCopy enclosingImageData) -> () Async
-    UpdateAttachmentIcon(String identifier, WebKit::ShareableBitmap::Handle qlThumbnailHandle)
+    UpdateAttachmentThumbnail(String identifier, WebKit::ShareableBitmap::Handle qlThumbnailHandle)
+    UpdateAttachmentIcon(String identifier, WebKit::ShareableBitmap::Handle icon, WebCore::FloatSize size)
 #endif
 
 #if ENABLE(APPLICATION_MANIFEST)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to