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.
23 #include <FBaseColArrayList.h>
24 #include <FBaseSysLog.h>
25 #include <FBaseUtilUri.h>
26 #include <FGrpDimension.h>
27 #include <FGrpRectangle.h>
28 #include <FIoDbEnumerator.h>
29 #include <FIoDbStatement.h>
30 #include <FSecCertX509Certificate.h>
31 #include <FUiCtrlButton.h>
32 #include <FUiCtrlLabel.h>
33 #include <FUiCtrlPanel.h>
34 #include <FUiKeyEventInfo.h>
35 #include <FUiLayout.h>
36 #include <FUiVerticalBoxLayout.h>
37 #include <FIo_DatabaseImpl.h>
38 #include <FSys_SystemResource.h>
39 #include <FUi_ControlManager.h>
40 #include <FUi_ResourceManager.h>
41 #include "FWebCtrl_EflWebkit.h"
42 #include "FWebCtrl_UserConfirmPopup.h"
43 #include "FWebCtrl_Utility.h"
44 #include "FWebCtrl_WebImpl.h"
47 using namespace Tizen::Base;
48 using namespace Tizen::Base::Collection;
49 using namespace Tizen::Base::Utility;
50 using namespace Tizen::Graphics;
51 using namespace Tizen::Io;
52 using namespace Tizen::Security::Cert;
53 using namespace Tizen::System;
54 using namespace Tizen::Ui;
55 using namespace Tizen::Ui::Controls;
58 namespace Tizen { namespace Web { namespace Controls
62 _UserConfirmPopup::_UserConfirmPopup(void)
63 : __pUserPolicyData(null)
64 , __userConfirmMode(USER_CONFIRM_USERMEDIA)
65 , __pCheckButton(null)
71 _UserConfirmPopup::~_UserConfirmPopup(void)
75 HandleUserAction(EINA_FALSE);
81 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, bool sync, String msg)
84 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
85 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
86 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
88 _SystemResource* pSysResource = _SystemResource::GetInstance();
89 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
91 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
92 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
94 __pUserPolicyData = pEventInfo;
95 __userConfirmMode = userConfirmMode;
99 int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->btnDim.height + 2*pPopupData->sideMargin;
101 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
103 popupMaxHeight += pPopupData->checkDim.height;
106 if (__userConfirmMode == USER_SCRIPT_ALERT)
108 popupMaxHeight -= 2*pPopupData->sideMargin;
112 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
113 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 if (userConfirmMode != USER_SCRIPT_ALERT)
117 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_HEADER_SECURITY_WARNING"));
120 Rectangle rect(0, 0, 0, 0);
123 rect.height = 2*pPopupData->labelDim.height;
124 rect.width = pPopupData->labelDim.width;
126 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
127 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
129 String message = L"";
130 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
136 message = GetMessageFromPolicy();
138 r = pLabel->Construct(rect, message);
139 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
143 r = AddControl(*pLabel);
144 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146 Label* pInfoLabel = pLabel.release();
148 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
151 rect.height = pPopupData->checkDim.height;
153 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
154 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
156 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"));
157 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
159 r = AddControl(*pCheckButton);
160 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
162 __pCheckButton = pCheckButton.release();
165 Panel* pButtonPanel = CreateAndAddPanel();
166 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
169 r = idList.Construct();
170 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
173 r = titleList.Construct();
174 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
176 if (userConfirmMode == USER_SCRIPT_ALERT)
178 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
179 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
183 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
184 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
185 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_CANCEL"))));
186 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
189 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
190 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
193 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
195 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
196 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
198 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
200 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
202 if ( __userConfirmMode != USER_SCRIPT_ALERT )
204 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
207 SetPropagatedKeyEventListener(this);
213 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
215 result r = E_SUCCESS;
219 case ID_BUTTON_USER_ALLOW:
220 HandleUserAction(EINA_TRUE);
223 case ID_BUTTON_USER_CANCEL:
224 HandleUserAction(EINA_FALSE);
234 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
239 switch(__userConfirmMode)
241 case USER_CONFIRM_USERMEDIA:
243 GetOwner()->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
246 case USER_CONFIRM_GEOLOCATION:
248 GetOwner()->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
251 case USER_CONFIRM_NOTIFICATION:
253 GetOwner()->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
256 case USER_SCRIPT_ALERT:
258 GetOwner()->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
269 _UserConfirmPopup::GetMessageFromPolicy(void)
271 _SystemResource* pSysResource = _SystemResource::GetInstance();
272 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
276 switch(__userConfirmMode)
278 case USER_CONFIRM_USERMEDIA:
280 message = L"Do you want to allow acccess to media?\n";
283 case USER_PROTOCOL_HANDLER:
285 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
286 SysAssertf(pHandlerData, "Failed to request");
288 String target(ewk_custom_handlers_data_target_get(pHandlerData));
289 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
291 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
294 case USER_CONTENT_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 = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
305 case USER_CONFIRM_GEOLOCATION:
307 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
308 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
310 message = _Utility::CreateOrigin(pSecurityOrigin);
311 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
314 case USER_CONFIRM_NOTIFICATION:
316 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
317 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
318 message = _Utility::CreateOrigin(pSecurityOrigin);
319 message.Append(L" wants to display notifications");
331 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
333 switch (__userConfirmMode)
335 case USER_CONFIRM_USERMEDIA:
337 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
338 ewk_user_media_permission_request_set(pPolicy, allow);
341 case USER_PROTOCOL_HANDLER:
343 RegisterHandler(false, allow);
346 case USER_CONTENT_HANDLER:
348 RegisterHandler(true, allow);
351 case USER_CONFIRM_GEOLOCATION:
353 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
354 if (__pCheckButton->IsSelected())
356 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
357 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
360 ewk_geolocation_permission_request_set(pPolicy, allow);
363 case USER_CONFIRM_NOTIFICATION:
365 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
366 ewk_notification_permission_request_set(pPermissionRequest, allow);
369 case USER_SCRIPT_ALERT:
371 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
372 ewk_view_javascript_alert_reply(pView);
375 case USER_CONFIRM_APP_CACHE:
377 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
378 ewk_view_application_cache_permission_reply(pObj, allow);
381 case USER_CONFIRM_DB_QUOTA_EXCEDED:
383 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
384 ewk_view_exceeded_database_quota_reply(pObj, allow);
387 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
389 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
390 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
393 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
395 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
396 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
406 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
409 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
410 String table(GEOLOCATION_TABLE_NAME);
412 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
413 String origin = _Utility::CreateOrigin(pSecurityOrigin);
415 result r = db.Construct(geolocationPath, "r+", null);
416 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
418 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
419 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
421 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
423 pStmt->BindString(0, origin);
424 pStmt->BindInt(1, static_cast < int >(enable));
426 db.BeginTransaction();
428 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
430 db.CommitTransaction();
437 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
440 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
444 if(checkHandler == true)
446 table = CUSTOM_CONTENT_TABLE_NAME;
450 table = CUSTOM_PROTOCOL_TABLE_NAME;
452 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
453 SysAssertf(pHandlerData, "Failed to request");
455 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
456 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
457 String target = ewk_custom_handlers_data_target_get(pHandlerData);
459 result r = db.Construct(handlerPath, "r+", null);
460 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
462 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"'"));
467 pEnum->GetIntAt(0, checkId);
469 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
470 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
472 pUpdateStmt->BindInt(0, static_cast < int >(allow));
473 pUpdateStmt->BindInt(1, checkId);
475 db.BeginTransaction();
477 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
479 db.CommitTransaction();
484 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
485 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
487 pStmt->BindString(0, baseUri);
488 pStmt->BindString(1, uri);
489 pStmt->BindString(2, target);
490 pStmt->BindInt(3, static_cast < int >(allow));
492 db.BeginTransaction();
494 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
496 db.CommitTransaction();
501 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
507 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
509 result r = E_SUCCESS;
510 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
512 HandleUserAction(EINA_FALSE);
517 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
520 switch (__userConfirmMode)
522 case USER_CONFIRM_USERMEDIA:
524 GetOwner()->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
527 case USER_CONFIRM_GEOLOCATION:
529 GetOwner()->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
532 case USER_CONFIRM_NOTIFICATION:
534 GetOwner()->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
537 case USER_SCRIPT_ALERT:
539 GetOwner()->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
542 case USER_PROTOCOL_HANDLER:
543 case USER_CONTENT_HANDLER:
544 case USER_CONFIRM_APP_CACHE:
545 case USER_CONFIRM_DB_QUOTA_EXCEDED:
546 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
547 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
557 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
563 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
569 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
575 }}} // Tizen::Web::Controls