2 * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "AuthenticationManager.h"
29 #include "AuthenticationManagerMessages.h"
30 #include "ChildProcess.h"
32 #include "DownloadProxyMessages.h"
33 #include "WebCoreArgumentCoders.h"
36 #include "WebPageProxyMessages.h"
37 #include <WebCore/AuthenticationChallenge.h>
38 #include <WebCore/AuthenticationClient.h>
39 #include <wtf/Atomics.h>
41 #if ENABLE(NETWORK_PROCESS)
42 #include "NetworkProcessProxyMessages.h"
45 using namespace WebCore;
49 static uint64_t generateAuthenticationChallengeID()
51 static int64_t uniqueAuthenticationChallengeID;
52 return atomicIncrement(&uniqueAuthenticationChallengeID);
55 const char* AuthenticationManager::supplementName()
57 return "AuthenticationManager";
60 AuthenticationManager::AuthenticationManager(ChildProcess* process)
63 m_process->addMessageReceiver(Messages::AuthenticationManager::messageReceiverName(), this);
66 uint64_t AuthenticationManager::establishIdentifierForChallenge(const WebCore::AuthenticationChallenge& authenticationChallenge)
68 uint64_t challengeID = generateAuthenticationChallengeID();
69 m_challenges.set(challengeID, authenticationChallenge);
73 void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const AuthenticationChallenge& authenticationChallenge)
76 ASSERT(frame->page());
78 m_process->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)), frame->page()->pageID());
81 #if ENABLE(NETWORK_PROCESS)
82 void AuthenticationManager::didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const AuthenticationChallenge& authenticationChallenge)
87 m_process->send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(pageID, frameID, authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
91 void AuthenticationManager::didReceiveAuthenticationChallenge(Download* download, const AuthenticationChallenge& authenticationChallenge)
93 download->send(Messages::DownloadProxy::DidReceiveAuthenticationChallenge(authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
96 // Currently, only Mac knows how to respond to authentication challenges with certificate info.
97 #if !USE(SECURITY_FRAMEWORK)
98 bool AuthenticationManager::tryUsePlatformCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const PlatformCertificateInfo&)
104 void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const Credential& credential, const PlatformCertificateInfo& certificateInfo)
106 AuthenticationChallenge challenge = m_challenges.take(challengeID);
107 ASSERT(!challenge.isNull());
109 if (tryUsePlatformCertificateInfoForChallenge(challenge, certificateInfo))
112 AuthenticationClient* coreClient = challenge.authenticationClient();
114 // This authentication challenge comes from a download.
115 Download::receivedCredential(challenge, credential);
119 coreClient->receivedCredential(challenge, credential);
122 void AuthenticationManager::continueWithoutCredentialForChallenge(uint64_t challengeID)
124 AuthenticationChallenge challenge = m_challenges.take(challengeID);
125 ASSERT(!challenge.isNull());
126 AuthenticationClient* coreClient = challenge.authenticationClient();
128 // This authentication challenge comes from a download.
129 Download::receivedRequestToContinueWithoutCredential(challenge);
133 coreClient->receivedRequestToContinueWithoutCredential(challenge);
136 void AuthenticationManager::cancelChallenge(uint64_t challengeID)
138 AuthenticationChallenge challenge = m_challenges.take(challengeID);
139 ASSERT(!challenge.isNull());
140 AuthenticationClient* coreClient = challenge.authenticationClient();
142 // This authentication challenge comes from a download.
143 Download::receivedCancellation(challenge);
147 coreClient->receivedCancellation(challenge);
150 } // namespace WebKit