File: WebKitCredential.cpp

package info (click to toggle)
webkit2gtk 2.6.2%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 115,572 kB
  • ctags: 216,388
  • sloc: cpp: 1,164,175; ansic: 18,422; perl: 16,884; python: 11,608; ruby: 9,409; xml: 8,376; asm: 4,765; yacc: 2,292; lex: 891; sh: 650; makefile: 79
file content (208 lines) | stat: -rw-r--r-- 6,182 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (C) 2013 Samsung Electronics Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "WebKitCredential.h"

#include "WebCredential.h"
#include "WebKitCredentialPrivate.h"
#include <wtf/text/CString.h>

using namespace WebKit;

struct _WebKitCredential {
    _WebKitCredential(const WebCore::Credential& coreCredential)
        : credential(coreCredential)
    {
    }

    WebCore::Credential credential;
    CString username;
    CString password;
};

G_DEFINE_BOXED_TYPE(WebKitCredential, webkit_credential, webkit_credential_copy, webkit_credential_free)

static inline WebKitCredentialPersistence toWebKitCredentialPersistence(WebCore::CredentialPersistence corePersistence)
{
    switch (corePersistence) {
    case WebCore::CredentialPersistenceNone:
        return WEBKIT_CREDENTIAL_PERSISTENCE_NONE;
    case WebCore::CredentialPersistenceForSession:
        return WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION;
    case WebCore::CredentialPersistencePermanent:
        return WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT;
    default:
        ASSERT_NOT_REACHED();
        return WEBKIT_CREDENTIAL_PERSISTENCE_NONE;
    }
}

static inline WebCore::CredentialPersistence toWebCoreCredentialPersistence(WebKitCredentialPersistence kitPersistence)
{
    switch (kitPersistence) {
    case WEBKIT_CREDENTIAL_PERSISTENCE_NONE:
        return WebCore::CredentialPersistenceNone;
    case WEBKIT_CREDENTIAL_PERSISTENCE_FOR_SESSION:
        return WebCore::CredentialPersistenceForSession;
    case WEBKIT_CREDENTIAL_PERSISTENCE_PERMANENT:
        return WebCore::CredentialPersistencePermanent;
    default:
        ASSERT_NOT_REACHED();
        return WebCore::CredentialPersistenceNone;
    }
}

WebKitCredential* webkitCredentialCreate(const WebCore::Credential& coreCredential)
{
    WebKitCredential* credential = g_slice_new(WebKitCredential);
    new (credential) WebKitCredential(coreCredential);
    return credential;
}

const WebCore::Credential& webkitCredentialGetCredential(WebKitCredential* credential)
{
    ASSERT(credential);
    return credential->credential;
}

/**
 * webkit_credential_new:
 * @username: The username for the new credential
 * @password: The password for the new credential
 * @persistence: The #WebKitCredentialPersistence of the new credential
 *
 * Create a new credential from the provided username, password and persistence mode.
 *
 * Returns: (transfer full): A #WebKitCredential.
 *
 * Since: 2.2
 */
WebKitCredential* webkit_credential_new(const gchar* username, const gchar* password, WebKitCredentialPersistence persistence)
{
    g_return_val_if_fail(username, 0);
    g_return_val_if_fail(password, 0);

    return webkitCredentialCreate(WebCore::Credential(String::fromUTF8(username), String::fromUTF8(password), toWebCoreCredentialPersistence(persistence)));
}

/**
 * webkit_credential_copy:
 * @credential: a #WebKitCredential
 *
 * Make a copy of the #WebKitCredential.
 *
 * Returns: (transfer full): A copy of passed in #WebKitCredential
 *
 * Since: 2.2
 */
WebKitCredential* webkit_credential_copy(WebKitCredential* credential)
{
    g_return_val_if_fail(credential, 0);

    return webkitCredentialCreate(credential->credential);
}

/**
 * webkit_credential_free:
 * @credential: A #WebKitCredential
 *
 * Free the #WebKitCredential.
 *
 * Since: 2.2
 */
void webkit_credential_free(WebKitCredential* credential)
{
    g_return_if_fail(credential);

    credential->~WebKitCredential();
    g_slice_free(WebKitCredential, credential);
}

/**
 * webkit_credential_get_username:
 * @credential: a #WebKitCredential
 *
 * Get the username currently held by this #WebKitCredential.
 *
 * Returns: The username stored in the #WebKitCredential.
 *
 * Since: 2.2
 */
const gchar* webkit_credential_get_username(WebKitCredential* credential)
{
    g_return_val_if_fail(credential, 0);

    if (credential->username.isNull())
        credential->username = credential->credential.user().utf8();
    return credential->username.data();
}

/**
 * webkit_credential_get_password:
 * @credential: a #WebKitCredential
 *
 * Get the password currently held by this #WebKitCredential.
 *
 * Returns: The password stored in the #WebKitCredential.
 *
 * Since: 2.2
 */
const gchar* webkit_credential_get_password(WebKitCredential* credential)
{
    g_return_val_if_fail(credential, 0);

    if (credential->password.isNull())
        credential->password = credential->credential.password().utf8();
    return credential->password.data();
}

/**
 * webkit_credential_has_password:
 * @credential: a #WebKitCredential
 *
 * Determine whether this credential has a password stored.
 *
 * Returns: %TRUE if the credential has a password or %FALSE otherwise.
 *
 * Since: 2.2
 */
gboolean webkit_credential_has_password(WebKitCredential* credential)
{
    g_return_val_if_fail(credential, FALSE);

    return credential->credential.hasPassword();
}

/**
 * webkit_credential_get_persistence:
 * @credential: a #WebKitCredential
 *
 * Get the persistence mode currently held by this #WebKitCredential.
 *
 * Returns: The #WebKitCredentialPersistence stored in the #WebKitCredential.
 *
 * Since: 2.2
 */
WebKitCredentialPersistence webkit_credential_get_persistence(WebKitCredential* credential)
{
    g_return_val_if_fail(credential, WEBKIT_CREDENTIAL_PERSISTENCE_NONE);

    return toWebKitCredentialPersistence(credential->credential.persistence());
}