Add WKUIDelegatePrivate equivalent of WKPageUIClient's toolbarsAreVisible
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2017 22:25:20 +0000 (22:25 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Sep 2017 22:25:20 +0000 (22:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176246
<rdar://problem/29270035>

Reviewed by Tim Horton.

Source/WebKit:

* UIProcess/API/APIUIClient.h:
(API::UIClient::toolbarsAreVisible):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::toolbarsAreVisible):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getToolbarsAreVisible):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(-[ToolbarDelegate _webView:getToolbarsAreVisibleWithCompletionHandler:]):
(-[ToolbarDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221503 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/APIUIClient.h
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

index b22667f..e625794 100644 (file)
@@ -1,5 +1,27 @@
 2017-09-01  Alex Christensen  <achristensen@webkit.org>
 
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's toolbarsAreVisible
+        https://bugs.webkit.org/show_bug.cgi?id=176246
+        <rdar://problem/29270035>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::toolbarsAreVisible):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::toolbarsAreVisible):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::getToolbarsAreVisible):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+
+2017-09-01  Alex Christensen  <achristensen@webkit.org>
+
         Make PageClientImplCocoa a proper superclass of PageClientImpls for Mac and iOS
         https://bugs.webkit.org/show_bug.cgi?id=176239
 
index ba1322f..1b8b339 100644 (file)
@@ -99,7 +99,7 @@ public:
     virtual void didNotHandleKeyEvent(WebKit::WebPageProxy*, const WebKit::NativeWebKeyboardEvent&) { }
     virtual void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) { }
 
-    virtual bool toolbarsAreVisible(WebKit::WebPageProxy*) { return true; }
+    virtual void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&& completionHandler) { completionHandler(true); }
     virtual void setToolbarsAreVisible(WebKit::WebPageProxy*, bool) { }
     virtual bool menuBarIsVisible(WebKit::WebPageProxy*) { return true; }
     virtual void setMenuBarIsVisible(WebKit::WebPageProxy*, bool) { }
index 52e1aba..efbe246 100644 (file)
@@ -1832,11 +1832,11 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
             m_client.didNotHandleWheelEvent(toAPI(page), event.nativeEvent(), m_client.base.clientInfo);
         }
 
-        bool toolbarsAreVisible(WebPageProxy* page) final
+        void toolbarsAreVisible(WebPageProxy& page, Function<void(bool)>&& completionHandler) final
         {
             if (!m_client.toolbarsAreVisible)
-                return true;
-            return m_client.toolbarsAreVisible(toAPI(page), m_client.base.clientInfo);
+                return completionHandler(true);
+            completionHandler(m_client.toolbarsAreVisible(toAPI(&page), m_client.base.clientInfo));
         }
 
         void setToolbarsAreVisible(WebPageProxy* page, bool visible) final
index c5b2691..b762cd2 100644 (file)
@@ -150,6 +150,7 @@ struct UIEdgeInsets;
 - (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView didClickAutoFillButtonWithUserInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView getToolbarsAreVisibleWithCompletionHandler:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView didExceedBackgroundResourceLimitWhileInForeground:(_WKResourceLimit)limit WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
index 859ebfa..aeb1377 100644 (file)
@@ -97,9 +97,9 @@ private:
         webkitWebViewMouseTargetChanged(m_webView, data, modifiers);
     }
 
-    bool toolbarsAreVisible(WebPageProxy*) override
+    void toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&& completionHandler) override
     {
-        return webkit_window_properties_get_toolbar_visible(webkit_web_view_get_window_properties(m_webView));
+        completionHandler(webkit_window_properties_get_toolbar_visible(webkit_web_view_get_window_properties(m_webView)));
     }
 
     void setToolbarsAreVisible(WebPageProxy*, bool visible) override
index 807d403..573b8d8 100644 (file)
@@ -103,6 +103,7 @@ private:
         void didNotHandleWheelEvent(WebPageProxy*, const NativeWebWheelEvent&) final;
         void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
+        void toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&&) final;
         bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
         void didExceedBackgroundResourceLimitWhileInForeground(WebPageProxy&, WKResourceLimit) final;
         void saveDataToFileInDownloadsFolder(WebPageProxy*, const WTF::String&, const WTF::String&, const WebCore::URL&, API::Data&) final;
@@ -152,6 +153,7 @@ private:
         bool webViewDidNotHandleWheelEvent : 1;
         bool webViewHandleAutoplayEventWithFlags : 1;
         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
+        bool webViewGetToolbarsAreVisibleWithCompletionHandler : 1;
         bool webViewDidExceedBackgroundResourceLimitWhileInForeground : 1;
         bool webViewSaveDataToFileSuggestedFilenameMimeTypeOriginatingURL : 1;
         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
index 5e5227c..3df1419 100644 (file)
@@ -106,6 +106,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.focusWebView = [delegate respondsToSelector:@selector(_focusWebView:)];
     m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
     m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
+    m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:getToolbarsAreVisibleWithCompletionHandler:)];
     m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
     m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
     m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo = [delegate respondsToSelector:@selector(_webView:didClickAutoFillButtonWithUserInfo:)];
@@ -490,6 +491,23 @@ static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
     return _WKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
 }
 
