2011-03-29 Anders Carlsson <andersca@apple.com>
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2011 00:02:44 +0000 (00:02 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Mar 2011 00:02:44 +0000 (00:02 +0000)
        Reviewed by Sam Weinig.

        Downloads: Authentication support
        https://bugs.webkit.org/show_bug.cgi?id=57403
        <rdar://problem/8691166>

        * UIProcess/API/C/WKContext.h:
        Add didReceiveAuthenticationChallenge callback.

        * UIProcess/Downloads/DownloadProxy.cpp:
        (WebKit::DownloadProxy::didReceiveAuthenticationChallenge):
        Call the download client.

        * UIProcess/Downloads/DownloadProxy.messages.in:
        Add DidReceiveAuthenticationChallenge message.

        * UIProcess/WebDownloadClient.cpp:
        (WebKit::WebDownloadClient::didReceiveAuthenticationChallenge):
        Call the client callback function.

        * UIProcess/WebDownloadClient.h:
        * WebProcess/Authentication/AuthenticationManager.cpp:
        (WebKit::AuthenticationManager::didReceiveAuthenticationChallenge):
        Send the DidReceiveAuthenticationChallenge message to the download proxy.

        (WebKit::AuthenticationManager::useCredentialForChallenge):
        (WebKit::AuthenticationManager::continueWithoutCredentialForChallenge):
        (WebKit::AuthenticationManager::cancelChallenge):
        If the authentication client is null, call the static download member functions.

        * WebProcess/Authentication/AuthenticationManager.h:
        * WebProcess/Downloads/Download.cpp:
        (WebKit::Download::didReceiveAuthenticationChallenge):
        Call the authentication manager.

        * WebProcess/Downloads/Download.h:
        * WebProcess/Downloads/mac/DownloadMac.mm:
        (WebKit::Download::receivedCredential):
        (WebKit::Download::receivedRequestToContinueWithoutCredential):
        (WebKit::Download::receivedCancellation):
        Call the right sender methods.

        (-[WKDownloadAsDelegate download:didReceiveAuthenticationChallenge:]):
        (-[WKDownloadAsDelegate downloadShouldUseCredentialStorage:]):
        Call the right Download member functions.

        * WebProcess/Downloads/qt/DownloadQt.cpp:
        (WebKit::Download::receivedCredential):
        (WebKit::Download::receivedRequestToContinueWithoutCredential):
        (WebKit::Download::receivedCancellation):
        * WebProcess/Downloads/soup/DownloadSoup.cpp:
        (WebKit::Download::receivedCredential):
        (WebKit::Download::receivedRequestToContinueWithoutCredential):
        (WebKit::Download::receivedCancellation):
        Add stubs.

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

14 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKContext.h
Source/WebKit2/UIProcess/Downloads/DownloadProxy.cpp
Source/WebKit2/UIProcess/Downloads/DownloadProxy.h
Source/WebKit2/UIProcess/Downloads/DownloadProxy.messages.in
Source/WebKit2/UIProcess/WebDownloadClient.cpp
Source/WebKit2/UIProcess/WebDownloadClient.h
Source/WebKit2/WebProcess/Authentication/AuthenticationManager.cpp
Source/WebKit2/WebProcess/Authentication/AuthenticationManager.h
Source/WebKit2/WebProcess/Downloads/Download.cpp
Source/WebKit2/WebProcess/Downloads/Download.h
Source/WebKit2/WebProcess/Downloads/mac/DownloadMac.mm
Source/WebKit2/WebProcess/Downloads/qt/DownloadQt.cpp
Source/WebKit2/WebProcess/Downloads/soup/DownloadSoup.cpp

index f2f4e12..25c524a 100644 (file)
@@ -2,6 +2,64 @@
 
         Reviewed by Sam Weinig.
 
+        Downloads: Authentication support
+        https://bugs.webkit.org/show_bug.cgi?id=57403
+        <rdar://problem/8691166>
+
+        * UIProcess/API/C/WKContext.h:
+        Add didReceiveAuthenticationChallenge callback.
+
+        * UIProcess/Downloads/DownloadProxy.cpp:
+        (WebKit::DownloadProxy::didReceiveAuthenticationChallenge):
+        Call the download client.
+
+        * UIProcess/Downloads/DownloadProxy.messages.in:
+        Add DidReceiveAuthenticationChallenge message.
+
+        * UIProcess/WebDownloadClient.cpp:
+        (WebKit::WebDownloadClient::didReceiveAuthenticationChallenge):
+        Call the client callback function.
+
+        * UIProcess/WebDownloadClient.h:
+        * WebProcess/Authentication/AuthenticationManager.cpp:
+        (WebKit::AuthenticationManager::didReceiveAuthenticationChallenge):
+        Send the DidReceiveAuthenticationChallenge message to the download proxy.
+
+        (WebKit::AuthenticationManager::useCredentialForChallenge):
+        (WebKit::AuthenticationManager::continueWithoutCredentialForChallenge):
+        (WebKit::AuthenticationManager::cancelChallenge):
+        If the authentication client is null, call the static download member functions.
+
+        * WebProcess/Authentication/AuthenticationManager.h:
+        * WebProcess/Downloads/Download.cpp:
+        (WebKit::Download::didReceiveAuthenticationChallenge):
+        Call the authentication manager.
+
+        * WebProcess/Downloads/Download.h:
+        * WebProcess/Downloads/mac/DownloadMac.mm:
+        (WebKit::Download::receivedCredential):
+        (WebKit::Download::receivedRequestToContinueWithoutCredential):
+        (WebKit::Download::receivedCancellation):
+        Call the right sender methods.
+
+        (-[WKDownloadAsDelegate download:didReceiveAuthenticationChallenge:]):
+        (-[WKDownloadAsDelegate downloadShouldUseCredentialStorage:]):
+        Call the right Download member functions.
+
+        * WebProcess/Downloads/qt/DownloadQt.cpp:
+        (WebKit::Download::receivedCredential):
+        (WebKit::Download::receivedRequestToContinueWithoutCredential):
+        (WebKit::Download::receivedCancellation):
+        * WebProcess/Downloads/soup/DownloadSoup.cpp:
+        (WebKit::Download::receivedCredential):
+        (WebKit::Download::receivedRequestToContinueWithoutCredential):
+        (WebKit::Download::receivedCancellation):
+        Add stubs.
+
+2011-03-29  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
         AuthenticationChallengeProxy objects should be associated with processes, not pages
         https://bugs.webkit.org/show_bug.cgi?id=57401
 
index 70a50bd..606574f 100644 (file)
@@ -77,6 +77,7 @@ typedef struct WKContextHistoryClient WKContextHistoryClient;
 
 // Download Client
 typedef void (*WKContextDownloadDidStartCallback)(WKContextRef context, WKDownloadRef download, const void *clientInfo);
+typedef void (*WKContextDownloadDidReceiveAuthenticationChallengeCallback)(WKContextRef context, WKDownloadRef download, WKAuthenticationChallengeRef authenticationChallenge, const void *clientInfo);
 typedef void (*WKContextDownloadDidReceiveResponseCallback)(WKContextRef context, WKDownloadRef download, WKURLResponseRef response, const void *clientInfo);
 typedef void (*WKContextDownloadDidReceiveDataCallback)(WKContextRef context, WKDownloadRef download, uint64_t length, const void *clientInfo);
 typedef bool (*WKContextDownloadShouldDecodeSourceDataOfMIMETypeCallback)(WKContextRef context, WKDownloadRef download, WKStringRef mimeType, const void *clientInfo);
@@ -91,6 +92,7 @@ struct WKContextDownloadClient {
     int                                                                 version;
     const void *                                                        clientInfo;
     WKContextDownloadDidStartCallback                                   didStart;
+    WKContextDownloadDidReceiveAuthenticationChallengeCallback          didReceiveAuthenticationChallenge;
     WKContextDownloadDidReceiveResponseCallback                         didReceiveResponse;
     WKContextDownloadDidReceiveDataCallback                             didReceiveData;
     WKContextDownloadShouldDecodeSourceDataOfMIMETypeCallback           shouldDecodeSourceDataOfMIMEType;
index 55168bc..ad61d33 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "DownloadProxy.h"
 
+#include "AuthenticationChallengeProxy.h"
 #include "DataReference.h"
 #include "WebContext.h"
 #include "WebData.h"
@@ -91,6 +92,15 @@ void DownloadProxy::didStart(const ResourceRequest& request)
     m_webContext->downloadClient().didStart(m_webContext, this);
 }
 
+void DownloadProxy::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge, uint64_t challengeID)
+{
+    if (!m_webContext)
+        return;
+
+    RefPtr<AuthenticationChallengeProxy> authenticationChallengeProxy = AuthenticationChallengeProxy::create(authenticationChallenge, challengeID, m_webContext->process());
+    m_webContext->downloadClient().didReceiveAuthenticationChallenge(m_webContext, this, authenticationChallengeProxy.get());
+}
+
 void DownloadProxy::didReceiveResponse(const ResourceResponse& response)
 {
     if (!m_webContext)
index a155d72..2643173 100644 (file)
@@ -34,6 +34,7 @@
 #include <wtf/PassRefPtr.h>
 
 namespace WebCore {
+    class AuthenticationChallenge;
     class ResourceError;
     class ResourceResponse;
 }
@@ -69,6 +70,7 @@ private:
 
     // Message handlers.
     void didStart(const WebCore::ResourceRequest&);
+    void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&, uint64_t challengeID);
     void didReceiveResponse(const WebCore::ResourceResponse&);
     void didReceiveData(uint64_t length);
     void shouldDecodeSourceDataOfMIMEType(const String& mimeType, bool& result);
