Title: [211165] trunk/Source/WebKit2
Revision
211165
Author
[email protected]
Date
2017-01-25 14:31:24 -0800 (Wed, 25 Jan 2017)

Log Message

[QuickLook] Display a WKPasswordView when a document is password-protected
https://bugs.webkit.org/show_bug.cgi?id=167407
<rdar://problem/28544527>

Reviewed by Alex Christensen.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _hidePasswordView]): Added an early return if there is no _passwordView.
* UIProcess/PageClient.h: Declared requestPasswordForQuickLookDocument().
(WebKit::PageClient::didStartProvisionalLoadForMainFrame): Added an no-op base class
implementation.
(WebKit::PageClient::didFailProvisionalLoadForMainFrame): Ditto.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Called
PageClient::didStartProvisionalLoadForMainFrame() if frame is the main frame.
(WebKit::WebPageProxy::didFailProvisionalLoadForFrame): Ditto for
PageClient::didFailProvisionalLoadForMainFrame().
* UIProcess/WebPageProxy.h: Declared didRequestPasswordForQuickLookDocumentInMainFrame().
* UIProcess/WebPageProxy.messages.in: Added message
DidRequestPasswordForQuickLookDocumentInMainFrame.
* UIProcess/ios/PageClientImplIOS.h: Overrode requestPasswordForQuickLookDocument(),
didStartProvisionalLoadForMainFrame(), and didFailProvisionalLoadForMainFrame().
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::didStartProvisionalLoadForMainFrame): Called
-[WKWebView _hidePasswordView].
(WebKit::PageClientImpl::didFailProvisionalLoadForMainFrame): Ditto.
(WebKit::PageClientImpl::didCommitLoadForMainFrame): Ditto.
(WebKit::PageClientImpl::requestPasswordForQuickLookDocument): If there is already a
password view, assert that it is for the same fileName. Call
-[WKPasswordView showPasswordFailureAlert] and update the userDidEnterPassword block.
Otherwise, call -[WKWebView _showPasswordViewWithDocumentName:passwordHandler:].
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame): Called
PageClient::requestPasswordForQuickLookDocument() with a completion handler that send
message WebPage::DidReceivePasswordForQuickLookDocument.
* WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp:
(WebKit::passwordCallbacks): Stores a map of page IDs to completion handler functions.
(WebKit::WebQuickLookHandleClient::~WebQuickLookHandleClient): Removes the current page ID
from passwordCallbacks().
(WebKit::WebQuickLookHandleClient::didRequestPassword): Asserts there is no current function
for this page ID in passwordCallbacks(), adds completionHandler to passwordCallbacks(), and
sends message WebPageProxy::DidRequestPasswordForQuickLookDocumentInMainFrame.
(WebKit::WebQuickLookHandleClient::didReceivePassword): Asserts there is a function for this
page ID in passwordCallbacks(), takes the completionHandler from passwordCallbacks(), and
calls it with the received password.
* WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h: Declared didReceivePassword()
and overrode supportsPasswordEntry() and didRequestPassword().
* WebProcess/WebPage/WebPage.h: Declared didReceivePasswordForQuickLookDocument().
* WebProcess/WebPage/WebPage.messages.in: Added message
DidReceivePasswordForQuickLookDocument.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::didReceivePasswordForQuickLookDocument): Called
WebQuickLookHandleClient::didReceivePassword() with the received password and current page ID.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (211164 => 211165)


