Set mime type for bundle in case of mmsto, sms
[platform/framework/web/wrt.git] / src / view / common / view_logic_security_origin_support.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    view_logic_security_origin_support.cpp
18  * @author  Jihoon Chung (jihoon.chung@samsung.com)
19  * @version 1.0
20  * @brief   Support security origin dao
21  */
22
23 #include "view_logic_security_origin_support.h"
24
25 #include <memory>
26 #include <Evas.h>
27 #include <Elementary.h>
28 #include <dpl/log/log.h>
29 #include <dpl/assert.h>
30 #include <wrt-commons/security-origin-dao/security_origin_dao.h>
31 #include <widget_model.h>
32
33 namespace ViewModule {
34 namespace {
35 const char* const DAEMON_EDJ_PATH = "/usr/share/edje/wrt/Daemon.edj";
36 }
37
38 class SecurityOriginSupportImplementation
39 {
40   private:
41     WidgetModel* m_model;
42     SecurityOriginDB::SecurityOriginDAOPtr m_securityOriginDAO;
43
44   public:
45     SecurityOriginSupportImplementation(WidgetModel* widgetModel) :
46         m_model(NULL)
47     {
48         Assert(widgetModel);
49         m_model = widgetModel;
50     }
51
52     ~SecurityOriginSupportImplementation()
53     {
54     }
55
56     SecurityOriginDB::SecurityOriginDAO* getSecurityOriginDAO(void)
57     {
58         Assert(m_model);
59         if (!m_securityOriginDAO) {
60             LogDebug("initialize securityOriginDAO");
61             m_securityOriginDAO =
62                 SecurityOriginDB::SecurityOriginDAOPtr(
63                     new SecurityOriginDB::SecurityOriginDAO(m_model->TizenId));
64             // initialize security result data. Remove allow, deny for
65             m_securityOriginDAO->removeSecurityOriginData(
66                 SecurityOriginDB::RESULT_ALLOW_ONCE);
67             m_securityOriginDAO->removeSecurityOriginData(
68                 SecurityOriginDB::RESULT_DENY_ONCE);
69         }
70         return m_securityOriginDAO.get();
71     }
72 };
73
74 SecurityOriginSupport::SecurityOriginSupport(WidgetModel* widgetModel) :
75     m_impl(new SecurityOriginSupportImplementation(widgetModel))
76 {
77 }
78
79 SecurityOriginSupport::~SecurityOriginSupport()
80 {
81 }
82
83 SecurityOriginDB::SecurityOriginDAO* SecurityOriginSupport::getSecurityOriginDAO(void)
84 {
85     return m_impl->getSecurityOriginDAO();
86 }
87
88 Evas_Object* SecurityOriginSupportUtil::createPopup(Evas_Object* window,
89                          const char* bodyText,
90                          const char* checkText,
91                          Evas_Smart_Cb buttonCallback,
92                          void* data)
93 {
94     LogDebug("createPopup");
95     Evas_Object* popup = elm_popup_add(window);
96
97     Evas_Object* label = elm_label_add(popup);
98     elm_object_style_set(label, "popup/default");
99     elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
100     elm_object_text_set(label, bodyText);
101     evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0.0);
102     evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
103     evas_object_show(label);
104
105     Evas_Object* layout = elm_layout_add(popup);
106     elm_layout_file_set(layout, DAEMON_EDJ_PATH, "popupWithCheck");
107     evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
108
109     Evas_Object* check = elm_check_add(popup);
110     evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
111     evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
112     evas_object_show(check);
113
114     elm_object_part_text_set(layout, "elm.text", checkText);
115     elm_object_part_content_set(layout, "elm.swallow.content", label);
116     elm_object_part_content_set(layout, "elm.swallow.end", check);
117
118     evas_object_show(layout);
119     elm_object_content_set(popup, layout);
120     Evas_Object* btn1 = elm_button_add(popup);
121     elm_object_text_set(btn1, "YES");
122     elm_object_part_content_set(popup, "button1", btn1);
123     evas_object_smart_callback_add(btn1, "clicked", buttonCallback, data);
124     Evas_Object* btn2 = elm_button_add(popup);
125     elm_object_text_set(btn2, "NO");
126     elm_object_part_content_set(popup, "button2", btn2);
127     evas_object_smart_callback_add(btn2, "clicked", buttonCallback, data);
128     return popup;
129 }
130
131 Evas_Object* SecurityOriginSupportUtil::getPopup(Evas_Object* button)
132 {
133     Assert(button);
134
135     Evas_Object* popup = button;
136     while (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
137         popup = elm_object_parent_widget_get(popup);
138         if (!popup) {
139             return NULL;
140         }
141     }
142     return popup;
143 }
144
145 Evas_Object* SecurityOriginSupportUtil::getCheck(Evas_Object* popup)
146 {
147     Assert(popup);
148     if (strcmp(elm_object_widget_type_get(popup), "elm_popup")) {
149         return NULL;
150     }
151     Evas_Object* check = elm_object_part_content_get(
152         elm_object_content_get(popup),
153         "elm.swallow.end");
154     return check;
155 }
156
157 SecurityOriginDB::Result SecurityOriginSupportUtil::getResult(Evas_Object* button)
158 {
159     using namespace SecurityOriginDB;
160
161     Assert(button);
162     // get popup evas_object
163     Evas_Object* popup = getPopup(button);
164     if (popup == NULL) {
165         return RESULT_UNKNOWN;
166     }
167     bool allow = !strcmp("YES", elm_object_text_get(button));
168
169     // get check evas_object
170     Evas_Object* check = getCheck(popup);
171     if (check == NULL) {
172         return RESULT_UNKNOWN;
173     }
174     if (allow) {
175         return elm_check_state_get(check) ? RESULT_ALLOW_ALWAYS : RESULT_ALLOW_ONCE;
176     } else {
177         return elm_check_state_get(check) ? RESULT_DENY_ALWAYS : RESULT_DENY_ONCE;
178     }
179 }
180 } // namespace ViewModule