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;
105 SysAssertf(__pImpl != null, "Failed to get _WebImpl");
107 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
109 popupMaxHeight += pPopupData->checkDim.height;
112 if (__userConfirmMode == USER_SCRIPT_ALERT)
114 popupMaxHeight -= 2*pPopupData->sideMargin;
118 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
119 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121 if (userConfirmMode != USER_SCRIPT_ALERT)
123 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_SECURITY_WARNING_ABB"));
126 Rectangle rect(0, 0, 0, 0);
129 rect.height = 2*pPopupData->labelDim.height;
130 rect.width = pPopupData->labelDim.width;
132 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
133 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
135 String message = L"";
136 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
142 message = GetMessageFromPolicy();
144 r = pLabel->Construct(rect, message);
145 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
147 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
149 r = AddControl(*pLabel);
150 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
152 Label* pInfoLabel = pLabel.release();
154 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
157 rect.height = pPopupData->checkDim.height;
159 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
160 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
162 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"));
163 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
165 r = AddControl(*pCheckButton);
166 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168 __pCheckButton = pCheckButton.release();
171 Panel* pButtonPanel = CreateAndAddPanel();
172 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
175 r = idList.Construct();
176 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179 r = titleList.Construct();
180 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182 if (userConfirmMode == USER_SCRIPT_ALERT)
184 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
185 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
189 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
190 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
191 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
192 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
195 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
196 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
198 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
199 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
201 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
202 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
204 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
206 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
208 if ( __userConfirmMode != USER_SCRIPT_ALERT )
210 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
213 SetPropagatedKeyEventListener(this);
219 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
221 result r = E_SUCCESS;
225 case ID_BUTTON_USER_ALLOW:
226 HandleUserAction(EINA_TRUE);
229 case ID_BUTTON_USER_CANCEL:
230 HandleUserAction(EINA_FALSE);
240 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
245 switch(__userConfirmMode)
247 case USER_CONFIRM_USERMEDIA:
249 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
252 case USER_CONFIRM_GEOLOCATION:
254 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
257 case USER_CONFIRM_NOTIFICATION:
259 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
262 case USER_SCRIPT_ALERT:
264 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
267 case USER_SCRIPT_CONFIRM:
269 __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
280 _UserConfirmPopup::GetMessageFromPolicy(void)
282 _SystemResource* pSysResource = _SystemResource::GetInstance();
283 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
287 switch(__userConfirmMode)
289 case USER_CONFIRM_USERMEDIA:
291 message = L"Do you want to allow acccess to media?\n";
294 case USER_PROTOCOL_HANDLER:
296 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
297 SysAssertf(pHandlerData, "Failed to request");
299 String target(ewk_custom_handlers_data_target_get(pHandlerData));
300 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
302 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
305 case USER_CONTENT_HANDLER:
307 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
308 SysAssertf(pHandlerData, "Failed to request");
310 String target(ewk_custom_handlers_data_target_get(pHandlerData));
311 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
313 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
316 case USER_CONFIRM_GEOLOCATION:
318 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
319 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
321 message = _Utility::CreateOrigin(pSecurityOrigin);
322 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
325 case USER_CONFIRM_NOTIFICATION:
327 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
328 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
329 message = _Utility::CreateOrigin(pSecurityOrigin);
330 message.Append(L" wants to display notifications");
342 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
344 switch (__userConfirmMode)
346 case USER_CONFIRM_USERMEDIA:
348 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
349 ewk_user_media_permission_request_set(pPolicy, allow);
352 case USER_PROTOCOL_HANDLER:
354 RegisterHandler(false, allow);
357 case USER_CONTENT_HANDLER:
359 RegisterHandler(true, allow);
362 case USER_CONFIRM_GEOLOCATION:
364 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
365 if (__pCheckButton->IsSelected())
367 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
368 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
371 ewk_geolocation_permission_request_set(pPolicy, allow);
374 case USER_CONFIRM_NOTIFICATION:
376 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
377 ewk_notification_permission_request_set(pPermissionRequest, allow);
380 case USER_SCRIPT_ALERT:
382 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
383 ewk_view_javascript_alert_reply(pView);
386 case USER_SCRIPT_CONFIRM:
388 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
389 ewk_view_javascript_confirm_reply(pView, allow);
392 case USER_CONFIRM_APP_CACHE:
394 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
395 ewk_view_application_cache_permission_reply(pObj, allow);
398 case USER_CONFIRM_DB_QUOTA_EXCEDED:
400 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
401 ewk_view_exceeded_database_quota_reply(pObj, allow);
404 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
406 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
407 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
410 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
412 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
413 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
423 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
426 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
427 String table(GEOLOCATION_TABLE_NAME);
429 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
430 String origin = _Utility::CreateOrigin(pSecurityOrigin);
432 result r = db.Construct(geolocationPath, "r+", null);
433 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
435 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
436 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
438 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
440 pStmt->BindString(0, origin);
441 pStmt->BindInt(1, static_cast < int >(enable));
443 db.BeginTransaction();
445 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
447 db.CommitTransaction();
454 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
457 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
461 if(checkHandler == true)
463 table = CUSTOM_CONTENT_TABLE_NAME;
467 table = CUSTOM_PROTOCOL_TABLE_NAME;
469 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
470 SysAssertf(pHandlerData, "Failed to request");
472 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
473 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
474 String target = ewk_custom_handlers_data_target_get(pHandlerData);
476 result r = db.Construct(handlerPath, "r+", null);
477 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
479 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"'"));
484 pEnum->GetIntAt(0, checkId);
486 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
487 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
489 pUpdateStmt->BindInt(0, static_cast < int >(allow));
490 pUpdateStmt->BindInt(1, checkId);
492 db.BeginTransaction();
494 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
496 db.CommitTransaction();
501 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
502 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
504 pStmt->BindString(0, baseUri);
505 pStmt->BindString(1, uri);
506 pStmt->BindString(2, target);
507 pStmt->BindInt(3, static_cast < int >(allow));
509 db.BeginTransaction();
511 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
513 db.CommitTransaction();
518 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
524 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
526 result r = E_SUCCESS;
527 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
529 HandleUserAction(EINA_FALSE);
534 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
537 switch (__userConfirmMode)
539 case USER_CONFIRM_USERMEDIA:
541 __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
544 case USER_CONFIRM_GEOLOCATION:
546 __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
549 case USER_CONFIRM_NOTIFICATION:
551 __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
554 case USER_SCRIPT_ALERT:
556 __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
559 case USER_SCRIPT_CONFIRM:
561 __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
564 case USER_PROTOCOL_HANDLER:
565 case USER_CONTENT_HANDLER:
566 case USER_CONFIRM_APP_CACHE:
567 case USER_CONFIRM_DB_QUOTA_EXCEDED:
568 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
569 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
579 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
585 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
591 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
597 }}} // Tizen::Web::Controls