9c99b70dd6dcce5b07f0933ab22384d4056fadca
[framework/osp/web.git] / src / controls / FWebCtrl_UserConfirmPopup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWebCtrl_UserConfirmPopup.cpp
20  * @brief               The file contains the definition of _UserConfirmPopup class.
21  */
22 #include <EWebKit2.h>
23 #include <FAppApp.h>
24 #include <FBaseColArrayList.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseUtilUri.h>
27 #include <FGrpDimension.h>
28 #include <FGrpFont.h>
29 #include <FGrpRectangle.h>
30 #include <FIoDbEnumerator.h>
31 #include <FIoDbStatement.h>
32 #include <FSecCertX509Certificate.h>
33 #include <FUiCtrlButton.h>
34 #include <FUiCtrlLabel.h>
35 #include <FUiCtrlPanel.h>
36 #include <FUiCtrlScrollPanel.h>
37 #include <FUiKeyEventInfo.h>
38 #include <FUiLayout.h>
39 #include <FUiVerticalBoxLayout.h>
40 #include <FGrp_TextTextObject.h>
41 #include <FGrp_TextTextSimple.h>
42 #include <FIo_DatabaseImpl.h>
43 #include <FSys_SystemResource.h>
44 #include <FUi_ControlManager.h>
45 #include <FUi_ResourceManager.h>
46 #include "FWebCtrl_EflWebkit.h"
47 #include "FWebCtrl_UserConfirmPopup.h"
48 #include "FWebCtrl_Utility.h"
49 #include "FWebCtrl_WebImpl.h"
50
51
52 using namespace Tizen::Base;
53 using namespace Tizen::Base::Collection;
54 using namespace Tizen::Base::Utility;
55 using namespace Tizen::Graphics;
56 using namespace Tizen::Graphics::_Text;
57 using namespace Tizen::Io;
58 using namespace Tizen::Security::Cert;
59 using namespace Tizen::System;
60 using namespace Tizen::Ui;
61 using namespace Tizen::Ui::Controls;
62
63
64 namespace Tizen { namespace Web { namespace Controls
65 {
66
67
68 static const int TEXT_SIZE_ADJUST = 1;
69
70
71 _UserConfirmPopup::_UserConfirmPopup(void)
72         : __pUserPolicyData(null)
73         , __userConfirmMode(USER_CONFIRM_USERMEDIA)
74         , __pCheckButton(null)
75         , __isUserActionNeeded(false)
76         , __sync(false)
77         , __pImpl(null)
78 {
79 }
80
81
82 _UserConfirmPopup::~_UserConfirmPopup(void)
83 {
84         if (__isUserActionNeeded == true)
85         {
86                 HandleUserAction(EINA_FALSE);
87                 __isUserActionNeeded = false;
88         }
89 }
90
91
92 result
93 _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, Tizen::Web::Controls::_WebImpl* pImpl, bool sync, String msg)
94 {
95         result r = E_SUCCESS;
96         SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
97         SysTryReturnResult(NID_WEB_CTRL, userConfirmMode >= USER_CONFIRM_USERMEDIA && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED, E_INVALID_ARG,
98                                         "Invalid userConfirmMode is used. [%d]", userConfirmMode);
99
100         _SystemResource* pSysResource = _SystemResource::GetInstance();
101         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
102
103         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
104         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
105
106         __pUserPolicyData = pEventInfo;
107         __userConfirmMode = userConfirmMode;
108         __sync = sync;
109
110         __isUserActionNeeded = true;
111
112         bool hasTitle = true;
113         int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->panelHeight;
114
115         __pImpl = pImpl;
116         SysAssertf(__pImpl != null, "Failed to get _WebImpl");
117
118         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
119         {
120                 popupMaxHeight +=  pPopupData->checkDim.height;
121         }
122
123         if (__userConfirmMode == USER_SCRIPT_ALERT)
124         {
125                 hasTitle = false;
126         }
127
128         r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
129         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
130
131         if (userConfirmMode != USER_SCRIPT_ALERT)
132         {
133                 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_SECURITY_WARNING_ABB"));
134         }
135
136         String message = L"";
137         if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
138         {
139                 message = msg;
140         }
141         else
142         {
143                 message = GetMessageFromPolicy();
144         }
145
146         Rectangle rect(0, 0, 0, 0);
147
148         //label
149         rect.height = 2*pPopupData->labelDim.height;
150         rect.width = pPopupData->labelDim.width;
151
152         //With the font of label and width of label, required height is calculated
153         //      using textobject. TEXT_SIZE_ADJUST is used to increase font size and get bigger height
154         //      as the accurate height is not fitting text in some cases.
155         Font font;
156         r = font.Construct(FONT_STYLE_PLAIN, pPopupData->labelFontSize + TEXT_SIZE_ADJUST);
157         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
158
159         std::unique_ptr<TextObject> pTextObject(new (std::nothrow) TextObject());
160         SysTryReturnResult(NID_WEB_CTRL, pTextObject.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
161
162         r = pTextObject->Construct();
163         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164
165         std::unique_ptr<TextSimple> pSimpleText(new (std::nothrow) TextSimple(message.GetPointer(), message.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, &font));
166         SysTryReturnResult(NID_WEB_CTRL, pSimpleText.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
167
168         r = pTextObject->AppendElement(*pSimpleText);
169         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
170
171         pSimpleText.release();
172
173         r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
174         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
175
176         r = pTextObject->SetBounds(rect);
177         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
178
179         r = pTextObject->SetFont(&font, 0, message.GetLength());
180         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
181
182         r = pTextObject->Compose();
183         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
184
185         int labelHeight = pTextObject->GetTotalHeight();
186
187         std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
188         SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
189
190         r = pLabel->Construct(rect, message);
191         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
192
193         pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
194
195         Control* pInfoLabel = null;
196
197         if (rect.height < labelHeight)
198         {
199                 //message text is bigger than label, scroll is created to accomodate it.
200                 std::unique_ptr<ScrollPanel> pScrollPanel(new (std::nothrow) ScrollPanel());
201                 SysTryReturnResult(NID_WEB_CTRL, pScrollPanel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
202
203                 r = pScrollPanel->Construct(rect);
204                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
205
206                 r = AddControl(*pScrollPanel);
207                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
208
209                 ScrollPanel* pSPanel = pScrollPanel.release();
210
211                 r = pLabel->SetSize(Dimension(rect.width, labelHeight));
212                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
213
214                 r = pSPanel->AddControl(*pLabel);
215                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
216
217                 pLabel.release();
218                 pInfoLabel = pSPanel;
219         }
220         else
221         {
222                 r = AddControl(*pLabel);
223                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
224
225                 pInfoLabel = pLabel.release();
226         }
227
228         //checkbutton
229         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
230         {
231                 rect.y = 0;
232                 rect.height = pPopupData->checkDim.height;
233
234                 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
235                 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
236
237                 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"));
238                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239
240                 r = AddControl(*pCheckButton);
241                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
242
243                 __pCheckButton = pCheckButton.release();
244         }
245
246         Panel* pButtonPanel = CreateAndAddPanel();
247         SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
248
249         ArrayList idList;
250         r = idList.Construct();
251         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
252
253         ArrayList titleList;
254         r = titleList.Construct();
255         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         if (userConfirmMode == USER_SCRIPT_ALERT)
258         {
259                 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
260                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
261         }
262         else
263         {
264                 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
265                 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
266                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
267                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
268         }
269
270         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
271         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
272
273         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
274         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
275
276         pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
277         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
278         {
279                 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
280         }
281
282         SetPropagatedKeyEventListener(this);
283         return E_SUCCESS;
284 }
285
286
287 void
288 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
289 {
290         result r = E_SUCCESS;
291
292         switch (actionId)
293         {
294         case ID_BUTTON_USER_ALLOW:
295                 HandleUserAction(EINA_TRUE);
296                 break;
297
298         case ID_BUTTON_USER_CANCEL:
299                 HandleUserAction(EINA_FALSE);
300                 break;
301
302         default:
303                 break;
304         }
305
306         r = HidePopup();
307         if (IsFailed(r))
308         {
309                 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
310         }
311
312         if (!__sync)
313         {
314                 switch(__userConfirmMode)
315                 {
316                 case USER_CONFIRM_USERMEDIA:
317                 {
318                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
319                         break;
320                 }
321                 case USER_CONFIRM_GEOLOCATION:
322                 {
323                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
324                         break;
325                 }
326                 case USER_CONFIRM_NOTIFICATION:
327                 {
328                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
329                         break;
330                 }
331                 case USER_SCRIPT_ALERT:
332                 {
333                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
334                         break;
335                 }
336                 case USER_SCRIPT_CONFIRM:
337                 {
338                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
339                         break;
340                 }
341                 default:
342                         SysAssert(false);
343                 }
344         }
345 }
346
347
348 String
349 _UserConfirmPopup::GetMessageFromPolicy(void)
350 {
351         _SystemResource* pSysResource = _SystemResource::GetInstance();
352         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
353
354         String message;
355
356         switch(__userConfirmMode)
357         {
358         case USER_CONFIRM_USERMEDIA:
359         {
360                 message = L"Do you want to allow acccess to media?\n";
361                 break;
362         }
363         case USER_PROTOCOL_HANDLER:
364         {
365                 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
366                 SysAssertf(pHandlerData, "Failed to request");
367
368                 String target(ewk_custom_handlers_data_target_get(pHandlerData));
369                 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
370
371                 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
372                 break;
373         }
374         case USER_CONTENT_HANDLER:
375         {
376                 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
377                 SysAssertf(pHandlerData, "Failed to request");
378
379                 String target(ewk_custom_handlers_data_target_get(pHandlerData));
380                 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
381
382                 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
383                 break;
384         }
385         case USER_CONFIRM_GEOLOCATION:
386         {
387                 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
388                 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
389
390                 message = _Utility::CreateOrigin(pSecurityOrigin);
391                 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
392                 break;
393         }
394         case USER_CONFIRM_NOTIFICATION:
395         {
396                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
397                 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
398                 message = _Utility::CreateOrigin(pSecurityOrigin);
399                 message.Append(L" wants to display notifications");
400                 break;
401         }
402         default:
403                 SysAssert(false);
404         }
405
406         return message;
407 }
408
409
410 void
411 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
412 {
413         switch (__userConfirmMode)
414         {
415         case USER_CONFIRM_USERMEDIA:
416         {
417                 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
418                 ewk_user_media_permission_request_set(pPolicy, allow);
419                 break;
420         }
421         case USER_PROTOCOL_HANDLER:
422         {
423                 RegisterHandler(false, allow);
424                 break;
425         }
426         case USER_CONTENT_HANDLER:
427         {
428                 RegisterHandler(true, allow);
429                 break;
430         }
431         case USER_CONFIRM_GEOLOCATION:
432         {
433                 Ewk_Geolocation_Permission_Request* pPolicy =  reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
434                 if (__pCheckButton->IsSelected())
435                 {
436                         result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
437                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
438                 }
439 CATCH:
440                 ewk_geolocation_permission_request_set(pPolicy, allow);
441                 break;
442         }
443         case USER_CONFIRM_NOTIFICATION:
444         {
445                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
446                 ewk_notification_permission_request_set(pPermissionRequest, allow);
447                 break;
448         }
449         case USER_SCRIPT_ALERT:
450         {
451                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
452                 ewk_view_javascript_alert_reply(pView);
453                 break;
454         }
455         case USER_SCRIPT_CONFIRM:
456         {
457                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
458                 ewk_view_javascript_confirm_reply(pView, allow);
459                 break;
460         }
461         case USER_CONFIRM_APP_CACHE:
462         {
463                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
464                 ewk_view_application_cache_permission_reply(pObj, allow);
465                 break;
466         }
467         case USER_CONFIRM_DB_QUOTA_EXCEDED:
468         {
469                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
470                 ewk_view_exceeded_database_quota_reply(pObj, allow);
471                 break;
472         }
473         case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
474         {
475                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
476                 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
477                 break;
478         }
479         case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
480         {
481                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
482                 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
483                 break;
484         }
485         default:
486                 SysAssert(false);
487         }
488         __isUserActionNeeded = false;
489 }
490
491
492 result
493 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
494 {
495         _DatabaseImpl db;
496         String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
497         String table(GEOLOCATION_TABLE_NAME);
498
499         const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
500         String origin = _Utility::CreateOrigin(pSecurityOrigin);
501
502         result r = db.Construct(geolocationPath, "r+", null);
503         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
504
505         std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
506         SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
507
508         SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
509
510         pStmt->BindString(0, origin);
511         pStmt->BindInt(1, static_cast < int >(enable));
512
513         db.BeginTransaction();
514
515         std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
516
517         db.CommitTransaction();
518
519         return E_SUCCESS;
520 }
521
522
523 void
524 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
525 {
526         _DatabaseImpl db;
527         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
528         String table;
529         int checkId = 0;
530
531         if(checkHandler == true)
532         {
533                 table = CUSTOM_CONTENT_TABLE_NAME;
534         }
535         else
536         {
537                 table = CUSTOM_PROTOCOL_TABLE_NAME;
538         }
539         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
540         SysAssertf(pHandlerData, "Failed to request");
541
542         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
543         String uri = ewk_custom_handlers_data_url_get(pHandlerData);
544         String target = ewk_custom_handlers_data_target_get(pHandlerData);
545
546         result r = db.Construct(handlerPath, "r+", null);
547         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
548
549         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"'"));
550
551         if(pEnum.get())
552         {
553                 pEnum->MoveNext();
554                 pEnum->GetIntAt(0, checkId);
555
556                 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
557                 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
558
559                 pUpdateStmt->BindInt(0, static_cast < int >(allow));
560                 pUpdateStmt->BindInt(1, checkId);
561
562                 db.BeginTransaction();
563
564                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
565
566                 db.CommitTransaction();
567
568         }
569         else
570         {
571                 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
572                 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
573
574                 pStmt->BindString(0, baseUri);
575                 pStmt->BindString(1, uri);
576                 pStmt->BindString(2, target);
577                 pStmt->BindInt(3, static_cast < int >(allow));
578
579                 db.BeginTransaction();
580
581                 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
582
583                 db.CommitTransaction();
584         }
585 }
586
587 bool
588 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
589 {
590         return false;
591 }
592
593 bool
594 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
595 {
596         result r = E_SUCCESS;
597         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
598         {
599                 HandleUserAction(EINA_FALSE);
600                 r = HidePopup();
601
602                 if (IsFailed(r))
603                 {
604                         SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
605                 }
606                 
607                 switch (__userConfirmMode)
608                 {
609                 case USER_CONFIRM_USERMEDIA:
610                 {
611                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
612                         break;
613                 }
614                 case USER_CONFIRM_GEOLOCATION:
615                 {
616                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
617                         break;
618                 }
619                 case USER_CONFIRM_NOTIFICATION:
620                 {
621                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
622                         break;
623                 }
624                 case USER_SCRIPT_ALERT:
625                 {
626                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
627                         break;
628                 }
629                 case USER_SCRIPT_CONFIRM:
630                 {
631                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
632                         break;
633                 }
634                 case USER_PROTOCOL_HANDLER:
635                 case USER_CONTENT_HANDLER:
636                 case USER_CONFIRM_APP_CACHE:
637                 case USER_CONFIRM_DB_QUOTA_EXCEDED:
638                 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
639                 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
640                         break;
641                 default:
642                         SysAssert(false);
643                 }
644         }
645         return false;
646 }
647
648 bool
649 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
650 {
651         return false;
652 }
653
654 bool
655 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
656 {
657         return false;
658 }
659
660 bool
661 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
662 {
663         return false;
664 }
665
666
667 }}} // Tizen::Web::Controls