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()
59 SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
62 if (!m_securityOriginDAO) {
63 LogDebug("initialize securityOriginDAO");
65 SecurityOriginDB::SecurityOriginDAOPtr(
66 new SecurityOriginDB::SecurityOriginDAO(m_model->TzPkgId.Get()));
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))
111 SecurityOriginSupport::~SecurityOriginSupport()
115 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::getSecurityOriginDAO(void)
117 return m_impl->getSecurityOriginDAO();
120 WrtDB::SettingsType SecurityOriginSupport::isNeedPermissionCheck(
121 SecurityOriginDB::Feature feature)
123 return m_impl->isNeedPermissionCheck(feature);
126 Evas_Object* SecurityOriginSupportUtil::createPopup(Evas_Object* window,
127 const char* bodyText,
128 const char* checkText,
129 Evas_Smart_Cb buttonCallback,
132 LogDebug("createPopup");
133 Evas_Object* popup = elm_popup_add(window);
135 Evas_Object* label = elm_label_add(popup);
136 elm_object_style_set(label, "popup/default");
137 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
138 elm_object_text_set(label, bodyText);
139 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
140 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
141 evas_object_show(label);
143 Evas_Object* layout = elm_layout_add(popup);
144 elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck");
145 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
147 Evas_Object* check = elm_check_add(popup);
148 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
149 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
150 evas_object_show(check);
152 elm_object_part_text_set(layout, "elm.text", checkText);
153 elm_object_part_content_set(layout, "elm.swallow.content", label);
154 elm_object_part_content_set(layout, "elm.swallow.end", check);
156 evas_object_show(layout);
157 elm_object_content_set(popup, layout);
158 Evas_Object* btn1 = elm_button_add(popup);
159 elm_object_text_set(btn1, "YES");
160 elm_object_part_content_set(popup, "button1", btn1);
161 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
162 Evas_Object* btn2 = elm_button_add(popup);
163 elm_object_text_set(btn2, "NO");
164 elm_object_part_content_set(popup, "button2", btn2);
165 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
169 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
173 Evas_Object* popup = button;
174 while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
175 popup = elm_object_parent_widget_get(popup);
183 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
186 if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
189 Evas_Object* check = elm_object_part_content_get(
190 elm_object_content_get(popup),
195 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(Evas_Object* button)
197 using namespace SecurityOriginDB;
200 // get popup evas_object
201 Evas_Object* popup = getPopup(button);
203 return RESULT_UNKNOWN;
205 bool allow = !strcmp("YES", elm_object_text_get(button));
207 // get check evas_object
208 Evas_Object* check = getCheck(popup);
210 return RESULT_UNKNOWN;
213 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS : RESULT_ALLOW_ONCE;
215 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS : RESULT_DENY_ONCE;
218 } // namespace ViewModule