Bug 209192

Summary: Add WKUIDelegatePrivate SPI _webView:printFrame:completionHandler:
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: ggaren, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch ggaren: review+

Description Alex Christensen 2020-03-17 12:34:57 PDT
Add WKUIDelegatePrivate SPI _webView:printFrame:completionHandler:
Comment 1 Alex Christensen 2020-03-17 12:38:04 PDT
Created attachment 393777 [details]
Patch
Comment 2 Alex Christensen 2020-03-17 12:38:12 PDT
<rdar://problem/51313336>
Comment 3 Geoffrey Garen 2020-03-17 12:40:56 PDT
Comment on attachment 393777 [details]
Patch

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

r=me

> Source/WebKit/UIProcess/Cocoa/UIDelegate.mm:1099
> +    auto handle = API::FrameHandle::create(webFrameProxy.frameID());
> +    if (m_uiDelegate.m_delegateMethods.webViewPrintFrame) {
> +        [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(handle)];
> +        completionHandler();
> +    } else if (m_uiDelegate.m_delegateMethods.webViewPrintFrameCompletionHandler) {
> +        auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:printFrame:completionHandler:));
> +        [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView printFrame:wrapper(handle) completionHandler:makeBlockPtr([checker = WTFMove(checker), completionHandler = WTFMove(completionHandler)] () mutable {
> +            if (checker->completionHandlerHasBeenCalled())
> +                return;
> +            checker->didCallCompletionHandler();
> +            completionHandler();
> +        }).get()];
> +    } else
> +        completionHandler();

I think you want to do the delegate method check in the opposite order, so the new API wins if implemented. That way, a client can implement both if they need to support older WebKits, without doing #ifdef stuff.
Comment 4 Alex Christensen 2020-03-17 12:47:48 PDT
They could also do crazy things with their own implementation of respondsToSelector, but you're right.  I switched them.

http://trac.webkit.org/r258574
Comment 5 Alex Christensen 2020-03-17 12:50:08 PDT
http://trac.webkit.org/r258575
Comment 6 Ryan Haddad 2020-03-17 15:56:17 PDT
This change caused assertion failures with multiple layout and API tests:

ASSERTION FAILED: Completion handler should always be called
!m_function
/Volumes/Data/slave/catalina-debug/build/WebKitBuild/Debug/usr/local/include/wtf/CompletionHandler.h(53) : WTF::CompletionHandler<void ()>::~CompletionHandler()


https://build.webkit.org/builders/Apple-Catalina-Debug-WK2-Tests/builds/2971
Comment 7 Alex Christensen 2020-03-17 15:58:45 PDT
Investigating now.
Comment 8 Alex Christensen 2020-03-17 16:33:18 PDT
http://trac.webkit.org/r258610

:(

Will be more careful in the future