--- trunk/Source/WebKit2/ChangeLog	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-25 22:31:24 UTC (rev 211165)
@@ -1,3 +1,59 @@
+2017-01-25  Andy Estes  <[email protected]>
+
+        [QuickLook] Display a WKPasswordView when a document is password-protected
+        https://bugs.webkit.org/show_bug.cgi?id=167407
+        <rdar://problem/28544527>
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _hidePasswordView]): Added an early return if there is no _passwordView.
+        * UIProcess/PageClient.h: Declared requestPasswordForQuickLookDocument().
+        (WebKit::PageClient::didStartProvisionalLoadForMainFrame): Added an no-op base class
+        implementation.
+        (WebKit::PageClient::didFailProvisionalLoadForMainFrame): Ditto.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didStartProvisionalLoadForFrame): Called
+        PageClient::didStartProvisionalLoadForMainFrame() if frame is the main frame.
+        (WebKit::WebPageProxy::didFailProvisionalLoadForFrame): Ditto for
+        PageClient::didFailProvisionalLoadForMainFrame().
+        * UIProcess/WebPageProxy.h: Declared didRequestPasswordForQuickLookDocumentInMainFrame().
+        * UIProcess/WebPageProxy.messages.in: Added message
+        DidRequestPasswordForQuickLookDocumentInMainFrame.
+        * UIProcess/ios/PageClientImplIOS.h: Overrode requestPasswordForQuickLookDocument(),
+        didStartProvisionalLoadForMainFrame(), and didFailProvisionalLoadForMainFrame().
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::didStartProvisionalLoadForMainFrame): Called
+        -[WKWebView _hidePasswordView].
+        (WebKit::PageClientImpl::didFailProvisionalLoadForMainFrame): Ditto.
+        (WebKit::PageClientImpl::didCommitLoadForMainFrame): Ditto.
+        (WebKit::PageClientImpl::requestPasswordForQuickLookDocument): If there is already a
+        password view, assert that it is for the same fileName. Call
+        -[WKPasswordView showPasswordFailureAlert] and update the userDidEnterPassword block.
+        Otherwise, call -[WKWebView _showPasswordViewWithDocumentName:passwordHandler:].
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame): Called
+        PageClient::requestPasswordForQuickLookDocument() with a completion handler that send
+        message WebPage::DidReceivePasswordForQuickLookDocument.
+        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp:
+        (WebKit::passwordCallbacks): Stores a map of page IDs to completion handler functions.
+        (WebKit::WebQuickLookHandleClient::~WebQuickLookHandleClient): Removes the current page ID
+        from passwordCallbacks().
+        (WebKit::WebQuickLookHandleClient::didRequestPassword): Asserts there is no current function
+        for this page ID in passwordCallbacks(), adds completionHandler to passwordCallbacks(), and
+        sends message WebPageProxy::DidRequestPasswordForQuickLookDocumentInMainFrame.
+        (WebKit::WebQuickLookHandleClient::didReceivePassword): Asserts there is a function for this
+        page ID in passwordCallbacks(), takes the completionHandler from passwordCallbacks(), and
+        calls it with the received password.
+        * WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h: Declared didReceivePassword()
+        and overrode supportsPasswordEntry() and didRequestPassword().
+        * WebProcess/WebPage/WebPage.h: Declared didReceivePasswordForQuickLookDocument().
+        * WebProcess/WebPage/WebPage.messages.in: Added message
+        DidReceivePasswordForQuickLookDocument.
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::didReceivePasswordForQuickLookDocument): Called
+        WebQuickLookHandleClient::didReceivePassword() with the received password and current page ID.
+
 2017-01-25  Youenn Fablet  <[email protected]>
 
         [WebRTC] Introduce libwebrtc abstraction for WK1/WK2 implementations

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2017-01-25 22:31:24 UTC (rev 211165)
@@ -2347,6 +2347,9 @@
 
 - (void)_hidePasswordView
 {
+    if (!_passwordView)
+        return;
+
     self._currentContentView.hidden = NO;
     [_passwordView removeFromSuperview];
     _passwordView = nil;

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2017-01-25 22:31:24 UTC (rev 211165)
@@ -138,6 +138,8 @@
         return false;
     }
 
+    virtual void didStartProvisionalLoadForMainFrame() { };
+    virtual void didFailProvisionalLoadForMainFrame() { };
     virtual void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) = 0;
 
 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
@@ -375,6 +377,10 @@
     virtual bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) { return false; }
 
     virtual WebCore::UserInterfaceLayoutDirection userInterfaceLayoutDirection() = 0;
+
+#if USE(QUICK_LOOK)
+    virtual void requestPasswordForQuickLookDocument(const String& fileName, std::function<void(const String&)>&&) = 0;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2017-01-25 22:31:24 UTC (rev 211165)
@@ -3171,6 +3171,7 @@
 
     if (frame->isMainFrame()) {
         m_pageLoadState.didStartProvisionalLoad(transaction, url, unreachableURL);
+        m_pageClient.didStartProvisionalLoadForMainFrame();
         hideValidationMessage();
     }
 
@@ -3246,8 +3247,10 @@
 
     auto transaction = m_pageLoadState.transaction();
 
-    if (frame->isMainFrame())
+    if (frame->isMainFrame()) {
         m_pageLoadState.didFailProvisionalLoad(transaction);
+        m_pageClient.didFailProvisionalLoadForMainFrame();
+    }
 
     frame->didFailProvisionalLoad();
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2017-01-25 22:31:24 UTC (rev 211165)
@@ -1571,6 +1571,7 @@
 #if USE(QUICK_LOOK)
     void didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti);
     void didFinishLoadForQuickLookDocumentInMainFrame(const QuickLookDocumentData&);