index 999080b..d725599 100644 (file)
@@ -22,6 +22,8 @@
 
 messages -> DownloadProxy {
     DidStart(WebCore::ResourceRequest request)
+    DidReceiveAuthenticationChallenge(WebCore::AuthenticationChallenge challenge, uint64_t challengeID)
+
     DidReceiveResponse(WebCore::ResourceResponse response)
     DidReceiveData(uint64_t length)
     ShouldDecodeSourceDataOfMIMEType(String mimeType) -> (bool result)
index 4b1b756..612a056 100644 (file)
@@ -42,6 +42,14 @@ void WebDownloadClient::didStart(WebContext* webContext, DownloadProxy* download
     m_client.didStart(toAPI(webContext), toAPI(downloadProxy), m_client.clientInfo);
 }
 
+void WebDownloadClient::didReceiveAuthenticationChallenge(WebContext* webContext, DownloadProxy* downloadProxy, AuthenticationChallengeProxy* authenticationChallengeProxy)
+{
+    if (!m_client.didReceiveAuthenticationChallenge)
+        return;
+
+    m_client.didReceiveAuthenticationChallenge(toAPI(webContext), toAPI(downloadProxy), toAPI(authenticationChallengeProxy), m_client.clientInfo);
+}
+
 void WebDownloadClient::didReceiveResponse(WebContext* webContext, DownloadProxy* downloadProxy, const ResourceResponse& response)
 {
     if (!m_client.didReceiveResponse)
index 902c870..46010a1 100644 (file)
@@ -37,12 +37,14 @@ namespace WebCore {
 
 namespace WebKit {
 
+class AuthenticationChallengeProxy;
 class DownloadProxy;
 class WebContext;
 
 class WebDownloadClient : public APIClient<WKContextDownloadClient> {
 public:
     void didStart(WebContext*, DownloadProxy*);
+    void didReceiveAuthenticationChallenge(WebContext*, DownloadProxy*, AuthenticationChallengeProxy*);
     void didReceiveResponse(WebContext*, DownloadProxy*, const WebCore::ResourceResponse&);
     void didReceiveData(WebContext*, DownloadProxy*, uint64_t length);
     bool shouldDecodeSourceDataOfMIMEType(WebContext*, DownloadProxy*, const String& mimeType);
index af35f75..e7550d0 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "AuthenticationManager.h"
 
+#include "Download.h"
+#include "DownloadProxyMessages.h"
 #include "MessageID.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebFrame.h"
@@ -35,6 +37,8 @@
 #include <WebCore/AuthenticationChallenge.h>
 #include <WebCore/AuthenticationClient.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
 static uint64_t generateAuthenticationChallengeID()
@@ -58,46 +62,64 @@ void AuthenticationManager::didReceiveMessage(CoreIPC::Connection* connection, C
     didReceiveAuthenticationManagerMessage(connection, messageID, arguments);
 }
 
-void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const WebCore::AuthenticationChallenge& authenticationChallenge)
+void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const AuthenticationChallenge& authenticationChallenge)
 {
     ASSERT(frame);
     ASSERT(frame->page());
 
-    uint64_t id = generateAuthenticationChallengeID();
-    m_challenges.set(id, authenticationChallenge);    
+    uint64_t challengeID = generateAuthenticationChallengeID();
+    m_challenges.set(challengeID, authenticationChallenge);    
     
-    WebProcess::shared().connection()->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, id), frame->page()->pageID());
+    WebProcess::shared().connection()->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, challengeID), frame->page()->pageID());
+}
+
+void AuthenticationManager::didReceiveAuthenticationChallenge(Download* download, const AuthenticationChallenge& authenticationChallenge)
+{
+    uint64_t challengeID = generateAuthenticationChallengeID();
+    m_challenges.set(challengeID, authenticationChallenge);
+
+    download->send(Messages::DownloadProxy::DidReceiveAuthenticationChallenge(authenticationChallenge, challengeID));
 }
 
