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)
77 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, bool sync, String msg)
80 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
81 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
82 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
84 _SystemResource* pSysResource = _SystemResource::GetInstance();
85 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
87 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
88 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
90 __pUserPolicyData = pEventInfo;
91 __userConfirmMode = userConfirmMode;
95 int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->btnDim.height + 2*pPopupData->sideMargin;
97 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
99 popupMaxHeight += pPopupData->checkDim.height;
102 if (__userConfirmMode == USER_SCRIPT_ALERT)
104 popupMaxHeight -= 2*pPopupData->sideMargin;
108 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
109 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111 if (userConfirmMode != USER_SCRIPT_ALERT)
113 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_HEADER_SECURITY_WARNING"));
116 Rectangle rect(0, 0, 0, 0);
119 rect.height = 2*pPopupData->labelDim.height;
120 rect.width = pPopupData->labelDim.width;
122 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
123 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
125 String message = L"";
126 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
132 message = GetMessageFromPolicy();
134 r = pLabel->Construct(rect, message);
135 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
137 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
139 r = AddControl(*pLabel);
140 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
142 Label* pInfoLabel = pLabel.release();
144 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
147 rect.height = pPopupData->checkDim.height;
149 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
150 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
152 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"));
153 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
155 r = AddControl(*pCheckButton);
156 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
158 __pCheckButton = pCheckButton.release();
161 Panel* pButtonPanel = CreateAndAddPanel();
162 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
165 r = idList.Construct();
166 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
169 r = titleList.Construct();
170 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
172 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
173 if (userConfirmMode == USER_SCRIPT_ALERT)
175 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
179 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
180 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
181 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_CANCEL"))));
184 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
185 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
187 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
188 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
190 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
191 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
193 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
195 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
197 if ( __userConfirmMode != USER_SCRIPT_ALERT )
199 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
202 SetPropagatedKeyEventListener(this);
208 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
210 result r = E_SUCCESS;
214 case ID_BUTTON_USER_ALLOW:
215 HandleUserAction(EINA_TRUE);
218 case ID_BUTTON_USER_CANCEL:
219 HandleUserAction(EINA_FALSE);
229 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
234 switch(__userConfirmMode)
236 case USER_CONFIRM_USERMEDIA:
238 GetOwner()->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
241 case USER_CONFIRM_GEOLOCATION:
243 GetOwner()->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
246 case USER_CONFIRM_NOTIFICATION:
248 GetOwner()->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
251 case USER_SCRIPT_ALERT:
253 GetOwner()->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
264 _UserConfirmPopup::GetMessageFromPolicy(void)
266 _SystemResource* pSysResource = _SystemResource::GetInstance();
267 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
271 switch(__userConfirmMode)
273 case USER_CONFIRM_USERMEDIA:
275 message = L"Do you want to allow acccess to media?\n";
278 case USER_PROTOCOL_HANDLER:
280 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
281 SysAssertf(pHandlerData, "Failed to request");
283 String target(ewk_custom_handlers_data_target_get(pHandlerData));
284 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
286 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
289 case USER_CONTENT_HANDLER:
291 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
292 SysAssertf(pHandlerData, "Failed to request");
294 String target(ewk_custom_handlers_data_target_get(pHandlerData));
295 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
297 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
300 case USER_CONFIRM_GEOLOCATION:
302 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
303 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
305 message = _Utility::CreateOrigin(pSecurityOrigin);
306 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
309 case USER_CONFIRM_NOTIFICATION:
311 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
312 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
313 message = _Utility::CreateOrigin(pSecurityOrigin);
314 message.Append(L" wants to display notifications");
326 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
328 switch (__userConfirmMode)
330 case USER_CONFIRM_USERMEDIA:
332 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
333 ewk_user_media_permission_request_set(pPolicy, allow);
336 case USER_PROTOCOL_HANDLER:
338 RegisterHandler(false, allow);
341 case USER_CONTENT_HANDLER:
343 RegisterHandler(true, allow);
346 case USER_CONFIRM_GEOLOCATION:
348 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
349 if (__pCheckButton->IsSelected())
351 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
352 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
355 ewk_geolocation_permission_request_set(pPolicy, allow);
358 case USER_CONFIRM_NOTIFICATION:
360 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
361 ewk_notification_permission_request_set(pPermissionRequest, allow);
364 case USER_SCRIPT_ALERT:
366 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
367 ewk_view_javascript_alert_reply(pView);
370 case USER_CONFIRM_APP_CACHE:
372 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
373 ewk_view_application_cache_permission_reply(pObj, allow);
376 case USER_CONFIRM_DB_QUOTA_EXCEDED:
378 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
379 ewk_view_exceeded_database_quota_reply(pObj, allow);
382 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
384 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
385 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
388 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
390 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
391 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
401 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
404 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
405 String table(GEOLOCATION_TABLE_NAME);
407 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
408 String origin = _Utility::CreateOrigin(pSecurityOrigin);
410 result r = db.Construct(geolocationPath, "r+", null);
411 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
413 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
414 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
416 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
418 pStmt->BindString(0, origin);
419 pStmt->BindInt(1, static_cast < int >(enable));
421 db.BeginTransaction();
423 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
425 db.CommitTransaction();
432 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
435 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
439 if(checkHandler == true)
441 table = CUSTOM_CONTENT_TABLE_NAME;
445 table = CUSTOM_PROTOCOL_TABLE_NAME;
447 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
448 SysAssertf(pHandlerData, "Failed to request");
450 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
451 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
452 String target = ewk_custom_handlers_data_target_get(pHandlerData);
454 result r = db.Construct(handlerPath, "r+", null);
455 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
457 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"'"));
462 pEnum->GetIntAt(0, checkId);
464 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
465 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
467 pUpdateStmt->BindInt(0, static_cast < int >(allow));
468 pUpdateStmt->BindInt(1, checkId);
470 db.BeginTransaction();
472 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
474 db.CommitTransaction();
479 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
480 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
482 pStmt->BindString(0, baseUri);
483 pStmt->BindString(1, uri);
484 pStmt->BindString(2, target);
485 pStmt->BindInt(3, static_cast < int >(allow));
487 db.BeginTransaction();
489 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
491 db.CommitTransaction();
496 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
502 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
504 result r = E_SUCCESS;
505 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
507 HandleUserAction(EINA_FALSE);
512 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
515 switch (__userConfirmMode)
517 case USER_CONFIRM_USERMEDIA:
519 GetOwner()->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
522 case USER_CONFIRM_GEOLOCATION:
524 GetOwner()->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
527 case USER_CONFIRM_NOTIFICATION:
529 GetOwner()->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
532 case USER_SCRIPT_ALERT:
534 GetOwner()->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
537 case USER_PROTOCOL_HANDLER:
538 case USER_CONTENT_HANDLER:
539 case USER_CONFIRM_APP_CACHE:
540 case USER_CONFIRM_DB_QUOTA_EXCEDED:
541 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
542 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
552 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
558 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
564 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
570 }}} // Tizen::Web::Controls