Set proper title to page on handling tizen scheme
[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
33 namespace ViewModule {
34 namespace CertificateConfirmSupport {
35 using namespace CertificateDB;
36 using namespace ViewModule::CertificateSupportUtil;
37
38 namespace {
39 const char* const CERTIFICATION_ASK_BODY =
40     "This site's security certificate is not trusted! Do you acess this site?";
41 const char* const CERTIFICATION_ASK_CHECK = "Don't ask again";
42
43 // function declare
44 void askUserForCertificatePermission(
45     Evas_Object* window,
46     PermissionData* data);
47 static void popupCallback(void* data, Evas_Object* obj, void* eventInfo);
48
49 void askUserForCertificatePermission(
50     Evas_Object* window,
51     PermissionData* data)
52 {
53     LogDebug("askUserForCertificatePermission called");
54     Evas_Object* popup = createPopup(window,
55                                      CERTIFICATION_ASK_BODY,
56                                      CERTIFICATION_ASK_CHECK,
57                                      popupCallback,
58                                      data);
59
60     if (popup == NULL) {
61         LogError("Fail to create popup object");
62         delete data;
63         return;
64     } else {
65         evas_object_show(popup);
66     }
67 }
68
69 void popupCallback(void* data, Evas_Object* obj, void* /*eventInfo*/)
70 {
71     LogDebug("popupCallback");
72     Assert(data);
73     PermissionData* permData = static_cast<PermissionData*>(data);
74     Ewk_Certificate_Policy_Decision* certificatePolicyDecision =
75         static_cast<Ewk_Certificate_Policy_Decision*>(permData->m_data);
76
77     Evas_Object* popup = getPopup(obj);
78     Result result = getResult(obj);
79
80     if (result != RESULT_UNKNOWN) {
81         permData->m_certiDao->setCertificateData(permData->m_certiData,
82                                                      result);
83     }
84     Eina_Bool ret =
85         (result == RESULT_ALLOW_ALWAYS || result == RESULT_ALLOW_ONCE) ?
86         EINA_TRUE : EINA_FALSE;
87
88     ewk_certificate_policy_decision_allowed_set(
89         certificatePolicyDecision,
90         ret);
91     delete permData;
92     evas_object_hide(popup);
93     evas_object_del(popup);
94 }
95 } // namespace
96
97 void certificatePermissionRequest(
98     Evas_Object* window,
99     CertificateDB::CertificateDAO* certificateDAO,
100     void* data)
101 {
102     LogDebug("certificationPermissionRequest called");
103     Assert(certificateDAO);
104     Assert(data);
105
106     Ewk_Certificate_Policy_Decision* certificatePolicyDecision =
107         static_cast<Ewk_Certificate_Policy_Decision*>(data);
108     ewk_certificate_policy_decision_suspend(certificatePolicyDecision);
109     Assert(certificatePolicyDecision);
110
111     CertificateData certificateData(
112              DPL::FromUTF8String(
113                 ewk_certificate_policy_decision_certificate_pem_get(
114                      certificatePolicyDecision)));
115
116     // check cache database
117     Result result = certificateDAO->getResult(certificateData);
118
119     if (RESULT_ALLOW_ONCE == result || RESULT_ALLOW_ALWAYS == result) {
120         LogDebug("allow");
121         ewk_certificate_policy_decision_allowed_set(
122             certificatePolicyDecision,
123             EINA_TRUE);
124          return;
125    } else if (RESULT_DENY_ONCE == result || RESULT_DENY_ALWAYS == result) {
126         LogDebug("Deny");
127         ewk_certificate_policy_decision_allowed_set(
128             certificatePolicyDecision,
129             EINA_FALSE);
130          return;
131     }
132     // ask to user
133     PermissionData* permissionData =
134         new PermissionData(certificateDAO,
135                            certificateData,
136                            certificatePolicyDecision);
137     askUserForCertificatePermission(window, permissionData);
138     return;
139 }
140 }
141 } // namespace ViewModule