2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file view_logic_authentication_challenge_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
21 #include "view_logic_authentication_challenge_support.h"
25 #include <dpl/assert.h>
26 #include <dpl/availability.h>
27 #include <dpl/log/wrt_log.h>
28 #include <efl_assist.h>
29 #include <Elementary.h>
31 #include <EWebKit_internal.h>
33 #include <widget_string.h>
35 namespace ViewModule {
37 struct authenticationData {
38 Ewk_Auth_Challenge* m_authChallenge;
39 std::string m_bodyText;
41 Evas_Object* m_idEdit;
42 Evas_Object* m_pwEdit;
46 void askUserInformation(authenticationData* authData);
47 void loginAuthentication(authenticationData* authData);
48 void cancelAuthentication(authenticationData* authData);
49 Evas_Object* getEvasObjectByWidgetName(Evas_Object* obj, const char* name);
50 Evas_Object* createEdit(Evas_Object* parent, bool isIdEdit);
51 void eaKeyCallback(void* data, Evas_Object* obj, void* eventInfo);
52 void buttonClickedCallback(void* data, Evas_Object* obj, void* eventInfo);
53 void editActivatedCallback(void* data, Evas_Object* obj, void* eventInfo);
55 void askUserInformation(authenticationData* authData)
57 Evas_Object* popup = elm_popup_add(authData->m_navi);
59 elm_object_style_set(popup, "popup/default");
60 evas_object_size_hint_weight_set(popup , EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61 evas_object_size_hint_align_set(popup , EVAS_HINT_FILL, EVAS_HINT_FILL);
62 elm_object_domain_translatable_part_text_set(popup, "title,text", "wrt", WRT_BODY_AUTHENTICATION_REQUIRED_IDS);
64 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, eaKeyCallback, authData);
66 Evas_Object* layout = elm_layout_add(popup);
67 elm_layout_file_set(layout, WRT_EDJ_PATH, "authChallengePopup");
68 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
69 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
71 Evas_Object* label = elm_label_add(layout);
72 elm_label_line_wrap_set(label , ELM_WRAP_WORD);
73 elm_object_text_set(label, authData->m_bodyText.c_str());
74 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
77 Evas_Object* idEdit = createEdit(layout, true);
78 authData->m_idEdit = idEdit;
80 Evas_Object* pwEdit = createEdit(layout, false);
81 authData->m_pwEdit = pwEdit;
83 elm_object_part_content_set(layout, "elm.swallow.label", label);
84 elm_object_part_content_set(layout, "elm.swallow.idfield", idEdit);
85 elm_object_part_content_set(layout, "elm.swallow.pwfield", pwEdit);
86 edje_object_part_text_set(elm_layout_edje_get(layout), "elm.swallow.idtext", WRT_BODY_AUTHUSERNAME);
87 edje_object_part_text_set(elm_layout_edje_get(layout), "elm.swallow.pwtext", WRT_BODY_PASSWORD);
88 elm_object_content_set(popup, layout);
90 Evas_Object* cancelButton = elm_button_add(popup);
91 elm_object_domain_translatable_part_text_set(cancelButton, 0, "wrt", WRT_SK_CANCEL_IDS);
92 elm_object_style_set(cancelButton, "popup");
93 elm_object_part_content_set(popup, "button1", cancelButton);
94 evas_object_smart_callback_add(cancelButton, "clicked", buttonClickedCallback, static_cast<void*>(authData));
96 Evas_Object* loginButton = elm_button_add(popup);
97 elm_object_domain_translatable_part_text_set(loginButton, 0, "sys_string", WRT_SK_LOGIN_IDS);
98 elm_object_style_set(loginButton, "popup");
99 elm_object_part_content_set(popup, "button2", loginButton);
100 evas_object_smart_callback_add(loginButton, "clicked", buttonClickedCallback, static_cast<void*>(authData));
102 evas_object_show(popup);
105 void loginAuthentication(authenticationData* authData)
111 const char* id = elm_entry_entry_get(authData->m_idEdit);
112 const char* pw = elm_entry_entry_get(authData->m_pwEdit);
113 ewk_auth_challenge_credential_use(authData->m_authChallenge, const_cast<char*>(id), const_cast<char*>(pw));
115 Evas_Object* popup = getEvasObjectByWidgetName(authData->m_idEdit, "elm_popup");
117 evas_object_hide(popup);
118 evas_object_del(popup);
122 void cancelAuthentication(authenticationData* authData)
128 ewk_auth_challenge_credential_cancel(authData->m_authChallenge);
130 Evas_Object* popup = getEvasObjectByWidgetName(authData->m_idEdit, "elm_popup");
132 evas_object_hide(popup);
133 evas_object_del(popup);
137 Evas_Object* getEvasObjectByWidgetName(Evas_Object* obj, const char* name)
140 Evas_Object* current = elm_object_parent_widget_get(obj);
141 while (strcmp(elm_object_widget_type_get(current), name)) {
142 current = elm_object_parent_widget_get(current);
150 Evas_Object* createEdit(Evas_Object* parent, bool isIdEdit)
152 Evas_Object* edit = ea_editfield_add(parent, EA_EDITFIELD_SCROLL_SINGLELINE);
153 elm_entry_cnp_mode_set(edit, ELM_CNP_MODE_PLAINTEXT);
154 elm_object_style_set(edit, "editfield/password/popup");
155 elm_entry_single_line_set(edit, EINA_TRUE);
156 elm_entry_scrollable_set(edit, EINA_TRUE);
157 elm_entry_prediction_allow_set(edit, EINA_FALSE);
158 elm_object_signal_emit(edit, "elm,action,hide,search_icon", "");
159 elm_entry_autocapital_type_set(edit, ELM_AUTOCAPITAL_TYPE_NONE);
162 evas_object_smart_callback_add(edit, "activated", editActivatedCallback, NULL);
164 elm_entry_password_set(edit, EINA_TRUE);
165 elm_entry_input_panel_layout_set(edit, ELM_INPUT_PANEL_LAYOUT_PASSWORD);
171 void eaKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
175 DPL_UNUSED_PARAM(obj);
176 DPL_UNUSED_PARAM(eventInfo);
180 authenticationData* authData = static_cast<authenticationData*>(data);
181 cancelAuthentication(authData);
184 void buttonClickedCallback(void* data, Evas_Object* obj, void* eventInfo)
188 DPL_UNUSED_PARAM(eventInfo);
193 bool isLogin = !strcmp(WRT_SK_LOGIN, elm_object_text_get(obj));
195 authenticationData* authData = static_cast<authenticationData*>(data);
197 loginAuthentication(authData);
199 cancelAuthentication(authData);
203 void editActivatedCallback(void* data, Evas_Object* obj, void* eventInfo)
205 DPL_UNUSED_PARAM(eventInfo);
206 DPL_UNUSED_PARAM(data);
209 elm_object_focus_set(obj, EINA_TRUE);
213 void AuthenticationChallengeSupport::authenticationChallengeRequest(
214 Evas_Object* webview,
219 authenticationData* authData = new authenticationData();
221 authData->m_navi = getEvasObjectByWidgetName(webview, "elm_naviframe");
224 authData->m_authChallenge = static_cast<Ewk_Auth_Challenge*>(data);
226 const char* authRealm =
227 ewk_auth_challenge_realm_get(authData->m_authChallenge);
228 authData->m_bodyText = url;
229 if (authRealm != NULL) {
230 authData->m_bodyText += "<br>";
231 authData->m_bodyText += std::string(authRealm);
233 ewk_auth_challenge_suspend(authData->m_authChallenge);
236 askUserInformation(authData);
238 } // namespace ViewModule