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 <FUiLayout.h>
35 #include <FUiVerticalBoxLayout.h>
36 #include <FIo_DatabaseImpl.h>
37 #include <FSys_SystemResource.h>
38 #include <FUi_ControlManager.h>
39 #include <FUi_ResourceManager.h>
40 #include "FWebCtrl_EflWebkit.h"
41 #include "FWebCtrl_UserConfirmPopup.h"
42 #include "FWebCtrl_Utility.h"
43 #include "FWebCtrl_WebImpl.h"
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Base::Utility;
49 using namespace Tizen::Graphics;
50 using namespace Tizen::Io;
51 using namespace Tizen::Security::Cert;
52 using namespace Tizen::System;
53 using namespace Tizen::Ui;
54 using namespace Tizen::Ui::Controls;
57 namespace Tizen { namespace Web { namespace Controls
61 _UserConfirmPopup::_UserConfirmPopup(void)
62 : __pUserPolicyData(null)
63 , __userConfirmMode(USER_CONFIRM_USERMEDIA)
64 , __pCheckButton(null)
70 _UserConfirmPopup::~_UserConfirmPopup(void)
76 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, bool sync, String msg)
79 SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
80 SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
81 "Invalid userConfirmMode is used. [%d]", userConfirmMode);
83 _SystemResource* pSysResource = _SystemResource::GetInstance();
84 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
86 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
87 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
89 __pUserPolicyData = pEventInfo;
90 __userConfirmMode = userConfirmMode;
94 int popupMaxHeight = 2*pPopupData->labelDim.height + 2*pPopupData->btnDim.height + 6*pPopupData->sideMargin;
96 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
98 popupMaxHeight += pPopupData->checkDim.height;
101 if (__userConfirmMode == USER_SCRIPT_ALERT)
103 popupMaxHeight -= pPopupData->labelDim.height;
107 r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
108 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110 if (userConfirmMode != USER_SCRIPT_ALERT)
112 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_HEADER_SECURITY_WARNING"));
115 Rectangle rect(0, 0, 0, 0);
118 rect.height = 2*pPopupData->labelDim.height;
119 rect.width = pPopupData->labelDim.width;
121 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
122 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
124 String message = L"";
125 if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
131 message = GetMessageFromPolicy();
133 r = pLabel->Construct(rect, message);
134 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
138 r = AddControl(*pLabel);
139 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 Label* pInfoLabel = pLabel.release();
143 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
146 rect.height = pPopupData->checkDim.height;
148 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
149 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
151 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"));
152 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154 r = AddControl(*pCheckButton);
155 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157 __pCheckButton = pCheckButton.release();
160 Panel* pButtonPanel = CreateAndAddPanel();
161 SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
164 r = idList.Construct();
165 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
168 r = titleList.Construct();
169 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
172 if (userConfirmMode == USER_SCRIPT_ALERT)
174 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
178 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
179 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
180 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_CANCEL"))));
183 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
184 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
186 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
187 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
189 pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
190 if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
192 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
194 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
196 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
203 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
205 result r = E_SUCCESS;
209 case ID_BUTTON_USER_ALLOW:
210 HandleUserAction(EINA_TRUE);
213 case ID_BUTTON_USER_CANCEL:
214 HandleUserAction(EINA_FALSE);
224 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
229 GetOwner()->SendUserEvent(ID_USER_CONFIRM_POPUP_CLOSE, null);
235 _UserConfirmPopup::GetMessageFromPolicy(void)
237 _SystemResource* pSysResource = _SystemResource::GetInstance();
238 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
242 switch(__userConfirmMode)
244 case USER_CONFIRM_USERMEDIA:
246 message = L"Do you want to allow acccess to media?\n";
249 case USER_PROTOCOL_HANDLER:
251 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
252 SysAssertf(pHandlerData, "Failed to request");
254 String target(ewk_custom_handlers_data_target_get(pHandlerData));
255 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
257 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
260 case USER_CONTENT_HANDLER:
262 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
263 SysAssertf(pHandlerData, "Failed to request");
265 String target(ewk_custom_handlers_data_target_get(pHandlerData));
266 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
268 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
271 case USER_CONFIRM_GEOLOCATION:
273 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
274 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
276 message = _Utility::CreateOrigin(pSecurityOrigin);
277 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
280 case USER_CONFIRM_NOTIFICATION:
282 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
283 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
284 message = _Utility::CreateOrigin(pSecurityOrigin);
285 message.Append(L" wants to display notifications");
297 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
299 switch (__userConfirmMode)
301 case USER_CONFIRM_USERMEDIA:
303 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
304 ewk_user_media_permission_request_set(pPolicy, allow);
307 case USER_PROTOCOL_HANDLER:
309 RegisterHandler(false, allow);
312 case USER_CONTENT_HANDLER:
314 RegisterHandler(true, allow);
317 case USER_CONFIRM_GEOLOCATION:
319 Ewk_Geolocation_Permission_Request* pPolicy = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
320 if (__pCheckButton->IsSelected())
322 result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
323 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
326 ewk_geolocation_permission_request_set(pPolicy, allow);
329 case USER_CONFIRM_NOTIFICATION:
331 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
332 ewk_notification_permission_request_set(pPermissionRequest, allow);
335 case USER_SCRIPT_ALERT:
337 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
338 ewk_view_javascript_alert_reply(pView);
341 case USER_CONFIRM_APP_CACHE:
343 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
344 ewk_view_application_cache_permission_reply(pObj, allow);
347 case USER_CONFIRM_DB_QUOTA_EXCEDED:
349 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
350 ewk_view_exceeded_database_quota_reply(pObj, allow);
353 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
355 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
356 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
359 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
361 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
362 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
372 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
375 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
376 String table(GEOLOCATION_TABLE_NAME);
378 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
379 String origin = _Utility::CreateOrigin(pSecurityOrigin);
381 result r = db.Construct(geolocationPath, "r+", null);
382 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
384 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
385 SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
387 SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
389 pStmt->BindString(0, origin);
390 pStmt->BindInt(1, static_cast < int >(enable));
392 db.BeginTransaction();
394 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
396 db.CommitTransaction();
402 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
405 String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
409 if(checkHandler == true)
411 table = CUSTOM_CONTENT_TABLE_NAME;
415 table = CUSTOM_PROTOCOL_TABLE_NAME;
417 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
418 SysAssertf(pHandlerData, "Failed to request");
420 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
421 String uri = ewk_custom_handlers_data_url_get(pHandlerData);
422 String target = ewk_custom_handlers_data_target_get(pHandlerData);
424 result r = db.Construct(handlerPath, "r+", null);
425 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
427 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"'"));
432 pEnum->GetIntAt(0, checkId);
434 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
435 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
437 pUpdateStmt->BindInt(0, static_cast < int >(allow));
438 pUpdateStmt->BindInt(1, checkId);
440 db.BeginTransaction();
442 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
444 db.CommitTransaction();
449 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
450 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
452 pStmt->BindString(0, baseUri);
453 pStmt->BindString(1, uri);
454 pStmt->BindString(2, target);
455 pStmt->BindInt(3, static_cast < int >(allow));
457 db.BeginTransaction();
459 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
461 db.CommitTransaction();
465 }}} // Tizen::Web::Controls