• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "config.h"
27 #include "AuthenticationManager.h"
28 
29 #include "Download.h"
30 #include "DownloadProxyMessages.h"
31 #include "MessageID.h"
32 #include "WebCoreArgumentCoders.h"
33 #include "WebFrame.h"
34 #include "WebPage.h"
35 #include "WebPageProxyMessages.h"
36 #include "WebProcess.h"
37 #include <WebCore/AuthenticationChallenge.h>
38 #include <WebCore/AuthenticationClient.h>
39 
40 using namespace WebCore;
41 
42 namespace WebKit {
43 
generateAuthenticationChallengeID()44 static uint64_t generateAuthenticationChallengeID()
45 {
46     static uint64_t uniqueAuthenticationChallengeID = 1;
47     return uniqueAuthenticationChallengeID++;
48 }
49 
shared()50 AuthenticationManager& AuthenticationManager::shared()
51 {
52     static AuthenticationManager& manager = *new AuthenticationManager;
53     return manager;
54 }
55 
AuthenticationManager()56 AuthenticationManager::AuthenticationManager()
57 {
58 }
59 
didReceiveMessage(CoreIPC::Connection * connection,CoreIPC::MessageID messageID,CoreIPC::ArgumentDecoder * arguments)60 void AuthenticationManager::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
61 {
62     didReceiveAuthenticationManagerMessage(connection, messageID, arguments);
63 }
64 
didReceiveAuthenticationChallenge(WebFrame * frame,const AuthenticationChallenge & authenticationChallenge)65 void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const AuthenticationChallenge& authenticationChallenge)
66 {
67     ASSERT(frame);
68     ASSERT(frame->page());
69 
70     uint64_t challengeID = generateAuthenticationChallengeID();
71     m_challenges.set(challengeID, authenticationChallenge);
72 
73     WebProcess::shared().connection()->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, challengeID), frame->page()->pageID());
74 }
75 
didReceiveAuthenticationChallenge(Download * download,const AuthenticationChallenge & authenticationChallenge)76 void AuthenticationManager::didReceiveAuthenticationChallenge(Download* download, const AuthenticationChallenge& authenticationChallenge)
77 {
78     uint64_t challengeID = generateAuthenticationChallengeID();
79     m_challenges.set(challengeID, authenticationChallenge);
80 
81     download->send(Messages::DownloadProxy::DidReceiveAuthenticationChallenge(authenticationChallenge, challengeID));
82 }
83 
useCredentialForChallenge(uint64_t challengeID,const Credential & credential)84 void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const Credential& credential)
85 {
86     AuthenticationChallenge challenge = m_challenges.take(challengeID);
87     ASSERT(!challenge.isNull());
88     AuthenticationClient* coreClient = challenge.authenticationClient();
89     if (!coreClient) {
90         // This authentication challenge comes from a download.
91         Download::receivedCredential(challenge, credential);
92         return;
93 
94     }
95 
96     coreClient->receivedCredential(challenge, credential);
97 }
98 
continueWithoutCredentialForChallenge(uint64_t challengeID)99 void AuthenticationManager::continueWithoutCredentialForChallenge(uint64_t challengeID)
100 {
101     AuthenticationChallenge challenge = m_challenges.take(challengeID);
102     ASSERT(!challenge.isNull());
103     AuthenticationClient* coreClient = challenge.authenticationClient();
104     if (!coreClient) {
105         // This authentication challenge comes from a download.
106         Download::receivedRequestToContinueWithoutCredential(challenge);
107         return;
108     }
109 
110     coreClient->receivedRequestToContinueWithoutCredential(challenge);
111 }
112 
cancelChallenge(uint64_t challengeID)113 void AuthenticationManager::cancelChallenge(uint64_t challengeID)
114 {
115     AuthenticationChallenge challenge = m_challenges.take(challengeID);
116     ASSERT(!challenge.isNull());
117     AuthenticationClient* coreClient = challenge.authenticationClient();
118     if (!coreClient) {
119         // This authentication challenge comes from a download.
120         Download::receivedCancellation(challenge);
121         return;
122     }
123 
124     coreClient->receivedCancellation(challenge);
125 }
126 
127 } // namespace WebKit
128