Title: [271378] trunk/Source
Revision
271378
Author
[email protected]
Date
2021-01-11 13:36:41 -0800 (Mon, 11 Jan 2021)

Log Message

Use sendWithAsyncReply instead of dataCallback for icon loading
https://bugs.webkit.org/show_bug.cgi?id=220381

Patch by Alex Christensen <[email protected]> on 2021-01-11
Reviewed by Youenn Fablet.

Source/WebCore:

Behavior covered by IconLoading API tests.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::stopLoading):
(WebCore::DocumentLoader::didGetLoadDecisionForIcon):
(WebCore::DocumentLoader::finishedLoadingIcon):
(WebCore::DocumentLoader::notifyFinishedLoadingIcon): Deleted.
* loader/DocumentLoader.h:
* loader/FrameLoaderClient.h:

Source/WebKit:

* Scripts/webkit/messages.py:
* Shared/API/APIData.cpp:
(API::Data::create):
* Shared/API/APIData.h:
(API::Data::create):
* UIProcess/API/APIIconLoadingClient.h:
(API::IconLoadingClient::getLoadDecisionForIcon):
* UIProcess/API/mac/WKView.mm:
(-[WKView maybeInstallIconLoadingClient]):
* UIProcess/Cocoa/IconLoadingDelegate.h:
* UIProcess/Cocoa/IconLoadingDelegate.mm:
(WebKit::IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getLoadDecisionForIcon):
(WebKit::WebPageProxy::finishedLoadingIcon): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
(WebKit::WebFrameLoaderClient::finishedLoadingIcon): Deleted.
* WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didGetLoadDecisionForIcon):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebFrameLoaderClient.h:
* WebCoreSupport/WebFrameLoaderClient.mm:
(WebFrameLoaderClient::prepareForDataSourceReplacement):
(WebFrameLoaderClient::getLoadDecisionForIcons):
(WebFrameLoaderClient::finishedLoadingIcon):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271377 => 271378)


--- trunk/Source/WebCore/ChangeLog	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebCore/ChangeLog	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1,3 +1,20 @@
+2021-01-11  Alex Christensen  <[email protected]>
+
+        Use sendWithAsyncReply instead of dataCallback for icon loading
+        https://bugs.webkit.org/show_bug.cgi?id=220381
+
+        Reviewed by Youenn Fablet.
+
+        Behavior covered by IconLoading API tests.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::stopLoading):
+        (WebCore::DocumentLoader::didGetLoadDecisionForIcon):
+        (WebCore::DocumentLoader::finishedLoadingIcon):
+        (WebCore::DocumentLoader::notifyFinishedLoadingIcon): Deleted.
+        * loader/DocumentLoader.h:
+        * loader/FrameLoaderClient.h:
+
 2021-01-11  Rob Buis  <[email protected]>
 
         Take aspect-ratio into account for percentage resolution

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (271377 => 271378)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -323,9 +323,8 @@
             m_frame->loader().stopLoading(UnloadEventPolicy::None);
     }
 
-    for (auto callbackIdentifier : m_iconLoaders.values())
-        notifyFinishedLoadingIcon(callbackIdentifier, nullptr);
-    m_iconLoaders.clear();
+    for (auto& callback : std::exchange(m_iconLoaders, { }).values())
+        callback(nullptr);
     m_iconsPendingLoadDecision.clear();
     
 #if ENABLE(APPLICATION_MANIFEST)
@@ -2174,25 +2173,23 @@
     m_frame->loader().client().getLoadDecisionForIcons(iconDecisions);
 }
 
