Title: [262799] trunk/Source/WebKit
Revision
262799
Author
[email protected]
Date
2020-06-09 11:38:17 -0700 (Tue, 09 Jun 2020)

Log Message

Expose PDF file URL in shouldAllowPDFToOpenFromFrame SPI
https://bugs.webkit.org/show_bug.cgi?id=212974

Patch by Alex Christensen <[email protected]> on 2020-06-09
Reviewed by Tim Horton.

* UIProcess/API/APIUIClient.h:
(API::UIClient::confirmPDFOpening):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::confirmPDFOpening):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication):
(WebKit::WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (262798 => 262799)


--- trunk/Source/WebKit/ChangeLog	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/ChangeLog	2020-06-09 18:38:17 UTC (rev 262799)
@@ -1,3 +1,21 @@
+2020-06-09  Alex Christensen  <[email protected]>
+
+        Expose PDF file URL in shouldAllowPDFToOpenFromFrame SPI
+        https://bugs.webkit.org/show_bug.cgi?id=212974
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::confirmPDFOpening):
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::confirmPDFOpening):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::savePDFToTemporaryFolderAndOpenWithNativeApplication):
+        (WebKit::WebPageProxy::openPDFFromTemporaryFolderWithNativeApplication):
+
 2020-06-09  Takashi Komori  <[email protected]>
 
         [Curl] Implement functions to use ResourceLoadStatistics.

Modified: trunk/Source/WebKit/UIProcess/API/APIUIClient.h (262798 => 262799)


--- trunk/Source/WebKit/UIProcess/API/APIUIClient.h	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/UIProcess/API/APIUIClient.h	2020-06-09 18:38:17 UTC (rev 262799)
@@ -196,7 +196,7 @@
     
     virtual void didShowSafeBrowsingWarning() { }
 
-    virtual void confirmPDFOpening(WebKit::WebPageProxy&, WebKit::FrameInfoData&&, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
+    virtual void confirmPDFOpening(WebKit::WebPageProxy&, const WTF::URL&, WebKit::FrameInfoData&&, CompletionHandler<void(bool)>&& completionHandler) { completionHandler(true); }
 
 #if ENABLE(WEB_AUTHN)
     virtual void runWebAuthenticationPanel(WebKit::WebPageProxy&, WebAuthenticationPanel&, WebKit::WebFrameProxy&, WebKit::FrameInfoData&&, CompletionHandler<void(WebKit::WebAuthenticationPanelResult)>&& completionHandler) { completionHandler(WebKit::WebAuthenticationPanelResult::Unavailable); }

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h (262798 => 262799)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h	2020-06-09 18:38:17 UTC (rev 262799)
@@ -115,7 +115,7 @@
 - (void)_webViewDidShowSafeBrowsingWarning:(WKWebView *)webView WK_API_AVAILABLE(macos(10.14.4), ios(12.2));
 - (void)_webViewDidLosePointerLock:(WKWebView *)webView WK_API_AVAILABLE(macos(10.12.3));
 - (void)_webView:(WKWebView *)webView hasVideoInPictureInPictureDidChange:(BOOL)hasVideoInPictureInPicture WK_API_AVAILABLE(macos(10.13), ios(11.0));
-- (void)_webView:(WKWebView *)webView shouldAllowPDFToOpenFromFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_webView:(WKWebView *)webView shouldAllowPDFAtURL:(NSURL *)fileURL toOpenFromFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (void)_webView:(WKWebView *)webView imageOrMediaDocumentSizeChanged:(CGSize)size WK_API_AVAILABLE(macos(10.12), ios(10.0));
 - (NSDictionary *)_dataDetectionContextForWebView:(WKWebView *)webView WK_API_AVAILABLE(macos(10.12), ios(10.0));

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h (262798 => 262799)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.h	2020-06-09 18:38:17 UTC (rev 262799)
@@ -154,7 +154,7 @@
 
         void imageOrMediaDocumentSizeChanged(const WebCore::IntSize&) final;
         void didShowSafeBrowsingWarning() final;
-        void confirmPDFOpening(WebPageProxy&, FrameInfoData&&, CompletionHandler<void(bool)>&&) final;
+        void confirmPDFOpening(WebPageProxy&, const WTF::URL&, FrameInfoData&&, CompletionHandler<void(bool)>&&) final;
 #if ENABLE(WEB_AUTHN)
         void runWebAuthenticationPanel(WebPageProxy&, API::WebAuthenticationPanel&, WebFrameProxy&, FrameInfoData&&, CompletionHandler<void(WebAuthenticationPanelResult)>&&) final;
 #endif
@@ -239,7 +239,7 @@
 #endif
         bool webViewHasVideoInPictureInPictureDidChange : 1;
         bool webViewDidShowSafeBrowsingWarning : 1;
-        bool webViewShouldAllowPDFToOpenFromFrameCompletionHandler : 1;
+        bool webViewShouldAllowPDFAtURLToOpenFromFrameCompletionHandler : 1;
 #if ENABLE(WEB_AUTHN)
         bool webViewRunWebAuthenticationPanelInitiatedByFrameCompletionHandler : 1;
 #endif

Modified: trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm (262798 => 262799)


--- trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/UIProcess/Cocoa/UIDelegate.mm	2020-06-09 18:38:17 UTC (rev 262799)
@@ -171,7 +171,7 @@
     
     m_delegateMethods.webViewHasVideoInPictureInPictureDidChange = [delegate respondsToSelector:@selector(_webView:hasVideoInPictureInPictureDidChange:)];
     m_delegateMethods.webViewDidShowSafeBrowsingWarning = [delegate respondsToSelector:@selector(_webViewDidShowSafeBrowsingWarning:)];
-    m_delegateMethods.webViewShouldAllowPDFToOpenFromFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:shouldAllowPDFToOpenFromFrame:completionHandler:)];
+    m_delegateMethods.webViewShouldAllowPDFAtURLToOpenFromFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:shouldAllowPDFAtURL:toOpenFromFrame:completionHandler:)];
 
 #if ENABLE(WEB_AUTHN)
     m_delegateMethods.webViewRunWebAuthenticationPanelInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(_webView:runWebAuthenticationPanel:initiatedByFrame:completionHandler:)];
