2 Copyright (C) 2012 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "ewk_auth_challenge.h"
24 #include "WKAPICast.h"
25 #include "WKAuthenticationChallenge.h"
26 #include "WKAuthenticationDecisionListener.h"
27 #include "WKCredential.h"
28 #include "WKProtectionSpace.h"
29 #include "WKRetainPtr.h"
31 #include "ewk_auth_challenge_private.h"
32 #include <wtf/text/CString.h>
34 using namespace WebKit;
37 * @brief Structure used to send credential for authentication challenge.
39 * Details If Authentication challenge requirement is received, AuthenticationChallenge is created,
40 * and realm, host url are received from server.
41 * These information are sent to notify by evas_object_smart_callback_call.
43 struct _Ewk_Auth_Challenge {
44 WKAuthenticationChallengeRef authenticationChallenge;
45 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
56 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
57 Ewk_Auth_Challenge* ewkAuthChallengeCreate(WKPageRef page, WKAuthenticationChallengeRef authenticationChallenge)
59 Ewk_Auth_Challenge* ewkAuthChallengeCreate(WKAuthenticationChallengeRef authenticationChallenge)
62 EINA_SAFETY_ON_NULL_RETURN_VAL(authenticationChallenge, 0);
64 WKProtectionSpaceRef protectionSpace = WKAuthenticationChallengeGetProtectionSpace(authenticationChallenge);
65 EINA_SAFETY_ON_NULL_RETURN_VAL(protectionSpace, 0);
67 WKRetainPtr<WKStringRef> hostString(AdoptWK, WKProtectionSpaceCopyHost(protectionSpace));
68 WKRetainPtr<WKStringRef> realmString(AdoptWK, WKProtectionSpaceCopyRealm(protectionSpace));
70 Ewk_Auth_Challenge* authChallenge = new Ewk_Auth_Challenge;
72 #if ENABLE(TIZEN_ON_AUTHENTICATION_REQUESTED)
73 authChallenge->page = page;
75 authChallenge->authenticationChallenge = authenticationChallenge;
76 authChallenge->realm = toImpl(realmString.get())->string().utf8();
77 authChallenge->url = toImpl(hostString.get())->string().utf8();
79 authChallenge->isDecided = false;
80 authChallenge->isSuspended = false;
85 void ewkAuthChallengeDelete(Ewk_Auth_Challenge* authChallenge)
87 EINA_SAFETY_ON_NULL_RETURN(authChallenge);
92 bool ewkAuthChallengeDecided(Ewk_Auth_Challenge* authChallenge)
94 EINA_SAFETY_ON_NULL_RETURN_VAL(authChallenge, false);
96 return authChallenge->isDecided;
99 bool ewkAuthChallengeSuspended(Ewk_Auth_Challenge* authChallenge)
101 EINA_SAFETY_ON_NULL_RETURN_VAL(authChallenge, false);
103 return authChallenge->isSuspended;
106 const char* ewk_auth_challenge_realm_get(Ewk_Auth_Challenge* authChallenge)
108 EINA_SAFETY_ON_NULL_RETURN_VAL(authChallenge, 0);
110 return authChallenge->realm.data();
113 const char* ewk_auth_challenge_url_get(Ewk_Auth_Challenge* authChallenge)
115 EINA_SAFETY_ON_NULL_RETURN_VAL(authChallenge, 0);
117 return authChallenge->url.data();
120 void ewk_auth_challenge_suspend(Ewk_Auth_Challenge* authChallenge)
122 EINA_SAFETY_ON_NULL_RETURN(authChallenge);
124 authChallenge->isSuspended = true;
127 void ewk_auth_challenge_credential_use(Ewk_Auth_Challenge* authChallenge, char* user, char* password)
129 EINA_SAFETY_ON_NULL_RETURN(authChallenge);
130 EINA_SAFETY_ON_NULL_RETURN(user);
131 EINA_SAFETY_ON_NULL_RETURN(password);
133 authChallenge->isDecided = true;
134 toImpl(authChallenge->page)->replyReceiveAuthenticationChallengeInFrame(true);
136 WKAuthenticationChallengeRef authenticationChallenge = authChallenge->authenticationChallenge;
137 WKAuthenticationDecisionListenerRef authenticationDecisionListener = WKAuthenticationChallengeGetDecisionListener(authenticationChallenge);
139 WKRetainPtr<WKStringRef> userString(AdoptWK, WKStringCreateWithUTF8CString(user));
140 WKRetainPtr<WKStringRef> passwordString(AdoptWK, WKStringCreateWithUTF8CString(password));
142 WKRetainPtr<WKCredentialRef> credential(AdoptWK, WKCredentialCreate(userString.get(), passwordString.get(), kWKCredentialPersistenceNone));
144 WKAuthenticationDecisionListenerUseCredential(authenticationDecisionListener, credential.get());
147 void ewk_auth_challenge_credential_cancel(Ewk_Auth_Challenge* authChallenge)
149 EINA_SAFETY_ON_NULL_RETURN(authChallenge);
151 authChallenge->isDecided = true;
152 toImpl(authChallenge->page)->replyReceiveAuthenticationChallengeInFrame(false);
154 WKAuthenticationChallengeRef authenticationChallenge = authChallenge->authenticationChallenge;
155 WKAuthenticationDecisionListenerRef authenticationDecisionListener = WKAuthenticationChallengeGetDecisionListener(authenticationChallenge);
157 WKAuthenticationDecisionListenerCancel(authenticationDecisionListener);
160 #endif // #if OS(TIZEN)