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>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31 #include <dpl/wrt-dao-ro/common_dao_types.h>
32 #include <dpl/wrt-dao-ro/vconf_config.h>
33 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
34 #include <widget_model.h>
36 namespace ViewModule {
38 const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj";
41 class SecurityOriginSupportImplementation
45 SecurityOriginDB::SecurityOriginDAOPtr m_securityOriginDAO;
48 SecurityOriginSupportImplementation(WidgetModel* widgetModel) :
52 m_model = widgetModel;
55 ~SecurityOriginSupportImplementation()
58 SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
61 if (!m_securityOriginDAO) {
62 LogDebug("initialize securityOriginDAO");
64 SecurityOriginDB::SecurityOriginDAOPtr(
65 new SecurityOriginDB::SecurityOriginDAO(m_model->TzPkgId.
67 // initialize security result data. Remove allow, deny for
68 m_securityOriginDAO->removeSecurityOriginData(
69 SecurityOriginDB::RESULT_ALLOW_ONCE);
70 m_securityOriginDAO->removeSecurityOriginData(
71 SecurityOriginDB::RESULT_DENY_ONCE);
73 return m_securityOriginDAO.get();
76 WrtDB::SettingsType isNeedPermissionCheck(
77 SecurityOriginDB::Feature feature)
79 using namespace SecurityOriginDB;
81 if (feature == FEATURE_GEOLOCATION) {
82 key = WrtDB::VconfConfig::GetVconfKeyGeolocationUsage(
84 } else if (feature == FEATURE_WEB_NOTIFICATION) {
85 key = WrtDB::VconfConfig::GetVconfKeyWebNotificationUsage(
87 } else if (feature == FEATURE_WEB_DATABASE) {
88 key = WrtDB::VconfConfig::GetVconfKeyWebDatabaseUsage(
90 } else if (feature == FEATURE_FILE_SYSTEM_ACCESS) {
91 key = WrtDB::VconfConfig::GetVconfKeyFilesystemUsage(
94 Assert("Wrong feature argument is input");
98 vconf_get_int(key.c_str(), &value);
99 LogDebug(key << " = " << value);
100 WrtDB::SettingsType ret = static_cast<WrtDB::SettingsType>(value);
106 SecurityOriginSupport::SecurityOriginSupport(WidgetModel* widgetModel) :
107 m_impl(new SecurityOriginSupportImplementation(widgetModel))
110 SecurityOriginSupport::~SecurityOriginSupport()
113 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::
114 getSecurityOriginDAO(void)
116 return m_impl->getSecurityOriginDAO();
119 WrtDB::SettingsType SecurityOriginSupport::isNeedPermissionCheck(
120 SecurityOriginDB::Feature feature)
122 return m_impl->isNeedPermissionCheck(feature);
125 Evas_Object* SecurityOriginSupportUtil::createPopup(
127 const char* bodyText,
128 const char* checkText,
133 LogDebug("createPopup");
134 Evas_Object* popup = elm_popup_add(window);
136 Evas_Object* label = elm_label_add(popup);
137 elm_object_style_set(label, "popup/default");
138 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
139 elm_object_text_set(label, bodyText);
140 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
141 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
142 evas_object_show(label);
144 Evas_Object* layout = elm_layout_add(popup);
145 elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck");
146 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148 Evas_Object* check = elm_check_add(popup);
149 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
150 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
151 evas_object_show(check);
153 elm_object_part_text_set(layout, "elm.text", checkText);
154 elm_object_part_content_set(layout, "elm.swallow.content", label);
155 elm_object_part_content_set(layout, "elm.swallow.end", check);
157 evas_object_show(layout);
158 elm_object_content_set(popup, layout);
159 Evas_Object* btn1 = elm_button_add(popup);
160 elm_object_text_set(btn1, "YES");
161 elm_object_part_content_set(popup, "button1", btn1);
162 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
163 Evas_Object* btn2 = elm_button_add(popup);
164 elm_object_text_set(btn2, "NO");
165 elm_object_part_content_set(popup, "button2", btn2);
166 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
170 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
174 Evas_Object* popup = button;
175 while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
176 popup = elm_object_parent_widget_get(popup);
184 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
187 if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
190 Evas_Object* check = elm_object_part_content_get(
191 elm_object_content_get(popup),
196 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(
199 using namespace SecurityOriginDB;
202 // get popup evas_object
203 Evas_Object* popup = getPopup(button);
205 return RESULT_UNKNOWN;
207 bool allow = !strcmp("YES", elm_object_text_get(button));
209 // get check evas_object
210 Evas_Object* check = getCheck(popup);
212 return RESULT_UNKNOWN;
215 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
218 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
222 } // namespace ViewModule