2 * Copyright (C) 2007 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 COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebKitDLL.h"
28 #include "WebURLAuthenticationChallenge.h"
32 #include "WebURLAuthenticationChallengeSender.h"
33 #include "WebURLCredential.h"
34 #include "WebURLProtectionSpace.h"
35 #include "WebURLResponse.h"
37 #include <WebCore/BString.h>
38 #include <WebCore/COMPtr.h>
39 #include <WebCore/ResourceHandle.h>
41 using namespace WebCore;
43 // WebURLAuthenticationChallenge ----------------------------------------------------------------
45 WebURLAuthenticationChallenge::WebURLAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge,
46 IWebURLAuthenticationChallengeSender* sender)
48 , m_authenticationChallenge(authenticationChallenge)
52 gClassNameCount.add("WebURLAuthenticationChallenge");
55 WebURLAuthenticationChallenge::~WebURLAuthenticationChallenge()
58 gClassNameCount.remove("WebURLAuthenticationChallenge");
61 WebURLAuthenticationChallenge* WebURLAuthenticationChallenge::createInstance(const AuthenticationChallenge& authenticationChallenge)
63 WebURLAuthenticationChallenge* instance = new WebURLAuthenticationChallenge(authenticationChallenge, 0);
68 WebURLAuthenticationChallenge* WebURLAuthenticationChallenge::createInstance(const AuthenticationChallenge& authenticationChallenge,
69 IWebURLAuthenticationChallengeSender* sender)
71 WebURLAuthenticationChallenge* instance = new WebURLAuthenticationChallenge(authenticationChallenge, sender);
76 // IUnknown -------------------------------------------------------------------
78 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::QueryInterface(REFIID riid, void** ppvObject)
81 if (IsEqualGUID(riid, IID_IUnknown))
82 *ppvObject = static_cast<IUnknown*>(this);
83 else if (IsEqualGUID(riid, __uuidof(this)))
84 *ppvObject = static_cast<WebURLAuthenticationChallenge*>(this);
85 else if (IsEqualGUID(riid, IID_IWebURLAuthenticationChallenge))
86 *ppvObject = static_cast<IWebURLAuthenticationChallenge*>(this);
94 ULONG STDMETHODCALLTYPE WebURLAuthenticationChallenge::AddRef(void)
99 ULONG STDMETHODCALLTYPE WebURLAuthenticationChallenge::Release(void)
101 ULONG newRef = --m_refCount;
108 // IWebURLAuthenticationChallenge -------------------------------------------------------------------
110 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::initWithProtectionSpace(
111 /* [in] */ IWebURLProtectionSpace* space,
112 /* [in] */ IWebURLCredential* proposedCredential,
113 /* [in] */ int previousFailureCount,
114 /* [in] */ IWebURLResponse* failureResponse,
115 /* [in] */ IWebError* error,
116 /* [in] */ IWebURLAuthenticationChallengeSender* sender)
118 LOG_ERROR("Calling the ala carte init for WebURLAuthenticationChallenge - is this really what you want to do?");
120 if (!space || !proposedCredential || !failureResponse || !sender)
124 COMPtr<WebURLProtectionSpace> webSpace;
125 hr = space->QueryInterface(&webSpace);
129 COMPtr<WebURLCredential> webCredential(Query, proposedCredential);
131 return E_NOINTERFACE;
133 COMPtr<WebURLResponse> webResponse;
134 hr = failureResponse->QueryInterface(&webResponse);
138 COMPtr<WebError> webError;
139 hr = error->QueryInterface(CLSID_WebError, (void**)&webError);
143 COMPtr<WebURLAuthenticationChallengeSender> webSender(Query, sender);
145 return E_NOINTERFACE;
147 // FIXME: After we change AuthenticationChallenge to use "ResourceHandle" as the abstract "Sender" or "Source of this Auth Challenge", then we'll
148 // construct the AuthenticationChallenge with that as obtained from the webSender
150 m_authenticationChallenge = AuthenticationChallenge(webSpace->protectionSpace(), webCredential->credential(),
151 previousFailureCount, webResponse->resourceResponse(), webError->resourceError());
156 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::initWithAuthenticationChallenge(
157 /* [in] */ IWebURLAuthenticationChallenge* challenge,
158 /* [in] */ IWebURLAuthenticationChallengeSender* sender)
160 if (!challenge || !sender)
163 COMPtr<WebURLAuthenticationChallenge> webChallenge(Query, challenge);
165 return E_NOINTERFACE;
167 COMPtr<WebURLAuthenticationChallengeSender> webSender(Query, sender);
169 return E_NOINTERFACE;
172 m_authenticationChallenge = AuthenticationChallenge(webChallenge->authenticationChallenge().cfURLAuthChallengeRef(), webSender->authenticationClient());
181 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::error(
182 /* [out, retval] */ IWebError** result)
184 *result = WebError::createInstance(m_authenticationChallenge.error());
188 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::failureResponse(
189 /* [out, retval] */ IWebURLResponse** result)
191 *result = WebURLResponse::createInstance(m_authenticationChallenge.failureResponse());
195 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::previousFailureCount(
196 /* [out, retval] */ UINT* result)
198 *result = m_authenticationChallenge.previousFailureCount();
202 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::proposedCredential(
203 /* [out, retval] */ IWebURLCredential** result)
205 *result = WebURLCredential::createInstance(m_authenticationChallenge.proposedCredential());
209 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::protectionSpace(
210 /* [out, retval] */ IWebURLProtectionSpace** result)
212 *result = WebURLProtectionSpace::createInstance(m_authenticationChallenge.protectionSpace());
216 HRESULT STDMETHODCALLTYPE WebURLAuthenticationChallenge::sender(
217 /* [out, retval] */ IWebURLAuthenticationChallengeSender** sender)
220 AuthenticationClient* client = m_authenticationChallenge.authenticationClient();
221 m_sender.adoptRef(WebURLAuthenticationChallengeSender::createInstance(client));
224 return m_sender.copyRefTo(sender);
227 // WebURLAuthenticationChallenge -------------------------------------------------------------------
228 const AuthenticationChallenge& WebURLAuthenticationChallenge::authenticationChallenge() const
230 return m_authenticationChallenge;