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>
40 #if ENABLE(NETWORK_PROCESS)
41 #include "NetworkProcessProxyMessages.h"
44 using namespace WebCore;
48 static uint64_t generateAuthenticationChallengeID()
50 ASSERT(isMainThread());
52 static int64_t uniqueAuthenticationChallengeID;
53 return ++uniqueAuthenticationChallengeID;
56 const char* AuthenticationManager::supplementName()
58 return "AuthenticationManager";
61 AuthenticationManager::AuthenticationManager(ChildProcess* process)
64 m_process->addMessageReceiver(Messages::AuthenticationManager::messageReceiverName(), this);
67 uint64_t AuthenticationManager::establishIdentifierForChallenge(const WebCore::AuthenticationChallenge& authenticationChallenge)
69 ASSERT(isMainThread());
71 uint64_t challengeID = generateAuthenticationChallengeID();
72 m_challenges.set(challengeID, authenticationChallenge);
76 void AuthenticationManager::didReceiveAuthenticationChallenge(WebFrame* frame, const AuthenticationChallenge& authenticationChallenge)
79 ASSERT(frame->page());
81 m_process->send(Messages::WebPageProxy::DidReceiveAuthenticationChallenge(frame->frameID(), authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)), frame->page()->pageID());
84 #if ENABLE(NETWORK_PROCESS)
85 void AuthenticationManager::didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const AuthenticationChallenge& authenticationChallenge)
90 m_process->send(Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge(pageID, frameID, authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
94 void AuthenticationManager::didReceiveAuthenticationChallenge(Download* download, const AuthenticationChallenge& authenticationChallenge)
96 download->send(Messages::DownloadProxy::DidReceiveAuthenticationChallenge(authenticationChallenge, establishIdentifierForChallenge(authenticationChallenge)));
99 // Currently, only Mac knows how to respond to authentication challenges with certificate info.
100 #if !USE(SECURITY_FRAMEWORK)
101 bool AuthenticationManager::tryUsePlatformCertificateInfoForChallenge(const WebCore::AuthenticationChallenge&, const PlatformCertificateInfo&)
107 void AuthenticationManager::useCredentialForChallenge(uint64_t challengeID, const Credential& credential, const PlatformCertificateInfo& certificateInfo)
109 ASSERT(isMainThread());
111 AuthenticationChallenge challenge = m_challenges.take(challengeID);
112 ASSERT(!challenge.isNull());
114 if (tryUsePlatformCertificateInfoForChallenge(challenge, certificateInfo))
117 AuthenticationClient* coreClient = challenge.authenticationClient();
119 // This authentication challenge comes from a download.
120 Download::receivedCredential(challenge, credential);
124 coreClient->receivedCredential(challenge, credential);
127 void AuthenticationManager::continueWithoutCredentialForChallenge(uint64_t challengeID)
129 ASSERT(isMainThread());
131 AuthenticationChallenge challenge = m_challenges.take(challengeID);
132 ASSERT(!challenge.isNull());
133 AuthenticationClient* coreClient = challenge.authenticationClient();
135 // This authentication challenge comes from a download.
136 Download::receivedRequestToContinueWithoutCredential(challenge);
140 coreClient->receivedRequestToContinueWithoutCredential(challenge);
143 void AuthenticationManager::cancelChallenge(uint64_t challengeID)
145 ASSERT(isMainThread());
147 AuthenticationChallenge challenge = m_challenges.take(challengeID);
148 ASSERT(!challenge.isNull());
149 AuthenticationClient* coreClient = challenge.authenticationClient();
151 // This authentication challenge comes from a download.
152 Download::receivedCancellation(challenge);
156 coreClient->receivedCancellation(challenge);
159 } // namespace WebKit