2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_UserConfirmPopup.cpp
20 * @brief The file contains the definition of _UserConfirmPopup class.
22 #include <FBaseColArrayList.h>
23 #include <FBaseSysLog.h>
24 #include <FBaseUtilUri.h>
25 #include <FGrpDimension.h>
26 #include <FGrpRectangle.h>
27 #include <FSecCertX509Certificate.h>
28 #include <FUiCtrlButton.h>
29 #include <FUiCtrlLabel.h>
30 #include <FUiCtrlPanel.h>
31 #include <FUiLayout.h>
32 #include <FUiVerticalBoxLayout.h>
33 #include <FUi_ControlManager.h>
34 #include <FUi_ResourceManager.h>
35 #include "FWebCtrl_CertificatePopup.h"
36 #include "FWebCtrl_UserConfirmPopup.h"
37 #include "FWebCtrl_Utility.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Base::Utility;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Io;
45 using namespace Tizen::Security::Cert;
46 using namespace Tizen::Ui;
47 using namespace Tizen::Ui::Controls;
50 namespace Tizen { namespace Web { namespace Controls
54 _UserConfirmPopup::_UserConfirmPopup(void)
55 : __pUserPolicyData(null)
56 , __userConfirmMode(USER_CONFIRM_CERTIFICATE)
61 _UserConfirmPopup::~_UserConfirmPopup(void)
67 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo)
70 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
71 SysTryReturnResult(NID_WEB_CTRL, (userConfirmMode <= USER_CONFIRM_USERMEDIA) && (userConfirmMode >= USER_CONFIRM_CERTIFICATE), E_INVALID_ARG,
72 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
74 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
75 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
77 __pUserPolicyData = pEventInfo;
78 __userConfirmMode = userConfirmMode;
80 int popupMaxHeight = 0;
81 popupMaxHeight = 2*pPopupData->labelDim.height + 2*pPopupData->btnDim.height + 6*pPopupData->sideMargin;
83 r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupMaxHeight));
84 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
86 SetTitleText("Security Warning");
88 Rectangle rect(0, 0, 0, 0);
91 rect.height = 2*pPopupData->labelDim.height;
92 rect.width = pPopupData->labelDim.width;
94 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
95 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
97 String message = GetMessageFromPolicy();
98 r = pLabel->Construct(rect, message);
99 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
101 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
103 r = AddControl(*pLabel);
104 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106 Label* pInfoLabel = pLabel.release();
108 Panel* pButtonPanel = CreateAndAddPanel();
109 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
112 r = idList.Construct();
113 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
114 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
115 if (__userConfirmMode == USER_CONFIRM_CERTIFICATE)
117 idList.Add(*(new Integer(ID_BUTTON_USER_CERT_VIEW)));
119 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
122 r = titleList.Construct();
123 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124 titleList.Add(*(new String(L"Allow")));
125 if (__userConfirmMode == USER_CONFIRM_CERTIFICATE)
127 titleList.Add(*(new String(L"View")));
129 titleList.Add(*(new String(L"Cancel")));
131 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
132 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
134 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
135 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
137 pLayout->SetHorizontalFitPolicy(*pInfoLabel, FIT_POLICY_PARENT);
138 pLayout->SetHorizontalFitPolicy(*pButtonPanel, FIT_POLICY_PARENT);
140 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
141 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
143 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
150 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
152 result r = E_SUCCESS;
156 case ID_BUTTON_USER_ALLOW:
157 HandleUserAction(EINA_TRUE);
160 case ID_BUTTON_USER_CERT_VIEW:
161 r = ShowCertificatePopup();
162 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
165 case ID_BUTTON_USER_CANCEL:
166 HandleUserAction(EINA_FALSE);
176 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
184 _UserConfirmPopup::GetMessageFromPolicy(void)
188 switch(__userConfirmMode)
190 case USER_CONFIRM_CERTIFICATE:
192 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
193 message = L"There are problems with the security certificate of this site.\n";
194 message.Append(ewk_certificate_policy_decision_url_get(pPolicy));
197 case USER_CONFIRM_USERMEDIA:
199 message = L"Do you want to allow acccess to media?\n";
211 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
213 switch (__userConfirmMode)
215 case USER_CONFIRM_CERTIFICATE:
217 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
218 ewk_certificate_policy_decision_allowed_set(pPolicy, allow);
221 case USER_CONFIRM_USERMEDIA:
223 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
224 ewk_user_media_permission_request_set(pPolicy, allow);
234 _UserConfirmPopup::ShowCertificatePopup(void)
236 //get Certificate information
237 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
238 SysTryReturnResult(NID_WEB_CTRL, pPolicy, E_SYSTEM, "Certificate policy is not set.");
240 std::unique_ptr<_CertificatePopup> pCertificatePopup(new (std::nothrow) _CertificatePopup());
241 SysTryReturnResult(NID_WEB_CTRL, pCertificatePopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
243 result r = pCertificatePopup->Construct(pPolicy);
244 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
246 r = pCertificatePopup->ShowPopup();
247 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
249 pCertificatePopup.release();
254 }}} // Tizen::Web::Controls