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 <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <dpl/wrt-dao-ro/common_dao_types.h>
31 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
32 #include <widget_model.h>
34 namespace ViewModule {
36 const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj";
39 class SecurityOriginSupportImplementation
43 SecurityOriginDB::SecurityOriginDAOPtr m_securityOriginDAO;
46 SecurityOriginSupportImplementation(WidgetModel* widgetModel) :
50 m_model = widgetModel;
53 ~SecurityOriginSupportImplementation()
56 SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
59 if (!m_securityOriginDAO) {
60 LogDebug("initialize securityOriginDAO");
62 SecurityOriginDB::SecurityOriginDAOPtr(
63 new SecurityOriginDB::SecurityOriginDAO(m_model->TzPkgId.
65 // initialize security result data. Remove allow, deny for
66 m_securityOriginDAO->removeSecurityOriginData(
67 SecurityOriginDB::RESULT_ALLOW_ONCE);
68 m_securityOriginDAO->removeSecurityOriginData(
69 SecurityOriginDB::RESULT_DENY_ONCE);
71 return m_securityOriginDAO.get();
75 SecurityOriginSupport::SecurityOriginSupport(WidgetModel* widgetModel) :
76 m_impl(new SecurityOriginSupportImplementation(widgetModel))
79 SecurityOriginSupport::~SecurityOriginSupport()
82 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::
83 getSecurityOriginDAO(void)
85 return m_impl->getSecurityOriginDAO();
88 Evas_Object* SecurityOriginSupportUtil::createPopup(
91 const char* checkText,
96 LogDebug("createPopup");
97 Evas_Object* popup = elm_popup_add(window);
99 Evas_Object* label = elm_label_add(popup);
100 elm_object_style_set(label, "popup/default");
101 elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
102 elm_object_text_set(label, bodyText);
103 evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
104 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
105 evas_object_show(label);
107 Evas_Object* layout = elm_layout_add(popup);
108 elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck");
109 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
111 Evas_Object* check = elm_check_add(popup);
112 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
113 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 evas_object_show(check);
116 elm_object_part_text_set(layout, "elm.text", checkText);
117 elm_object_part_content_set(layout, "elm.swallow.content", label);
118 elm_object_part_content_set(layout, "elm.swallow.end", check);
120 evas_object_show(layout);
121 elm_object_content_set(popup, layout);
122 Evas_Object* btn1 = elm_button_add(popup);
123 elm_object_text_set(btn1, "Allow");
124 elm_object_part_content_set(popup, "button1", btn1);
125 evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
126 Evas_Object* btn2 = elm_button_add(popup);
127 elm_object_text_set(btn2, "Deny");
128 elm_object_part_content_set(popup, "button2", btn2);
129 evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
133 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
137 Evas_Object* popup = button;
138 while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
139 popup = elm_object_parent_widget_get(popup);
147 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
150 if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
153 Evas_Object* check = elm_object_part_content_get(
154 elm_object_content_get(popup),
159 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(
162 using namespace SecurityOriginDB;
165 // get popup evas_object
166 Evas_Object* popup = getPopup(button);
168 return RESULT_UNKNOWN;
170 bool allow = !strcmp("Allow", elm_object_text_get(button));
172 // get check evas_object
173 Evas_Object* check = getCheck(popup);
175 return RESULT_UNKNOWN;
178 return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS :
181 return elm_check_state_get(check) ? RESULT_DENY_ALWAYS :
185 } // namespace ViewModule