+    void didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName);
 #endif
 
 #if ENABLE(CONTENT_FILTERING)

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2017-01-25 22:31:24 UTC (rev 211165)
@@ -431,6 +431,7 @@
 #if USE(QUICK_LOOK)
     DidStartLoadForQuickLookDocumentInMainFrame(String fileName, String uti)
     DidFinishLoadForQuickLookDocumentInMainFrame(WebKit::QuickLookDocumentData data)
+    DidRequestPasswordForQuickLookDocumentInMainFrame(String fileName)
 #endif
 
 #if ENABLE(CONTENT_FILTERING)

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2017-01-25 22:31:24 UTC (rev 211165)
@@ -65,6 +65,8 @@
     void preferencesDidChange() override;
     void toolTipChanged(const String&, const String&) override;
     bool decidePolicyForGeolocationPermissionRequest(WebFrameProxy&, API::SecurityOrigin&, GeolocationPermissionRequestProxy&) override;
+    void didStartProvisionalLoadForMainFrame() override;
+    void didFailProvisionalLoadForMainFrame() override;
     void didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider) override;
     void handleDownloadRequest(DownloadProxy*) override;
     void didChangeContentSize(const WebCore::IntSize&) override;
@@ -196,6 +198,8 @@
 
     void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime) override;
 
+    void requestPasswordForQuickLookDocument(const String& fileName, std::function<void(const String&)>&&) override;
+
     WKContentView *m_contentView;
     WKWebView *m_webView;
     RetainPtr<WKEditorUndoTargetObjC> m_undoTarget;

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2017-01-25 22:31:24 UTC (rev 211165)
@@ -40,6 +40,7 @@
 #import "WKContentView.h"
 #import "WKContentViewInteraction.h"
 #import "WKGeolocationProviderIOS.h"
+#import "WKPasswordView.h"
 #import "WKProcessPoolInternal.h"
 #import "WKWebViewConfigurationInternal.h"
 #import "WKWebViewContentProviderRegistry.h"
@@ -227,8 +228,19 @@
     return true;
 }
 
+void PageClientImpl::didStartProvisionalLoadForMainFrame()
+{
+    [m_webView _hidePasswordView];
+}
+
+void PageClientImpl::didFailProvisionalLoadForMainFrame()
+{
+    [m_webView _hidePasswordView];
+}
+
 void PageClientImpl::didCommitLoadForMainFrame(const String& mimeType, bool useCustomContentProvider)
 {
+    [m_webView _hidePasswordView];
     [m_webView _setHasCustomContentView:useCustomContentProvider loadedMIMEType:mimeType];
     [m_contentView _didCommitLoadForMainFrame];
 }
@@ -755,6 +767,20 @@
     [m_webView _handleActiveNowPlayingSessionInfoResponse:hasActiveSession title:nsStringFromWebCoreString(title) duration:duration elapsedTime:elapsedTime];
 }
 
+void PageClientImpl::requestPasswordForQuickLookDocument(const String& fileName, std::function<void(const String&)>&& completionHandler)
+{
+    auto passwordHandler = [completionHandler = WTFMove(completionHandler)](NSString *password) {
+        completionHandler(password);
+    };
+
+    if (WKPasswordView *passwordView = m_webView._passwordView) {
+        ASSERT(fileName == String { passwordView.documentName });
+        [passwordView showPasswordFailureAlert];
+        passwordView.userDidEnterPassword = passwordHandler;
+    } else
+        [m_webView _showPasswordViewWithDocumentName:fileName passwordHandler:passwordHandler];
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)

Modified: trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm (211164 => 211165)


--- trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm	2017-01-25 22:31:24 UTC (rev 211165)
@@ -1100,6 +1100,14 @@
     else
         m_loaderClient->didFinishLoadForQuickLookDocumentInMainFrame(data);
 }
+
+void WebPageProxy::didRequestPasswordForQuickLookDocumentInMainFrame(const String& fileName)
+{
+    m_pageClient.requestPasswordForQuickLookDocument(fileName, [protectedThis = makeRefPtr(this)](const String& password) {
+        protectedThis->process().send(Messages::WebPage::DidReceivePasswordForQuickLookDocument(password), protectedThis->m_pageID);
+    });
+}
+
 #endif
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp (211164 => 211165)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.cpp	2017-01-25 22:31:24 UTC (rev 211165)
@@ -31,9 +31,19 @@
 #include "WebPageProxyMessages.h"
 #include "WebProcess.h"
 #include <WebCore/QuickLook.h>
