WebURLAuthenticationChallenge.cpp [plain text]
#include "WebKitDLL.h"
#include "WebURLAuthenticationChallenge.h"
#include "WebError.h"
#include "WebKit.h"
#include "WebURLAuthenticationChallengeSender.h"
#include "WebURLCredential.h"
#include "WebURLProtectionSpace.h"
#include "WebURLResponse.h"
#include "WebKit.h"
#include <WebCore/BString.h>
#include <WebCore/COMPtr.h>
#include <WebCore/ResourceHandle.h>
using namespace WebCore;
WebURLAuthenticationChallenge::WebURLAuthenticationChallenge(const AuthenticationChallenge& authenticationChallenge, IWebURLAuthenticationChallengeSender* sender)
: m_authenticationChallenge(authenticationChallenge)
, m_sender(sender)
{
gClassCount++;
gClassNameCount().add("WebURLAuthenticationChallenge");
}
WebURLAuthenticationChallenge::~WebURLAuthenticationChallenge()
{
gClassCount--;
gClassNameCount().remove("WebURLAuthenticationChallenge");
}
WebURLAuthenticationChallenge* WebURLAuthenticationChallenge::createInstance(const AuthenticationChallenge& authenticationChallenge)
{
WebURLAuthenticationChallenge* instance = new WebURLAuthenticationChallenge(authenticationChallenge, 0);
instance->AddRef();
return instance;
}
WebURLAuthenticationChallenge* WebURLAuthenticationChallenge::createInstance(const AuthenticationChallenge& authenticationChallenge,
IWebURLAuthenticationChallengeSender* sender)
{
WebURLAuthenticationChallenge* instance = new WebURLAuthenticationChallenge(authenticationChallenge, sender);
instance->AddRef();
return instance;
}
HRESULT WebURLAuthenticationChallenge::QueryInterface(_In_ REFIID riid, _COM_Outptr_ void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = nullptr;
if (IsEqualGUID(riid, IID_IUnknown))
*ppvObject = static_cast<IUnknown*>(this);
else if (IsEqualGUID(riid, __uuidof(this)))
*ppvObject = static_cast<WebURLAuthenticationChallenge*>(this);
else if (IsEqualGUID(riid, IID_IWebURLAuthenticationChallenge))
*ppvObject = static_cast<IWebURLAuthenticationChallenge*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
ULONG WebURLAuthenticationChallenge::AddRef()
{
return ++m_refCount;
}
ULONG WebURLAuthenticationChallenge::Release()
{
ULONG newRef = --m_refCount;
if (!newRef)
delete(this);
return newRef;
}
HRESULT WebURLAuthenticationChallenge::initWithProtectionSpace(_In_opt_ IWebURLProtectionSpace* space,
_In_opt_ IWebURLCredential* proposedCredential, int previousFailureCount, _In_opt_ IWebURLResponse* failureResponse,
_In_opt_ IWebError* error, _In_opt_ IWebURLAuthenticationChallengeSender* sender)
{
LOG_ERROR("Calling the ala carte init for WebURLAuthenticationChallenge - is this really what you want to do?");
if (!space || !proposedCredential || !failureResponse || !sender)
return E_POINTER;
HRESULT hr = S_OK;
COMPtr<WebURLProtectionSpace> webSpace;
hr = space->QueryInterface(&webSpace);
if (FAILED(hr))
return hr;
COMPtr<WebURLCredential> webCredential(Query, proposedCredential);
if (!webCredential)
return E_NOINTERFACE;
COMPtr<WebURLResponse> webResponse;
hr = failureResponse->QueryInterface(&webResponse);
if (FAILED(hr))
return hr;
COMPtr<WebError> webError;
hr = error->QueryInterface(CLSID_WebError, (void**)&webError);
if (FAILED(hr))
return hr;
COMPtr<WebURLAuthenticationChallengeSender> webSender(Query, sender);
if (!webSender)
return E_NOINTERFACE;
#if USE(CFNETWORK)
m_authenticationChallenge = AuthenticationChallenge(webSpace->protectionSpace(), webCredential->credential(),
previousFailureCount, webResponse->resourceResponse(), webError->resourceError());
#endif
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::initWithAuthenticationChallenge(_In_opt_ IWebURLAuthenticationChallenge* challenge,
_In_opt_ IWebURLAuthenticationChallengeSender* sender)
{
if (!challenge || !sender)
return E_POINTER;
COMPtr<WebURLAuthenticationChallenge> webChallenge(Query, challenge);
if (!webChallenge)
return E_NOINTERFACE;
COMPtr<WebURLAuthenticationChallengeSender> webSender(Query, sender);
if (!webSender)
return E_NOINTERFACE;
#if USE(CFNETWORK)
m_authenticationChallenge = AuthenticationChallenge(webChallenge->authenticationChallenge().cfURLAuthChallengeRef(), webSender->authenticationClient());
return S_OK;
#else
return E_FAIL;
#endif
}
HRESULT WebURLAuthenticationChallenge::error(_COM_Outptr_opt_ IWebError** result)
{
if (!result)
return E_POINTER;
*result = WebError::createInstance(m_authenticationChallenge.error());
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::failureResponse(_COM_Outptr_opt_ IWebURLResponse** result)
{
if (!result)
return E_POINTER;
*result = WebURLResponse::createInstance(m_authenticationChallenge.failureResponse());
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::previousFailureCount(_Out_ UINT* result)
{
if (!result)
return E_POINTER;
*result = m_authenticationChallenge.previousFailureCount();
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::proposedCredential(_COM_Outptr_opt_ IWebURLCredential** result)
{
if (!result)
return E_POINTER;
*result = WebURLCredential::createInstance(m_authenticationChallenge.proposedCredential());
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::protectionSpace(_COM_Outptr_opt_ IWebURLProtectionSpace** result)
{
if (!result)
return E_POINTER;
*result = WebURLProtectionSpace::createInstance(m_authenticationChallenge.protectionSpace());
return S_OK;
}
HRESULT WebURLAuthenticationChallenge::sender(_COM_Outptr_opt_ IWebURLAuthenticationChallengeSender** sender)
{
if (!sender)
return E_POINTER;
*sender = nullptr;
if (!m_sender) {
AuthenticationClient* client = m_authenticationChallenge.authenticationClient();
m_sender.adoptRef(WebURLAuthenticationChallengeSender::createInstance(client));
}
return m_sender.copyRefTo(sender);
}
const AuthenticationChallenge& WebURLAuthenticationChallenge::authenticationChallenge() const
{
return m_authenticationChallenge;
}