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)
63 _UserConfirmPopup::~_UserConfirmPopup(void)
69 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, bool sync)
72 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
73 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_CERTIFICATE && userConfirmMode <= USER_CONFIRM_USERMEDIA, E_INVALID_ARG,
74 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
76 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
77 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
79 __pUserPolicyData = pEventInfo;
80 __userConfirmMode = userConfirmMode;
83 int popupMaxHeight = 0;
84 popupMaxHeight = 2*pPopupData->labelDim.height + 2*pPopupData->btnDim.height + 6*pPopupData->sideMargin;
86 r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupMaxHeight));
87 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89 SetTitleText("Security Warning");
91 Rectangle rect(0, 0, 0, 0);
94 rect.height = 2*pPopupData->labelDim.height;
95 rect.width = pPopupData->labelDim.width;
97 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
98 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
100 String message = GetMessageFromPolicy();
101 r = pLabel->Construct(rect, message);
102 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
104 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
106 r = AddControl(*pLabel);
107 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109 Label* pInfoLabel = pLabel.release();
111 Panel* pButtonPanel = CreateAndAddPanel();
112 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
115 r = idList.Construct();
116 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
117 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
118 if (__userConfirmMode == USER_CONFIRM_CERTIFICATE)
120 idList.Add(*(new Integer(ID_BUTTON_USER_CERT_VIEW)));
122 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
125 r = titleList.Construct();
126 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
127 titleList.Add(*(new String(L"Allow")));
128 if (__userConfirmMode == USER_CONFIRM_CERTIFICATE)
130 titleList.Add(*(new String(L"View")));
132 titleList.Add(*(new String(L"Cancel")));
134 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
135 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
137 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
138 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
140 pLayout->SetHorizontalFitPolicy(*pInfoLabel, FIT_POLICY_PARENT);
141 pLayout->SetHorizontalFitPolicy(*pButtonPanel, FIT_POLICY_PARENT);
143 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
144 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
146 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
153 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
155 result r = E_SUCCESS;
159 case ID_BUTTON_USER_ALLOW:
160 HandleUserAction(EINA_TRUE);
163 case ID_BUTTON_USER_CERT_VIEW:
164 r = ShowCertificatePopup();
165 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
168 case ID_BUTTON_USER_CANCEL:
169 HandleUserAction(EINA_FALSE);
179 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
190 _UserConfirmPopup::GetConfirmResult() const
197 _UserConfirmPopup::GetMessageFromPolicy(void)
201 switch(__userConfirmMode)
203 case USER_CONFIRM_CERTIFICATE:
205 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
206 message = L"There are problems with the security certificate of this site.\n";
207 message.Append(ewk_certificate_policy_decision_url_get(pPolicy));
210 case USER_CONFIRM_USERMEDIA:
212 message = L"Do you want to allow acccess to media?\n";
224 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
226 switch (__userConfirmMode)
228 case USER_CONFIRM_CERTIFICATE:
230 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
231 ewk_certificate_policy_decision_allowed_set(pPolicy, allow);
234 case USER_CONFIRM_USERMEDIA:
236 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
237 ewk_user_media_permission_request_set(pPolicy, allow);
244 __confirm = static_cast< bool >(allow);
249 _UserConfirmPopup::ShowCertificatePopup(void)
251 //get Certificate information
252 Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(__pUserPolicyData);
253 SysTryReturnResult(NID_WEB_CTRL, pPolicy, E_SYSTEM, "Certificate policy is not set.");
255 std::unique_ptr<_CertificatePopup> pCertificatePopup(new (std::nothrow) _CertificatePopup());
256 SysTryReturnResult(NID_WEB_CTRL, pCertificatePopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
258 result r = pCertificatePopup->Construct(pPolicy);
259 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
261 r = pCertificatePopup->ShowPopup();
262 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
264 pCertificatePopup.release();
269 }}} // Tizen::Web::Controls