-void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const WebCore::Credential& credential)
+void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const Credential& credential)
 {
-    WebCore::AuthenticationChallenge challenge = m_challenges.take(challengeID);
+    AuthenticationChallenge challenge = m_challenges.take(challengeID);
     ASSERT(!challenge.isNull());
-    WebCore::AuthenticationClient* coreClient = challenge.authenticationClient();
-    if (!coreClient)
+    AuthenticationClient* coreClient = challenge.authenticationClient();
+    if (!coreClient) {
+        // This authentication challenge comes from a download.
+        Download::receivedCredential(challenge, credential);
         return;
+        
+    }
 
     coreClient->receivedCredential(challenge, credential);
 }
 
 void AuthenticationManager::continueWithoutCredentialForChallenge(uint64_t challengeID)
 {
-    WebCore::AuthenticationChallenge challenge = m_challenges.take(challengeID);
+    AuthenticationChallenge challenge = m_challenges.take(challengeID);
     ASSERT(!challenge.isNull());
-    WebCore::AuthenticationClient* coreClient = challenge.authenticationClient();
-    if (!coreClient)
+    AuthenticationClient* coreClient = challenge.authenticationClient();
+    if (!coreClient) {
+        // This authentication challenge comes from a download.
+        Download::receivedRequestToContinueWithoutCredential(challenge);
         return;
+    }
 
     coreClient->receivedRequestToContinueWithoutCredential(challenge);
 }
 
 void AuthenticationManager::cancelChallenge(uint64_t challengeID)
 {
-    WebCore::AuthenticationChallenge challenge = m_challenges.take(challengeID);
+    AuthenticationChallenge challenge = m_challenges.take(challengeID);
     ASSERT(!challenge.isNull());
-    WebCore::AuthenticationClient* coreClient = challenge.authenticationClient();
-    if (!coreClient)
+    AuthenticationClient* coreClient = challenge.authenticationClient();
+    if (!coreClient) {
+        // This authentication challenge comes from a download.
+        Download::receivedCancellation(challenge);
         return;
+    }
 
     coreClient->receivedCancellation(challenge);
 }