+#include <wtf/Function.h>
+#include <wtf/HashMap.h>
+#include <wtf/NeverDestroyed.h>
 
 namespace WebKit {
 
+using PasswordCallbackMap = HashMap<uint64_t, Function<void(const String&)>>;
+static PasswordCallbackMap& passwordCallbacks()
+{
+    static NeverDestroyed<PasswordCallbackMap> callbackMap;
+    return callbackMap.get();
+}
+
 WebQuickLookHandleClient::WebQuickLookHandleClient(const WebCore::QuickLookHandle& handle, uint64_t pageID)
     : m_fileName(handle.previewFileName())
     , m_uti(handle.previewUTI())
@@ -42,6 +52,11 @@
     WebProcess::singleton().send(Messages::WebPageProxy::DidStartLoadForQuickLookDocumentInMainFrame(m_fileName, m_uti), m_pageID);
 }
 
+WebQuickLookHandleClient::~WebQuickLookHandleClient()
+{
+    passwordCallbacks().remove(m_pageID);
+}
+
 void WebQuickLookHandleClient::didReceiveDataArray(CFArrayRef dataArray)
 {
     CFArrayApplyFunction(dataArray, CFRangeMake(0, CFArrayGetCount(dataArray)), [](const void* value, void* context) {
@@ -61,6 +76,20 @@
     m_data.clear();
 }
 
+void WebQuickLookHandleClient::didRequestPassword(Function<void(const String&)>&& completionHandler)
+{
+    ASSERT(!passwordCallbacks().contains(m_pageID));
+    passwordCallbacks().add(m_pageID, WTFMove(completionHandler));
+    WebProcess::singleton().send(Messages::WebPageProxy::DidRequestPasswordForQuickLookDocumentInMainFrame(m_fileName), m_pageID);
+}
+
+void WebQuickLookHandleClient::didReceivePassword(const String& password, uint64_t pageID)
+{
+    ASSERT(passwordCallbacks().contains(pageID));
+    auto completionHandler = passwordCallbacks().take(pageID);
+    completionHandler(password);
+}
+
 } // namespace WebKit
 
 #endif // USE(QUICK_LOOK)

Modified: trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h (211164 => 211165)


--- trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/WebProcess/WebCoreSupport/ios/WebQuickLookHandleClient.h	2017-01-25 22:31:24 UTC (rev 211165)
@@ -46,12 +46,17 @@
     {
         return adoptRef(*new WebQuickLookHandleClient(handle, pageID));
     }
+    ~WebQuickLookHandleClient();
 
+    static void didReceivePassword(const String&, uint64_t pageID);
+
 private:
     WebQuickLookHandleClient(const WebCore::QuickLookHandle&, uint64_t pageID);
     void didReceiveDataArray(CFArrayRef) override;
     void didFinishLoading() override;
     void didFail() override;
+    bool supportsPasswordEntry() const override { return true; }
+    void didRequestPassword(Function<void(const String&)>&&) override;
 
     const String m_fileName;
     const String m_uti;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (211164 => 211165)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h	2017-01-25 22:31:24 UTC (rev 211165)
@@ -1253,6 +1253,10 @@
 
     bool canPluginHandleResponse(const WebCore::ResourceResponse&);
 
+#if USE(QUICK_LOOK)
+    void didReceivePasswordForQuickLookDocument(const String&);
+#endif
+
     uint64_t m_pageID;
 
     std::unique_ptr<WebCore::Page> m_page;

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (211164 => 211165)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in	2017-01-25 22:31:24 UTC (rev 211165)
@@ -464,4 +464,8 @@
 #if ENABLE(GAMEPAD)
     GamepadActivity(Vector<WebKit::GamepadData> gamepadDatas, bool shouldMakeGamepadsVisible)
 #endif
+
+#if USE(QUICK_LOOK)
+    DidReceivePasswordForQuickLookDocument(String password)
+#endif
 }

Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (211164 => 211165)


--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-01-25 22:05:02 UTC (rev 211164)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm	2017-01-25 22:31:24 UTC (rev 211165)
@@ -49,6 +49,7 @@
 #import "WebKitSystemInterface.h"
 #import "WebPageProxyMessages.h"
 #import "WebProcess.h"
+#import "WebQuickLookHandleClient.h"
 #import <CoreText/CTFont.h>
 #import <WebCore/Autofill.h>
 #import <WebCore/Chrome.h>
@@ -3173,6 +3174,13 @@
     return String();
 }
 
+#if USE(QUICK_LOOK)
+void WebPage::didReceivePasswordForQuickLookDocument(const String& password)
+{
+    WebQuickLookHandleClient::didReceivePassword(password, m_pageID);
+}
+#endif
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to