fix build error
[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->btnDim.height + 2*pPopupData->sideMargin;
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                 popupMaxHeight -=  2*pPopupData->sideMargin;
126                 hasTitle = false;
127         }
128
129         r = _WebPopup::Construct(hasTitle, Dimension(pPopupData->popupDim.width, popupMaxHeight));
130         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131
132         if (userConfirmMode != USER_SCRIPT_ALERT)
133         {
134                 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_SECURITY_WARNING_ABB"));
135         }
136
137         String message = L"";
138         if (userConfirmMode >= USER_SCRIPT_ALERT && userConfirmMode <= USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED)
139         {
140                 message = msg;
141         }
142         else
143         {
144                 message = GetMessageFromPolicy();
145         }
146
147         Rectangle rect(0, 0, 0, 0);
148
149         //label
150         rect.height = 2*pPopupData->labelDim.height;
151         rect.width = pPopupData->labelDim.width;
152
153         //With the font of label and width of label, required height is calculated
154         //      using textobject. TEXT_SIZE_ADJUST is used to increase font size and get bigger height
155         //      as the accurate height is not fitting text in some cases.
156         Font font;
157         r = font.Construct(FONT_STYLE_PLAIN, pPopupData->labelFontSize + TEXT_SIZE_ADJUST);
158         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
159
160         std::unique_ptr<TextObject> pTextObject(new (std::nothrow) TextObject());
161         SysTryReturnResult(NID_WEB_CTRL, pTextObject.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
162
163         r = pTextObject->Construct();
164         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
165
166         std::unique_ptr<TextSimple> pSimpleText(new (std::nothrow) TextSimple(message.GetPointer(), message.GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL, &font));
167         SysTryReturnResult(NID_WEB_CTRL, pSimpleText.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
168
169         r = pTextObject->AppendElement(*pSimpleText);
170         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
171
172         pSimpleText.release();
173
174         r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
175         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
176
177         r = pTextObject->SetBounds(rect);
178         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         r = pTextObject->SetFont(&font, 0, message.GetLength());
181         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
182
183         r = pTextObject->Compose();
184         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
185
186         int labelHeight = pTextObject->GetTotalHeight();
187
188         std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
189         SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
190
191         r = pLabel->Construct(rect, message);
192         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
193
194         pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
195
196         Control* pInfoLabel = null;
197
198         if (rect.height < labelHeight)
199         {
200                 //message text is bigger than label, scroll is created to accomodate it.
201                 std::unique_ptr<ScrollPanel> pScrollPanel(new (std::nothrow) ScrollPanel());
202                 SysTryReturnResult(NID_WEB_CTRL, pScrollPanel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
203
204                 r = pScrollPanel->Construct(rect);
205                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
206
207                 r = AddControl(*pScrollPanel);
208                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
209
210                 ScrollPanel* pSPanel = pScrollPanel.release();
211
212                 r = pLabel->SetSize(Dimension(rect.width, labelHeight));
213                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
214
215                 r = pSPanel->AddControl(*pLabel);
216                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
217
218                 pLabel.release();
219                 pInfoLabel = pSPanel;
220         }
221         else
222         {
223                 r = AddControl(*pLabel);
224                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
225
226                 pInfoLabel = pLabel.release();
227         }
228
229         //checkbutton
230         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
231         {
232                 rect.y = 0;
233                 rect.height = pPopupData->checkDim.height;
234
235                 std::unique_ptr<CheckButton> pCheckButton (new (std::nothrow) CheckButton());
236                 SysTryReturnResult(NID_WEB_CTRL, pCheckButton.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
237
238                 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"));
239                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
240
241                 r = AddControl(*pCheckButton);
242                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
243
244                 __pCheckButton = pCheckButton.release();
245         }
246
247         Panel* pButtonPanel = CreateAndAddPanel();
248         SysTryReturn(NID_WEB_CTRL, pButtonPanel, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
249
250         ArrayList idList;
251         r = idList.Construct();
252         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
253
254         ArrayList titleList;
255         r = titleList.Construct();
256         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
257
258         if (userConfirmMode == USER_SCRIPT_ALERT)
259         {
260                 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
261                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
262         }
263         else
264         {
265                 idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
266                 idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
267                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
268                 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
269         }
270
271         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
272         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
273
274         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
275         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
276
277         pLayout->SetHorizontalAlignment(*pInfoLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
278         if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
279         {
280                 pLayout->SetHorizontalAlignment(*__pCheckButton, LAYOUT_HORIZONTAL_ALIGN_CENTER);
281         }
282         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
283
284         if ( __userConfirmMode == USER_SCRIPT_ALERT )
285         {
286                 pLayout->SetSpacing(*pButtonPanel, pPopupData->sideMargin);
287         }
288         else
289         {
290                 pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
291         }
292
293         SetPropagatedKeyEventListener(this);
294         return E_SUCCESS;
295 }
296
297
298 void
299 _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
300 {
301         result r = E_SUCCESS;
302
303         switch (actionId)
304         {
305         case ID_BUTTON_USER_ALLOW:
306                 HandleUserAction(EINA_TRUE);
307                 break;
308
309         case ID_BUTTON_USER_CANCEL:
310                 HandleUserAction(EINA_FALSE);
311                 break;
312
313         default:
314                 break;
315         }
316
317         r = HidePopup();
318         if (IsFailed(r))
319         {
320                 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
321         }
322
323         if (!__sync)
324         {
325                 switch(__userConfirmMode)
326                 {
327                 case USER_CONFIRM_USERMEDIA:
328                 {
329                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
330                         break;
331                 }
332                 case USER_CONFIRM_GEOLOCATION:
333                 {
334                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
335                         break;
336                 }
337                 case USER_CONFIRM_NOTIFICATION:
338                 {
339                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
340                         break;
341                 }
342                 case USER_SCRIPT_ALERT:
343                 {
344                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
345                         break;
346                 }
347                 case USER_SCRIPT_CONFIRM:
348                 {
349                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
350                         break;
351                 }
352                 default:
353                         SysAssert(false);
354                 }
355         }
356 }
357
358
359 String
360 _UserConfirmPopup::GetMessageFromPolicy(void)
361 {
362         _SystemResource* pSysResource = _SystemResource::GetInstance();
363         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
364
365         String message;
366
367         switch(__userConfirmMode)
368         {
369         case USER_CONFIRM_USERMEDIA:
370         {
371                 message = L"Do you want to allow acccess to media?\n";
372                 break;
373         }
374         case USER_PROTOCOL_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 = baseUri + String(L" is asking to register ") + target + String(L" protocol handler.");
383                 break;
384         }
385         case USER_CONTENT_HANDLER:
386         {
387                 Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
388                 SysAssertf(pHandlerData, "Failed to request");
389
390                 String target(ewk_custom_handlers_data_target_get(pHandlerData));
391                 String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
392
393                 message = String(baseUri) + String(L" is asking to register ") + String(target) + String(L" content handler.");
394                 break;
395         }
396         case USER_CONFIRM_GEOLOCATION:
397         {
398                 Ewk_Geolocation_Permission_Request* pGeoLocPermReq = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
399                 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pGeoLocPermReq);
400
401                 message = _Utility::CreateOrigin(pSecurityOrigin);
402                 message.Append(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_PS_REQUESTS_YOUR_LOCATION"));
403                 break;
404         }
405         case USER_CONFIRM_NOTIFICATION:
406         {
407                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
408                 const Ewk_Security_Origin* pSecurityOrigin = ewk_notification_permission_request_origin_get(pPermissionRequest);
409                 message = _Utility::CreateOrigin(pSecurityOrigin);
410                 message.Append(L" wants to display notifications");
411                 break;
412         }
413         default:
414                 SysAssert(false);
415         }
416
417         return message;
418 }
419
420
421 void
422 _UserConfirmPopup::HandleUserAction(Eina_Bool allow)
423 {
424         switch (__userConfirmMode)
425         {
426         case USER_CONFIRM_USERMEDIA:
427         {
428                 Ewk_User_Media_Permission_Request* pPolicy = reinterpret_cast< Ewk_User_Media_Permission_Request* >(__pUserPolicyData);
429                 ewk_user_media_permission_request_set(pPolicy, allow);
430                 break;
431         }
432         case USER_PROTOCOL_HANDLER:
433         {
434                 RegisterHandler(false, allow);
435                 break;
436         }
437         case USER_CONTENT_HANDLER:
438         {
439                 RegisterHandler(true, allow);
440                 break;
441         }
442         case USER_CONFIRM_GEOLOCATION:
443         {
444                 Ewk_Geolocation_Permission_Request* pPolicy =  reinterpret_cast< Ewk_Geolocation_Permission_Request* >(__pUserPolicyData);
445                 if (__pCheckButton->IsSelected())
446                 {
447                         result r = AddGeolocationDb(pPolicy, static_cast < bool >(allow));
448                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
449                 }
450 CATCH:
451                 ewk_geolocation_permission_request_set(pPolicy, allow);
452                 break;
453         }
454         case USER_CONFIRM_NOTIFICATION:
455         {
456                 Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(__pUserPolicyData);
457                 ewk_notification_permission_request_set(pPermissionRequest, allow);
458                 break;
459         }
460         case USER_SCRIPT_ALERT:
461         {
462                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
463                 ewk_view_javascript_alert_reply(pView);
464                 break;
465         }
466         case USER_SCRIPT_CONFIRM:
467         {
468                 Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
469                 ewk_view_javascript_confirm_reply(pView, allow);
470                 break;
471         }
472         case USER_CONFIRM_APP_CACHE:
473         {
474                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
475                 ewk_view_application_cache_permission_reply(pObj, allow);
476                 break;
477         }
478         case USER_CONFIRM_DB_QUOTA_EXCEDED:
479         {
480                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
481                 ewk_view_exceeded_database_quota_reply(pObj, allow);
482                 break;
483         }
484         case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
485         {
486                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
487                 ewk_view_exceeded_local_file_system_quota_reply(pObj, allow);
488                 break;
489         }
490         case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
491         {
492                 Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
493                 ewk_view_exceeded_indexed_database_quota_reply(pObj, allow);
494                 break;
495         }
496         default:
497                 SysAssert(false);
498         }
499         __isUserActionNeeded = false;
500 }
501
502
503 result
504 _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy, bool enable)
505 {
506         _DatabaseImpl db;
507         String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
508         String table(GEOLOCATION_TABLE_NAME);
509
510         const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPolicy);
511         String origin = _Utility::CreateOrigin(pSecurityOrigin);
512
513         result r = db.Construct(geolocationPath, "r+", null);
514         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
515
516         std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (origin, permission) Values (?, ?)"));
517         SysTryReturn(NID_WEB_CTRL, pStmt.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518
519         SysLog(NID_WEB_CTRL, "The current value of stmt is %u, host is %ls", pStmt.get(), origin.GetPointer());
520
521         pStmt->BindString(0, origin);
522         pStmt->BindInt(1, static_cast < int >(enable));
523
524         db.BeginTransaction();
525
526         std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pStmt));
527
528         db.CommitTransaction();
529
530         return E_SUCCESS;
531 }
532
533
534 void
535 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
536 {
537         _DatabaseImpl db;
538         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
539         String table;
540         int checkId = 0;
541
542         if(checkHandler == true)
543         {
544                 table = CUSTOM_CONTENT_TABLE_NAME;
545         }
546         else
547         {
548                 table = CUSTOM_PROTOCOL_TABLE_NAME;
549         }
550         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(__pUserPolicyData);
551         SysAssertf(pHandlerData, "Failed to request");
552
553         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
554         String uri = ewk_custom_handlers_data_url_get(pHandlerData);
555         String target = ewk_custom_handlers_data_target_get(pHandlerData);
556
557         result r = db.Construct(handlerPath, "r+", null);
558         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
559
560         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"'"));
561
562         if(pEnum.get())
563         {
564                 pEnum->MoveNext();
565                 pEnum->GetIntAt(0, checkId);
566
567                 std::unique_ptr<DbStatement> pUpdateStmt(db.CreateStatementN(L"Update " + table + L" Set allow = (?) Where id = (?)"));
568                 SysTryReturnVoidResult(NID_WEB_CTRL, pUpdateStmt.get(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
569
570                 pUpdateStmt->BindInt(0, static_cast < int >(allow));
571                 pUpdateStmt->BindInt(1, checkId);
572
573                 db.BeginTransaction();
574
575                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pUpdateStmt));
576
577                 db.CommitTransaction();
578
579         }
580         else
581         {
582                 std::unique_ptr<DbStatement> pStmt(db.CreateStatementN(L"Insert Into " + table + L" (baseUrl, url, mime, allow) Values (?, ?, ?, ?)"));
583                 SysTryReturnVoidResult(NID_WEB_CTRL, pStmt.get(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
584
585                 pStmt->BindString(0, baseUri);
586                 pStmt->BindString(1, uri);
587                 pStmt->BindString(2, target);
588                 pStmt->BindInt(3, static_cast < int >(allow));
589
590                 db.BeginTransaction();
591
592                 std::unique_ptr<DbEnumerator> pRegisterEnum(db.ExecuteStatementN(*pStmt));
593
594                 db.CommitTransaction();
595         }
596 }
597
598 bool
599 _UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
600 {
601         return false;
602 }
603
604 bool
605 _UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
606 {
607         result r = E_SUCCESS;
608         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
609         {
610                 HandleUserAction(EINA_FALSE);
611                 r = HidePopup();
612
613                 if (IsFailed(r))
614                 {
615                         SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
616                 }
617                 
618                 switch (__userConfirmMode)
619                 {
620                 case USER_CONFIRM_USERMEDIA:
621                 {
622                         __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
623                         break;
624                 }
625                 case USER_CONFIRM_GEOLOCATION:
626                 {
627                         __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
628                         break;
629                 }
630                 case USER_CONFIRM_NOTIFICATION:
631                 {
632                         __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
633                         break;
634                 }
635                 case USER_SCRIPT_ALERT:
636                 {
637                         __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
638                         break;
639                 }
640                 case USER_SCRIPT_CONFIRM:
641                 {
642                         __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
643                         break;
644                 }
645                 case USER_PROTOCOL_HANDLER:
646                 case USER_CONTENT_HANDLER:
647                 case USER_CONFIRM_APP_CACHE:
648                 case USER_CONFIRM_DB_QUOTA_EXCEDED:
649                 case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
650                 case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
651                         break;
652                 default:
653                         SysAssert(false);
654                 }
655         }
656         return false;
657 }
658
659 bool
660 _UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
661 {
662         return false;
663 }
664
665 bool
666 _UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
667 {
668         return false;
669 }
670
671 bool
672 _UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
673 {
674         return false;
675 }
676
677
678 }}} // Tizen::Web::Controls