+void UIDelegate::UIClient::toolbarsAreVisible(WebKit::WebPageProxy&, Function<void(bool)>&& completionHandler)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler)
+        return completionHandler(true);
+    
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return completionHandler(true);
+    
+    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView getToolbarsAreVisibleWithCompletionHandler:BlockPtr<void(BOOL)>::fromCallable([completionHandler = WTFMove(completionHandler), checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:getToolbarsAreVisibleWithCompletionHandler:))](BOOL visible) {
+        if (checker->completionHandlerHasBeenCalled())
+            return;
+        checker->didCallCompletionHandler();
+        completionHandler(visible);
+    }).get()];
+}
+
 void UIDelegate::UIClient::didClickAutoFillButton(WebPageProxy&, API::Object* userInfo)
 {
     if (!m_uiDelegate.m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo)
index a8432df..2180250 100644 (file)
@@ -4066,9 +4066,11 @@ void WebPageProxy::setToolbarsAreVisible(bool toolbarsAreVisible)
     m_uiClient->setToolbarsAreVisible(this, toolbarsAreVisible);
 }
 
-void WebPageProxy::getToolbarsAreVisible(bool& toolbarsAreVisible)
+void WebPageProxy::getToolbarsAreVisible(Ref<Messages::WebPageProxy::GetToolbarsAreVisible::DelayedReply>&& reply)
 {
-    toolbarsAreVisible = m_uiClient->toolbarsAreVisible(this);
+    m_uiClient->toolbarsAreVisible(*this, [reply = WTFMove(reply)](bool visible) {
+        reply->send(visible);
+    });
 }
 
 void WebPageProxy::setMenuBarIsVisible(bool menuBarIsVisible)
index 08df6eb..53e1ad7 100644 (file)
@@ -1306,7 +1306,7 @@ private:
     void resolveWebGLPolicyForURL(WebCore::URL&&, Ref<Messages::WebPageProxy::ResolveWebGLPolicyForURL::DelayedReply>&&);
 #endif // ENABLE(WEBGL)
     void setToolbarsAreVisible(bool toolbarsAreVisible);
-    void getToolbarsAreVisible(bool& toolbarsAreVisible);
+    void getToolbarsAreVisible(Ref<Messages::WebPageProxy::GetToolbarsAreVisible::DelayedReply>&&);
     void setMenuBarIsVisible(bool menuBarIsVisible);
     void getMenuBarIsVisible(bool& menuBarIsVisible);
     void setStatusBarIsVisible(bool statusBarIsVisible);
index de830e4..50c5611 100644 (file)
@@ -51,7 +51,7 @@ messages -> WebPageProxy {
     FrameSetLargestFrameChanged(uint64_t frameID)
     SetRenderTreeSize(uint64_t treeSize)
     SetToolbarsAreVisible(bool toolbarsAreVisible)
-    GetToolbarsAreVisible() -> (bool toolbarsAreVisible)
+    GetToolbarsAreVisible() -> (bool toolbarsAreVisible) Delayed
     SetMenuBarIsVisible(bool menuBarIsVisible);
     GetMenuBarIsVisible() -> (bool menuBarIsVisible);
     SetStatusBarIsVisible(bool statusBarIsVisible)
index 94ae9c4..a210a21 100644 (file)
@@ -1,3 +1,16 @@
+2017-09-01  Alex Christensen  <achristensen@webkit.org>
+
+        Add WKUIDelegatePrivate equivalent of WKPageUIClient's toolbarsAreVisible
+        https://bugs.webkit.org/show_bug.cgi?id=176246
+        <rdar://problem/29270035>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (-[ToolbarDelegate _webView:getToolbarsAreVisibleWithCompletionHandler:]):
+        (-[ToolbarDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TEST):
+
 2017-09-01  Eric Carlson  <eric.carlson@apple.com>
 
         Switch HTMLMediaElement to release logging
index f5568e8..1c8fdbc 100644 (file)
@@ -122,6 +122,41 @@ TEST(WebKit2, ShowWebView)
     ASSERT_EQ(webViewFromDelegateCallback, createdWebView);
 }
 
+bool firstToolbarDone;
+
+@interface ToolbarDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation ToolbarDelegate
+
+- (void)_webView:(WKWebView *)webView getToolbarsAreVisibleWithCompletionHandler:(void(^)(BOOL))completionHandler
+{
+    completionHandler(firstToolbarDone);
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    if (firstToolbarDone) {
+        EXPECT_STREQ(message.UTF8String, "visible:true");
+        done = true;
+    } else {
+        EXPECT_STREQ(message.UTF8String, "visible:false");
+        firstToolbarDone = true;
+    }
+    completionHandler();
+}
+
+@end
+
+TEST(WebKit2, ToolbarVisible)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:[[[WKWebViewConfiguration alloc] init] autorelease]]);
+    auto delegate = adoptNS([[ToolbarDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+    [webView synchronouslyLoadHTMLString:@"<script>alert('visible:' + window.toolbar.visible);alert('visible:' + window.toolbar.visible)</script>"];
+    TestWebKitAPI::Util::run(&done);
+}
+
 static bool readyForClick;
 
 @interface AutoFillDelegate : NSObject <WKUIDelegatePrivate>