Tizen 2.2.1
[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_WebManager.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 if (userConfirmMode == USER_BEFORE_UNLOAD_CONFIRM)
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_LEAVE"))));
267                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_STAY"))));
268         }
269         else
270         {
271                 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
272                 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
273                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
274                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
275         }
276
277         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
278         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
279
280         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
281         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
282
283         pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
284         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
285         {
286                 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
287         }
288
289         SetPropagatedKeyEventListener(this);
290         return E_SUCCESS;
291 }
292
293
294 void
295 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
296 {
297         result r = E_SUCCESS;
298
299         switch (actionId)
300         {
301         case ID_BUTTON_USER_ALLOW:
302                 HandleUserAction(EINA_TRUE);
303                 break;
304
305         case ID_BUTTON_USER_CANCEL:
306                 HandleUserAction(EINA_FALSE);
307                 break;
308
309         default:
310                 break;
311         }
312
313         r = HidePopup();
314         if (IsFailed(r))
315         {
316                 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
317         }
318
319         if (!__sync)
320         {
321                 switch(__userConfirmMode)
322                 {
323                 case USER_CONFIRM_USERMEDIA:
324                 {
325                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
326                         break;
327                 }
328                 case USER_CONFIRM_GEOLOCATION:
329                 {
330                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
331                         break;
332                 }
333                 case USER_CONFIRM_NOTIFICATION:
334                 {
335                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
336                         break;
337                 }
338                 case USER_SCRIPT_ALERT:
339                 {
340                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
341                         break;
342                 }
343                 case USER_SCRIPT_CONFIRM:
344                 {
345                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
346                         break;
347                 }
348                 case USER_BEFORE_UNLOAD_CONFIRM:
349                 {
350                         __pImpl->SendUserEvent(ID_USER_BEFORE_UNLOAD_CONFIRM_CLOSE, null);
351                         break;
352                 }
353                 default:
354                         SysAssert(false);
355                 }
356         }
357 }
358
359
360 String
361 _UserConfirmPopup::GetMessageFromPolicy(void)
362 {
363         _SystemResource* pSysResource = _SystemResource::GetInstance();
364         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
365
366         String message;
367
368         switch(__userConfirmMode)
369         {
370         case USER_CONFIRM_USERMEDIA:
371         {
372                 message = L"Do you want to allow acccess to media?\n";
373                 break;
374         }
375         case USER_PROTOCOL_HANDLER:
376         {
377                 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
378                 SysAssertf(pHandlerData, "Failed to request");
379
380                 String target(ewk_custom_handlers_data_target_get(pHandlerData));
381                 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
382
383                 message = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
384                 break;
385         }
386         case USER_CONTENT_HANDLER:
387         {
388                 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
389                 SysAssertf(pHandlerData, "Failed to request");
390
391                 String target(ewk_custom_handlers_data_target_get(pHandlerData));
392                 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
393
394                 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
395                 break;
396         }
397         case USER_CONFIRM_GEOLOCATION:
398         {
399                 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
400                 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
401
402                 message = _Utility::CreateOrigin(pSecurityOrigin);
403                 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
404                 break;
405         }
406         case USER_CONFIRM_NOTIFICATION:
407         {
408                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
409                 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
410                 message = _Utility::CreateOrigin(pSecurityOrigin);
411                 message.Append(L" wants to display notifications");
412                 break;
413         }
414         default:
415                 SysAssert(false);
416         }
417
418         return message;
419 }
420
421
422 void
423 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
424 {
425         switch (__userConfirmMode)
426         {
427         case USER_CONFIRM_USERMEDIA:
428         {
429                 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
430                 ewk_user_media_permission_request_set(pPolicy, allow);
431                 break;
432         }
433         case USER_PROTOCOL_HANDLER:
434         {
435                 RegisterHandler(false, allow);
436                 break;
437         }
438         case USER_CONTENT_HANDLER:
439         {
440                 RegisterHandler(true, allow);
441                 break;
442         }
443         case USER_CONFIRM_GEOLOCATION:
444         {
445                 Ewk_Geolocation_Permission_Request* pPolicy =  reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
446                 if (__pCheckButton->IsSelected())
447                 {
448                         result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
449                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
450                 }
451 CATCH:
452                 ewk_geolocation_permission_request_set(pPolicy, allow);
453                 break;
454         }
455         case USER_CONFIRM_NOTIFICATION:
456         {
457                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
458                 ewk_notification_permission_request_set(pPermissionRequest, allow);
459                 break;
460         }
461         case USER_SCRIPT_ALERT:
462         {
463                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
464                 ewk_view_javascript_alert_reply(pView);
465                 break;
466         }
467         case USER_SCRIPT_CONFIRM:
468         {
469                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
470                 ewk_view_javascript_confirm_reply(pView, allow);
471                 break;
472         }
473         case USER_BEFORE_UNLOAD_CONFIRM:
474         {
475                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
476                 ewk_view_before_unload_confirm_panel_reply(pView, !allow);
477                 break;
478         }
479         case USER_CONFIRM_APP_CACHE:
480         {
481                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
482                 ewk_view_application_cache_permission_reply(pObj, allow);
483                 break;
484         }
485         case USER_CONFIRM_DB_QUOTA_EXCEDED:
486         {
487                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
488                 ewk_view_exceeded_database_quota_reply(pObj, allow);
489                 break;
490         }
491         case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
492         {
493                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
494                 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
495                 break;
496         }
497         case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
498         {
499                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
500                 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
501                 break;
502         }
503         default:
504                 SysAssert(false);
505         }
506         __isUserActionNeeded = false;
507 }
508
509
510 result
511 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
512 {
513         _DatabaseImpl db;
514         String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
515         String table(GEOLOCATION_TABLE_NAME);
516
517         const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
518         String origin = _Utility::CreateOrigin(pSecurityOrigin);
519
520         result r = db.Construct(geolocationPath, "r+", null);
521         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
522
523         std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
524         SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
525
526         SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
527
528         pStmt->BindString(0, origin);
529         pStmt->BindInt(1, static_cast < int >(enable));
530
531         db.BeginTransaction();
532
533         std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
534
535         db.CommitTransaction();
536
537         return E_SUCCESS;
538 }
539
540
541 void
542 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
543 {
544         _DatabaseImpl db;
545         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
546         String table;
547         int checkId = 0;
548
549         if(checkHandler == true)
550         {
551                 table = CUSTOM_CONTENT_TABLE_NAME;
552         }
553         else
554         {
555                 table = CUSTOM_PROTOCOL_TABLE_NAME;
556         }
557         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
558         SysAssertf(pHandlerData, "Failed to request");
559
560         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
561         String uri = ewk_custom_handlers_data_url_get(pHandlerData);
562         String target = ewk_custom_handlers_data_target_get(pHandlerData);
563
564         result r = db.Construct(handlerPath, "r+", null);
565         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
566
567         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"'"));
568
569         if(pEnum.get())
570         {
571                 pEnum->MoveNext();
572                 pEnum->GetIntAt(0, checkId);
573
574                 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
575                 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
576
577                 pUpdateStmt->BindInt(0, static_cast < int >(allow));
578                 pUpdateStmt->BindInt(1, checkId);
579
580                 db.BeginTransaction();
581
582                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
583
584                 db.CommitTransaction();
585
586         }
587         else
588         {
589                 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
590                 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
591
592                 pStmt->BindString(0, baseUri);
593                 pStmt->BindString(1, uri);
594                 pStmt->BindString(2, target);
595                 pStmt->BindInt(3, static_cast < int >(allow));
596
597                 db.BeginTransaction();
598
599                 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
600
601                 db.CommitTransaction();
602         }
603 }
604
605 bool
606 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
607 {
608         return false;
609 }
610
611 bool
612 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
613 {
614         result r = E_SUCCESS;
615         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
616         {
617                 HandleUserAction(EINA_FALSE);
618                 r = HidePopup();
619
620                 if (IsFailed(r))
621                 {
622                         SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
623                 }
624                 
625                 switch (__userConfirmMode)
626                 {
627                 case USER_CONFIRM_USERMEDIA:
628                 {
629                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
630                         break;
631                 }
632                 case USER_CONFIRM_GEOLOCATION:
633                 {
634                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
635                         break;
636                 }
637                 case USER_CONFIRM_NOTIFICATION:
638                 {
639                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
640                         break;
641                 }
642                 case USER_SCRIPT_ALERT:
643                 {
644                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
645                         break;
646                 }
647                 case USER_SCRIPT_CONFIRM:
648                 {
649                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
650                         break;
651                 }
652                 case USER_BEFORE_UNLOAD_CONFIRM:
653                 {
654                         __pImpl->SendUserEvent(ID_USER_BEFORE_UNLOAD_CONFIRM_CLOSE, null);
655                         break;
656                 }
657                 case USER_PROTOCOL_HANDLER:
658                 case USER_CONTENT_HANDLER:
659                 case USER_CONFIRM_APP_CACHE:
660                 case USER_CONFIRM_DB_QUOTA_EXCEDED:
661                 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
662                 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
663                         break;
664                 default:
665                         SysAssert(false);
666                 }
667         }
668         return false;
669 }
670
671 bool
672 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
673 {
674         return false;
675 }
676
677 bool
678 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
679 {
680         return false;
681 }
682
683 bool
684 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
685 {
686         return false;
687 }
688
689
690 }}} // Tizen::Web::Controls