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_security_origin_support.cpp
18 * @author Jihoon Chung (jihoon.chung@samsung.com)
20 * @brief Support security origin dao
23 #include "view_logic_security_origin_support.h"
27 #include <Elementary.h>
28 #include <efl_assist.h>
29 #include <dpl/assert.h>
30 #include <dpl/log/log.h>
31 #include <dpl/log/secure_log.h>
32 #include <dpl/availability.h>
33 #include <dpl/wrt-dao-ro/common_dao_types.h>
34 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
35 #include <widget_model.h>
36 #include <widget_string.h>
37 #include <common/view_logic_get_parent_window_util.h>
40 #if (ELM_VERSION_MAJOR == 1 && ELM_VERSION_MINOR == 7)
41 #define POPUP_CLASSNAME "popup"
43 //#if ELM_VERSION_MAJOR == 1 && ELM_VERSION_MINOR == 8)
44 #define POPUP_CLASSNAME "elm_popup"
46 namespace ViewModule {
48 const double MAX_POPUP_HEIGHT = 0.80;
49 const double MAX_SCROLLER_HEIGHT = 0.5;
52 Evas_Smart_Cb eaKeyCallback;
55 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
56 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
58 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
63 DPL_UNUSED_PARAM(eventInfo);
65 CallbackData* callbackData = static_cast<CallbackData*>(data);
68 ea_object_event_callback_del(obj, EA_CALLBACK_BACK, callbackData->eaKeyCallback);
71 evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, resizeCallback);
73 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
77 DPL_UNUSED_PARAM(data);
79 DPL_UNUSED_PARAM(eventInfo);
82 Evas_Object* popup = obj;
84 evas_object_geometry_get(popup, 0, 0, 0, &popupH);
86 Evas_Object* parent = PopupUtil::getParentWindow(popup);
88 evas_object_geometry_get(parent, 0, 0, &parentW, &parentH);
90 // compare current popup height with screen height.
91 // To avoid popup is filled full screen, used magic number to be filled 80% of screen height.
92 // TODO: Automatically add scroller feature should implement in the elementary
93 double threshold = parentH * MAX_POPUP_HEIGHT;
94 double currentH = popupH;
95 if (threshold < currentH) {
96 _D("text is overflow popup height. add scroller");
97 Evas_Object* layout = elm_object_content_get(obj);
98 Evas_Object* label = elm_object_part_content_get(layout, "elm.swallow.label");
100 Evas_Object* scroller = elm_scroller_add(layout);
101 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO);
102 evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
103 evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
104 elm_scroller_content_min_limit(scroller, EINA_TRUE, EINA_TRUE);
105 int scrollerHeight = parentW > parentH ? parentH : parentW;
106 evas_object_size_hint_max_set(scroller, -1, scrollerHeight * MAX_SCROLLER_HEIGHT);
108 elm_object_part_content_unset(layout, "elm.swallow.label");
109 elm_object_content_set(scroller, label);
110 elm_object_part_content_set(layout, "elm.swallow.label", scroller);
111 evas_object_show(layout);
116 class SecurityOriginSupportImplementation
119 WidgetModel* m_model;
120 SecurityOriginDB::SecurityOriginDAOPtr m_securityOriginDAO;
123 SecurityOriginSupportImplementation(WidgetModel* widgetModel) :
127 m_model = widgetModel;
130 ~SecurityOriginSupportImplementation()
133 SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
136 if (!m_securityOriginDAO) {
137 LogDebug("initialize securityOriginDAO");
138 m_securityOriginDAO =
139 SecurityOriginDB::SecurityOriginDAOPtr(
140 new SecurityOriginDB::SecurityOriginDAO(m_model->TzPkgId.
142 // initialize security result data. Remove allow, deny for
143 m_securityOriginDAO->removeSecurityOriginData(
144 SecurityOriginDB::RESULT_ALLOW_ONCE);
145 m_securityOriginDAO->removeSecurityOriginData(
146 SecurityOriginDB::RESULT_DENY_ONCE);
148 return m_securityOriginDAO.get();
152 SecurityOriginSupport::SecurityOriginSupport(WidgetModel* widgetModel) :
153 m_impl(new SecurityOriginSupportImplementation(widgetModel))
156 SecurityOriginSupport::~SecurityOriginSupport()
159 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::
160 getSecurityOriginDAO(void)
162 return m_impl->getSecurityOriginDAO();
165 Evas_Object* SecurityOriginSupportUtil::createPopup(
167 const char* bodyText,
168 const char* checkText,
169 Evas_Smart_Cb buttonCallback,
170 Evas_Smart_Cb keyCallback,
173 LogDebug("createPopup");
174 Evas_Object* parentWindow = PopupUtil::getParentWindow(window);
175 Evas_Object* popup = elm_popup_add(parentWindow);
177 CallbackData* callbackData = NULL;
179 callbackData = new CallbackData;
180 callbackData->eaKeyCallback = keyCallback;
181 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, keyCallback, data);
183 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, deleteCallback, static_cast<void*>(callbackData));
184 evas_object_event_callback_add(popup, EVAS_CALLBACK_RESIZE, resizeCallback, NULL);
186 elm_object_style_set(popup, "popup/default");
187 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
188 evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
190 Evas_Object* layout = elm_layout_add(popup);
191 elm_layout_file_set(layout, WRT_EDJ_PATH, "popupWithCheck");
192 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
193 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
195 Evas_Object* label = elm_label_add(popup);
196 elm_label_line_wrap_set(label, ELM_WRAP_WORD);
197 elm_object_text_set(label, bodyText);
198 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
199 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
201 Evas_Object* check = elm_check_add(layout);
202 elm_object_text_set(check, checkText);
204 elm_object_part_content_set(layout, "elm.swallow.label", label);
205 elm_object_part_content_set(layout, "elm.swallow.checkbox", check);
206 elm_object_content_set(popup, layout);
208 Evas_Object* btn1 = elm_button_add(popup);
209 elm_object_text_set(btn1, WRT_SK_YES);
210 elm_object_part_content_set(popup, "button1", btn1);
211 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
212 Evas_Object* btn2 = elm_button_add(popup);
213 elm_object_text_set(btn2, WRT_SK_NO);
214 elm_object_part_content_set(popup, "button2", btn2);
215 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
219 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
223 Evas_Object* popup = button;
224 while (strcmp(elm_object_widget_type_get(popup), POPUP_CLASSNAME )) {
225 popup = elm_object_parent_widget_get(popup);
233 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
236 if (strcmp(elm_object_widget_type_get(popup), POPUP_CLASSNAME )) {
239 Evas_Object* check = elm_object_part_content_get(
240 elm_object_content_get(popup),
241 "elm.swallow.checkbox");
245 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(
248 using namespace SecurityOriginDB;
251 // get popup evas_object
252 Evas_Object* popup = getPopup(button);
254 return RESULT_UNKNOWN;
256 bool allow = !strcmp(WRT_SK_YES, elm_object_text_get(button));
258 // get check evas_object
259 Evas_Object* check = getCheck(popup);
261 return RESULT_UNKNOWN;
264 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
267 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
271 } // namespace ViewModule