-void DocumentLoader::didGetLoadDecisionForIcon(bool decision, uint64_t loadIdentifier, uint64_t newCallbackID)
+void DocumentLoader::didGetLoadDecisionForIcon(bool decision, uint64_t loadIdentifier, CompletionHandler<void(SharedBuffer*)>&& completionHandler)
 {
     auto icon = m_iconsPendingLoadDecision.take(loadIdentifier);
 
     // If the decision was not to load or this DocumentLoader is already detached, there is no load to perform.
     if (!decision || !m_frame)
-        return;
+        return completionHandler(nullptr);
 
     // If the LinkIcon we just took is empty, then the DocumentLoader had all of its loaders stopped
     // while this icon load decision was pending.
     // In this case we need to notify the client that the icon finished loading with empty data.
-    if (icon.url.isEmpty()) {
-        notifyFinishedLoadingIcon(newCallbackID, nullptr);
-        return;
-    }
+    if (icon.url.isEmpty())
+        return completionHandler(nullptr);
 
     auto iconLoader = makeUnique<IconLoader>(*this, icon.url);
     auto* rawIconLoader = iconLoader.get();
-    m_iconLoaders.set(WTFMove(iconLoader), newCallbackID);
+    m_iconLoaders.add(WTFMove(iconLoader), WTFMove(completionHandler));
 
     rawIconLoader->startLoading();
 }
@@ -2202,17 +2199,10 @@
     // If the DocumentLoader has detached from its frame, all icon loads should have already been cancelled.
     ASSERT(m_frame);
 
-    auto callbackIdentifier = m_iconLoaders.take(&loader);
-    notifyFinishedLoadingIcon(callbackIdentifier, buffer);
+    if (auto callback = m_iconLoaders.take(&loader))
+        callback(buffer);
 }
 
-void DocumentLoader::notifyFinishedLoadingIcon(uint64_t callbackIdentifier, SharedBuffer* buffer)
-{
-    RELEASE_ASSERT(callbackIdentifier);
-    RELEASE_ASSERT(m_frame);
-    m_frame->loader().client().finishedLoadingIcon(callbackIdentifier, buffer);
-}
-
 void DocumentLoader::dispatchOnloadEvents()
 {
     m_wasOnloadDispatched = true;

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (271377 => 271378)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -387,7 +387,7 @@
     bool isAlwaysOnLoggingAllowed() const;
 
     void startIconLoading();
-    WEBCORE_EXPORT void didGetLoadDecisionForIcon(bool decision, uint64_t loadIdentifier, uint64_t newCallbackID);
+    WEBCORE_EXPORT void didGetLoadDecisionForIcon(bool decision, uint64_t loadIdentifier, CompletionHandler<void(SharedBuffer*)>&&);
     void finishedLoadingIcon(IconLoader&, SharedBuffer*);
 
     const Vector<LinkIcon>& linkIcons() const { return m_linkIcons; }
@@ -503,8 +503,6 @@
     void cancelPolicyCheckIfNeeded();
     void becomeMainResourceClient();
 
-    void notifyFinishedLoadingIcon(uint64_t callbackIdentifier, SharedBuffer*);
-
 #if ENABLE(APPLICATION_MANIFEST)
     void notifyFinishedLoadingApplicationManifest(uint64_t callbackIdentifier, Optional<ApplicationManifest>);
 #endif
@@ -605,7 +603,7 @@
     bool m_waitingForNavigationPolicy { false };
 
     HashMap<uint64_t, LinkIcon> m_iconsPendingLoadDecision;
-    HashMap<std::unique_ptr<IconLoader>, uint64_t> m_iconLoaders;
+    HashMap<std::unique_ptr<IconLoader>, CompletionHandler<void(SharedBuffer*)>> m_iconLoaders;
     Vector<LinkIcon> m_linkIcons;
 
 #if ENABLE(APPLICATION_MANIFEST)

Modified: trunk/Source/WebCore/loader/FrameLoaderClient.h (271377 => 271378)


--- trunk/Source/WebCore/loader/FrameLoaderClient.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebCore/loader/FrameLoaderClient.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -361,7 +361,6 @@
     virtual void didRestoreScrollPosition() { }
 
     virtual void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) { }
-    virtual void finishedLoadingIcon(uint64_t, SharedBuffer*) { }
 
     virtual void didCreateWindow(DOMWindow&) { }
 

Modified: trunk/Source/WebKit/ChangeLog (271377 => 271378)