index ce5ff1c..2c67430 100644 (file)
@@ -41,6 +41,7 @@ namespace WebCore {
 
 namespace WebKit {
 
+class Download;
 class WebFrame;
 
 class AuthenticationManager {
@@ -52,6 +53,7 @@ public:
     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
 
     void didReceiveAuthenticationChallenge(WebFrame*, const WebCore::AuthenticationChallenge&);
+    void didReceiveAuthenticationChallenge(Download*, const WebCore::AuthenticationChallenge&);
 
     void useCredentialForChallenge(uint64_t challengeID, const WebCore::Credential&);
     void continueWithoutCredentialForChallenge(uint64_t challengeID);
index 1c36df2..3fc87d9 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "Download.h"
 
+#include "AuthenticationManager.h"
 #include "Connection.h"
 #include "DataReference.h"
 #include "DownloadProxyMessages.h"
@@ -68,6 +69,11 @@ void Download::didStart()
     send(Messages::DownloadProxy::DidStart(m_request));
 }
 
+void Download::didReceiveAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge)
+{
+    AuthenticationManager::shared().didReceiveAuthenticationChallenge(this, authenticationChallenge);
+}
+
 void Download::didReceiveResponse(const ResourceResponse& response)
 {
     send(Messages::DownloadProxy::DidReceiveResponse(response));
index 4ec7d96..780e8c2 100644 (file)
@@ -47,6 +47,8 @@ namespace CoreIPC {
 }
 
 namespace WebCore {
+    class AuthenticationChallenge;
+    class Credential;
     class ResourceError;
     class ResourceHandle;
     class ResourceResponse;
@@ -74,6 +76,7 @@ public:
     uint64_t downloadID() const { return m_downloadID; }
 
     void didStart();
+    void didReceiveAuthenticationChallenge(const WebCore::AuthenticationChallenge&);
     void didReceiveResponse(const WebCore::ResourceResponse&);
     void didReceiveData(uint64_t length);
     bool shouldDecodeSourceDataOfMIMEType(const String& mimeType);
@@ -89,6 +92,11 @@ public:
     const String& destination() const { return m_destination; }
 #endif
 
+    // Authentication
+    static void receivedCredential(const WebCore::AuthenticationChallenge&, const WebCore::Credential&);
+    static void receivedRequestToContinueWithoutCredential(const WebCore::AuthenticationChallenge&);
+    static void receivedCancellation(const WebCore::AuthenticationChallenge&);
+
 private:
     Download(uint64_t downloadID, const WebCore::ResourceRequest&);
 
index f7fe8dc..2d09612 100644 (file)
@@ -26,6 +26,7 @@
 #import "config.h"
 #import "Download.h"
 
+#import <WebCore/AuthenticationMac.h>
 #import <WebCore/BackForwardController.h>
 #import <WebCore/HistoryItem.h>
 #import <WebCore/NotImplemented.h>
@@ -177,6 +178,21 @@ void Download::platformDidFinish()
 {
 }
 
+void Download::receivedCredential(const AuthenticationChallenge& authenticationChallenge, const Credential& credential)
+{
+    [authenticationChallenge.sender() useCredential:mac(credential) forAuthenticationChallenge:authenticationChallenge.nsURLAuthenticationChallenge()];
+}
+
+void Download::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& authenticationChallenge)
+{
+    [authenticationChallenge.sender() continueWithoutCredentialForAuthenticationChallenge:authenticationChallenge.nsURLAuthenticationChallenge()];
+}
+
+void Download::receivedCancellation(const AuthenticationChallenge& authenticationChallenge)
+{
+    [authenticationChallenge.sender() cancelAuthenticationChallenge:authenticationChallenge.nsURLAuthenticationChallenge()];
+}
+
 } // namespace WebKit
 
 @implementation WKDownloadAsDelegate
@@ -216,8 +232,8 @@ void Download::platformDidFinish()
 
 - (void)download:(NSURLDownload *)download didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
 {
-    // FIXME: Implement.
-    notImplemented();
+    if (_download)
+        _download->didReceiveAuthenticationChallenge(core(challenge));
 }
 
 - (void)download:(NSURLDownload *)download didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
@@ -228,9 +244,7 @@ void Download::platformDidFinish()
 
 - (BOOL)downloadShouldUseCredentialStorage:(NSURLDownload *)download
 {
-    // FIXME: Implement.
-    notImplemented();
-    return YES;
+    return NO;
 }
 
 - (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
index 19b86f0..ad5e7de 100644 (file)
@@ -62,4 +62,19 @@ void Download::platformDidFinish()
     notImplemented();
 }
 
+void Download::receivedCredential(const AuthenticationChallenge& authenticationChallenge, const Credential& credential)
+{
+    notImplemented();
+}
+
+void Download::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& authenticationChallenge)
+{
+    notImplemented();
+}
+
+void Download::receivedCancellation(const AuthenticationChallenge& authenticationChallenge)
+{
+    notImplemented();
+}
+
 } // namespace WebKit
index 6ebce01..a228916 100644 (file)
@@ -63,4 +63,19 @@ void Download::platformDidFinish()
     notImplemented();
 }
 
+void Download::receivedCredential(const AuthenticationChallenge& authenticationChallenge, const Credential& credential)
+{
+    notImplemented();
+}
+
+void Download::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& authenticationChallenge)
+{
+    notImplemented();
+}
+
+void Download::receivedCancellation(const AuthenticationChallenge& authenticationChallenge)
+{
+    notImplemented();
+}
+
 } // namespace WebKit