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.
24 #include <FBaseColArrayList.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilUri.h>
27 #include <FGrpDimension.h>
28 #include <FGrpRectangle.h>
29 #include <FIoDbEnumerator.h>
30 #include <FIoDbStatement.h>
31 #include <FSecCertX509Certificate.h>
32 #include <FUiCtrlButton.h>
33 #include <FUiCtrlLabel.h>
34 #include <FUiCtrlPanel.h>
35 #include <FUiKeyEventInfo.h>
36 #include <FUiLayout.h>
37 #include <FUiVerticalBoxLayout.h>
38 #include <FIo_DatabaseImpl.h>
39 #include <FSys_SystemResource.h>
40 #include <FUi_ControlManager.h>
41 #include <FUi_ResourceManager.h>
42 #include "FWebCtrl_EflWebkit.h"
43 #include "FWebCtrl_UserConfirmPopup.h"
44 #include "FWebCtrl_Utility.h"
45 #include "FWebCtrl_WebImpl.h"
48 using namespace Tizen::Base;
49 using namespace Tizen::Base::Collection;
50 using namespace Tizen::Base::Utility;
51 using namespace Tizen::Graphics;
52 using namespace Tizen::Io;
53 using namespace Tizen::Security::Cert;
54 using namespace Tizen::System;
55 using namespace Tizen::Ui;
56 using namespace Tizen::Ui::Controls;
59 namespace Tizen { namespace Web { namespace Controls
63 _UserConfirmPopup::_UserConfirmPopup(void)
64 : __pUserPolicyData(null)
65 , __userConfirmMode(USER_CONFIRM_USERMEDIA)
66 , __pCheckButton(null)
67 , __isUserActionNeeded(false)
74 _UserConfirmPopup::~_UserConfirmPopup(void)
76 if (__isUserActionNeeded == true)
78 HandleUserAction(EINA_FALSE);
79 __isUserActionNeeded = false;
85 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, Tizen::Web::Controls::_WebImpl* pImpl, bool sync, String msg)
88 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
89 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
90 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
92 _SystemResource* pSysResource = _SystemResource::GetInstance();
93 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
95 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
96 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
98 __pUserPolicyData = pEventInfo;
99 __userConfirmMode = userConfirmMode;
102 __isUserActionNeeded = true;
104 bool hasTitle = true;
105 int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->btnDim.height + 2*pPopupData->sideMargin;
108 SysAssertf(__pImpl != null, "Failed to get _WebImpl");
110 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
112 popupMaxHeight += pPopupData->checkDim.height;
115 if (__userConfirmMode == USER_SCRIPT_ALERT)
117 popupMaxHeight -= 2*pPopupData->sideMargin;
121 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
122 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
124 if (userConfirmMode != USER_SCRIPT_ALERT)
126 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_SECURITY_WARNING_ABB"));
129 Rectangle rect(0, 0, 0, 0);
132 rect.height = 2*pPopupData->labelDim.height;
133 rect.width = pPopupData->labelDim.width;
135 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
136 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
138 String message = L"";
139 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
145 message = GetMessageFromPolicy();
147 r = pLabel->Construct(rect, message);
148 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
152 r = AddControl(*pLabel);
153 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155 Label* pInfoLabel = pLabel.release();
157 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
160 rect.height = pPopupData->checkDim.height;
162 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
163 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
165 r = pCheckButton->Construct(Rectangle(0, 0, rect.width, rect.height), CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE, false, pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_REMEMBER_PREFERENCE"));
166 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168 r = AddControl(*pCheckButton);
169 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 __pCheckButton = pCheckButton.release();
174 Panel* pButtonPanel = CreateAndAddPanel();
175 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
178 r = idList.Construct();
179 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182 r = titleList.Construct();
183 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
185 if (userConfirmMode == USER_SCRIPT_ALERT)
187 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
188 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
192 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
193 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
194 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
195 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
198 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
199 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
201 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
202 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
204 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
205 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
207 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
209 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
211 if ( __userConfirmMode != USER_SCRIPT_ALERT )
213 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
216 SetPropagatedKeyEventListener(this);
222 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
224 result r = E_SUCCESS;
228 case ID_BUTTON_USER_ALLOW:
229 HandleUserAction(EINA_TRUE);
232 case ID_BUTTON_USER_CANCEL:
233 HandleUserAction(EINA_FALSE);
243 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
248 switch(__userConfirmMode)
250 case USER_CONFIRM_USERMEDIA:
252 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
255 case USER_CONFIRM_GEOLOCATION:
257 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
260 case USER_CONFIRM_NOTIFICATION:
262 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
265 case USER_SCRIPT_ALERT:
267 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
270 case USER_SCRIPT_CONFIRM:
272 __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
283 _UserConfirmPopup::GetMessageFromPolicy(void)
285 _SystemResource* pSysResource = _SystemResource::GetInstance();
286 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
290 switch(__userConfirmMode)
292 case USER_CONFIRM_USERMEDIA:
294 message = L"Do you want to allow acccess to media?\n";
297 case USER_PROTOCOL_HANDLER:
299 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
300 SysAssertf(pHandlerData, "Failed to request");
302 String target(ewk_custom_handlers_data_target_get(pHandlerData));
303 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
305 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
308 case USER_CONTENT_HANDLER:
310 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
311 SysAssertf(pHandlerData, "Failed to request");
313 String target(ewk_custom_handlers_data_target_get(pHandlerData));
314 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
316 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
319 case USER_CONFIRM_GEOLOCATION:
321 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
322 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
324 message = _Utility::CreateOrigin(pSecurityOrigin);
325 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
328 case USER_CONFIRM_NOTIFICATION:
330 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
331 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
332 message = _Utility::CreateOrigin(pSecurityOrigin);
333 message.Append(L" wants to display notifications");
345 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
347 switch (__userConfirmMode)
349 case USER_CONFIRM_USERMEDIA:
351 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
352 ewk_user_media_permission_request_set(pPolicy, allow);
355 case USER_PROTOCOL_HANDLER:
357 RegisterHandler(false, allow);
360 case USER_CONTENT_HANDLER:
362 RegisterHandler(true, allow);
365 case USER_CONFIRM_GEOLOCATION:
367 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
368 if (__pCheckButton->IsSelected())
370 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
371 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
374 ewk_geolocation_permission_request_set(pPolicy, allow);
377 case USER_CONFIRM_NOTIFICATION:
379 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
380 ewk_notification_permission_request_set(pPermissionRequest, allow);
383 case USER_SCRIPT_ALERT:
385 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
386 ewk_view_javascript_alert_reply(pView);
389 case USER_SCRIPT_CONFIRM:
391 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
392 ewk_view_javascript_confirm_reply(pView, allow);
395 case USER_CONFIRM_APP_CACHE:
397 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
398 ewk_view_application_cache_permission_reply(pObj, allow);
401 case USER_CONFIRM_DB_QUOTA_EXCEDED:
403 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
404 ewk_view_exceeded_database_quota_reply(pObj, allow);
407 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
409 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
410 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
413 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
415 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
416 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
422 __isUserActionNeeded = false;
427 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
430 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
431 String table(GEOLOCATION_TABLE_NAME);
433 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
434 String origin = _Utility::CreateOrigin(pSecurityOrigin);
436 result r = db.Construct(geolocationPath, "r+", null);
437 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
439 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
440 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
442 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
444 pStmt->BindString(0, origin);
445 pStmt->BindInt(1, static_cast < int >(enable));
447 db.BeginTransaction();
449 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
451 db.CommitTransaction();
458 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
461 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
465 if(checkHandler == true)
467 table = CUSTOM_CONTENT_TABLE_NAME;
471 table = CUSTOM_PROTOCOL_TABLE_NAME;
473 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
474 SysAssertf(pHandlerData, "Failed to request");
476 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
477 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
478 String target = ewk_custom_handlers_data_target_get(pHandlerData);
480 result r = db.Construct(handlerPath, "r+", null);
481 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
483 std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select id From " + table + L" Where baseUrl = '" + baseUri + L"' AND url = '" + uri + L"' AND mime = '" + target + L"'"));
488 pEnum->GetIntAt(0, checkId);
490 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
491 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
493 pUpdateStmt->BindInt(0, static_cast < int >(allow));
494 pUpdateStmt->BindInt(1, checkId);
496 db.BeginTransaction();
498 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
500 db.CommitTransaction();
505 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
506 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
508 pStmt->BindString(0, baseUri);
509 pStmt->BindString(1, uri);
510 pStmt->BindString(2, target);
511 pStmt->BindInt(3, static_cast < int >(allow));
513 db.BeginTransaction();
515 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
517 db.CommitTransaction();
522 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
528 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
530 result r = E_SUCCESS;
531 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
533 HandleUserAction(EINA_FALSE);
538 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
541 switch (__userConfirmMode)
543 case USER_CONFIRM_USERMEDIA:
545 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
548 case USER_CONFIRM_GEOLOCATION:
550 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
553 case USER_CONFIRM_NOTIFICATION:
555 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
558 case USER_SCRIPT_ALERT:
560 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
563 case USER_SCRIPT_CONFIRM:
565 __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
568 case USER_PROTOCOL_HANDLER:
569 case USER_CONTENT_HANDLER:
570 case USER_CONFIRM_APP_CACHE:
571 case USER_CONFIRM_DB_QUOTA_EXCEDED:
572 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
573 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
583 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
589 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
595 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
601 }}} // Tizen::Web::Controls