--- trunk/Source/WebKit/ChangeLog	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/ChangeLog	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1,3 +1,35 @@
+2021-01-11  Alex Christensen  <[email protected]>
+
+        Use sendWithAsyncReply instead of dataCallback for icon loading
+        https://bugs.webkit.org/show_bug.cgi?id=220381
+
+        Reviewed by Youenn Fablet.
+
+        * Scripts/webkit/messages.py:
+        * Shared/API/APIData.cpp:
+        (API::Data::create):
+        * Shared/API/APIData.h:
+        (API::Data::create):
+        * UIProcess/API/APIIconLoadingClient.h:
+        (API::IconLoadingClient::getLoadDecisionForIcon):
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView maybeInstallIconLoadingClient]):
+        * UIProcess/Cocoa/IconLoadingDelegate.h:
+        * UIProcess/Cocoa/IconLoadingDelegate.mm:
+        (WebKit::IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::getLoadDecisionForIcon):
+        (WebKit::WebPageProxy::finishedLoadingIcon): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp:
+        (WebKit::WebFrameLoaderClient::finishedLoadingIcon): Deleted.
+        * WebProcess/WebCoreSupport/WebFrameLoaderClient.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::didGetLoadDecisionForIcon):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2021-01-11  BJ Burg  <[email protected]>
 
         Web Inspector: add nullptr check for WebInspectorProxy::m_extensionsController

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (271377 => 271378)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2021-01-11 21:36:41 UTC (rev 271378)
@@ -139,6 +139,12 @@
     return 'const %s&' % type
 
 
+def reply_type(type):
+    if type == 'IPC::SharedBufferDataReference':
+        return 'IPC::DataReference'
+    return type
+
+
 def reply_parameter_type(type):
     return '%s&' % type
 
@@ -151,12 +157,12 @@
     return 'std::tuple<%s>' % ', '.join(function_parameter_type(parameter.type, parameter.kind) for parameter in message.parameters)
 
 
-def reply_type(message):
+def reply_tuple(message):
     return 'std::tuple<%s>' % (', '.join(reply_parameter_type(parameter.type) for parameter in message.reply_parameters))
 
 
 def reply_arguments_type(message):
-    return 'std::tuple<%s>' % (', '.join(parameter.type for parameter in message.reply_parameters))
+    return 'std::tuple<%s>' % (', '.join(reply_type(parameter.type) for parameter in message.reply_parameters))
 
 
 def message_to_reply_forward_declaration(message):
@@ -193,7 +199,7 @@
         send_parameters = [(function_parameter_type(x.type, x.kind), x.name) for x in message.reply_parameters]
         completion_handler_parameters = '%s' % ', '.join([' '.join(x) for x in send_parameters])
         if message.has_attribute(ASYNC_ATTRIBUTE):
-            move_parameters = ', '.join([move_type(x.type) for x in message.reply_parameters])
+            move_parameters = ', '.join([move_type(reply_type(x.type)) for x in message.reply_parameters])
             result.append('    static void callReply(IPC::Decoder&, CompletionHandler<void(%s)>&&);\n' % move_parameters)
             result.append('    static void cancelReply(CompletionHandler<void(%s)>&&);\n' % move_parameters)
             result.append('    static IPC::MessageName asyncMessageReplyName() { return IPC::MessageName::%s_%sReply; }\n' % (receiver.name, message.name))
@@ -205,7 +211,7 @@
             if len(send_parameters):
                 result.append(', %s' % completion_handler_parameters)
             result.append(');\n')
-        result.append('    using Reply = %s;\n' % reply_type(message))
+        result.append('    using Reply = %s;\n' % reply_tuple(message))
         result.append('    using ReplyArguments = %s;\n' % reply_arguments_type(message))
 
     if len(function_parameters):
@@ -865,10 +871,10 @@
                 result.append('#if %s\n\n' % message.condition)
 
             if message.has_attribute(ASYNC_ATTRIBUTE):
-                move_parameters = message.name, ', '.join([move_type(x.type) for x in message.reply_parameters])
+                move_parameters = message.name, ', '.join([move_type(reply_type(x.type)) for x in message.reply_parameters])
                 result.append('void %s::callReply(IPC::Decoder& decoder, CompletionHandler<void(%s)>&& completionHandler)\n{\n' % move_parameters)
                 for x in message.reply_parameters:
