[Release] wrt_0.8.264
[platform/framework/web/wrt.git] / src / view / webkit / view_logic_certificate_confirm_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_certificate_confirm_support.cpp
18  * @author  Leerang Song (leerang.song@samsung.com)
19  */
20
21 #include "view_logic_certificate_confirm_support.h"
22
23 #include <string>
24 #include <sstream>
25 #include <dpl/log/log.h>
26 #include <dpl/assert.h>
27 #include <wrt-commons/certificate-dao/certificate_dao_types.h>
28 #include <wrt-commons/certificate-dao/certificate_dao.h>
29 #include <EWebKit2.h>
30 #include <common/view_logic_certificate_support.h>
31 #include <Elementary.h>
32 #include <widget_string.h>
33
34 namespace ViewModule {
35 namespace CertificateConfirmSupport {
36 using namespace CertificateDB;
37 using namespace ViewModule::CertificateSupportUtil;
38
39 namespace {
40
41 // function declare
42 void askUserForCertificatePermission(
43     Evas_Object* window,
44     PermissionData* data);
45 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
46
47 void askUserForCertificatePermission(
48     Evas_Object* window,
49     PermissionData* data)
50 {
51     LogDebug("askUserForCertificatePermission called");
52     Ewk_Certificate_Policy_Decision* certificatePolicyDecision =
53         static_cast<Ewk_Certificate_Policy_Decision*>(data->m_data);
54     Assert(certificatePolicyDecision);
55
56     std::string msg = std::string(WRT_POP_CERTIFICATE_PERMISSION)
57         + " " + ewk_certificate_policy_decision_url_get(certificatePolicyDecision);
58     Evas_Object* popup = createPopup(window,
59                                      msg.c_str(),
60                                      WRT_BODY_REMEMBER_PREFERENCE,
61                                      popupCallback,
62                                      data);
63
64     if (popup == NULL) {
65         LogError("Fail to create popup object");
66         delete data;
67         return;
68     } else {
69         evas_object_show(popup);
70     }
71 }
72
73 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
74 {
75     LogDebug("popupCallback");
76     Assert(data);
77     PermissionData* permData = static_cast<PermissionData*>(data);
78     Ewk_Certificate_Policy_Decision* certificatePolicyDecision =
79         static_cast<Ewk_Certificate_Policy_Decision*>(permData->m_data);
80
81     Evas_Object* popup = getPopup(obj);
82     Result result = getResult(obj);
83
84     if (result != RESULT_UNKNOWN) {
85         permData->m_certiDao->setCertificateData(permData->m_certiData,
86                                                      result);
87     }
88     Eina_Bool ret =
89         (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
90         EINA_TRUE : EINA_FALSE;
91
92     ewk_certificate_policy_decision_allowed_set(
93         certificatePolicyDecision,
94         ret);
95     delete permData;
96     evas_object_hide(popup);
97     evas_object_del(popup);
98 }
99 } // namespace
100
101 void certificatePermissionRequest(
102     Evas_Object* window,
103     CertificateDB::CertificateDAO* certificateDAO,
104     void* data)
105 {
106     LogDebug("certificationPermissionRequest called");
107     Assert(certificateDAO);
108     Assert(data);
109
110     Ewk_Certificate_Policy_Decision* certificatePolicyDecision =
111         static_cast<Ewk_Certificate_Policy_Decision*>(data);
112     ewk_certificate_policy_decision_suspend(certificatePolicyDecision);
113     Assert(certificatePolicyDecision);
114
115     CertificateData certificateData(
116              DPL::FromUTF8String(
117                 ewk_certificate_policy_decision_certificate_pem_get(
118                      certificatePolicyDecision)));
119
120     // check cache database
121     Result result = certificateDAO->getResult(certificateData);
122
123     if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
124         LogDebug("allow");
125         ewk_certificate_policy_decision_allowed_set(
126             certificatePolicyDecision,
127             EINA_TRUE);
128          return;
129    } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
130         LogDebug("Deny");
131         ewk_certificate_policy_decision_allowed_set(
132             certificatePolicyDecision,
133             EINA_FALSE);
134          return;
135     }
136     // ask to user
137     PermissionData* permissionData =
138         new PermissionData(certificateDAO,
139                            certificateData,
140                            certificatePolicyDecision);
141     askUserForCertificatePermission(window, permissionData);
142     return;
143 }
144 }
145 } // namespace ViewModule