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)
73 _UserConfirmPopup::~_UserConfirmPopup(void)
78 HandleUserAction(EINA_FALSE);
84 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, Tizen::Web::Controls::_WebImpl* pImpl, bool sync, String msg)
87 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
88 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
89 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
91 _SystemResource* pSysResource = _SystemResource::GetInstance();
92 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
94 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
95 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
97 __pUserPolicyData = pEventInfo;
98 __userConfirmMode = userConfirmMode;
101 bool hasTitle = true;
102 int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->btnDim.height + 2*pPopupData->sideMargin;
109 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
111 popupMaxHeight += pPopupData->checkDim.height;
114 if (__userConfirmMode == USER_SCRIPT_ALERT)
116 popupMaxHeight -= 2*pPopupData->sideMargin;
120 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
121 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123 if (userConfirmMode != USER_SCRIPT_ALERT)
125 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_HEADER_SECURITY_WARNING"));
128 Rectangle rect(0, 0, 0, 0);
131 rect.height = 2*pPopupData->labelDim.height;
132 rect.width = pPopupData->labelDim.width;
134 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
135 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
137 String message = L"";
138 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
144 message = GetMessageFromPolicy();
146 r = pLabel->Construct(rect, message);
147 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
149 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
151 r = AddControl(*pLabel);
152 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154 Label* pInfoLabel = pLabel.release();
156 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
159 rect.height = pPopupData->checkDim.height;
161 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
162 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
164 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"));
165 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
167 r = AddControl(*pCheckButton);
168 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
170 __pCheckButton = pCheckButton.release();
173 Panel* pButtonPanel = CreateAndAddPanel();
174 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
177 r = idList.Construct();
178 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181 r = titleList.Construct();
182 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
184 if (userConfirmMode == USER_SCRIPT_ALERT)
186 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
187 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
191 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
192 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
193 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_CANCEL"))));
194 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
197 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
198 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
200 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
201 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
203 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
204 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
206 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
208 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
210 if ( __userConfirmMode != USER_SCRIPT_ALERT )
212 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
215 SetPropagatedKeyEventListener(this);
221 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
223 result r = E_SUCCESS;
227 case ID_BUTTON_USER_ALLOW:
228 HandleUserAction(EINA_TRUE);
231 case ID_BUTTON_USER_CANCEL:
232 HandleUserAction(EINA_FALSE);
242 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
247 switch(__userConfirmMode)
249 case USER_CONFIRM_USERMEDIA:
251 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
254 case USER_CONFIRM_GEOLOCATION:
256 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
259 case USER_CONFIRM_NOTIFICATION:
261 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
264 case USER_SCRIPT_ALERT:
266 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
269 case USER_SCRIPT_CONFIRM:
271 //__pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
282 _UserConfirmPopup::GetMessageFromPolicy(void)
284 _SystemResource* pSysResource = _SystemResource::GetInstance();
285 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
289 switch(__userConfirmMode)
291 case USER_CONFIRM_USERMEDIA:
293 message = L"Do you want to allow acccess to media?\n";
296 case USER_PROTOCOL_HANDLER:
298 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
299 SysAssertf(pHandlerData, "Failed to request");
301 String target(ewk_custom_handlers_data_target_get(pHandlerData));
302 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
304 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
307 case USER_CONTENT_HANDLER:
309 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
310 SysAssertf(pHandlerData, "Failed to request");
312 String target(ewk_custom_handlers_data_target_get(pHandlerData));
313 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
315 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
318 case USER_CONFIRM_GEOLOCATION:
320 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
321 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
323 message = _Utility::CreateOrigin(pSecurityOrigin);
324 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
327 case USER_CONFIRM_NOTIFICATION:
329 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
330 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
331 message = _Utility::CreateOrigin(pSecurityOrigin);
332 message.Append(L" wants to display notifications");
344 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
346 switch (__userConfirmMode)
348 case USER_CONFIRM_USERMEDIA:
350 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
351 ewk_user_media_permission_request_set(pPolicy, allow);
354 case USER_PROTOCOL_HANDLER:
356 RegisterHandler(false, allow);
359 case USER_CONTENT_HANDLER:
361 RegisterHandler(true, allow);
364 case USER_CONFIRM_GEOLOCATION:
366 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
367 if (__pCheckButton->IsSelected())
369 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
370 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
373 ewk_geolocation_permission_request_set(pPolicy, allow);
376 case USER_CONFIRM_NOTIFICATION:
378 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
379 ewk_notification_permission_request_set(pPermissionRequest, allow);
382 case USER_SCRIPT_ALERT:
384 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
385 ewk_view_javascript_alert_reply(pView);
388 case USER_SCRIPT_CONFIRM:
390 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
391 ewk_view_javascript_confirm_reply(pView, allow);
394 case USER_CONFIRM_APP_CACHE:
396 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
397 ewk_view_application_cache_permission_reply(pObj, allow);
400 case USER_CONFIRM_DB_QUOTA_EXCEDED:
402 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
403 ewk_view_exceeded_database_quota_reply(pObj, allow);
406 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
408 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
409 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
412 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
414 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
415 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
425 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
428 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
429 String table(GEOLOCATION_TABLE_NAME);
431 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
432 String origin = _Utility::CreateOrigin(pSecurityOrigin);
434 result r = db.Construct(geolocationPath, "r+", null);
435 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
437 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
438 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
440 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
442 pStmt->BindString(0, origin);
443 pStmt->BindInt(1, static_cast < int >(enable));
445 db.BeginTransaction();
447 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
449 db.CommitTransaction();
456 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
459 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
463 if(checkHandler == true)
465 table = CUSTOM_CONTENT_TABLE_NAME;
469 table = CUSTOM_PROTOCOL_TABLE_NAME;
471 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
472 SysAssertf(pHandlerData, "Failed to request");
474 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
475 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
476 String target = ewk_custom_handlers_data_target_get(pHandlerData);
478 result r = db.Construct(handlerPath, "r+", null);
479 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
481 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"'"));
486 pEnum->GetIntAt(0, checkId);
488 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
489 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
491 pUpdateStmt->BindInt(0, static_cast < int >(allow));
492 pUpdateStmt->BindInt(1, checkId);
494 db.BeginTransaction();
496 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
498 db.CommitTransaction();
503 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
504 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
506 pStmt->BindString(0, baseUri);
507 pStmt->BindString(1, uri);
508 pStmt->BindString(2, target);
509 pStmt->BindInt(3, static_cast < int >(allow));
511 db.BeginTransaction();
513 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
515 db.CommitTransaction();
520 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
526 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
528 result r = E_SUCCESS;
529 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
531 HandleUserAction(EINA_FALSE);
536 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
539 switch (__userConfirmMode)
541 case USER_CONFIRM_USERMEDIA:
543 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
546 case USER_CONFIRM_GEOLOCATION:
548 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
551 case USER_CONFIRM_NOTIFICATION:
553 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
556 case USER_SCRIPT_ALERT:
558 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
561 case USER_SCRIPT_CONFIRM:
563 __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
566 case USER_PROTOCOL_HANDLER:
567 case USER_CONTENT_HANDLER:
568 case USER_CONFIRM_APP_CACHE:
569 case USER_CONFIRM_DB_QUOTA_EXCEDED:
570 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
571 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
581 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
587 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
593 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
599 }}} // Tizen::Web::Controls