@@ -1270,9 +1270,9 @@
     [static_cast<id <WKUIDelegatePrivate>>(delegate) _webViewDidShowSafeBrowsingWarning:m_uiDelegate.m_webView];
 }
 
-void UIDelegate::UIClient::confirmPDFOpening(WebPageProxy& page, FrameInfoData&& frameInfo, CompletionHandler<void(bool)>&& completionHandler)
+void UIDelegate::UIClient::confirmPDFOpening(WebPageProxy& page, const WTF::URL& fileURL, FrameInfoData&& frameInfo, CompletionHandler<void(bool)>&& completionHandler)
 {
-    if (!m_uiDelegate.m_delegateMethods.webViewShouldAllowPDFToOpenFromFrameCompletionHandler)
+    if (!m_uiDelegate.m_delegateMethods.webViewShouldAllowPDFAtURLToOpenFromFrameCompletionHandler)
         return completionHandler(true);
 
     auto delegate = m_uiDelegate.m_delegate.get();
@@ -1279,8 +1279,8 @@
     if (!delegate)
         return completionHandler(true);
 
-    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:shouldAllowPDFToOpenFromFrame:completionHandler:));
-    [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView shouldAllowPDFToOpenFromFrame:wrapper(API::FrameInfo::create(WTFMove(frameInfo), &page)) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
+    auto checker = CompletionHandlerCallChecker::create(delegate.get(), @selector(_webView:shouldAllowPDFAtURL:toOpenFromFrame:completionHandler:));
+    [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView shouldAllowPDFAtURL:fileURL toOpenFromFrame:wrapper(API::FrameInfo::create(WTFMove(frameInfo), &page)) completionHandler:makeBlockPtr([completionHandler = WTFMove(completionHandler), checker = WTFMove(checker)] (BOOL result) mutable {
         if (checker->completionHandlerHasBeenCalled())
             return;
         checker->didCallCompletionHandler();

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (262798 => 262799)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-06-09 18:16:08 UTC (rev 262798)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2020-06-09 18:38:17 UTC (rev 262799)
@@ -511,10 +511,11 @@
 
     m_temporaryPDFFiles.add(pdfUUID, nsPath.get());
 
-    m_uiClient->confirmPDFOpening(*this, WTFMove(frameInfo), [nsPath = WTFMove(nsPath)] (bool allowed) {
+    auto pdfFileURL = URL::fileURLWithFileSystemPath(String(nsPath.get()));
+    m_uiClient->confirmPDFOpening(*this, pdfFileURL, WTFMove(frameInfo), [pdfFileURL] (bool allowed) {
         if (!allowed)
             return;
-        [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:nsPath.get() isDirectory:NO]];
+        [[NSWorkspace sharedWorkspace] openURL:pdfFileURL];
     });
 }
 
@@ -527,10 +528,11 @@
     if (!pdfFilename.endsWithIgnoringASCIICase(".pdf"))
         return;
 
-    m_uiClient->confirmPDFOpening(*this, WTFMove(frameInfo), [pdfFilename = WTFMove(pdfFilename)] (bool allowed) {
+    auto pdfFileURL = URL::fileURLWithFileSystemPath(pdfFilename);
+    m_uiClient->confirmPDFOpening(*this, pdfFileURL, WTFMove(frameInfo), [pdfFileURL] (bool allowed) {
         if (!allowed)
             return;
-        [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:pdfFilename isDirectory:NO]];
+        [[NSWorkspace sharedWorkspace] openURL:pdfFileURL];
     });
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to