~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebKit2/UIProcess/API/efl/ewk_auth_request.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Intel Corporation. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#include "config.h"
 
27
#include "ewk_auth_request.h"
 
28
 
 
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>
 
36
 
 
37
using namespace WebKit;
 
38
using namespace WebCore;
 
39
 
 
40
EwkAuthRequest::EwkAuthRequest(AuthenticationChallengeProxy* authenticationChallenge)
 
41
    : m_authenticationChallenge(authenticationChallenge)
 
42
    , m_wasHandled(false)
 
43
{
 
44
    ASSERT(m_authenticationChallenge);
 
45
}
 
46
 
 
47
EwkAuthRequest::~EwkAuthRequest()
 
48
{
 
49
    if (!m_wasHandled)
 
50
        continueWithoutCredential();
 
51
}
 
52
 
 
53
const char* EwkAuthRequest::suggestedUsername() const
 
54
{
 
55
    if (!m_suggestedUsername) {
 
56
        WebCredential* credential = m_authenticationChallenge->proposedCredential();
 
57
        ASSERT(credential);
 
58
 
 
59
        const String& suggestedUsername = credential->user();
 
60
        if (suggestedUsername.isEmpty())
 
61
            return 0;
 
62
 
 
63
        m_suggestedUsername = suggestedUsername.utf8().data();
 
64
    }
 
65
 
 
66
    return m_suggestedUsername;
 
67
}
 
68
 
 
69
const char* EwkAuthRequest::realm() const
 
70
{
 
71
    if (!m_realm) {
 
72
        WebProtectionSpace* protectionSpace = m_authenticationChallenge->protectionSpace();
 
73
        ASSERT(protectionSpace);
 
74
 
 
75
        const String& realm = protectionSpace->realm();
 
76
        if (realm.isEmpty())
 
77
            return 0;
 
78
 
 
79
        m_realm = realm.utf8().data();
 
80
    }
 
81
 
 
82
    return m_realm;
 
83
}
 
84
 
 
85
const char* EwkAuthRequest::host() const
 
86
{
 
87
    if (!m_host) {
 
88
        WebProtectionSpace* protectionSpace = m_authenticationChallenge->protectionSpace();
 
89
        ASSERT(protectionSpace);
 
90
 
 
91
        const String& host = protectionSpace->host();
 
92
        if (host.isEmpty())
 
93
            return 0;
 
94
 
 
95
        m_host = host.utf8().data();
 
96
    }
 
97
 
 
98
    return m_host;
 
99
}
 
100
 
 
101
bool EwkAuthRequest::continueWithoutCredential()
 
102
{
 
103
    if (m_wasHandled)
 
104
        return false;
 
105
 
 
106
    m_wasHandled = true;
 
107
    m_authenticationChallenge->useCredential(0);
 
108
 
 
109
    return true;
 
110
}
 
111
 
 
112
bool EwkAuthRequest::authenticate(const String& username, const String& password)
 
113
{
 
114
    if (m_wasHandled)
 
115
        return false;
 
116
 
 
117
    m_wasHandled = true;
 
118
    RefPtr<WebCredential> credential = WebCredential::create(WebString::create(username).get(), WebString::create(password).get(), CredentialPersistenceForSession);
 
119
    m_authenticationChallenge->useCredential(credential.get());
 
120
 
 
121
    return true;
 
122
}
 
123
 
 
124
bool EwkAuthRequest::isRetrying() const
 
125
{
 
126
    return m_authenticationChallenge->previousFailureCount() > 0;
 
127
}
 
128
 
 
129
const char* ewk_auth_request_suggested_username_get(const Ewk_Auth_Request* request)
 
130
{
 
131
    EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);
 
132
 
 
133
    return impl->suggestedUsername();
 
134
}
 
135
 
 
136
Eina_Bool ewk_auth_request_cancel(Ewk_Auth_Request* request)
 
137
{
 
138
    EWK_OBJ_GET_IMPL_OR_RETURN(EwkAuthRequest, request, impl, false);
 
139
 
 
140
    return impl->continueWithoutCredential();
 
141
}
 
142
 
 
143
Eina_Bool ewk_auth_request_authenticate(Ewk_Auth_Request* request, const char* username, const char* password)
 
144
{
 
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);
 
148
 
 
149
    return impl->authenticate(String::fromUTF8(username), String::fromUTF8(password));
 
150
}
 
151
 
 
152
Eina_Bool ewk_auth_request_retrying_get(const Ewk_Auth_Request* request)
 
153
{
 
154
    EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, false);
 
155
 
 
156
    return impl->isRetrying();
 
157
}
 
158
 
 
159
const char* ewk_auth_request_realm_get(const Ewk_Auth_Request* request)
 
160
{
 
161
    EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);
 
162
 
 
163
    return impl->realm();
 
164
}
 
165
 
 
166
const char* ewk_auth_request_host_get(const Ewk_Auth_Request* request)
 
167
{
 
168
    EWK_OBJ_GET_IMPL_OR_RETURN(const EwkAuthRequest, request, impl, 0);
 
169
 
 
170
    return impl->host();
 
171
}