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/unused.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>
39 namespace ViewModule {
41 const double MAX_POPUP_HEIGHT = 0.80;
42 const double MAX_SCROLLER_HEIGHT = 0.5;
45 Evas_Smart_Cb eaKeyCallback;
48 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
49 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo);
51 static void deleteCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
56 DPL_UNUSED_PARAM(eventInfo);
58 CallbackData* callbackData = static_cast<CallbackData*>(data);
61 ea_object_event_callback_del(obj, EA_CALLBACK_BACK, callbackData->eaKeyCallback);
64 evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, resizeCallback);
66 static void resizeCallback(void* data, Evas* e, Evas_Object* obj, void* eventInfo)
70 DPL_UNUSED_PARAM(data);
72 DPL_UNUSED_PARAM(eventInfo);
75 Evas_Object* popup = obj;
77 evas_object_geometry_get(popup, 0, 0, 0, &popupH);
79 Evas_Object* parent = PopupUtil::getParentWindow(popup);
81 evas_object_geometry_get(parent, 0, 0, &parentW, &parentH);
83 // compare current popup height with screen height.
84 // To avoid popup is filled full screen, used magic number to be filled 80% of screen height.
85 // TODO: Automatically add scroller feature should implement in the elementary
86 double threshold = parentH * MAX_POPUP_HEIGHT;
87 double currentH = popupH;
88 if (threshold < currentH) {
89 _D("text is overflow popup height. add scroller");
90 Evas_Object* layout = elm_object_content_get(obj);
91 Evas_Object* label = elm_object_part_content_get(layout, "elm.swallow.label");
93 Evas_Object* scroller = elm_scroller_add(layout);
94 elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_ON, ELM_SCROLLER_POLICY_AUTO);
95 evas_object_size_hint_weight_set(scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96 evas_object_size_hint_align_set(scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
97 elm_scroller_content_min_limit(scroller, EINA_TRUE, EINA_TRUE);
98 int scrollerHeight = parentW > parentH ? parentH : parentW;
99 evas_object_size_hint_max_set(scroller, -1, scrollerHeight * MAX_SCROLLER_HEIGHT);
101 elm_object_part_content_unset(layout, "elm.swallow.label");
102 elm_object_content_set(scroller, label);
103 elm_object_part_content_set(layout, "elm.swallow.label", scroller);
104 evas_object_show(layout);
109 class SecurityOriginSupportImplementation
112 WidgetModel* m_model;
113 SecurityOriginDB::SecurityOriginDAOPtr m_securityOriginDAO;
116 SecurityOriginSupportImplementation(WidgetModel* widgetModel) :
120 m_model = widgetModel;
123 ~SecurityOriginSupportImplementation()
126 SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
129 if (!m_securityOriginDAO) {
130 LogDebug("initialize securityOriginDAO");
131 m_securityOriginDAO =
132 SecurityOriginDB::SecurityOriginDAOPtr(
133 new SecurityOriginDB::SecurityOriginDAO(m_model->TzPkgId.
135 // initialize security result data. Remove allow, deny for
136 m_securityOriginDAO->removeSecurityOriginData(
137 SecurityOriginDB::RESULT_ALLOW_ONCE);
138 m_securityOriginDAO->removeSecurityOriginData(
139 SecurityOriginDB::RESULT_DENY_ONCE);
141 return m_securityOriginDAO.get();
145 SecurityOriginSupport::SecurityOriginSupport(WidgetModel* widgetModel) :
146 m_impl(new SecurityOriginSupportImplementation(widgetModel))
149 SecurityOriginSupport::~SecurityOriginSupport()
152 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::
153 getSecurityOriginDAO(void)
155 return m_impl->getSecurityOriginDAO();
158 Evas_Object* SecurityOriginSupportUtil::createPopup(
160 const char* bodyText,
161 const char* checkText,
162 Evas_Smart_Cb buttonCallback,
163 Evas_Smart_Cb keyCallback,
166 LogDebug("createPopup");
167 Evas_Object* parentWindow = PopupUtil::getParentWindow(window);
168 Evas_Object* popup = elm_popup_add(parentWindow);
170 CallbackData* callbackData = NULL;
172 CallbackData* callbackData = new CallbackData;
173 callbackData->eaKeyCallback = keyCallback;
174 ea_object_event_callback_add(popup, EA_CALLBACK_BACK, keyCallback, data);
176 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, deleteCallback, static_cast<void*>(callbackData));
177 evas_object_event_callback_add(popup, EVAS_CALLBACK_RESIZE, resizeCallback, NULL);
179 elm_object_style_set(popup, "popup/default");
180 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
181 evas_object_size_hint_align_set(popup, EVAS_HINT_FILL, EVAS_HINT_FILL);
183 Evas_Object* layout = elm_layout_add(popup);
184 elm_layout_file_set(layout, WRT_EDJ_PATH, "popupWithCheck");
185 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
186 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
188 Evas_Object* label = elm_label_add(popup);
189 elm_label_line_wrap_set(label, ELM_WRAP_WORD);
190 elm_object_text_set(label, bodyText);
191 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
192 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
194 Evas_Object* check = elm_check_add(layout);
195 elm_object_text_set(check, checkText);
197 elm_object_part_content_set(layout, "elm.swallow.label", label);
198 elm_object_part_content_set(layout, "elm.swallow.checkbox", check);
199 elm_object_content_set(popup, layout);
201 Evas_Object* btn1 = elm_button_add(popup);
202 elm_object_text_set(btn1, WRT_SK_YES);
203 elm_object_part_content_set(popup, "button1", btn1);
204 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
205 Evas_Object* btn2 = elm_button_add(popup);
206 elm_object_text_set(btn2, WRT_SK_NO);
207 elm_object_part_content_set(popup, "button2", btn2);
208 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
212 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
216 Evas_Object* popup = button;
217 while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
218 popup = elm_object_parent_widget_get(popup);
226 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
229 if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
232 Evas_Object* check = elm_object_part_content_get(
233 elm_object_content_get(popup),
234 "elm.swallow.checkbox");
238 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(
241 using namespace SecurityOriginDB;
244 // get popup evas_object
245 Evas_Object* popup = getPopup(button);
247 return RESULT_UNKNOWN;
249 bool allow = !strcmp(WRT_SK_YES, elm_object_text_get(button));
251 // get check evas_object
252 Evas_Object* check = getCheck(popup);
254 return RESULT_UNKNOWN;
257 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
260 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
264 } // namespace ViewModule