2
* Copyright (C) 2012 Intel Corporation. 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 "ewk_auth_request.h"
29
#include "AuthenticationChallengeProxy.h"
30
#include "AuthenticationDecisionListener.h"
31
#include "WebCredential.h"
32
#include "WebProtectionSpace.h"
33
#include "WebString.h"
34
#include "ewk_auth_request_private.h"
35
#include <wtf/text/CString.h>
37
using namespace WebKit;
38
using namespace WebCore;
40
EwkAuthRequest::EwkAuthRequest(AuthenticationChallengeProxy* authenticationChallenge)
41
: m_authenticationChallenge(authenticationChallenge)
44
ASSERT(m_authenticationChallenge);
47
EwkAuthRequest::~EwkAuthRequest()
50
continueWithoutCredential();
53
const char* EwkAuthRequest::suggestedUsername() const
55
if (!m_suggestedUsername) {
56
WebCredential* credential = m_authenticationChallenge->proposedCredential();
59
const String& suggestedUsername = credential->user();
60
if (suggestedUsername.isEmpty())
63
m_suggestedUsername = suggestedUsername.utf8().data();
66
return m_suggestedUsername;
69
const char* EwkAuthRequest::realm() const
72
WebProtectionSpace* protectionSpace = m_authenticationChallenge->protectionSpace();
73
ASSERT(protectionSpace);
75
const String& realm = protectionSpace->realm();
79
m_realm = realm.utf8().data();
85
const char* EwkAuthRequest::host() const
88
WebProtectionSpace* protectionSpace = m_authenticationChallenge->protectionSpace();
89
ASSERT(protectionSpace);
91
const String& host = protectionSpace->host();
95
m_host = host.utf8().data();
101
bool EwkAuthRequest::continueWithoutCredential()
107
m_authenticationChallenge->useCredential(0);
112
bool EwkAuthRequest::authenticate(const String& username, const String& password)
118
RefPtr<WebCredential> credential = WebCredential::create(WebString::create(username).get(), WebString::create(password).get(), CredentialPersistenceForSession);
119
m_authenticationChallenge->useCredential(credential.get());
124
bool EwkAuthRequest::isRetrying() const
126
return m_authenticationChallenge->previousFailureCount() > 0;
129
const char* ewk_auth_request_suggested_username_get(const Ewk_Auth_Request* request)
131
EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);
133
return impl->suggestedUsername();
136
Eina_Bool ewk_auth_request_cancel(Ewk_Auth_Request* request)
138
EWK_OBJ_GET_IMPL_OR_RETURN(EwkAuthRequest, request, impl, false);
140
return impl->continueWithoutCredential();
143
Eina_Bool ewk_auth_request_authenticate(Ewk_Auth_Request* request, const char* username, const char* password)
145
EWK_OBJ_GET_IMPL_OR_RETURN(EwkAuthRequest, request, impl, false);
146
EINA_SAFETY_ON_NULL_RETURN_VAL(username, false);
147
EINA_SAFETY_ON_NULL_RETURN_VAL(password, false);
149
return impl->authenticate(String::fromUTF8(username), String::fromUTF8(password));
152
Eina_Bool ewk_auth_request_retrying_get(const Ewk_Auth_Request* request)
154
EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, false);
156
return impl->isRetrying();
159
const char* ewk_auth_request_realm_get(const Ewk_Auth_Request* request)
161
EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);
163
return impl->realm();
166
const char* ewk_auth_request_host_get(const Ewk_Auth_Request* request)
168
EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);