-                    result.append('    Optional<%s> %s;\n' % (x.type, x.name))
+                    result.append('    Optional<%s> %s;\n' % (reply_type(x.type), x.name))
                     result.append('    decoder >> %s;\n' % x.name)
                     result.append('    if (!%s) {\n        ASSERT_NOT_REACHED();\n        cancelReply(WTFMove(completionHandler));\n        return;\n    }\n' % x.name)
                 result.append('    completionHandler(')
@@ -876,7 +882,7 @@
                     result.append('WTFMove(*%s)' % ('), WTFMove(*'.join(x.name for x in message.reply_parameters)))
                 result.append(');\n}\n\n')
                 result.append('void %s::cancelReply(CompletionHandler<void(%s)>&& completionHandler)\n{\n    completionHandler(' % move_parameters)
-                result.append(', '.join(['IPC::AsyncReplyError<' + x.type + '>::create()' for x in message.reply_parameters]))
+                result.append(', '.join(['IPC::AsyncReplyError<' + reply_type(x.type) + '>::create()' for x in message.reply_parameters]))
                 result.append(');\n}\n\n')
 
             result.append('void %s::send(std::unique_ptr<IPC::Encoder>&& encoder, IPC::Connection& connection' % (message.name))

Modified: trunk/Source/WebKit/Shared/API/APIData.cpp (271377 => 271378)


--- trunk/Source/WebKit/Shared/API/APIData.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/Shared/API/APIData.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -27,11 +27,19 @@
 #include "APIData.h"
 
 #include "ArgumentCoders.h"
