Title: [233165] trunk/Source/WebKit
Revision
233165
Author
cdu...@apple.com
Date
2018-06-25 12:54:21 -0700 (Mon, 25 Jun 2018)

Log Message

Make sure API::IconLoadingClient::getLoadDecisionForIcon()'s completion handler gets called
https://bugs.webkit.org/show_bug.cgi?id=187007
<rdar://problem/41293989>

Reviewed by Brady Eidson.

Make sure API::IconLoadingClient::getLoadDecisionForIcon()'s completion handler gets called by
switching its type to WTF::CompletionHandler instead of WTF::Function. This also has the benefit
of destroying our captured objects when the completion handler gets called by the client on the
main thread instead of whatever thread the ObjC block gets released on.

* UIProcess/API/APIIconLoadingClient.h:
(API::IconLoadingClient::getLoadDecisionForIcon):
* UIProcess/API/glib/WebKitIconLoadingClient.cpp:
* UIProcess/API/mac/WKView.mm:
(-[WKView maybeInstallIconLoadingClient]):
* UIProcess/Cocoa/IconLoadingDelegate.h:
* UIProcess/Cocoa/IconLoadingDelegate.mm:
(WebKit::IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (233164 => 233165)


--- trunk/Source/WebKit/ChangeLog	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/ChangeLog	2018-06-25 19:54:21 UTC (rev 233165)
@@ -1,3 +1,25 @@
+2018-06-25  Chris Dumez  <cdu...@apple.com>
+
+        Make sure API::IconLoadingClient::getLoadDecisionForIcon()'s completion handler gets called
+        https://bugs.webkit.org/show_bug.cgi?id=187007
+        <rdar://problem/41293989>
+
+        Reviewed by Brady Eidson.
+
+        Make sure API::IconLoadingClient::getLoadDecisionForIcon()'s completion handler gets called by
+        switching its type to WTF::CompletionHandler instead of WTF::Function. This also has the benefit
+        of destroying our captured objects when the completion handler gets called by the client on the
+        main thread instead of whatever thread the ObjC block gets released on.
+
+        * UIProcess/API/APIIconLoadingClient.h:
+        (API::IconLoadingClient::getLoadDecisionForIcon):
+        * UIProcess/API/glib/WebKitIconLoadingClient.cpp:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView maybeInstallIconLoadingClient]):
+        * UIProcess/Cocoa/IconLoadingDelegate.h:
+        * UIProcess/Cocoa/IconLoadingDelegate.mm:
+        (WebKit::IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon):
+
 2018-06-25  Youenn Fablet  <you...@apple.com>
 
         Add API to control mock media devices

Modified: trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h (233164 => 233165)


--- trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/UIProcess/API/APIIconLoadingClient.h	2018-06-25 19:54:21 UTC (rev 233165)
@@ -27,6 +27,7 @@
 
 #include "GenericCallback.h"
 #include <WebCore/LinkIcon.h>
+#include <wtf/CompletionHandler.h>
 #include <wtf/Function.h>
 
 namespace IPC {
@@ -39,7 +40,8 @@
 public:
     virtual ~IconLoadingClient() { }
 
-    virtual void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::Function<void (WTF::Function<void (API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) {
+    virtual void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler)
+    {
         completionHandler(nullptr);
     }
 };

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


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitIconLoadingClient.cpp	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitIconLoadingClient.cpp	2018-06-25 19:54:21 UTC (rev 233165)
@@ -33,7 +33,7 @@
     }
 
 private:
-    void getLoadDecisionForIcon(const WebCore::LinkIcon& icon, Function<void (Function<void (API::Data*, CallbackBase::Error)>&&)>&& completionHandler) override
+    void getLoadDecisionForIcon(const WebCore::LinkIcon& icon, CompletionHandler<void(Function<void(API::Data*, CallbackBase::Error)>&&)>&& completionHandler) override
     {
         // WebCore can send non HTTP icons.
         if (!icon.url.protocolIsInHTTPFamily()) {

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


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2018-06-25 19:54:21 UTC (rev 233165)
@@ -883,10 +883,12 @@
     private:
         typedef void (^IconLoadCompletionHandler)(NSData*);
 
-        void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::Function<void (WTF::Function<void (API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) override {
+        void getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) override
+        {
             RetainPtr<_WKLinkIconParameters> parameters = adoptNS([[_WKLinkIconParameters alloc] _initWithLinkIcon:linkIcon]);
 
             [m_wkView performSelector:delegateSelector() withObject:parameters.get() withObject:BlockPtr<void (IconLoadCompletionHandler)>::fromCallable([completionHandler = WTFMove(completionHandler)](IconLoadCompletionHandler loadCompletionHandler) {
+                ASSERT(RunLoop::isMain());
                 if (loadCompletionHandler) {
                     completionHandler([loadCompletionHandler = BlockPtr<void (NSData *)>(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
                         if (error != CallbackBase::Error::None || !data)

Modified: trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h (233164 => 233165)


--- trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.h	2018-06-25 19:54:21 UTC (rev 233165)
@@ -55,7 +55,7 @@
         ~IconLoadingClient();
 
     private:
-        void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::Function<void (WTF::Function<void (API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler) override;
+        void getLoadDecisionForIcon(const WebCore::LinkIcon&, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&&) override;
 
         IconLoadingDelegate& m_iconLoadingDelegate;
     };

Modified: trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm (233164 => 233165)


--- trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm	2018-06-25 19:24:44 UTC (rev 233164)
+++ trunk/Source/WebKit/UIProcess/Cocoa/IconLoadingDelegate.mm	2018-06-25 19:54:21 UTC (rev 233165)
@@ -72,7 +72,7 @@
 
 typedef void (^IconLoadCompletionHandler)(NSData*);
 
-void IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::Function<void (WTF::Function<void (API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler)
+void IconLoadingDelegate::IconLoadingClient::getLoadDecisionForIcon(const WebCore::LinkIcon& linkIcon, WTF::CompletionHandler<void(WTF::Function<void(API::Data*, WebKit::CallbackBase::Error)>&&)>&& completionHandler)
 {
     if (!m_iconLoadingDelegate.m_delegateMethods.webViewShouldLoadIconWithParametersCompletionHandler) {
         completionHandler(nullptr);
@@ -88,6 +88,7 @@
     RetainPtr<_WKLinkIconParameters> parameters = adoptNS([[_WKLinkIconParameters alloc] _initWithLinkIcon:linkIcon]);
 
     [delegate webView:m_iconLoadingDelegate.m_webView shouldLoadIconWithParameters:parameters.get() completionHandler:BlockPtr<void (IconLoadCompletionHandler loadCompletionHandler)>::fromCallable([completionHandler = WTFMove(completionHandler)] (IconLoadCompletionHandler loadCompletionHandler) {
+        ASSERT(RunLoop::isMain());
         if (loadCompletionHandler) {
             completionHandler([loadCompletionHandler = Block_copy(loadCompletionHandler)](API::Data* data, WebKit::CallbackBase::Error error) {
                 if (error != CallbackBase::Error::None || !data)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to