+#include "DataReference.h"
 #include "Decoder.h"
 #include "Encoder.h"
 
 namespace API {
 
+RefPtr<Data> Data::create(const IPC::DataReference& data)
+{
+    if (data.isEmpty())
+        return nullptr;
+    return create(data.data(), data.size());
+}
+
 void Data::encode(IPC::Encoder& encoder) const
 {
     encoder << dataReference();

Modified: trunk/Source/WebKit/Shared/API/APIData.h (271377 => 271378)


--- trunk/Source/WebKit/Shared/API/APIData.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/Shared/API/APIData.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -44,7 +44,7 @@
 
 class Data : public ObjectImpl<API::Object::Type::Data> {
 public:
-    typedef void (*FreeDataFunction)(unsigned char*, const void* context);
+    using FreeDataFunction = void (*)(unsigned char*, const void* context);
 
     static Ref<Data> createWithoutCopying(const unsigned char* bytes, size_t size, FreeDataFunction freeDataFunction, const void* context)
     {
@@ -53,7 +53,7 @@
 
     static Ref<Data> create(const unsigned char* bytes, size_t size)
     {
-        unsigned char *copiedBytes = 0;
+        unsigned char *copiedBytes = nullptr;
 
         if (size) {
             copiedBytes = static_cast<unsigned char*>(fastMalloc(size));
@@ -60,7 +60,7 @@
             memcpy(copiedBytes, bytes, size);
         }
 
-        return createWithoutCopying(copiedBytes, size, fastFreeBytes, 0);
+        return createWithoutCopying(copiedBytes, size, fastFreeBytes, nullptr);
     }
     
     static Ref<Data> create(const Vector<unsigned char>& buffer)
@@ -68,6 +68,8 @@
         return create(buffer.data(), buffer.size());
     }
 
+    static RefPtr<Data> create(const IPC::DataReference&);
+    
 #if PLATFORM(COCOA)
     static Ref<Data> createWithoutCopying(RetainPtr<NSData>);
 #endif
@@ -100,11 +102,11 @@
             fastFree(static_cast<void*>(bytes));
     }
 
-    const unsigned char* m_bytes;
-    size_t m_size;
+    const unsigned char* m_bytes { nullptr };
+    size_t m_size { 0 };
 
-    FreeDataFunction m_freeDataFunction;
-    const void* m_context;
+    FreeDataFunction m_freeDataFunction { nullptr };
+    const void* m_context { nullptr };
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -37,7 +37,7 @@
 public:
     virtual ~IconLoadingClient() { }
 
-    virtual void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler)
+    virtual void getLoadDecisionForIcon(const WebCore::LinkIcon&, CompletionHandler<void(CompletionHandler<void(API::Data*)>&&)>&& completionHandler)
     {
         completionHandler(nullptr);
     }

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitIconLoadingClient.cpp (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitIconLoadingClient.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitIconLoadingClient.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -34,7 +34,7 @@
     }
 
 private:
-    void getLoadDecisionForIcon(const WebCore::LinkIcon& icon, CompletionHandler<void(Function<void(API::Data*, CallbackBase::Error)>&&)>&& completionHandler) override
+    void getLoadDecisionForIcon(const WebCore::LinkIcon& icon, CompletionHandler<void(CompletionHandler<void(API::Data*)>&&)>&& completionHandler) override
     {
         // WebCore can send non HTTP icons.
         if (!icon.url.protocolIsInHTTPFamily()) {
@@ -49,8 +49,8 @@
                 return;
             }
 
-            completionHandler([protectedWebView = WTFMove(protectedWebView), icon = WTFMove(icon)] (API::Data* iconData, CallbackBase::Error error) {
-                if (error != CallbackBase::Error::None || !iconData)
+            completionHandler([protectedWebView = WTFMove(protectedWebView), icon = WTFMove(icon)] (API::Data* iconData) {
+                if (!iconData)
                     return;
                 webkitWebViewSetIcon(protectedWebView.get(), icon, *iconData);
             });

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKView.mm (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-01-11 21:36:41 UTC (rev 271378)
@@ -926,7 +926,7 @@
     private:
         typedef void (^IconLoadCompletionHandler)(NSData*);
 
-        void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) override
+        void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, CompletionHandler<void(CompletionHandler<void(API::Data*)>&&)>&& completionHandler) override
         {
             RetainPtr<_WKLinkIconParameters> parameters = adoptNS([[_WKLinkIconParameters alloc] _initWithLinkIcon:linkIcon]);
 
@@ -933,11 +933,8 @@
             [m_wkView _shouldLoadIconWithParameters:parameters.get() completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler)](IconLoadCompletionHandler loadCompletionHandler) mutable {
                 ASSERT(RunLoop::isMain());
                 if (loadCompletionHandler) {
-                    completionHandler([loadCompletionHandler = BlockPtr<void (NSData *)>(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
-                        if (error != WebKit::CallbackBase::Error::None || !data)
-                            loadCompletionHandler(nil);
-                        else
-                            loadCompletionHandler(wrapper(*data));
+                    completionHandler([loadCompletionHandler = makeBlockPtr(loadCompletionHandler)](API::Data* data) {
+                        loadCompletionHandler(wrapper(data));
                     });
                 } else
                     completionHandler(nullptr);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -55,7 +55,7 @@
         ~IconLoadingClient();
 
     private:
-        void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&&) override;
+        void getLoadDecisionForIcon(const WebCore::LinkIcon&, CompletionHandler<void(CompletionHandler<void(API::Data*)>&&)>&&) override;
 
         IconLoadingDelegate& m_iconLoadingDelegate;
     };

Modified: trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm	2021-01-11 21:36:41 UTC (rev 271378)
@@ -70,7 +70,7 @@
 
 typedef void (^IconLoadCompletionHandler)(NSData*);
 
-void IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler)
+void IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, CompletionHandler<void(CompletionHandler<void(API::Data*)>&&)>&& completionHandler)
 {
     if (!m_iconLoadingDelegate.m_delegateMethods.webViewShouldLoadIconWithParametersCompletionHandler) {
         completionHandler(nullptr);
@@ -88,11 +88,8 @@
     [delegate webView:m_iconLoadingDelegate.m_webView shouldLoadIconWithParameters:parameters.get() completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler)] (IconLoadCompletionHandler loadCompletionHandler) mutable {
         ASSERT(RunLoop::isMain());
         if (loadCompletionHandler) {
-            completionHandler([loadCompletionHandler = makeBlockPtr(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
-                if (error != CallbackBase::Error::None || !data)
-                    loadCompletionHandler(nil);
-                else
-                    loadCompletionHandler(wrapper(*data));
+            completionHandler([loadCompletionHandler = makeBlockPtr(loadCompletionHandler)](API::Data* data) {
+                loadCompletionHandler(wrapper(data));
             });
         } else
             completionHandler(nullptr);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -9405,25 +9405,21 @@
 
 void WebPageProxy::getLoadDecisionForIcon(const WebCore::LinkIcon& icon, CallbackID loadIdentifier)
 {
-    m_iconLoadingClient->getLoadDecisionForIcon(icon, [this, protectedThis = RefPtr<WebPageProxy>(this), loadIdentifier](WTF::Function<void (API::Data*, CallbackBase::Error)>&& callbackFunction) {
+    m_iconLoadingClient->getLoadDecisionForIcon(icon, [this, protectedThis = makeRef(*this), loadIdentifier] (CompletionHandler<void(API::Data*)>&& callback) {
         if (!hasRunningProcess()) {
-            if (callbackFunction)
-                callbackFunction(nullptr, CallbackBase::Error::Unknown);
+            if (callback)
+                callback(nullptr);
             return;
         }
 
-        bool decision = (bool)callbackFunction;
-        auto newCallbackIdentifier = decision ? OptionalCallbackID(m_callbacks.put(WTFMove(callbackFunction), m_process->throttler().backgroundActivity("WebPageProxy::getLoadDecisionForIcon"_s))) : OptionalCallbackID();
-
-        send(Messages::WebPage::DidGetLoadDecisionForIcon(decision, loadIdentifier, newCallbackIdentifier));
+        if (!callback)
+            return sendWithAsyncReply(Messages::WebPage::DidGetLoadDecisionForIcon(false, loadIdentifier), [](auto) { });
+        sendWithAsyncReply(Messages::WebPage::DidGetLoadDecisionForIcon(true, loadIdentifier), [callback = WTFMove(callback)](const IPC::DataReference& iconData) mutable {
+            callback(API::Data::create(iconData).get());
+        });
     });
 }
 
-void WebPageProxy::finishedLoadingIcon(CallbackID callbackID, const IPC::DataReference& data)
-{
-    dataCallback(data, callbackID);
-}
-
 WebCore::UserInterfaceLayoutDirection WebPageProxy::userInterfaceLayoutDirection()
 {
     return pageClient().userInterfaceLayoutDirection();

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1548,7 +1548,6 @@
     void didRestoreScrollPosition();
 
     void getLoadDecisionForIcon(const WebCore::LinkIcon&, WebKit::CallbackID);
-    void finishedLoadingIcon(WebKit::CallbackID, const IPC::DataReference&);
 
     void setFocus(bool focused);
     void setWindowFrame(const WebCore::FloatRect&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (271377 => 271378)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-01-11 21:36:41 UTC (rev 271378)
@@ -508,7 +508,6 @@
     DidRestoreScrollPosition()
 
     GetLoadDecisionForIcon(struct WebCore::LinkIcon icon, WebKit::CallbackID callbackID)
-    FinishedLoadingIcon(WebKit::CallbackID callbackID, IPC::SharedBufferDataReference data);
 
 #if PLATFORM(MAC)
     DidHandleAcceptedCandidate()

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp (271377 => 271378)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1909,17 +1909,6 @@
         webPage->send(Messages::WebPageProxy::GetLoadDecisionForIcon(icon.first, CallbackID::fromInteger(icon.second)));
 }
 
-void WebFrameLoaderClient::finishedLoadingIcon(uint64_t callbackIdentifier, SharedBuffer* data)
-{
-    auto callbackID = CallbackID::fromInteger(callbackIdentifier);
-    if (WebPage* webPage { m_frame->page() }) {
-        if (data)
-            webPage->send(Messages::WebPageProxy::FinishedLoadingIcon(callbackID, { *data }));
-        else
-            webPage->send(Messages::WebPageProxy::FinishedLoadingIcon(callbackID, { }));
-    }
-}
-
 void WebFrameLoaderClient::didCreateWindow(DOMWindow& window)
 {
     auto* webPage = m_frame->page();

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h (271377 => 271378)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFrameLoaderClient.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -267,7 +267,6 @@
     void didRestoreScrollPosition() final;
 
     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
-    void finishedLoadingIcon(uint64_t callbackIdentifier, WebCore::SharedBuffer*) final;
 
     void didCreateWindow(WebCore::DOMWindow&) final;
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (271377 => 271378)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-11 21:36:41 UTC (rev 271378)
@@ -6548,10 +6548,15 @@
 }
 #endif
 
-void WebPage::didGetLoadDecisionForIcon(bool decision, CallbackID loadIdentifier, OptionalCallbackID newCallbackID)
+void WebPage::didGetLoadDecisionForIcon(bool decision, CallbackID loadIdentifier, CompletionHandler<void(const IPC::SharedBufferDataReference&)>&& completionHandler)
 {
-    if (auto* documentLoader = corePage()->mainFrame().loader().documentLoader())
-        documentLoader->didGetLoadDecisionForIcon(decision, loadIdentifier.toInteger(), newCallbackID.toInteger());
+    auto* documentLoader = corePage()->mainFrame().loader().documentLoader();
+    if (!documentLoader)
+        return completionHandler({ });
+
+    documentLoader->didGetLoadDecisionForIcon(decision, loadIdentifier.toInteger(), [completionHandler = WTFMove(completionHandler)] (WebCore::SharedBuffer* iconData) mutable {
+        completionHandler({ iconData });
+    });
 }
 
 void WebPage::setUseIconLoadingClient(bool useIconLoadingClient)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (271377 => 271378)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1199,7 +1199,7 @@
     void didLosePointerLock();
 #endif
 
-    void didGetLoadDecisionForIcon(bool decision, CallbackID loadIdentifier, OptionalCallbackID);
+    void didGetLoadDecisionForIcon(bool decision, CallbackID, CompletionHandler<void(const IPC::SharedBufferDataReference&)>&&);
     void setUseIconLoadingClient(bool);
 
 #if PLATFORM(IOS_FAMILY) && ENABLE(DRAG_SUPPORT)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (271377 => 271378)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-01-11 21:36:41 UTC (rev 271378)
@@ -540,7 +540,7 @@
 
     SetUserInterfaceLayoutDirection(uint32_t direction)
 
-    DidGetLoadDecisionForIcon(bool decision, WebKit::CallbackID loadIdentifier, WebKit::OptionalCallbackID newCallbackID)
+    DidGetLoadDecisionForIcon(bool decision, WebKit::CallbackID loadIdentifier) -> (IPC::SharedBufferDataReference iconData) Async
     SetUseIconLoadingClient(bool useIconLoadingClient)
 
 #if ENABLE(GAMEPAD)

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (271377 => 271378)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1,3 +1,16 @@
+2021-01-11  Alex Christensen  <[email protected]>
+
+        Use sendWithAsyncReply instead of dataCallback for icon loading
+        https://bugs.webkit.org/show_bug.cgi?id=220381
+
+        Reviewed by Youenn Fablet.
+
+        * WebCoreSupport/WebFrameLoaderClient.h:
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::prepareForDataSourceReplacement):
+        (WebFrameLoaderClient::getLoadDecisionForIcons):
+        (WebFrameLoaderClient::finishedLoadingIcon):
+
 2021-01-07  Alexey Shvayka  <[email protected]>
 
         [JSC] Simplify get*PropertyNames() methods and EnumerationMode

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h (271377 => 271378)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.h	2021-01-11 21:36:41 UTC (rev 271378)
@@ -32,6 +32,7 @@
 #import <wtf/HashMap.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/WeakObjCPtr.h>
+#import <wtf/WeakPtr.h>
 
 @class WebDownload;
 @class WebFrame;
@@ -52,7 +53,7 @@
 class ResourceRequest;
 }
 
-class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
+class WebFrameLoaderClient : public WebCore::FrameLoaderClient, public CanMakeWeakPtr<WebFrameLoaderClient> {
 public:
     explicit WebFrameLoaderClient(WebFrame* = nullptr);
     ~WebFrameLoaderClient();
@@ -246,9 +247,11 @@
     void sendH2Ping(const URL&, CompletionHandler<void(Expected<Seconds, WebCore::ResourceError>&&)>&&) final;
 
     void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) final;
-    void finishedLoadingIcon(uint64_t, WebCore::SharedBuffer*) final;
+    void finishedLoadingIcon(WebCore::SharedBuffer*);
 
-    uint64_t m_activeIconLoadCallbackID { 0 };
+#if !PLATFORM(IOS_FAMILY)
+    bool m_loadingIcon { false };
+#endif
 
     RetainPtr<WebFrame> m_webFrame;
 

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm (271377 => 271378)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2021-01-11 21:33:56 UTC (rev 271377)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebFrameLoaderClient.mm	2021-01-11 21:36:41 UTC (rev 271378)
@@ -1301,8 +1301,6 @@
 
 void WebFrameLoaderClient::prepareForDataSourceReplacement()
 {
-    m_activeIconLoadCallbackID = 0;
-
     if (![m_webFrame.get() _dataSource]) {
         ASSERT(!core(m_webFrame.get())->tree().childCount());
         return;
@@ -2198,7 +2196,7 @@
 #if PLATFORM(MAC)
     if (!WebKitLinkedOnOrAfter(WEBKIT_FIRST_VERSION_WITH_DEFAULT_ICON_LOADING)) {
         for (auto& icon : icons)
-            documentLoader->didGetLoadDecisionForIcon(false, icon.second, 0);
+            documentLoader->didGetLoadDecisionForIcon(false, icon.second, [](auto) { });
 
         return;
     }
@@ -2210,29 +2208,32 @@
 
     if (disallowedDueToImageLoadSettings || !frame->isMainFrame() || !documentLoader->url().protocolIsInHTTPFamily() || ![WebView _isIconLoadingEnabled]) {
         for (auto& icon : icons)
-            documentLoader->didGetLoadDecisionForIcon(false, icon.second, 0);
+            documentLoader->didGetLoadDecisionForIcon(false, icon.second, [](auto) { });
 
         return;
     }
 
-    ASSERT(!m_activeIconLoadCallbackID);
-
 #if !PLATFORM(IOS_FAMILY)
+    ASSERT(!m_loadingIcon);
     // WebKit 1, which only supports one icon per page URL, traditionally has preferred the last icon in case of multiple icons listed.
     // To preserve that behavior we walk the list backwards.
     for (auto icon = icons.rbegin(); icon != icons.rend(); ++icon) {
-        if (icon->first.type != WebCore::LinkIconType::Favicon || m_activeIconLoadCallbackID) {
-            documentLoader->didGetLoadDecisionForIcon(false, icon->second, 0);
+        if (icon->first.type != WebCore::LinkIconType::Favicon || m_loadingIcon) {
+            documentLoader->didGetLoadDecisionForIcon(false, icon->second, [](auto) { });
             continue;
         }
 
-        m_activeIconLoadCallbackID = 1;
-        documentLoader->didGetLoadDecisionForIcon(true, icon->second, m_activeIconLoadCallbackID);
+        m_loadingIcon = true;
+        documentLoader->didGetLoadDecisionForIcon(true, icon->second, [this, weakThis = makeWeakPtr(*this)] (WebCore::SharedBuffer* buffer) {
+            if (!weakThis)
+                return;
+            finishedLoadingIcon(buffer);
+        });
     }
 #else
     // No WebCore icon loading on iOS
     for (auto& icon : icons)
-        documentLoader->didGetLoadDecisionForIcon(false, icon.second, 0);
+        documentLoader->didGetLoadDecisionForIcon(false, icon.second, [](auto) { });
 #endif
 }
 
@@ -2260,12 +2261,11 @@
 }
 #endif // !PLATFORM(IOS_FAMILY)
 
-void WebFrameLoaderClient::finishedLoadingIcon(uint64_t callbackID, WebCore::SharedBuffer* iconData)
+void WebFrameLoaderClient::finishedLoadingIcon(WebCore::SharedBuffer* iconData)
 {
 #if !PLATFORM(IOS_FAMILY)
-    ASSERT(m_activeIconLoadCallbackID);
-    ASSERT(callbackID = m_activeIconLoadCallbackID);
-    m_activeIconLoadCallbackID = 0;
+    ASSERT(m_loadingIcon);
+    m_loadingIcon = false;
 
     WebView *webView = getWebView(m_webFrame.get());
     if (!webView)
@@ -2279,7 +2279,6 @@
     if (icon)
         [webView _setMainFrameIcon:icon];
 #else
-    UNUSED_PARAM(callbackID);
     UNUSED_PARAM(iconData);
 #endif
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to