change ewk API and UA
[framework/osp/web.git] / src / controls / FWebCtrl_WebImpl.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_WebImpl.cpp
20  * @brief               The file contains the definition of _WebImpl class.
21  *
22  * The file contains the definition of _WebImpl class.
23  */
24 #include <Ecore_IMF_Evas.h>
25 #include <Ecore_Evas.h>
26 #include <elm_config.h>
27 #include <elm_win.h>
28 #include <EWebKit2.h>
29 #include <ewk_popup_menu_item.h>
30 #include <libsoup/soup-status.h>
31 #include <FAppApp.h>
32 #include <FAppAppControl.h>
33 #include <FAppIAppControlListener.h>
34 #include <FBaseColAllElementsDeleter.h>
35 #include <FBaseColHashMapT.h>
36 #include <FBaseRtMutex.h>
37 #include <FBaseRtMutexGuard.h>
38 #include <FBaseSysLog.h>
39 #include <FBaseUtilUri.h>
40 #include <FCntDownloadRequest.h>
41 #include <FGrpColor.h>
42 #include <FGrpPoint.h>
43 #include <FGrpRectangle.h>
44 #include <FIoDbEnumerator.h>
45 #include <FIoDbStatement.h>
46 #include <FIoFile.h>
47 #include <FMediaImage.h>
48 #include <FMediaImageTypes.h>
49 #include <FNetHttpHttpHeader.h>
50 #include <FSysVibrator.h>
51 #include <FUiControl.h>
52 #include <FUiCtrlKeypad.h>
53 #include <FWebCtrlHitElementResult.h>
54 #include <FWebCtrlITextSearchListener.h>
55 #include <FWebCtrlIWebDownloadListener.h>
56 #include <FWebCtrlIWebUiEventListener.h>
57 #include <FWebCtrlIWebUiEventListenerF.h>
58 #include <FWebCtrlIWebKeypadEventListener.h>
59 #include <FWebCtrlIJavaScriptBridge.h>
60 #include <FWebCtrlPageNavigationList.h>
61 #include <FWebCtrlAuthenticationChallenge.h>
62 #include <FWebCtrlWeb.h>
63 #include <FWebCtrlWebSetting.h>
64 #include <FWebHistoryItem.h>
65 #include <FWebJsonJsonObject.h>
66 #include <FWebJsonJsonParser.h>
67 #include <FWebJsonJsonString.h>
68 #include <FApp_AppControlImpl.h>
69 #include <FApp_AppControlManager.h>
70 #include <FApp_AppInfo.h>
71 #include <FApp_AppManagerImpl.h>
72 #include <FBase_StringConverter.h>
73 #include <FCnt_DownloadManagerImpl.h>
74 #include <FGrp_CoordinateSystem.h>
75 #include <FIo_DatabaseImpl.h>
76 #include <FIo_NormalFile.h>
77 #include <FSys_VibratorImpl.h>
78 #include <FUi_Control.h>
79 #include <FUi_CoordinateSystemUtils.h>
80 #include <FUi_EcoreEvasMgr.h>
81 #include <FUi_EcoreEvas.h>
82 #include <FUi_ResourceSizeInfo.h>
83 #include <FUi_Window.h>
84 #include <FUiAnim_EflNode.h>
85 #include <FUiAnim_VisualElement.h>
86 #include <FUiCtrl_FooterImpl.h>
87 #include <FUiCtrl_Form.h>
88 #include "FWeb_HistoryItemImpl.h"
89 #include "FWebCtrl_AppControlListener.h"
90 #include "FWebCtrl_AuthConfirmPopup.h"
91 #include "FWebCtrl_AuthenticationChallengeImpl.h"
92 #include "FWebCtrl_EflWebkit.h"
93 #include "FWebCtrl_GeolocationPermissionManagerImpl.h"
94 #include "FWebCtrl_HitElementResultImpl.h"
95 #include "FWebCtrl_InputPickerPopup.h"
96 #include "FWebCtrl_WebNotification.h"
97 #include "FWebCtrl_PageNavigationListImpl.h"
98 #include "FWebCtrl_PromptPopup.h"
99 #include "FWebCtrl_SelectBox.h"
100 #include "FWebCtrl_Utility.h"
101 #include "FWebCtrl_Web.h"
102 #include "FWebCtrl_WebDataHandler.h"
103 #include "FWebCtrl_WebEvent.h"
104 #include "FWebCtrl_WebEventArg.h"
105 #include "FWebCtrl_WebImpl.h"
106 #include "FWebCtrl_WebPresenter.h"
107 #include "FWebCtrl_WebSettingImpl.h"
108
109
110 using namespace Tizen::App;
111 using namespace Tizen::Base;
112 using namespace Tizen::Base::Collection;
113 using namespace Tizen::Base::Runtime;
114 using namespace Tizen::Base::Utility;
115 using namespace Tizen::Content;
116 using namespace Tizen::Graphics;
117 using namespace Tizen::Io;
118 using namespace Tizen::Media;
119 using namespace Tizen::Net::Http;
120 using namespace Tizen::System;
121 using namespace Tizen::Ui;
122 using namespace Tizen::Ui::Animations;
123 using namespace Tizen::Ui::Controls;
124 using namespace Tizen::Web::Json;
125
126
127 namespace Tizen { namespace Web { namespace Controls
128 {
129
130
131 static const char WEB_CTRL[] = "webcontrol";
132 static const char PARENT_WEB_CTRL[] = "parentwebcontrol";
133
134
135 static const float MIN_ZOOM_LEVEL = 0.3;
136 static const float MAX_ZOOM_LEVEL = 2;
137
138
139 static const int REDIRECTION_HEADER_GROUP = 300;
140
141
142 static const int MAX_TEXT_MATCH = pow(2, 31) - 1;
143
144
145 static const int PORTRAIT_KEYPAD_HEIGHT = 444;
146 static const int LANDSCAPE_KEYPAD_HEIGHT = 316;
147 static const int DEFAULT_LIST_ITEM_COUNT = 4;
148
149
150 Eina_Bool
151 AddHttpHeaderData(const Eina_Hash* pHash, const void* pKey, void* pValue, void* pUserData)
152 {
153         result r = E_SUCCESS;
154
155         String key(reinterpret_cast< const char* >(pKey));
156         String value(reinterpret_cast< char* >(pValue));
157
158         SysLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", key.GetPointer(), value.GetPointer());
159
160         r = reinterpret_cast< HttpHeader* >(pUserData)->AddField(key, value);
161         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
162
163         return EINA_TRUE;
164 }
165
166
167 Eina_Bool
168 AddHttpAttributeData(const Eina_Hash* pHash, const void* pKey, void* pValue, void* pUserData)
169 {
170         result r = E_SUCCESS;
171
172         std::unique_ptr<String> pAttrKey(new (std::nothrow) String(reinterpret_cast< char* >(const_cast< void* >(pKey))));
173         std::unique_ptr<String> pAttrValue(new (std::nothrow) String(reinterpret_cast< char* >(pValue)));
174         SysTryReturn(NID_WEB_CTRL, pAttrKey.get() && pAttrValue.get(), EINA_FALSE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
175
176         SysLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", pAttrKey->GetPointer(), pAttrValue->GetPointer());
177
178         r = reinterpret_cast< HashMap* >(pUserData)->Add(*pAttrKey, *pAttrValue);
179         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
180         pAttrKey.release();
181         pAttrValue.release();
182
183         return EINA_TRUE;
184 }
185
186
187 void
188 FreeCharArray(void* pData)
189 {
190         delete[] reinterpret_cast<char*>(pData);
191 }
192
193
194 LoadingErrorType
195 ConvertErrorCode(int error)
196 {
197         LoadingErrorType errorCode = WEB_ERROR_UNKNOWN;
198
199         switch (error)
200         {
201         case EWK_ERROR_NETWORK_STATUS_CANCELLED:
202         //fall through
203         case EWK_ERROR_NETWORK_STATUS_CANT_RESOLVE:
204         //fall through
205         case EWK_ERROR_NETWORK_STATUS_CANT_RESOLVE_PROXY:
206         //fall through
207         case EWK_ERROR_NETWORK_STATUS_CANT_CONNECT:
208         //fall through
209         case EWK_ERROR_NETWORK_STATUS_CANT_CONNECT_PROXY:
210         //fall through
211         case EWK_ERROR_NETWORK_STATUS_IO_ERROR:
212         //fall through
213         case EWK_ERROR_NETWORK_STATUS_MALFORMED:
214         //fall through
215         case EWK_ERROR_NETWORK_STATUS_TRY_AGAIN:
216         //fall through
217         case EWK_ERROR_NETWORK_STATUS_TOO_MANY_REDIRECTS:
218         //fall through
219         case EWK_ERROR_NETWORK_STATUS_TLS_FAILED:
220         //fall through
221         case EWK_ERROR_NETWORK_STATUS_INTERNAL_SERVER_ERROR:
222         //fall through
223         case EWK_ERROR_NETWORK_STATUS_BAD_GATEWAY:
224         //fall through
225         case EWK_ERROR_NETWORK_STATUS_SERVICE_UNAVAILABLE:
226         //fall through
227         case EWK_ERROR_NETWORK_STATUS_GATEWAY_TIMEOUT:
228                 errorCode = WEB_NO_CONNECTION;
229                 break;
230
231         case EWK_ERROR_NETWORK_STATUS_BAD_REQUEST:
232         //fall through
233         case EWK_ERROR_NETWORK_STATUS_REQUEST_URI_TOO_LONG:
234                 errorCode = WEB_BAD_URL;
235                 break;
236
237         case EWK_ERROR_NETWORK_STATUS_FORBIDDEN:
238                 errorCode = WEB_FILE_ACCESS_FAILED;
239                 break;
240
241         case EWK_ERROR_NETWORK_STATUS_REQUEST_TIMEOUT:
242                 errorCode = WEB_REQUEST_TIMEOUT;
243                 break;
244
245         case EWK_ERROR_NETWORK_STATUS_UNSUPPORTED_MEDIA_TYPE:
246                 errorCode = WEB_MIME_NOT_SUPPORTED;
247                 break;
248
249         case EWK_ERROR_NETWORK_STATUS_INSUFFICIENT_STORAGE:
250                 errorCode = WEB_OUT_OF_MEMORY;
251                 break;
252
253         case EWK_ERROR_NETWORK_STATUS_REQUEST_ENTITY_TOO_LARGE:
254                 errorCode = WEB_REQUEST_MAX_EXCEEDED;
255                 break;
256
257         case EWK_ERROR_NETWORK_STATUS_CONTINUE:
258         //fall through
259         case EWK_ERROR_NETWORK_STATUS_SWITCHING_PROTOCOLS:
260         //fall through
261         case EWK_ERROR_NETWORK_STATUS_PROCESSING:
262         //fall through
263         case EWK_ERROR_NETWORK_STATUS_OK:
264         //fall through
265         case EWK_ERROR_NETWORK_STATUS_CREATED:
266         //fall through
267         case EWK_ERROR_NETWORK_STATUS_ACCEPTED:
268         //fall through
269         case EWK_ERROR_NETWORK_STATUS_NON_AUTHORITATIVE:
270         //fall through
271         case EWK_ERROR_NETWORK_STATUS_NO_CONTENT:
272         //fall through
273         case EWK_ERROR_NETWORK_STATUS_RESET_CONTENT:
274         //fall through
275         case EWK_ERROR_NETWORK_STATUS_PARTIAL_CONTENT:
276         //fall through
277         case EWK_ERROR_NETWORK_STATUS_MULTI_STATUS:
278         //fall through
279         case EWK_ERROR_NETWORK_STATUS_MULTIPLE_CHOICES:
280         //fall through
281         case EWK_ERROR_NETWORK_STATUS_MOVED_PERMANENTLY:
282         //fall through
283         case EWK_ERROR_NETWORK_STATUS_FOUND:
284         //fall through
285         case EWK_ERROR_NETWORK_STATUS_SEE_OTHER:
286         //fall through
287         case EWK_ERROR_NETWORK_STATUS_NOT_MODIFIED:
288         //fall through
289         case EWK_ERROR_NETWORK_STATUS_USE_PROXY:
290         //fall through
291         case EWK_ERROR_NETWORK_STATUS_NOT_APPEARING_IN_THIS_PROTOCOL:
292         //fall through
293         case EWK_ERROR_NETWORK_STATUS_TEMPORARY_REDIRECT:
294                 errorCode = WEB_HTTP_RESPONSE;
295                 break;
296
297         case EWK_ERROR_NETWORK_STATUS_SSL_FAILED:
298                 errorCode = WEB_INVALID_CERTIFICATE;
299                 break;
300
301         default:
302                 errorCode = WEB_ERROR_UNKNOWN;
303                 break;
304         }
305
306         return errorCode;
307 }
308
309
310 result
311 FireLoadingErrorOccurredEvent(_WebImpl* pImpl, int code, const char* pDescription)
312 {
313         result r = E_SUCCESS;
314
315         std::unique_ptr<Integer> pErrorCode(new (std::nothrow) Integer(code));
316         std::unique_ptr<String> pErrorDescription(new (std::nothrow) String(pDescription));
317         std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED));
318         SysTryReturnResult(NID_WEB_CTRL, pErrorCode.get() && pErrorDescription.get() && pEventArg.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
319
320         r = pEventArg->SetEventInfo(_LoadingEventArg::ERROR_TYPE, *pErrorCode.get());
321         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
322         pErrorCode.release();
323
324         r = pEventArg->SetEventInfo(_LoadingEventArg::ERROR_MESSAGE, *pErrorDescription.get());
325         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
326         pErrorDescription.release();
327
328         r = pImpl->GetWebEvent()->FireAsync(*pEventArg);
329         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
330         pEventArg.release();
331
332         return E_SUCCESS;
333 }
334
335
336 Eina_Bool
337 OnScriptAlertRequested(Evas_Object* pView, const char* pMessage, void* pUserData)
338 {
339         SysLog(NID_WEB_CTRL, "The current value of message is %s", pMessage);
340
341         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
342         String msg(pMessage);
343
344         result r = pImpl->ShowUserConfirmPopupAsync(USER_SCRIPT_ALERT, pView, msg);
345         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
346         return EINA_TRUE;
347
348 CATCH:
349         ewk_view_javascript_alert_reply(pView);
350         return EINA_TRUE;
351 }
352
353
354 Eina_Bool
355 OnScriptConfirmRequested(Evas_Object* pView, const char* pMessage, void* pUserData)
356 {
357         SysLog(NID_WEB_CTRL, "The current value of message is %s", pMessage);
358
359         result r = E_SUCCESS;
360         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
361         String msg(pMessage);
362
363         MessageBox messageBox;
364         r = messageBox.Construct(L"", msg, MSGBOX_STYLE_OKCANCEL);
365         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
366
367         int modalResult = 0;
368
369         messageBox.SetOwner(&pImpl->GetPublic());
370
371         r = messageBox.ShowAndWait(modalResult);
372         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
373
374         if (modalResult == MSGBOX_RESULT_OK)
375         {
376                 ewk_view_javascript_confirm_reply(pView, EINA_TRUE);
377         }
378         else
379         {
380                 ewk_view_javascript_confirm_reply(pView, EINA_FALSE);
381         }
382
383         return EINA_TRUE;
384 }
385
386
387 Eina_Bool
388 OnScriptPromptRequested(Evas_Object* pView, const char* pMessage, const char* pDefaultValue, void* pUserData)
389 {
390         SysLog(NID_WEB_CTRL, "The current value of message is %s, defaulValue is %s", pMessage, pDefaultValue);
391
392         result r = E_SUCCESS;
393         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
394         String msg(pMessage);
395         String defVal(pDefaultValue);
396
397         std::unique_ptr< _PromptPopup > pPromptPopup(new (std::nothrow) _PromptPopup());
398         SysTryCatch(NID_WEB_CTRL, pPromptPopup.get(), , E_OUT_OF_MEMORY, "Memory allocation failed.");
399
400         r = pPromptPopup->Construct(msg, defVal, pView);
401         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
402
403         pPromptPopup->SetOwner(&pImpl->GetPublic());
404
405         r = pPromptPopup->ShowPopup();
406         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
407
408         pPromptPopup.release();
409
410         return EINA_TRUE;
411
412 CATCH:
413         ewk_view_javascript_prompt_reply(pView, null);
414
415         return EINA_FALSE;
416 }
417
418
419 void
420 OnCertificateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
421 {
422         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
423         Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(pEventInfo);
424         SysAssertf(pImpl && pPolicy, "Failed to request");
425
426         switch (pImpl->GetSetting().GetCertificateErrorHandlingMode())
427         {
428         case WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM:
429         {
430                 if (pImpl->IsCertificateRequested())
431                 {
432                         ewk_certificate_policy_decision_allowed_set(pPolicy, static_cast< Eina_Bool >(pImpl->IsCertificateConfirmed()));
433                         return;
434                 }
435
436                 result r = E_SUCCESS;
437
438                 r = pImpl->ShowCertificateConfirmPopup(CERTIFICATE_POPUP_MODE_USER_CONFIRM, pPolicy);
439                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
440
441                 pImpl->SetCertificateRequested(true);
442                 break;
443         }
444         case WEB_CERTIFICATE_ERROR_HANDLING_MODE_CANCEL:
445 CATCH:
446                 ewk_certificate_policy_decision_allowed_set(pPolicy, EINA_FALSE);
447                 break;
448         case WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE :
449                 ewk_certificate_policy_decision_allowed_set(pPolicy, EINA_TRUE);
450                 break;
451         default:
452                 SysAssert(false);
453         }
454 }
455
456
457 void
458 OnHttpAuthenticationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
459 {
460         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
461         Ewk_Auth_Challenge* pChallenge = reinterpret_cast< Ewk_Auth_Challenge* >(pEventInfo);
462         SysAssertf(pImpl && pChallenge, "Failed to request");
463
464         result r = E_SUCCESS;
465
466         r = pImpl->HttpAuthenticationRequested(pChallenge);
467         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
468         return;
469
470 CATCH:
471         ewk_auth_challenge_credential_cancel(pChallenge);
472         evas_object_smart_callback_call(pView, "authentication,canceled", NULL);
473 }
474
475
476 void
477 OnHttpAuthenticationCanceled(void* pUserData, Evas_Object* pView, void* pEventInfo)
478 {
479         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
480         SysAssertf(pImpl , "Failed to request");
481
482         if (pImpl->GetLoadingListener())
483         {
484                 result r = E_SUCCESS;
485
486                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED));
487                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
488
489                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
490                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
491                 pEventArg.release();
492         }
493 }
494
495
496 void
497 OnGeolocationPermissionRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
498 {
499         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
500         Ewk_Geolocation_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Geolocation_Permission_Request* >(pEventInfo);
501         SysAssertf(pImpl && pPermissionRequest, "Failed to request");
502
503         if (pImpl->GetSetting().IsGeolocationEnabled())
504         {
505                 result r = E_SUCCESS;
506
507                 std::unique_ptr<DbEnumerator> pEnum;
508
509                 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
510                 String table(GEOLOCATION_TABLE_NAME);
511                 _DatabaseImpl db;
512
513                 const Ewk_Security_Origin* pSecurityOrigin = ewk_geolocation_permission_request_origin_get(pPermissionRequest);
514                 String origin = _Utility::CreateOrigin(pSecurityOrigin);
515
516                 r = db.Construct(geolocationPath, "r", null);
517                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
518
519                 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select permission From " + table + L" Where origin = '" + origin + L"'"));
520                 if (pEnum.get())
521                 {
522                         r = pEnum->MoveNext();
523                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
524
525                         int permission = 0;
526                         r = pEnum->GetIntAt(0, permission);
527                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
528
529                         SysLog(NID_WEB_CTRL, "The current value of permission is %d", permission);
530
531                         ewk_geolocation_permission_request_set(pPermissionRequest, static_cast < Eina_Bool >(permission));
532                 }
533                 else
534                 {
535                         ewk_geolocation_permission_request_suspend(pPermissionRequest);
536
537                         r = pImpl->ShowUserConfirmPopupAsync(USER_CONFIRM_GEOLOCATION, pPermissionRequest);
538                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
539                 }
540
541                 return;
542         }
543
544 CATCH:
545         ewk_geolocation_permission_request_set(pPermissionRequest, EINA_FALSE);
546 }
547
548
549 void
550 OnGetUserMediaPermissionRequsted(void* pUserData, Evas_Object* pView, void* pEventInfo)
551 {
552         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
553         Ewk_User_Media_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_User_Media_Permission_Request* >(pEventInfo);
554         SysAssertf(pImpl && pPermissionRequest, "Failed to request");
555
556         result r = pImpl->ShowUserConfirmPopupAsync(USER_CONFIRM_USERMEDIA, pEventInfo);
557         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
558         return;
559
560 CATCH:
561         ewk_user_media_permission_request_set(pPermissionRequest, EINA_FALSE);
562 }
563
564
565 void
566 OnNotificationPermissionRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
567 {
568         result r = E_SUCCESS;
569         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
570
571         Ewk_Notification_Permission_Request* pPermissionRequest = reinterpret_cast< Ewk_Notification_Permission_Request* >(pEventInfo);
572         SysAssertf(pImpl && pPermissionRequest, "Failed to request");
573
574         ewk_notification_permission_request_suspend(pPermissionRequest);
575
576         r = pImpl->ShowUserConfirmPopupAsync(USER_CONFIRM_NOTIFICATION, pPermissionRequest);
577         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
578         return;
579
580 CATCH:
581         ewk_notification_permission_request_set(pPermissionRequest, EINA_FALSE);
582 }
583
584
585 void
586 OnNotificationShow(void* pUserData, Evas_Object* pView, void* pEventInfo)
587 {
588         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
589         Ewk_Notification* pNotification = reinterpret_cast< Ewk_Notification* >(pEventInfo);
590         SysAssertf(pImpl && pNotification, "Failed to request");
591
592         result r = E_SUCCESS;
593         Ewk_Context* pContext = ewk_view_context_get(pView);
594         SysAssertf(pContext, "Failed to get webkit instance.");
595         uint64_t notificationId = ewk_notification_id_get(pNotification);
596
597         //ewk_notification_security_origin_get(pNotification)
598
599         const char* text = ewk_notification_body_get(pNotification);
600         SysLog(NID_WEB_CTRL, "The current value of icon path is %s",ewk_notification_icon_url_get(pNotification));
601
602         std::unique_ptr<_WebNotification> pNotificationWindow( new (std::nothrow) _WebNotification());
603         SysTryReturnVoidResult(NID_WEB_CTRL, pNotificationWindow.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
604
605         r = pNotificationWindow->Construct(pContext, notificationId, pImpl);
606         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Error propogated.", GetErrorMessage(r));
607
608         pNotificationWindow->SetText(String(text));
609         pNotificationWindow->LaunchNotification();
610         pNotificationWindow.release();
611
612         ewk_notification_showed(pContext, notificationId);
613 }
614
615
616 void
617 OnNotificationCancel(void* pUserData, Evas_Object* pView, void* pEventInfo)
618 {
619         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
620         uint64_t* pNotificationID = reinterpret_cast< uint64_t* >(pEventInfo);
621         SysAssertf(pImpl && pNotificationID, "Failed to request");
622
623         //ToDo : Where is ewk API for cancel operation?
624 }
625
626
627 void
628 OnProtocolHandlerRegistrationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
629 {
630         result r = E_SUCCESS;
631         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
632         SysAssertf(pImpl, "Failed to request");
633
634         r = pImpl->ShowUserConfirmPopup(USER_PROTOCOL_HANDLER, pEventInfo);
635         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
636 }
637
638
639 void
640 OnIsProtocolHandlerRegistered(void* pUserData, Evas_Object* pView, void* pEventInfo)
641 {
642         int checkHandler = 0;
643         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
644         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(pEventInfo);
645         SysAssertf(pImpl && pHandlerData, "Failed to request");
646
647         checkHandler = pImpl->SearchHandler(pHandlerData, false);
648         SysTryReturnVoidResult(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
649         switch (checkHandler)
650         {
651         case -1:
652                 return;
653         case 0:
654                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_DECLINED);
655                 break;
656         case 1:
657                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_REGISTERED);
658                 break;
659         case 2:
660                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_NEW);
661                 break;
662         default:
663                 SysAssert(false);
664         }
665 }
666
667 void
668 OnProtocolHandlerUnregistrationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
669 {
670         result r = E_SUCCESS;
671         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
672         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(pEventInfo);
673         SysAssertf(pImpl && pHandlerData, "Failed to request");
674
675         r = pImpl->UnregistrationHandler(pHandlerData, false);
676         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
677 }
678
679
680 void
681 OnContentHandlerRegistrationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
682 {
683         result r = E_SUCCESS;
684         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
685         SysAssertf(pImpl, "Failed to request");
686         
687         r = pImpl->ShowUserConfirmPopup(USER_CONTENT_HANDLER, pEventInfo);
688         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
689 }
690
691
692 void
693 OnIsContentHandlerRegistered(void* pUserData, Evas_Object* pView, void* pEventInfo)
694 {
695         int checkHandler = 0;
696         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
697         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(pEventInfo);
698         SysAssertf(pImpl && pHandlerData, "Failed to request");
699
700         checkHandler = pImpl->SearchHandler(pHandlerData, true);
701         SysTryReturnVoidResult(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
702         
703         switch (checkHandler)
704         {
705         case -1:
706                 return;
707         case 0:
708                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_DECLINED);
709                 break;
710         case 1:
711                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_REGISTERED);
712                 break;
713         case 2:
714                 ewk_custom_handlers_data_result_set(pHandlerData, EWK_CUSTOM_HANDLERS_NEW);
715                 break;
716         default:
717                 SysAssert(false);
718         }
719 }
720
721
722 void
723 OnContentHandlerUnregistrationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
724 {
725         result r = E_SUCCESS;
726         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
727         Ewk_Custom_Handlers_Data* pHandlerData = reinterpret_cast< Ewk_Custom_Handlers_Data* >(pEventInfo);
728         SysAssertf(pImpl && pHandlerData, "Failed to request");
729
730         r = pImpl->UnregistrationHandler(pHandlerData, true);
731         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
732 }
733
734
735 void
736 OnVibrationRequested(uint64_t duration, void* pUserData)
737 {
738         result r = E_SUCCESS;
739
740         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
741         SysAssertf(pImpl, "Failed to request");
742
743         r = pImpl->VibrationRequested(duration);
744         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
745 }
746
747
748 void
749 OnVibrationCanceled(void* pUserData)
750 {
751         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
752         SysAssertf(pImpl, "Failed to request");
753
754         pImpl->VibrationCanceled();
755 }
756
757
758 Eina_Bool
759 OnApplicationCachePermissionRequested(Evas_Object* pView, Ewk_Security_Origin* pOrigin, void* pUserData)
760 {
761         ewk_view_application_cache_permission_reply(pView, EINA_TRUE);
762
763         return EINA_TRUE;
764 }
765
766
767 void
768 OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
769 {
770         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
771         Ewk_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Policy_Decision* >(pEventInfo);
772         SysAssertf(pImpl && pPolicy, "Failed to request");
773
774         String url(ewk_policy_decision_url_get(pPolicy));
775         SysSecureLog(NID_WEB_CTRL, "The current value of url is %ls", url.GetPointer());
776
777         if (url == L"about:blank")
778         {
779                 ewk_policy_decision_use(pPolicy);
780                 return;
781         }
782
783         if (pImpl->GetLoadingListener() && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy))
784                 && !pImpl->IsRedirectRequested())
785         {
786                 pImpl->SetCertificateRequested(false);
787
788                 if (pImpl->GetTextSearchListener())
789                 {
790                         pImpl->DisableAsyncSearch();
791                 }
792         
793                 WebNavigationType navigationType = WEB_NAVIGATION_OTHER;
794                 Ewk_Policy_Navigation_Type ewkNavigationType = ewk_policy_decision_navigation_type_get(pPolicy);
795
796                 switch (ewkNavigationType)
797                 {
798                 case EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED:
799                         navigationType = WEB_NAVIGATION_LINK_CLICKED;
800                         break;
801                 case EWK_POLICY_NAVIGATION_TYPE_FORM_SUBMITTED:
802                         navigationType = WEB_NAVIGATION_FORM_SUBMITTED;
803                         break;
804                 case EWK_POLICY_NAVIGATION_TYPE_BACK_FORWARD:
805                         navigationType = WEB_NAVIGATION_BACKFORWARD;
806                         break;
807                 case EWK_POLICY_NAVIGATION_TYPE_RELOAD:
808                         navigationType = WEB_NAVIGATION_RELOAD;
809                         break;
810                 case EWK_POLICY_NAVIGATION_TYPE_FORM_RESUBMITTED:
811                         navigationType = WEB_NAVIGATION_FORM_RESUBMITTED;
812                         break;
813                 case EWK_POLICY_NAVIGATION_TYPE_OTHER:
814                         navigationType = WEB_NAVIGATION_OTHER;
815                         break;
816                 default:
817                         SysAssert(false);
818                 }
819
820                 if (pImpl->GetLoadingListener()->OnLoadingRequested(url, navigationType))
821                 {
822                         ewk_policy_decision_ignore(pPolicy);
823
824                         return;
825                 }
826         }
827
828         String currentUrl(pImpl->GetUrl());
829         String redirectUrl(pImpl->GetProtocolFromUri(url,  currentUrl));
830         if (redirectUrl != L"")
831         {
832                 pImpl->LoadUrl(redirectUrl);
833                 ewk_policy_decision_ignore(pPolicy);
834
835                 return;
836         }
837         
838         Uri uri;
839         uri.SetUri(url);
840
841         String uriScheme(uri.GetScheme());
842         SysLog(NID_WEB_CTRL, "The current value of scheme is %ls", uriScheme.GetPointer());
843
844         if ((uriScheme != L"http") && (uriScheme != L"https") && (uriScheme != L"file"))
845         {
846                 ewk_policy_decision_ignore(pPolicy);
847
848                 if (uriScheme == L"")
849                 {
850                         return;
851                 }
852
853                 result r = E_SUCCESS;
854
855                 _WebEventType eventType = WEB_EVENT_REQUEST_UNKNOWN;
856
857                 if (uriScheme == L"rtsp")
858                 {
859                         eventType = WEB_EVENT_REQUEST_RTSP;
860                 }
861                 else if (uriScheme == L"mailto")
862                 {
863                         eventType = WEB_EVENT_REQUEST_EMAIL;
864                 }
865                 else if (uriScheme == L"tel")
866                 {
867                         eventType = WEB_EVENT_REQUEST_TEL;
868                 }
869                 else if (uriScheme == L"sms" || uriScheme == L"smsto" )
870                 {
871                         eventType = WEB_EVENT_REQUEST_SMS;
872                 }
873                 else if (uriScheme == L"mms" || uriScheme == L"mmsto" )
874                 {
875                         eventType = WEB_EVENT_REQUEST_MMS;
876                 }
877
878                 std::unique_ptr<_WebEventArg> pEventArg(new _WebEventArg(eventType, url));
879                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
880
881                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
882                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
883                 pEventArg.release();
884
885                 return;
886         }
887
888         ewk_policy_decision_use(pPolicy);
889 }
890
891
892 void
893 OnLoadingStarted(void* pUserData, Evas_Object* pView, void* pEventInfo)
894 {
895         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
896         SysAssertf(pImpl, "Failed to request");
897
898         if (pImpl->GetLoadingListener())
899         {
900                 result r = E_SUCCESS;
901
902                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_STARTED));
903                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
904
905                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
906                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
907                 pEventArg.release();
908         }
909 }
910
911
912 void
913 OnPageTitleReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
914 {
915         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
916         char* pTitle = reinterpret_cast< char* >(pEventInfo);
917         SysAssertf(pImpl, "Failed to request");
918
919         SysLog(NID_WEB_CTRL, "The current value of title is %s", pTitle);
920
921         if (pImpl->GetLoadingListener())
922         {
923                 result r = E_SUCCESS;
924
925                 std::unique_ptr<String> pPageTitle(new (std::nothrow) String(pTitle));
926                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED));
927                 SysTryReturnVoidResult(NID_WEB_CTRL, pPageTitle.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
928
929                 r = pEventArg->SetEventInfo(_LoadingEventArg::PAGE_TITLE, *pPageTitle.get());
930                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
931                 pPageTitle.release();
932
933                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
934                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
935                 pEventArg.release();
936         }
937 }
938
939
940 void
941 OnEstimatedProgress(void* pUserData, Evas_Object* pView, void* pEventInfo)
942 {
943         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
944         double* pProgress = reinterpret_cast< double* >(pEventInfo);
945         SysAssertf(pImpl, "Failed to request");
946
947         SysLog(NID_WEB_CTRL, "The current value of progress is %lf", *pProgress);
948
949         if (pImpl->GetLoadingListener())
950         {
951                 result r = E_SUCCESS;
952
953                 std::unique_ptr<Integer> pProgressPercentage(new (std::nothrow) Integer(static_cast< int >(*pProgress * 100)));
954                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_PROGRESS));
955                 SysTryReturnVoidResult(NID_WEB_CTRL, pProgressPercentage.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
956
957                 r = pEventArg->SetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS, *pProgressPercentage.get());
958                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
959                 pProgressPercentage.release();
960
961                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
962                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
963                 pEventArg.release();
964         }
965 }
966
967
968 void
969 OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
970 {
971         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
972         Ewk_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Policy_Decision* >(pEventInfo);
973         SysAssertf(pImpl && pPolicy, "Failed to request");
974
975         result r = E_SUCCESS;
976
977         const char* pUrl = ewk_policy_decision_url_get(pPolicy);
978         int code = ewk_policy_decision_response_status_code_get(pPolicy);
979         String mime(ewk_policy_decision_response_mime_get(pPolicy));
980         SysSecureLog(NID_WEB_CTRL, "url : %s, mime : %ls, code : %d", pUrl, mime.GetPointer(), code);
981
982         ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
983
984         String url(ewk_policy_decision_url_get(pPolicy));
985
986         
987         if (pLoadingListener && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy)))
988         {
989                 const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
990
991                 DecisionPolicy policy;
992                 HttpHeader httpHeader;
993
994                 if (code >= REDIRECTION_HEADER_GROUP && code < REDIRECTION_HEADER_GROUP + 100)
995                 {
996                         pImpl->SetRedirectRequested(true);
997                         mime = L"";
998                 }
999
1000                 eina_hash_foreach(pHeader, AddHttpHeaderData, &httpHeader);
1001                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1002
1003                 policy = pLoadingListener->OnWebDataReceived(mime, httpHeader);
1004                 pImpl->SetPolicyDecision(policy);
1005         }
1006
1007         switch (pImpl->GetPolicyDecision())
1008         {
1009         case WEB_DECISION_CONTINUE:
1010         {
1011                 String currentUrl(pImpl->GetUrl());
1012                 String redirectUrl(pImpl->GetRedirectUri(url, currentUrl, mime));
1013                 if (redirectUrl != L"")
1014                 {
1015                         pImpl->LoadUrl(redirectUrl);
1016                         ewk_policy_decision_ignore(pPolicy);
1017
1018                         return;
1019                 }
1020
1021                 if (pImpl->IsMimeSupported(mime) || mime == L"")
1022                 {
1023                         break;
1024                 }
1025                 
1026                 else
1027                 {
1028                         SysLog(NID_WEB_CTRL, "Launch native app to handle the mime");
1029
1030                         ewk_policy_decision_ignore(pPolicy);
1031
1032                         AppControl* pAppControl = null;
1033                         _SelectBox selectBox;
1034                         int appCount = 0;
1035                         int selectedIndex = 0;
1036
1037                         std::unique_ptr<IList, AllElementsDeleter> pList(_AppManagerImpl::FindAppControlsN(NULL, NULL, &mime, NULL));
1038
1039                         if (pList.get())
1040                         {
1041                                 appCount = pList->GetCount();
1042                         }
1043
1044                         r = selectBox.Construct(false, L"", appCount+1); //+1 for Downloader
1045                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1046
1047                         selectBox.AddListItem(L"Download", _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
1048                         for (int i = 0; i < appCount; i++)
1049                         {
1050                                 pAppControl = dynamic_cast< AppControl* >(pList->GetAt(i));
1051                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppControl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1052
1053                                 String text = pAppControl->GetAppName();
1054                                 SysLog(NID_WEB_CTRL, "AppName : %S", text.GetPointer());
1055
1056                                 selectBox.AddListItem(text, _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
1057                         }
1058                         r = selectBox.ShowAndWait(selectedIndex);
1059                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1060
1061                         if (selectedIndex == 0) //download
1062                         {
1063                                 RequestId reqId = 0;
1064                                 DownloadRequest request(pUrl);
1065
1066                                 _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
1067                                 SysTryReturnVoidResult(NID_WEB_CTRL, pManagerImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1068
1069                                 r = pManagerImpl->Start(request, reqId);
1070                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1071                         }
1072                         else if (selectedIndex != -1) // -1 for cancel
1073                         {
1074                                 String path("path");
1075                                 String pathVal(pUrl);
1076
1077                                 HashMap dataList;
1078                                 r = dataList.Construct();
1079                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1080
1081                                 r = dataList.Add(path, pathVal);
1082                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1083
1084                                 pAppControl = dynamic_cast< AppControl* >(pList->GetAt(selectedIndex));
1085                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppControl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1086
1087                                 _AppControlImpl* pAcImpl = _AppControlImpl::GetInstance(*pAppControl);
1088                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAcImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1089
1090                                 r = pAcImpl->Start(null, null, &dataList, null);
1091                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1092                         }
1093
1094                         return;
1095                 }
1096                 break;
1097         }
1098         case WEB_DECISION_DOWNLOAD:
1099         {
1100                 ewk_policy_decision_ignore(pPolicy);
1101
1102                 _WebDataHandler* pDownloadHandler = pImpl->GetDownloadHandler();
1103                 SysTryReturnVoidResult(NID_WEB_CTRL, pDownloadHandler, E_SYSTEM, "[%s] A system error has been occurred. Failed to get DownloadHandler.", GetErrorMessage(E_SYSTEM));
1104
1105                 Ewk_Context* pContext = ewk_view_context_get(pView);
1106                 SysAssertf(pContext, "Failed to get webkit instance.");
1107
1108                 pDownloadHandler->StartDownload(pUrl);
1109
1110                 return;
1111         }
1112         case WEB_DECISION_IGNORE:
1113         {
1114                 ewk_policy_decision_ignore(pPolicy);
1115
1116                 return;
1117         }
1118         default:
1119         {
1120                 SysAssert(false);
1121         }
1122         }
1123
1124         ewk_policy_decision_use(pPolicy);
1125
1126         return;
1127
1128 CATCH:
1129         ewk_policy_decision_ignore(pPolicy);
1130 }
1131
1132
1133 void
1134 OnProgressCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
1135 {
1136         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1137         SysAssertf(pImpl, "Failed to request");
1138
1139         if (pImpl->IsRedirectRequested())
1140         {
1141                 pImpl->SetRedirectRequested(false);
1142         }
1143
1144         if (pImpl->IsLoadingErrorOccurred())
1145         {
1146                 pImpl->SetLoadingErrorOccurred(false);
1147                 evas_object_smart_callback_call(pView, "load,finished", NULL);
1148         }
1149 }
1150
1151
1152 void
1153 OnLoadingErrorOccurred(void* pUserData, Evas_Object* pView, void* pEventInfo)
1154 {
1155         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1156         Ewk_Error* pErrorData = reinterpret_cast< Ewk_Error* >(pEventInfo);
1157         SysAssertf(pImpl && pErrorData, "Failed to request");
1158
1159         int code = ewk_error_code_get(pErrorData);
1160         const char* pDescription = ewk_error_description_get(pErrorData);
1161
1162         SysLog(NID_WEB_CTRL, "The current value of code is %d, description is %s", code, pDescription);
1163
1164         pImpl->SetLoadingErrorOccurred(true);
1165         switch (code)
1166         {
1167         case EWK_ERROR_CODE_FRAMELOADINTERRUPTEDBYPOLICYCHANGE:
1168                 //fall through
1169         case EWK_ERROR_CODE_PLUGINWILLHANDLELOAD:
1170                 break;
1171
1172         case EWK_ERROR_NETWORK_STATUS_CANCELLED:
1173                 evas_object_smart_callback_call(pView, "load,stop", NULL);
1174                 break;
1175
1176         default:
1177                 if (pImpl->GetLoadingListener())
1178                 {
1179                         result r = E_SUCCESS;
1180
1181                         r = FireLoadingErrorOccurredEvent(pImpl, code, pDescription);
1182                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1183                 }
1184                 break;
1185         }
1186 }
1187
1188
1189 void
1190 OnLoadingCanceled(void* pUserData, Evas_Object* pView, void* pEventInfo)
1191 {
1192         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1193         SysAssertf(pImpl, "Failed to request");
1194
1195         if (pImpl->GetLoadingListener())
1196         {
1197                 result r = E_SUCCESS;
1198
1199                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_CANCELED));
1200                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1201
1202                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1203                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1204                 pEventArg.release();
1205         }
1206
1207 }
1208
1209
1210 void
1211 OnLoadingCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
1212 {
1213         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1214         SysAssertf(pImpl, "Failed to request");
1215
1216         if (pImpl->GetLoadingListener())
1217         {
1218                 result r = E_SUCCESS;
1219
1220                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_COMPLETED));
1221                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1222
1223                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1224                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1225                 pEventArg.release();
1226         }
1227
1228 }
1229
1230
1231 void
1232 OnLoadingCommitted(void* pUserData, Evas_Object* pView, void* pEventInfo)
1233 {
1234         evas_object_focus_set(pView, EINA_FALSE);
1235 }
1236
1237
1238 void
1239 OnFaviconReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
1240 {
1241         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1242         SysAssertf(pImpl, "Failed to request");
1243
1244         if (pImpl->GetLoadingListener())
1245         {
1246                 result r = E_SUCCESS;
1247
1248                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_FAVICON_RECEIVED));
1249                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1250
1251                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1252                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1253                 pEventArg.release();
1254         }
1255
1256 }
1257
1258
1259 void
1260 OnDidStartDownloadCallback(const char* pUrl, void* pUserData)
1261 {
1262         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1263         SysAssertf(pUrl && pImpl != null, "Failed to request");
1264
1265         SysSecureLog(NID_WEB_CTRL, "The current value of url is %s", pUrl);
1266 }
1267
1268
1269 result
1270 FireWebPageShowRequestedEvent(_WebImpl* pImpl, int event)
1271 {
1272         result r = E_SUCCESS;
1273
1274         std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(event));
1275         SysTryReturnResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
1276
1277         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1278         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1279         pEventArg.release();
1280
1281         return E_SUCCESS;
1282 }
1283
1284
1285 void
1286 OnWebPageShowRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
1287 {
1288         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1289         SysAssertf(pImpl, "Failed to request");
1290
1291         if (pImpl->GetUiEventListener())
1292         {
1293                 result r = E_SUCCESS;
1294
1295                 r = FireWebPageShowRequestedEvent(pImpl, WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED);
1296                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1297         }
1298         if (pImpl->GetUiEventListenerF())
1299         {
1300                 result r = E_SUCCESS;
1301
1302                 r = FireWebPageShowRequestedEvent(pImpl, WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED_FLOAT);
1303                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1304         }
1305 }
1306
1307
1308 void
1309 OnWebWindowCreateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
1310 {
1311         _WebImpl* pParentImpl = reinterpret_cast< _WebImpl* >(pUserData);
1312         Evas_Object** pChildView = reinterpret_cast< Evas_Object** >(pEventInfo);
1313         SysAssertf(pParentImpl && pChildView, "Failed to request");
1314
1315         IWebUiEventListener* pUserUiListener = pParentImpl->GetUiEventListener();
1316         IWebUiEventListenerF* pUserUiListenerF = pParentImpl->GetUiEventListenerF();
1317         if (pUserUiListener)
1318         {
1319                 Web* pWeb = pUserUiListener->OnWebWindowCreateRequested();
1320                 if (pWeb)
1321                 {
1322                         _WebImpl* pChildImpl = _WebImpl::GetInstance(pWeb);
1323                         SysTryReturnVoidResult(NID_WEB_CTRL, pChildImpl, E_SYSTEM, "[%s] A system error has been occurred. Failed to get ChildImpl object.", GetErrorMessage(E_SYSTEM));
1324
1325                         *pChildView = dynamic_cast< _Web* >(&pChildImpl->GetCore())->GetWebNativeNode();
1326                         evas_object_data_set(*pChildView, PARENT_WEB_CTRL, pParentImpl);
1327                 }
1328         }
1329         if (pUserUiListenerF)
1330         {
1331                 Web* pWeb = pUserUiListenerF->OnWebWindowCreateRequested();
1332                 if (pWeb)
1333                 {
1334                         _WebImpl* pChildImpl = _WebImpl::GetInstance(pWeb);
1335                         SysTryReturnVoidResult(NID_WEB_CTRL, pChildImpl, E_SYSTEM, "[%s] A system error has been occurred. Failed to get ChildImpl object.", GetErrorMessage(E_SYSTEM));
1336
1337                         *pChildView = dynamic_cast< _Web* >(&pChildImpl->GetCore())->GetWebNativeNode();
1338                         evas_object_data_set(*pChildView, PARENT_WEB_CTRL, pParentImpl);
1339                 }
1340         }
1341 }
1342
1343
1344 result
1345 FireWebWindowClosedRequestedEvent(_WebImpl* pImpl, int event)
1346 {
1347         result r = E_SUCCESS;
1348
1349         std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(event));
1350         SysTryReturnResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
1351
1352         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1353         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1354         pEventArg.release();
1355
1356         return E_SUCCESS;
1357 }
1358
1359
1360 void
1361 OnWebWindowClosedRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
1362 {
1363         _WebImpl* pChildImpl = reinterpret_cast< _WebImpl* >(pUserData);
1364         SysAssertf(pChildImpl, "Failed to request");
1365
1366         _WebImpl* pParentImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, PARENT_WEB_CTRL));
1367         if (pParentImpl == null)
1368         {
1369                 return;
1370         }
1371
1372         if (pParentImpl->GetUiEventListener())
1373         {
1374                 result r = E_SUCCESS;
1375
1376                 r = FireWebWindowClosedRequestedEvent(pChildImpl, WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED);
1377                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1378         }
1379         if (pParentImpl->GetUiEventListenerF())
1380         {
1381                 result r = E_SUCCESS;
1382
1383                 r = FireWebWindowClosedRequestedEvent(pChildImpl, WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED_FLOAT);
1384                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1385         }
1386 }
1387
1388
1389 result
1390 FireWebPreventDefaultTriggeredEvent(_WebImpl* pImpl, int event, bool trigger)
1391 {
1392         result r = E_SUCCESS;
1393
1394         std::unique_ptr<Boolean> pPreventTrigger(new (std::nothrow) Boolean(trigger));
1395         std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(event));
1396         SysTryReturnResult(NID_WEB_CTRL, pPreventTrigger.get() && pEventArg.get(), E_OUT_OF_MEMORY, " Memory allocation failed." );
1397
1398         r = pEventArg->SetEventInfo(_WebUiEventArg::PREVENT_DEFAULT, *pPreventTrigger.get());
1399         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1400         pPreventTrigger.release();
1401
1402         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1403         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1404         pEventArg.release();
1405
1406         return E_SUCCESS;
1407 }
1408
1409
1410 void
1411 OnWebPreventDefaultTriggered(void* pUserData, Evas_Object* pView, void* pEventInfo)
1412 {
1413         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1414         Eina_Bool* pTrigger = reinterpret_cast< Eina_Bool* >(pEventInfo);
1415         SysAssertf(pImpl && pTrigger, "Failed to request");
1416
1417         if (pImpl->GetUiEventListener())
1418         {
1419                 result r = E_SUCCESS;
1420
1421                 r = FireWebPreventDefaultTriggeredEvent(pImpl, WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED, static_cast< bool >(*pTrigger));
1422                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1423         }
1424         if (pImpl->GetUiEventListenerF())
1425         {
1426                 result r = E_SUCCESS;
1427
1428                 r = FireWebPreventDefaultTriggeredEvent(pImpl, WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED_FLOAT, static_cast< bool >(*pTrigger));
1429                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1430         }
1431 }
1432
1433
1434 result
1435 FireWebPageBlockSelectedEvent(_WebImpl* pImpl)
1436 {
1437         result r = E_SUCCESS;
1438
1439         std::unique_ptr<Point> startPoint(new (std::nothrow) Point());
1440         std::unique_ptr<Point> endPoint(new (std::nothrow) Point());
1441         SysTryReturnResult(NID_WEB_CTRL, startPoint.get() && endPoint.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
1442
1443         pImpl->GetBlockRange(*startPoint.get(), *endPoint.get());
1444
1445         if ((endPoint->x != 0) && (endPoint->y != 0))
1446         {
1447                 std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED));
1448                 SysTryReturnResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
1449
1450                 r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_START, *startPoint.get());
1451                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1452                 startPoint.release();
1453
1454                 r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_END, *endPoint.get());
1455                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1456                 endPoint.release();
1457
1458                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1459                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1460                 pEventArg.release();
1461         }
1462
1463         return E_SUCCESS;
1464 }
1465
1466
1467 result
1468 FireWebPageBlockSelectedEventF(_WebImpl* pImpl)
1469 {
1470         result r = E_SUCCESS;
1471
1472         std::unique_ptr<FloatPoint> startPoint(new (std::nothrow) FloatPoint());
1473         std::unique_ptr<FloatPoint> endPoint(new (std::nothrow) FloatPoint());
1474
1475         SysTryReturnResult(NID_WEB_CTRL, startPoint.get() && endPoint.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
1476
1477         pImpl->GetBlockRange(*startPoint.get(), *endPoint.get());
1478
1479         if ((endPoint->x != 0.0f) && (endPoint->y != 0.0f))
1480         {
1481                 std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED_FLOAT));
1482                 SysTryReturnResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
1483
1484                 r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_START, *startPoint.get());
1485                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1486                 startPoint.release();
1487
1488                 r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_END, *endPoint.get());
1489                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1490                 endPoint.release();
1491
1492                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1493                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1494                 pEventArg.release();
1495         }
1496
1497         return E_SUCCESS;
1498 }
1499
1500
1501 void
1502 OnWebPageBlockSelected(void* pUserData, Evas_Object* pView, void* pEventInfo)
1503 {
1504         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1505         SysAssertf(pImpl, "Failed to request");
1506
1507         if (pImpl->GetUiEventListener())
1508         {
1509                 result r = E_SUCCESS;
1510
1511                 r = FireWebPageBlockSelectedEvent(pImpl);
1512                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1513         }
1514         if (pImpl->GetUiEventListenerF())
1515         {
1516                 result r = E_SUCCESS;
1517
1518                 r = FireWebPageBlockSelectedEventF(pImpl);
1519                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1520         }
1521 }
1522
1523
1524 void
1525 OnWebPageBlockSelectedByOrientation(void* pUserData, Evas_Object* pView, void* pEventInfo)
1526 {
1527         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1528         SysAssertf(pImpl, "Failed to request");
1529
1530         if (!pImpl->IsOrientationChanged())
1531         {
1532                 return;
1533         }
1534
1535         pImpl->SetOrientationChanged(false);
1536         OnWebPageBlockSelected(pUserData, pView, pEventInfo);
1537 }
1538
1539
1540 Eina_Bool
1541 OnSelectUploadFile(Evas_Object* pView, Eina_Bool multipleFile, Eina_List* pAcceptTypes, const char* pCapture, void* pUserData)
1542 {
1543         String isMultipleSelection(L"single");
1544         result r = E_SUCCESS;
1545
1546         HashMap dataList;
1547         String mode(L"selectionType");
1548         String type(L"type");
1549         _AppControlImpl* pMediaAppControlImpl = null;
1550
1551         int itemCount = 0;
1552         String fileType = L"all";
1553
1554         if (multipleFile)
1555         {
1556                 isMultipleSelection.Append(L"multiple");
1557         }
1558
1559         std::unique_ptr<AppControl> pMediaAppControl(_AppManagerImpl::FindAppControlN(L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick"));
1560         SysTryReturn(NID_WEB_CTRL, pMediaAppControl.get(), EINA_TRUE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1561
1562         std::unique_ptr<_MediaSelectionListener> pMediaListener(new (std::nothrow) _MediaSelectionListener());
1563         SysTryReturn(NID_WEB_CTRL, pMediaListener.get(), EINA_TRUE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1564
1565         pMediaListener->Construct(pView, pMediaAppControl.get());
1566
1567         itemCount = eina_list_count(pAcceptTypes);
1568
1569         if (itemCount == 1)
1570         {
1571                 String item((char*)eina_list_nth(pAcceptTypes, 0));
1572                 if (item.StartsWith("image/",0))
1573                 {
1574                         fileType = L"image";
1575                 }
1576                 else if (item.StartsWith("audio/",0))
1577                 {
1578                         fileType = L"audio";
1579                 }
1580                 else if (item.StartsWith("video/",0))
1581                 {
1582                         fileType = L"video";
1583                 }
1584         }
1585
1586         r = dataList.Construct();
1587         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1588
1589         r = dataList.Add(mode, isMultipleSelection);
1590         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1591
1592         r = dataList.Add(type, fileType);
1593         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1594
1595         pMediaAppControlImpl = _AppControlImpl::GetInstance(*pMediaAppControl.get());
1596         r = pMediaAppControlImpl->Start(null, null, &dataList, pMediaListener.get());
1597         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1598
1599         pMediaListener.release();
1600         pMediaAppControl.release();
1601
1602         return EINA_TRUE;
1603
1604 CATCH:
1605         ewk_view_open_panel_reply(pView, null, EINA_FALSE);
1606         return EINA_TRUE;
1607 }
1608
1609
1610 void
1611 OnHandleJavaScriptRequest(void* pUserData, Evas_Object* pView, void* pEventInfo)
1612 {
1613         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1614         char* pJsonText = reinterpret_cast< char* >(pEventInfo);
1615         SysAssertf(pImpl && pJsonText, "Failed to request");
1616
1617         result r = E_SUCCESS;
1618
1619         SysLog(NID_WEB_CTRL, "The current value of jsontext is %s", pJsonText);
1620
1621         std::unique_ptr<_JsBridgeArg> pEventArg(new (std::nothrow) _JsBridgeArg());
1622         SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1623
1624         r = pEventArg->Construct(pJsonText);
1625         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1626
1627         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1628         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1629         pEventArg.release();
1630 }
1631
1632
1633 void
1634 OnWebKeypadStateChanged(void* pUserData, Evas_Object* pView, void* pEventInfo)
1635 {
1636         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1637         Eina_Rectangle* pEinaRect = reinterpret_cast< Eina_Rectangle* >(pEventInfo);
1638         SysAssertf(pImpl && pEinaRect, "Failed to request");
1639
1640         if (pImpl->GetSetting().GetInputStyle() == INPUT_STYLE_OVERLAY)
1641         {
1642                 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1643                 SysAssertf(pXformer, "Failed to get CoordinateTransformer");
1644
1645                 Rectangle rect(pEinaRect->x, pEinaRect->y, pEinaRect->w, pEinaRect->h);
1646
1647                 if (rect.height == 0)
1648                 {
1649                         return;
1650                 }
1651
1652                 _Form* pFormCore = pImpl->GetParentFormCore(dynamic_cast< _Control* >(&pImpl->GetCore()));
1653                 if (pFormCore)
1654                 {
1655                         if (pFormCore->HasFooter() && pFormCore->IsFooterVisible())
1656                         {
1657                                 pImpl->SetFooterVisibleState(true);
1658                                 pFormCore->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
1659                         }
1660
1661                         pFormCore->DeflateClientRectHeight(pXformer->TransformVertical(rect.height));
1662                 }
1663
1664                 if (pImpl->GetWebKeypadEventListener())
1665                 {
1666                         if (pImpl->IsKeypadVisible() == true)
1667                         {
1668                                 if ((pImpl->GetPreviousKeypadBounds().width == rect.width) && (pImpl->GetPreviousKeypadBounds().height != rect.height))
1669                                 {
1670                                         pImpl->GetWebKeypadEventListener()->OnWebKeypadBoundsChanged(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1671                                 }
1672                         }
1673                         else
1674                         {
1675                                 pImpl->GetWebKeypadEventListener()->OnWebKeypadWillOpen(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1676                         }
1677                 }
1678                 pImpl->SetKeypadVisibleState(true);
1679                 pImpl->SetPreviousKeypadBounds(rect);
1680         }
1681         else
1682         {
1683                 result r = pImpl->SetFullScreenKeypad();
1684                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1685         }
1686 }
1687
1688
1689 void
1690 OnWebKeypadOpened(void* pUserData, Evas_Object* pView, void* pEventInfo)
1691 {
1692         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1693         SysAssertf(pImpl, "Failed to request");
1694
1695         if (pImpl->GetWebKeypadEventListener())
1696         {
1697                 pImpl->GetWebKeypadEventListener()->OnWebKeypadOpened(*static_cast< Web* >(&pImpl->GetPublic()));
1698         }
1699 }
1700
1701
1702 void
1703 OnWebKeypadClosed(void* pUserData, Evas_Object* pView, void* pEventInfo)
1704 {
1705         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1706         SysAssertf(pImpl, "Failed to request");
1707
1708         _Form* pFormCore = pImpl->GetParentFormCore(dynamic_cast< _Control* >(&pImpl->GetCore()));
1709         if (pFormCore)
1710         {
1711                 if (pFormCore->HasFooter() && pImpl->IsFooterVisible())
1712                 {
1713                         pImpl->SetFooterVisibleState(false);
1714                         pFormCore->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1715                 }
1716
1717                 pFormCore->DeflateClientRectHeight(0);
1718         }
1719
1720         if (pImpl->GetWebKeypadEventListener())
1721         {
1722                 pImpl->GetWebKeypadEventListener()->OnWebKeypadClosed(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1723         }
1724
1725         pImpl->SetKeypadVisibleState(false);
1726 }
1727
1728
1729 void
1730 OnWindowObjectFocusGained(void *pUserData, Evas_Object *pWin, void *pEvent_info)
1731 {
1732         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1733         SysAssertf(pImpl, "Failed to request");
1734
1735         if (pImpl->IsKeypadOpened() == true)
1736         {
1737                 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
1738                 SysAssertf(pWebCore, "Failed to get Web core object");
1739
1740                 evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
1741
1742                 pImpl->SetKeypadOpened(false);
1743         }
1744 }
1745
1746
1747 void
1748 OnWebNativeNodeFocusGained(void *pUserData, Evas *pCanvas, Evas_Object* pView, void* pEventInfo)
1749 {
1750         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1751         SysAssertf(pImpl, "Failed to request");
1752
1753         if (pImpl->IsKeypadOpened() == true)
1754         {
1755                 pImpl->SetKeypadOpened(false);
1756         }
1757
1758
1759
1760 Eina_Bool
1761 OnColorPickerProviderRequested(Ewk_View_Smart_Data *pSmartData, int red, int green, int blue, int alpha)
1762 {
1763         SysAssertf(pSmartData, "invalid smartdata");
1764         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1765         SysAssertf(pWebImpl, "Failed to get Impl");
1766
1767         result r = E_SUCCESS;
1768
1769         if (pWebImpl->GetColorpicker())
1770         {
1771                 return EINA_FALSE;
1772         }
1773
1774         Color color;
1775
1776         r = pWebImpl->ShowColorPicker(red, green, blue, alpha, color);
1777         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1778
1779         byte r1, g1, b1, a1;
1780         color.GetColorComponents(r1, g1, b1, a1);
1781         ewk_view_color_picker_color_set(pSmartData->self, r1, g1, b1, a1);
1782
1783         return EINA_TRUE;
1784 }
1785
1786
1787 Eina_Bool
1788 OnColorPickerProviderDismissed(Ewk_View_Smart_Data *pSmartData)
1789 {
1790         SysAssertf(pSmartData, "invalid smartdata");
1791
1792         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1793         SysAssertf(pWebImpl, "Failed to get Impl");
1794
1795         return pWebImpl->HideColorPicker();
1796 }
1797
1798
1799 Eina_Bool
1800 OnDatePickerProviderRequested(Ewk_View_Smart_Data *pSmartData, Ewk_Input_Type inputType, const char* inputValue)
1801 {
1802         SysAssertf(pSmartData, "Failed to request");
1803         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1804         SysAssertf(pWebImpl, "Failed to get Impl");
1805
1806         result r = E_SUCCESS;
1807
1808         if (pWebImpl->GetDatepicker())
1809         {
1810                 ewk_view_focused_input_element_value_set(pSmartData->self, inputValue);
1811
1812                 return EINA_FALSE;
1813         }
1814
1815         String dateStr;
1816
1817         r = pWebImpl->ShowDatePicker(inputType, inputValue, dateStr);
1818         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1819
1820         std::unique_ptr<char[]> pDateStr(_StringConverter::CopyToCharArrayN(dateStr));
1821         SysTryReturn(NID_WEB_CTRL, pDateStr.get(), EINA_FALSE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1822
1823         ewk_view_focused_input_element_value_set(pSmartData->self, pDateStr.get());
1824
1825         return EINA_TRUE;
1826 }
1827
1828
1829 Eina_Bool
1830 OnSelectBoxRequested(Ewk_View_Smart_Data *pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, double pageScaleFactor, Eina_List* pItems, int selectedIndex)
1831 {
1832         SysAssertf(pSmartData, "Failed to request");
1833
1834         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1835         SysAssertf(pWebImpl, "Failed to get Impl");
1836
1837         result r = pWebImpl->ShowSelectBoxPopup(false, L"", pItems, pSmartData->self, selectedIndex);
1838         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1839
1840         return EINA_TRUE;
1841 }
1842
1843
1844 Eina_Bool
1845 OnSelectBoxClosed(Ewk_View_Smart_Data *pSmartData)
1846 {
1847         SysAssertf(pSmartData, "invalid smartdata");
1848
1849         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1850         SysAssertf(pWebImpl, "Failed to get Impl");
1851
1852         result r = pWebImpl->ClearSelectBoxPopup();
1853         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1854
1855         return EINA_TRUE;
1856 }
1857
1858
1859 Eina_Bool
1860 OnSelectBoxUpdateRequested(Ewk_View_Smart_Data *pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, Eina_List* pItems, int selectedIndex)
1861 {
1862         SysAssertf(pSmartData, "invalid smartdata");
1863
1864         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1865         SysAssertf(pWebImpl, "Failed to get Impl");
1866
1867         result r = pWebImpl->UpdateSelectBoxPopup(pItems, selectedIndex, false);
1868         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1869
1870         return EINA_TRUE;
1871 }
1872
1873
1874 void
1875 OnCookiesPolicyGot(Ewk_Cookie_Accept_Policy policy, Ewk_Web_Error *pError, void *pUserData)
1876 {
1877         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
1878         SysAssertf(pPresenter && !pError, "Failed to request");
1879
1880         bool ret = EINA_TRUE;
1881
1882         switch (policy)
1883         {
1884         case EWK_COOKIE_ACCEPT_POLICY_ALWAYS:
1885                 //fall through
1886         case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY:
1887                 ret = EINA_TRUE;
1888                 break;
1889
1890         case EWK_COOKIE_ACCEPT_POLICY_NEVER:
1891                 //fall through
1892                 ret = EINA_FALSE;
1893                 break;
1894
1895         default:
1896                 SysAssert(false);
1897         }
1898
1899         SysLog(NID_WEB_CTRL, "The current value of policy is %d", ret);
1900
1901         pPresenter->EndAsyncProcess(ret);
1902 }
1903
1904
1905 void
1906 OnScriptExecuted(Evas_Object* pView, const char* pResult, void* pUserData)
1907 {
1908         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
1909         SysAssertf(pPresenter, "Failed to request");
1910
1911         String result(pResult);
1912         SysLog(NID_WEB_CTRL, "result : %ls", result.GetPointer());
1913
1914         pPresenter->EndAsyncProcess(result);
1915 }
1916
1917
1918 void
1919 OnTextFound(void* pUserData, Evas_Object* pView, void* pEventInfo)
1920 {
1921         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1922         SysAssertf(pImpl, "Failed to request");
1923
1924         int* pTotalCount = reinterpret_cast< int* >(pEventInfo);
1925         SysLog(NID_WEB_CTRL, "The current value of totalCount is %d", *pTotalCount);
1926
1927         _WebPresenter* pWebPresenter = pImpl->GetSearchPresenter();
1928
1929         if (pWebPresenter)
1930         {
1931                 pWebPresenter->EndAsyncProcess(*pTotalCount);
1932         }
1933         else
1934         {
1935                 if (pImpl->GetTextSearchListener())
1936                 {
1937                         result r = E_SUCCESS;
1938
1939                         int ordinal = 0;
1940
1941                         if (*pTotalCount > 0)
1942                         {
1943                                 ordinal = pImpl->GetAsyncSearchOrdinal();
1944                                 pImpl->SetAsyncSearchResult(*pTotalCount);
1945                         }
1946
1947                         if (pImpl->GetPendingAsyncSearchCount() > 0)
1948                         {
1949                                 return;
1950                         }
1951
1952                         std::unique_ptr<Integer> pCount(new (std::nothrow) Integer(*pTotalCount));
1953                         std::unique_ptr<Integer> pOrdinal(new (std::nothrow) Integer(ordinal));
1954                         std::unique_ptr<_TextSearchEventArg> pEventArg(new (std::nothrow) _TextSearchEventArg(WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND));
1955                         SysTryReturnVoidResult(NID_WEB_CTRL, pCount.get() && pOrdinal.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1956
1957                         r = pEventArg->SetEventInfo(_TextSearchEventArg::TOTAL_COUNT, *pCount.get());
1958                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1959                         pCount.release();
1960
1961                         r = pEventArg->SetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL, *pOrdinal.get());
1962                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1963                         pOrdinal.release();
1964
1965                         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1966                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1967                         pEventArg.release();
1968                 }
1969         }
1970 }
1971
1972
1973 class _JsBridgeHashCodeProvider
1974         : public Tizen::Base::Collection::IHashCodeProviderT< Tizen::Base::String >
1975 {
1976 public:
1977         _JsBridgeHashCodeProvider(){}
1978         virtual ~_JsBridgeHashCodeProvider(void) {}
1979
1980
1981         int GetHashCode(const Tizen::Base::String& obj) const
1982         {
1983                 return obj.GetHashCode();
1984         }
1985
1986 };
1987
1988
1989 //Comparer implementation
1990 class _JsBridgeComparer
1991         : public Tizen::Base::Collection::IComparerT< Tizen::Base::String >
1992 {
1993 public:
1994         _JsBridgeComparer(){}
1995         virtual ~_JsBridgeComparer(void) {}
1996
1997
1998         result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
1999         {
2000                 if (obj1 == obj2)
2001                 {
2002                         cmp = 0;
2003                 }
2004                 else
2005                 {
2006                         cmp = 1;
2007                 }
2008
2009                 return E_SUCCESS;
2010         }
2011
2012 };
2013
2014
2015 _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
2016         : _ContainerImpl(pWeb, pCore)
2017         , __isFooterVisible(false)
2018         , __isKeypadVisible(false)
2019         , __isKeypadOpened(false)
2020         , __isLoadingErrorOccurred(false)
2021         , __isRedirectRequested(false)
2022         , __isCertificateRequested(false)
2023         , __isCertificateConfirmed(false)
2024         , __isOrientationChanged(false)
2025         , __keypadBounds(0, 0, 0, 0)
2026         , __pWebCore(null)
2027         , __pUserLoadingListener(null)
2028         , __pUserUiListener(null)
2029         , __pUserUiListenerF(null)
2030         , __pUserKeypadEventListener(null)
2031         , __pTextSearchListener(null)
2032         , __pKeypad(null)
2033         , __pJsBridgeList(null)
2034         , __pJsProvider(null)
2035         , __pJsComparer(null)
2036         , __pWebDownloadHandler(null)
2037         , __pWebEvent(null)
2038         , __pAuthChallenge(null)
2039         , __pAuthPopup(null)
2040         , __pUserConfirmPopup(null)
2041         , __pCertConfirmPopup(null)
2042         , __pSelectBox(null)
2043         , __pDatePicker(null)
2044         , __pColorPicker(null)
2045         , __pVibrator(null)
2046         , __policy(WEB_DECISION_CONTINUE)
2047         , __defaultUserAgent(L"");
2048 {
2049         __textSearch.__searchAll = false;
2050         __textSearch.__searchForward = true;
2051         __textSearch.__caseSensitive = false;
2052         __textSearch.__pending = 0;
2053         __textSearch.__currentIndex = 1;
2054         __textSearch.__totalCount = -1;
2055         __textSearch.__text = L"";
2056 }
2057
2058
2059 _WebImpl::~_WebImpl()
2060 {
2061         RemoveEventListenerCallback();
2062 }
2063
2064 _WebImpl*
2065 _WebImpl::CreateWebImplN(Web* pControl, const Rectangle& bounds)
2066 {
2067         result r = E_SUCCESS;
2068
2069         r = GET_SIZE_INFO(Web).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
2070         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2071
2072         _Web* pCore = _Web::CreateWebN();
2073         SysTryReturn(NID_WEB_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2074
2075         _WebImpl* pImpl = new (std::nothrow) _WebImpl(pControl, pCore);
2076
2077         r = CheckConstruction(pCore, pImpl);
2078         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2079
2080         r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Web), bounds, pCore->GetOrientation());
2081         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2082
2083         r = pImpl->Construct();
2084         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2085
2086         return pImpl;
2087
2088 CATCH:
2089         delete pImpl;
2090
2091         return null;
2092 }
2093
2094
2095 _WebImpl*
2096 _WebImpl::CreateWebImplN(Web* pControl, const FloatRectangle& bounds)
2097 {
2098         result r = E_SUCCESS;
2099
2100         r = GET_SIZE_INFO(Web).CheckInitialSizeValidF(FloatDimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
2101         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2102
2103         _Web* pCore = _Web::CreateWebN();
2104         SysTryReturn(NID_WEB_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2105
2106         _WebImpl* pImpl = new (std::nothrow) _WebImpl(pControl, pCore);
2107
2108         r = CheckConstruction(pCore, pImpl);
2109         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2110
2111         r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Web), bounds, pCore->GetOrientation());
2112         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2113
2114         r = pImpl->Construct();
2115         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2116
2117         return pImpl;
2118
2119 CATCH:
2120         delete pImpl;
2121
2122         return null;
2123 }
2124
2125
2126 result
2127 _WebImpl::Construct(void)
2128 {
2129         result r = E_SUCCESS;
2130
2131         r = __mutex.Create();
2132         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2133
2134         r = __textSearch.__searchQueue.Construct();
2135         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2136
2137         r = InitJsBridgeList();
2138         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2139
2140         r = InitWebEvent();
2141         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2142
2143         __pWebCore = dynamic_cast< _Web* >(&(GetCore()));
2144         SysTryReturnResult(NID_WEB_CTRL, __pWebCore, E_SYSTEM, "A system error has been occurred. Failed to get web control");
2145
2146         return E_SUCCESS;
2147 }
2148
2149
2150 result
2151 _WebImpl::InitializeSetting(void)
2152 {
2153         result r = E_SUCCESS;
2154
2155         WebSetting* pWebSetting = __pWebCore->GetSetting();
2156         _WebSettingImpl* pWebSettingImpl = _WebSettingImpl::GetInstance(pWebSetting);
2157
2158         SetCookieEnabled(pWebSettingImpl->IsCookieEnabled());
2159         SetPrivateBrowsingEnabled(pWebSettingImpl->IsPrivateBrowsingEnabled());
2160         SetZoomLevel(pWebSettingImpl->GetZoomLevel());
2161
2162         __defaultUserAgent = pWebSettingImpl->GetUserAgent();
2163
2164         r = SetSetting(*pWebSetting);
2165         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2166
2167         SetEventListenerCallback();
2168
2169         return E_SUCCESS;
2170 }
2171
2172
2173 bool
2174 _WebImpl::IsLayoutable(void) const
2175 {
2176         return true;
2177 }
2178
2179
2180 result
2181 _WebImpl::InitWebEvent(void)
2182 {
2183         __pWebEvent = std::unique_ptr<_WebEvent>(new (std::nothrow) _WebEvent());
2184         SysTryReturnResult(NID_WEB_CTRL, __pWebEvent.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
2185
2186         return __pWebEvent->Construct(*this);
2187 }
2188
2189
2190 _WebEvent*
2191 _WebImpl::GetWebEvent(void) const
2192 {
2193         return __pWebEvent.get();
2194 }
2195
2196
2197 Eina_Hash*
2198 _WebImpl::ConvertToSlpHeaderN(const HttpHeader& header) const
2199 {
2200         Eina_Hash* pHttpHeader = null;
2201
2202         std::unique_ptr<IList> pFieldNameList(header.GetFieldNamesN());
2203         if (pFieldNameList.get())
2204         {
2205                 pHttpHeader = eina_hash_string_small_new(FreeCharArray);
2206                 SysTryReturn(NID_WEB_CTRL, pHttpHeader, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2207                 
2208                 int count = pFieldNameList->GetCount();
2209
2210                 for (int i = 0; i < count; i++)
2211                 {
2212                         String* pFieldName = dynamic_cast< String* >(pFieldNameList->GetAt(i));
2213                         SysTryCatch(NID_WEB_CTRL, pFieldName, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2214
2215                         std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(*pFieldName));
2216                         SysTryCatch(NID_WEB_CTRL, pKey.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2217
2218                         std::unique_ptr<IEnumerator> pFieldValueEnum(header.GetFieldValuesN(*pFieldName));
2219                         SysTryCatch(NID_WEB_CTRL, pFieldValueEnum.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2220                         
2221                         while (pFieldValueEnum->MoveNext() == E_SUCCESS)
2222                         {
2223                                 Eina_Bool ret = false;
2224
2225                                 String* pFieldValue = dynamic_cast< String* >(pFieldValueEnum->GetCurrent());
2226                                 SysTryCatch(NID_WEB_CTRL, pFieldValue, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2227
2228                                 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pFieldValue));
2229                                 SysTryCatch(NID_WEB_CTRL, pValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2230
2231                                 ret = eina_hash_add(pHttpHeader, pKey.get(), pValue.release());
2232                                 SysTryCatch(NID_WEB_CTRL, ret == EINA_TRUE, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2233                         }
2234                 }
2235         }
2236         return pHttpHeader;
2237
2238 CATCH:
2239         eina_hash_free(pHttpHeader);
2240
2241         return null;
2242 }
2243
2244
2245 result
2246 _WebImpl::LoadUrl(const String& url) const
2247 {
2248         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2249         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2250
2251         ewk_view_url_set(__pWebCore->GetWebNativeNode(), pUrl.get());
2252
2253         return E_SUCCESS;
2254 }
2255
2256
2257 result 
2258 _WebImpl::LoadUrl(const String& url, const HttpHeader& header)
2259 {
2260         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2261         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2262         
2263         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
2264
2265         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_GET, pHttpHeader, null);
2266
2267         eina_hash_free(pHttpHeader);
2268
2269         return E_SUCCESS;
2270 }
2271
2272
2273 result
2274 _WebImpl::LoadUrlWithPostRequest(const String& url, const HttpHeader& header, const ByteBuffer& body) const
2275 {
2276         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2277         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2278
2279         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
2280
2281         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_POST, pHttpHeader, reinterpret_cast< const char* >(body.GetPointer()));
2282
2283         eina_hash_free(pHttpHeader);
2284
2285         return E_SUCCESS;
2286 }
2287
2288
2289 result
2290 _WebImpl::LoadData(const String& baseUrl, const ByteBuffer& content, const String& mime, const String& encoding) const
2291 {
2292         SysTryReturnResult(NID_WEB_CTRL, content.GetLimit() > 0, E_INVALID_ARG, "The content buffer is empty.");
2293
2294         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(baseUrl));
2295         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
2296         std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(encoding));
2297         SysTryReturn(NID_WEB_CTRL, pUrl.get() && pMime.get() && pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2298
2299         ewk_view_contents_set(__pWebCore->GetWebNativeNode(), reinterpret_cast< const char* >(content.GetPointer()), content.GetLimit(), pMime.get(), pEncoding.get(), pUrl.get());
2300
2301         return E_SUCCESS;
2302 }
2303
2304
2305 void
2306 _WebImpl::Pause(void)
2307 {
2308         ewk_view_suspend(__pWebCore->GetWebNativeNode());
2309 }
2310
2311
2312 void
2313 _WebImpl::Resume(void)
2314 {
2315         ewk_view_resume(__pWebCore->GetWebNativeNode());
2316 }
2317
2318
2319 result
2320 _WebImpl::ShowSelectBoxPopup(bool isMultiSelect, const String& title, Eina_List* pItems, Evas_Object* pWebView, int selectedIndex)
2321 {
2322         __pSelectBox.reset();
2323
2324         SysTryReturnResult(NID_WEB_CTRL, eina_list_count(pItems) > 0, E_SYSTEM, "ItemCount is invalid.");
2325
2326         result r = E_SUCCESS;
2327
2328         std::unique_ptr<_SelectBox> pSelectBox(new (std::nothrow) _SelectBox());
2329         SysTryReturnResult(NID_WEB_CTRL, pSelectBox.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
2330
2331         r = pSelectBox->Construct(isMultiSelect, title, DEFAULT_LIST_ITEM_COUNT, pWebView);
2332         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2333
2334         r = pSelectBox->UpdateList(pItems, selectedIndex, false, false);
2335         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2336
2337         __pSelectBox = std::move(pSelectBox);
2338
2339         __pSelectBox->SetOwner(&GetPublic());
2340
2341         return __pSelectBox->ShowPopup();
2342 }
2343
2344
2345 result
2346 _WebImpl::UpdateSelectBoxPopup(Eina_List* pItems, int selectedIndex, bool isGroupedList)
2347 {
2348         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2349
2350         return __pSelectBox->UpdateList(pItems, selectedIndex, true, isGroupedList);
2351 }
2352
2353
2354 result
2355 _WebImpl::ClearSelectBoxPopup(void)
2356 {
2357         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2358
2359         __pSelectBox.reset();
2360
2361         return E_SUCCESS;
2362 }
2363
2364
2365 _InputPickerPopup*
2366 _WebImpl::GetDatepicker(void)
2367 {
2368         _InputPickerPopup* pInputPicker =null;
2369         if (__pDatePicker)
2370         {
2371                 pInputPicker =  __pDatePicker.get();
2372         }
2373         return pInputPicker;
2374 }
2375
2376
2377 _InputPickerPopup*
2378 _WebImpl::GetColorpicker(void)
2379 {
2380         _InputPickerPopup* pInputPicker =null;
2381         if (__pColorPicker)
2382         {
2383                 pInputPicker =  __pColorPicker.get();
2384         }
2385         return pInputPicker;
2386 }
2387
2388
2389 bool
2390 _WebImpl::CanGoBack(void) const
2391 {
2392         return static_cast< bool >(ewk_view_back_possible(__pWebCore->GetWebNativeNode()));
2393 }
2394
2395
2396 bool
2397 _WebImpl::CanGoForward(void) const
2398 {
2399         return static_cast< bool >(ewk_view_forward_possible(__pWebCore->GetWebNativeNode()));
2400 }
2401
2402
2403 void
2404 _WebImpl::GoBack(void) const
2405 {
2406         ewk_view_back(__pWebCore->GetWebNativeNode());
2407 }
2408
2409
2410 void
2411 _WebImpl::GoForward(void) const
2412 {
2413         ewk_view_forward(__pWebCore->GetWebNativeNode());
2414 }
2415
2416
2417 Tizen::Base::String
2418 _WebImpl::GetUrl(void) const
2419 {
2420         return ewk_view_url_get(__pWebCore->GetWebNativeNode());
2421 }
2422
2423
2424 Tizen::Base::String
2425 _WebImpl::GetTitle(void) const
2426 {
2427         return ewk_view_title_get(__pWebCore->GetWebNativeNode());
2428 }
2429
2430
2431 void
2432 _WebImpl::StopLoading(void) const
2433 {
2434         ewk_view_stop(__pWebCore->GetWebNativeNode());
2435 }
2436
2437
2438 void
2439 _WebImpl::Reload(void) const
2440 {
2441         ewk_view_reload_bypass_cache(__pWebCore->GetWebNativeNode());
2442 }
2443
2444
2445 String*
2446 _WebImpl::EvaluateJavascriptN(const String& scriptCode) const
2447 {
2448         if (scriptCode.GetLength())
2449         {
2450                 std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
2451                 SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2452
2453                 std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter());
2454                 SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2455                 pPresenter->InitAsyncProcess();
2456
2457                 ewk_view_script_execute(__pWebCore->GetWebNativeNode(), pScript.get(), OnScriptExecuted, pPresenter.get());
2458
2459                 std::unique_ptr<String> pResult(new (std::nothrow) String(L""));
2460                 SysTryReturn(NID_WEB_CTRL, pResult.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2461                 pPresenter->WaitAsyncProcess(*pResult.get());
2462
2463                 return pResult.release();
2464         }
2465
2466         return null;
2467 }
2468
2469
2470 result
2471 _WebImpl::SetZoomLevel(float level)
2472 {
2473         SysTryReturnResult(NID_WEB_CTRL, level >= MIN_ZOOM_LEVEL && level <= MAX_ZOOM_LEVEL, E_OUT_OF_RANGE, "The level(%f) must be between 0.3 and 2.0(%f).", level, level);
2474
2475         ewk_view_scale_set(__pWebCore->GetWebNativeNode(), static_cast< double >(level), 0, 0);
2476
2477         return E_SUCCESS;
2478 }
2479
2480
2481 float
2482 _WebImpl::GetZoomLevel(void) const
2483 {
2484         return static_cast< float >(ewk_view_scale_get(__pWebCore->GetWebNativeNode()));
2485 }
2486
2487
2488 const PageNavigationList*
2489 _WebImpl::GetBackForwardListN(void) const
2490 {
2491         result r = E_SUCCESS;
2492
2493         _PageNavigationListImpl* pNavigationListImpl = null;
2494         _HistoryItemImpl* pHistoryItemImpl = null;
2495
2496         std::unique_ptr<PageNavigationList> pNavigationList;
2497         std::unique_ptr<ArrayList, AllElementsDeleter> pHistoryList;
2498
2499         int backCount = 0;
2500         int forwardCount = 0;
2501
2502         String url(L"");
2503         String title(L"");
2504
2505         Ewk_History* pEwkHistoryList = ewk_view_history_get(__pWebCore->GetWebNativeNode());
2506         SysTryReturn(NID_WEB_CTRL, pEwkHistoryList, null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get full history.", GetErrorMessage(E_SYSTEM));
2507
2508         Ewk_History_Item* pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, 0);
2509         SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_DATA_NOT_FOUND, "[%s] There is no history.", GetErrorMessage(E_DATA_NOT_FOUND));
2510
2511         pNavigationList = std::unique_ptr<PageNavigationList>(new (std::nothrow) PageNavigationList());
2512         SysTryCatch(NID_WEB_CTRL, pNavigationList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2513
2514         pNavigationListImpl = _PageNavigationListImpl::GetInstance(pNavigationList.get());
2515         SysTryCatch(NID_WEB_CTRL, pNavigationListImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2516
2517         pHistoryList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
2518         SysTryCatch(NID_WEB_CTRL, pHistoryList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2519
2520         r = pHistoryList->Construct();
2521         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2522
2523         backCount = ewk_history_back_list_length_get(pEwkHistoryList);
2524         forwardCount = ewk_history_forward_list_length_get(pEwkHistoryList);
2525         SysLog(NID_WEB_CTRL, "The current value of backCount is %d, forwardCount is %d", backCount, forwardCount);
2526
2527         for (int i = -backCount; i < forwardCount + 1; i++)
2528         {
2529                 std::unique_ptr<HistoryItem> pHistoryItem(new (std::nothrow) HistoryItem());
2530                 SysTryCatch(NID_WEB_CTRL, pHistoryItem.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2531
2532                 pHistoryItemImpl = _HistoryItemImpl::GetInstance(pHistoryItem.get());
2533                 SysTryCatch(NID_WEB_CTRL, pHistoryItemImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2534
2535                 pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, i);
2536                 SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2537
2538                 url = ewk_history_item_uri_get(pEwkItem);
2539                 title = ewk_history_item_title_get(pEwkItem);
2540                 SysSecureLog(NID_WEB_CTRL, "The current value of url is %s, title is %s", url.GetPointer(), title.GetPointer());
2541
2542                 pHistoryItemImpl->SetHistoryItem(url, title);
2543
2544                 r = pHistoryList->Add(*pHistoryItem.get());
2545                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2546                 pHistoryItem.release();
2547         }
2548
2549         pNavigationListImpl->SetPageNavigationList(pHistoryList.release(), backCount);
2550
2551         ewk_history_free(pEwkHistoryList);
2552
2553         return pNavigationList.release();
2554
2555 CATCH:
2556         ewk_history_free(pEwkHistoryList);
2557
2558         return null;
2559 }
2560
2561
2562 bool
2563 _WebImpl::SearchText(const String& text, bool searchForward)
2564 {
2565         result r = E_SUCCESS;
2566
2567         Ewk_Find_Options condition = static_cast< Ewk_Find_Options >(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2568
2569         if (!searchForward)
2570         {
2571             condition = static_cast < Ewk_Find_Options >(condition | EWK_FIND_OPTIONS_BACKWARDS);
2572         }
2573
2574         _WebPresenter presenter;
2575         presenter.InitAsyncProcess();
2576
2577         r = SynchronizeSearch(SEARCH_SYNC, __pWebCore->GetWebNativeNode(), condition, text, searchForward, false, &presenter);
2578         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2579
2580         int result = 0;
2581         presenter.WaitAsyncProcess(result);
2582
2583         return static_cast < bool >(result);
2584 }
2585
2586
2587 result
2588 _WebImpl::SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive)
2589 {
2590         result r = E_SUCCESS;
2591
2592         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2593
2594         if (!caseSensitive)
2595         {
2596             condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2597         }
2598
2599         r = SynchronizeSearch(SEARCH_ALL_ASYNC, __pWebCore->GetWebNativeNode(), condition, text, true, caseSensitive);
2600         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2601
2602         return E_SUCCESS;
2603 }
2604
2605
2606 result
2607 _WebImpl::SearchNextAsync(bool searchForward)
2608 {
2609         SysTryReturnResult(NID_WEB_CTRL, __textSearch.__searchAll && __textSearch.__totalCount > -1, E_INVALID_OPERATION, "The SearchTextAllAsync() method is not called or completed.");
2610         SysTryReturnResult(NID_WEB_CTRL, (searchForward && __textSearch.__currentIndex < __textSearch.__totalCount) || (!searchForward && __textSearch.__currentIndex > 1)
2611                 , E_OBJ_NOT_FOUND,  "The Next instance is not available.");
2612
2613         result r = E_SUCCESS;
2614
2615         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2616
2617         if (__textSearch.__caseSensitive)
2618         {
2619                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2620         }
2621
2622         if (!searchForward)
2623         {
2624                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_BACKWARDS);
2625         }
2626
2627         r = SynchronizeSearch(SEARCH_NEXT_ASYNC, __pWebCore->GetWebNativeNode(), condition, __textSearch.__text, searchForward);
2628         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2629
2630         return E_SUCCESS;
2631 }
2632
2633
2634 result
2635 _WebImpl::SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Options condition, const Tizen::Base::String& text, bool searchForward, bool caseSensitive,  _WebPresenter* pWebPresenter)
2636 {
2637         MutexGuard lock(__mutex);
2638
2639         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(text));
2640         SysTryReturn(NID_WEB_CTRL, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2641
2642         switch (type)
2643         {
2644         case SEARCH_SYNC:
2645                 if (__textSearch.__searchAll)
2646                 {
2647                         DisableAsyncSearch();
2648
2649                         __textSearch.__searchQueue.Enqueue(this);
2650                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2651
2652                         ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2653                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2654                 }
2655                 else
2656                 {
2657                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2658
2659                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2660                 }
2661                 break;
2662
2663         case SEARCH_ALL_ASYNC:
2664                 __textSearch.__searchAll = true;
2665                 __textSearch.__text = text;
2666                 __textSearch.__searchForward = true;
2667                 __textSearch.__caseSensitive = caseSensitive;
2668                 __textSearch.__totalCount = -1;
2669                 __textSearch.__currentIndex = 1;
2670
2671                 __textSearch.__searchQueue.Enqueue(this);
2672                 __textSearch.__searchQueue.Enqueue(this);
2673
2674                 ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2675                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2676                 break;
2677
2678         case SEARCH_NEXT_ASYNC:
2679                 __textSearch.__searchForward = searchForward;
2680
2681                 CalculateAsyncSearchOrdinal();
2682
2683                 __textSearch.__searchQueue.Enqueue(this);
2684
2685                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2686                 break;
2687
2688         default:
2689                 SysAssert(false);
2690         }
2691
2692         return E_SUCCESS;
2693 }
2694
2695
2696 void
2697 _WebImpl::SetAsyncSearchResult(int totalCount)
2698 {
2699         __textSearch.__totalCount = totalCount;
2700 }
2701
2702
2703 _WebPresenter*
2704 _WebImpl::GetSearchPresenter(void)
2705 {
2706         MutexGuard lock(__mutex);
2707
2708         return dynamic_cast< _WebPresenter* >(__textSearch.__searchQueue.Dequeue());
2709 }
2710
2711
2712  int
2713  _WebImpl::GetPendingAsyncSearchCount(void) const
2714 {
2715         return __textSearch.__searchQueue.GetCount();
2716 }
2717
2718
2719 void
2720 _WebImpl::CalculateAsyncSearchOrdinal(void)
2721 {
2722         if (__textSearch.__searchForward)
2723         {
2724                 __textSearch.__currentIndex++;
2725         }
2726         else
2727         {
2728                 __textSearch.__currentIndex--;
2729         }
2730 }
2731
2732
2733  int
2734  _WebImpl::GetAsyncSearchOrdinal(void) const
2735 {
2736         return __textSearch.__currentIndex;
2737 }
2738
2739
2740  void
2741  _WebImpl::DisableAsyncSearch(void)
2742 {
2743         __textSearch.__searchAll = false;
2744 }
2745
2746
2747 result
2748 _WebImpl::SetSetting(const WebSetting& setting)
2749 {
2750         if (__pWebCore->GetWebNativeNode())
2751         {
2752                 Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2753                 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2754                 SysAssertf(pContext && pSettings, "Failed to get webkit instance.");
2755
2756                 std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(setting.GetDefaultTextEncoding()));
2757                 SysTryReturn(NID_WEB_CTRL, pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2758
2759                 ewk_settings_default_encoding_set(pSettings, pEncoding.get());
2760
2761                 switch (setting.GetCacheControl())
2762                 {
2763                 case WEB_CACHE_VALIDATED:
2764                         ewk_context_cache_disabled_set(pContext, EINA_FALSE);
2765                         break;
2766
2767                 case WEB_CACHE_IGNORE:
2768                         ewk_context_cache_disabled_set(pContext, EINA_TRUE);
2769                         break;
2770
2771                 default:
2772                         SysAssert(false);
2773                 }
2774
2775                 if (setting.GetInputStyle() == INPUT_STYLE_OVERLAY)
2776                 {
2777                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_TRUE);
2778                 }
2779                 else
2780                 {
2781                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_FALSE);
2782                 }
2783
2784                 ewk_settings_font_default_size_set(pSettings, static_cast< Eina_Bool >(setting.GetFontSize()));
2785
2786                 ewk_settings_javascript_enabled_set(pSettings, static_cast< Eina_Bool >(setting.IsJavascriptEnabled()));
2787
2788                 ewk_settings_loads_images_automatically_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoImageLoadEnabled()));
2789
2790                 if (__defaultUserAgent != setting.GetUserAgent())
2791                 {
2792                         std::unique_ptr<char[]> pAgent(_StringConverter::CopyToCharArrayN(setting.GetUserAgent()));
2793                         SysTryReturn(NID_WEB_CTRL, pAgent.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2794
2795                         ewk_view_user_agent_set(__pWebCore->GetWebNativeNode(), pAgent.get());
2796                 }
2797
2798                 ewk_settings_auto_fitting_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoFittingEnabled()));
2799
2800                 ewk_settings_scripts_window_open_set(pSettings,  static_cast< Eina_Bool >(setting.IsJavaScriptPopupEnabled()));
2801
2802                 ewk_settings_form_candidate_data_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoFormDataShowEnabled()));
2803
2804                 ewk_settings_autofill_password_form_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoLoginFormFillEnabled()));
2805         }
2806
2807         _WebSettingImpl* pWebSettingImpl = _WebSettingImpl::GetInstance(__pWebCore->GetSetting());
2808
2809         pWebSettingImpl->SetCertificateErrorHandlingMode(setting.GetCertificateErrorHandlingMode());
2810         pWebSettingImpl->SetDefaultTextEncoding(setting.GetDefaultTextEncoding());
2811         pWebSettingImpl->SetCacheControl(setting.GetCacheControl());
2812         pWebSettingImpl->SetFontSize(setting.GetFontSize());
2813         pWebSettingImpl->SetJavascriptEnabled(setting.IsJavascriptEnabled());
2814         pWebSettingImpl->SetAutoImageLoadEnabled(setting.IsAutoImageLoadEnabled());
2815         pWebSettingImpl->SetInputStyle(setting.GetInputStyle());
2816         pWebSettingImpl->SetUserAgent(setting.GetUserAgent());
2817         pWebSettingImpl->SetAutoFittingEnabled(setting.IsAutoFittingEnabled());
2818         pWebSettingImpl->SetJavaScriptPopupEnabled(setting.IsJavaScriptPopupEnabled());
2819         pWebSettingImpl->SetGeolocationEnabled(setting.IsGeolocationEnabled());
2820         pWebSettingImpl->SetAutoFormDataShowEnabled(setting.IsAutoFormDataShowEnabled());
2821         pWebSettingImpl->SetAutoLoginFormFillEnabled(setting.IsAutoLoginFormFillEnabled());
2822
2823         return E_SUCCESS;
2824 }
2825
2826
2827 WebSetting
2828 _WebImpl::GetSetting(void) const
2829 {
2830         return *__pWebCore->GetSetting();
2831 }
2832
2833
2834 const HitElementResult*
2835 _WebImpl::GetElementByPointN(const Point& point) const
2836 {
2837         result r = E_SUCCESS;
2838
2839         _HitElementResultImpl* pHitElementResultImpl = null;
2840
2841         std::unique_ptr<HitElementResult> pHitElementResult;
2842         std::unique_ptr<Bitmap> pImage;
2843         std::unique_ptr<HashMap, AllElementsDeleter> pAttributeMap;
2844
2845         Point absPoint(__pWebCore->GetAbsoluteCoordinate(point));
2846
2847         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(__pWebCore->GetWebNativeNode(), absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
2848         SysTryReturn(NID_WEB_CTRL, pEwkHitTest, null, E_SYSTEM, "[%s] Failed to get hit test.", GetErrorMessage(E_SYSTEM));
2849
2850         Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
2851         Ewk_Hit_Test_Result_Context context = ewk_hit_test_result_context_get(pEwkHitTest);
2852         String url(ewk_hit_test_link_uri_get(pEwkHitTest));
2853         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
2854         String nodeValue(ewk_hit_test_node_value_get(pEwkHitTest));
2855
2856         SysSecureLog(NID_WEB_CTRL, "The current value of url is %ls, tag is %ls, value is %ls", url.GetPointer(), tagName.GetPointer(), nodeValue.GetPointer());
2857
2858         pHitElementResult = std::unique_ptr<HitElementResult>(new (std::nothrow) HitElementResult());
2859         SysTryCatch(NID_WEB_CTRL, pHitElementResult.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2860
2861         pHitElementResultImpl = _HitElementResultImpl::GetInstance(pHitElementResult.get());
2862         SysTryCatch(NID_WEB_CTRL, pHitElementResultImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2863
2864         if (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
2865         {
2866                 ByteBuffer buf;
2867                 Image image;
2868                 ImageFormat format;
2869
2870                 int imageLength = ewk_hit_test_image_buffer_length_get(pEwkHitTest);
2871                 void* pImageBuffer = ewk_hit_test_image_buffer_get(pEwkHitTest);
2872                 const char* pExtension = ewk_hit_test_image_file_name_extension_get(pEwkHitTest);
2873                 SysLog(NID_WEB_CTRL, "The current value of imageBuffer is %u, bufferLength is %d, extension is %s", pImageBuffer, imageLength, pExtension);
2874
2875                 r = buf.Construct(imageLength);
2876                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2877
2878                 r = buf.SetArray(reinterpret_cast< byte* >(pImageBuffer), 0, imageLength);
2879                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2880
2881                 buf.Rewind();
2882
2883 //              ToDo : webkit doesn't support types such as IMG_FORMAT_WBMP and IMG_FORMAT_TIFF
2884 //              webkit support types such as ico and vp8 additionally
2885                 if (strcmp(pExtension, "gif") == 0)
2886                 {
2887                         format = IMG_FORMAT_GIF;
2888                 }
2889                 else if (strcmp(pExtension, "jpg") == 0)
2890                 {
2891                         format = IMG_FORMAT_JPG;
2892                 }
2893                 else if (strcmp(pExtension, "png") == 0)
2894                 {
2895                         format = IMG_FORMAT_PNG;
2896                 }
2897                 else if (strcmp(pExtension, "bmp") == 0)
2898                 {
2899                         format = IMG_FORMAT_BMP;
2900                 }
2901                 else
2902                 {
2903                         SysLogException(NID_WEB_CTRL, E_UNSUPPORTED_FORMAT, "[%s] The %s format is not supported", GetErrorMessage(E_UNSUPPORTED_FORMAT), pExtension);
2904                         goto CATCH;
2905                 }
2906
2907                 r = image.Construct();
2908                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2909
2910                 pImage = std::unique_ptr<Bitmap>(image.DecodeN(buf, format, BITMAP_PIXEL_FORMAT_RGB565));
2911                 SysTryCatch(NID_WEB_CTRL, pImage.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2912         }
2913
2914         if (pAttrHash)
2915         {
2916                 pAttributeMap = std::unique_ptr<HashMap, AllElementsDeleter>(new (std::nothrow) HashMap());
2917                 SysTryCatch(NID_WEB_CTRL, pAttributeMap.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2918
2919                 r = pAttributeMap->Construct(eina_hash_population(pAttrHash));
2920                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2921
2922                 eina_hash_foreach(pAttrHash, AddHttpAttributeData, pAttributeMap.get());
2923                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2924         }
2925
2926         pHitElementResultImpl->SetHitElementResult(pAttributeMap.release(), pImage.release(), tagName, nodeValue, url);
2927
2928         ewk_hit_test_free(pEwkHitTest);
2929
2930         return pHitElementResult.release();
2931
2932 CATCH:
2933         ewk_hit_test_free(pEwkHitTest);
2934
2935         return null;
2936 }
2937
2938
2939 const HitElementResult*
2940 _WebImpl::GetElementByPointN(const FloatPoint& point) const
2941 {
2942         const Point integerPoint(_CoordinateSystemUtils::ConvertToInteger(point));
2943
2944         std::unique_ptr<const HitElementResult> pHitElementResult(GetElementByPointN(integerPoint));
2945         SysTryReturn(NID_WEB_CTRL, pHitElementResult.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2946
2947         return pHitElementResult.release();
2948 }
2949
2950
2951 bool
2952 _WebImpl::IsLoading(void) const
2953 {
2954         double percent = ewk_view_load_progress_get(__pWebCore->GetWebNativeNode());
2955
2956         if (Double::Compare(percent, 0.0) > 0 && Double::Compare(percent, 1.0) < 0)
2957         {
2958                 return true;
2959         }
2960         else
2961         {
2962                 return false;
2963         }
2964 }
2965
2966
2967 String
2968 _WebImpl::GetTextFromBlock(void) const
2969 {
2970         return ewk_view_text_selection_text_get(__pWebCore->GetWebNativeNode());
2971 }
2972
2973
2974 bool
2975 _WebImpl::IsPrivateBrowsingEnabled(void) const
2976 {
2977         if (__pWebCore->GetWebNativeNode() == null)
2978         {
2979                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsPrivateBrowsingEnabled();
2980         }
2981
2982         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2983         SysAssertf(pSettings, "Failed to get webkit instance.");
2984
2985         return static_cast< bool >(ewk_settings_private_browsing_enabled_get(pSettings));
2986 }
2987
2988
2989 void
2990 _WebImpl::SetPrivateBrowsingEnabled(bool enable)
2991 {
2992         if (__pWebCore->GetWebNativeNode() == null)
2993         {
2994                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetPrivateBrowsingEnabled(enable);
2995                 return;
2996         }
2997
2998         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2999         SysAssertf(pSettings, "Failed to get webkit instance.");
3000
3001         ewk_settings_private_browsing_enabled_set(pSettings, static_cast< Eina_Bool >(enable));
3002 }
3003
3004
3005 void
3006 _WebImpl::ClearHistory(void)
3007 {
3008         ewk_view_back_forward_list_clear(__pWebCore->GetWebNativeNode());
3009 }
3010
3011
3012 void
3013 _WebImpl::ClearCache(void)
3014 {
3015         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3016         SysAssertf(pContext, "Failed to get webkit instance.");
3017
3018         ewk_context_cache_clear(pContext);
3019 }
3020
3021
3022 void
3023 _WebImpl::ClearCookie(void)
3024 {
3025         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3026         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3027         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3028
3029         ewk_cookie_manager_cookies_clear(pCookieManager);
3030 }
3031
3032
3033 void
3034 _WebImpl::ClearFormData(void)
3035 {
3036         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3037         SysAssertf(pContext, "Failed to get webkit instance.");
3038
3039         ewk_context_form_candidate_data_clear(pContext);
3040 }
3041
3042
3043 void
3044 _WebImpl::ClearLoginFormData(void)
3045 {
3046         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3047         SysAssertf(pContext, "Failed to get webkit instance.");
3048
3049         ewk_context_form_password_data_clear(pContext);
3050 }
3051
3052
3053 bool
3054 _WebImpl::IsCookieEnabled(void) const
3055 {
3056         if (__pWebCore->GetWebNativeNode() == null)
3057         {
3058                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsCookieEnabled();
3059         }
3060
3061         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3062         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3063         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3064
3065         _WebPresenter presenter;
3066         presenter.InitAsyncProcess();
3067
3068         ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, &presenter);
3069
3070         bool result = false;
3071         presenter.WaitAsyncProcess(result);
3072
3073         return result;
3074 }
3075
3076
3077 void
3078 _WebImpl::SetCookieEnabled(bool enable)
3079 {
3080         if (__pWebCore->GetWebNativeNode() == null)
3081         {
3082                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetCookiEnabled(enable);
3083
3084                 return;
3085         }
3086
3087         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3088         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3089         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3090
3091         if (enable)
3092         {
3093                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
3094         }
3095         else
3096         {
3097                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_NEVER);
3098                 ewk_cookie_manager_cookies_clear(pCookieManager);
3099         }
3100 }
3101
3102
3103 result 
3104 _WebImpl::SavePageAsPdf(const String& filePath, const Dimension* pSize) const
3105 {
3106         result r = E_SUCCESS;
3107
3108         std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
3109         SysTryReturn(NID_WEB_CTRL, pFilePath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3110
3111         String dirPath;
3112         String fileExtension = File::GetFileExtension(filePath);
3113         int pathLength = filePath.GetLength();
3114         int index = 0;
3115
3116         SysTryReturnResult(NID_WEB_CTRL, fileExtension.Equals("pdf", false), E_INVALID_ARG, "Invalid argument(s) is used. File extension is not pdf.");
3117
3118         r = filePath.LastIndexOf(L"/", pathLength - 1, index);
3119         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3120         r = filePath.SubString(0, index + 1, dirPath);
3121         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3122
3123         std::unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(dirPath));
3124         SysTryReturnResult(NID_WEB_CTRL, access(pDirPath.get(), W_OK) == 0, E_INACCESSIBLE_PATH, "Directory permission is read-only.");
3125
3126         if (pSize)
3127         {
3128                 SysTryReturnResult(NID_WEB_CTRL, pSize->width > 0 && pSize->height > 0, E_INVALID_ARG, "Invalid argument(s) is used. Size of pdf file is invalid.");
3129
3130                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), pSize->width, pSize->height, pFilePath.get());
3131         }
3132         else
3133         {
3134                 Evas_Coord contentsWidth;
3135                 Evas_Coord contentsHeight;
3136
3137                 ewk_view_contents_size_get(__pWebCore->GetWebNativeNode(), &contentsWidth, &contentsHeight);
3138                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), contentsWidth, contentsHeight, pFilePath.get());
3139         }
3140
3141         return E_SUCCESS;
3142 }
3143
3144
3145 bool
3146 _WebImpl::IsMimeSupported(const String& mime) const
3147 {
3148         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
3149         SysTryReturn(NID_WEB_CTRL, pMime.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3150
3151         return static_cast< bool >(ewk_frame_can_show_mime_type(ewk_view_main_frame_get(__pWebCore->GetWebNativeNode()), pMime.get()));
3152 }
3153
3154
3155 void
3156 _WebImpl::SetLoadingListener(ILoadingListener* pLoadingListener)
3157 {
3158         __pUserLoadingListener = const_cast< ILoadingListener* >(pLoadingListener);
3159 }
3160
3161
3162 void
3163 _WebImpl::SetWebUiEventListener(IWebUiEventListener* pUiEventListener)
3164 {
3165         __pUserUiListener = pUiEventListener;
3166 }
3167
3168
3169 void
3170 _WebImpl::SetWebUiEventListenerF(IWebUiEventListenerF* pUiEventListener)
3171 {
3172         __pUserUiListenerF = pUiEventListener;
3173 }
3174
3175
3176 void
3177 _WebImpl::SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener)
3178 {
3179         __pUserKeypadEventListener = pKeypadEventListener;
3180 }
3181
3182
3183 void
3184 _WebImpl::SetDownloadListener(IWebDownloadListener* pDownLoadListener)
3185 {
3186         if (__pWebDownloadHandler.get() == null)
3187         {
3188                 __pWebDownloadHandler = std::unique_ptr<_WebDataHandler>(new (std::nothrow) _WebDataHandler());
3189                 SysTryReturnVoidResult(NID_WEB_CTRL, __pWebDownloadHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3190         }
3191
3192         __pWebDownloadHandler->SetDownloadListener(pDownLoadListener);
3193         __pWebDownloadHandler->SetWebEvent(__pWebEvent.get());
3194 }
3195
3196
3197 void
3198 _WebImpl::SetTextSearchListener(ITextSearchListener* pTextSearchListener)
3199 {
3200         __pTextSearchListener = pTextSearchListener;
3201 }
3202
3203
3204 void
3205 _WebImpl::SetScrollEnabled(bool enable)
3206 {
3207         _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetScrollEnabled(enable);
3208 }
3209
3210
3211 bool
3212 _WebImpl::IsScrollEnabled(void) const
3213 {
3214         return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled();
3215 }
3216
3217
3218 result
3219 _WebImpl::InitJsBridgeList(void)
3220 {
3221         result r = E_SUCCESS;
3222
3223         __pJsProvider = std::unique_ptr<_JsBridgeHashCodeProvider>(new (std::nothrow) _JsBridgeHashCodeProvider());
3224         SysTryReturnResult(NID_WEB_CTRL, __pJsProvider.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3225
3226         __pJsComparer = std::unique_ptr<_JsBridgeComparer>(new (std::nothrow) _JsBridgeComparer());
3227         SysTryReturnResult(NID_WEB_CTRL, __pJsComparer.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3228
3229         std::unique_ptr<HashMapT< String, IJavaScriptBridge* > > pJsBridgeList(new (std::nothrow) HashMapT< String, IJavaScriptBridge* >);
3230         SysTryReturnResult(NID_WEB_CTRL, pJsBridgeList.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3231
3232         r = pJsBridgeList->Construct(0, 0, *__pJsProvider.get(), *__pJsComparer.get());
3233         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3234
3235         __pJsBridgeList = std::move(pJsBridgeList);
3236
3237         return E_SUCCESS;
3238 }
3239
3240
3241 result
3242 _WebImpl::AddJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3243 {
3244         result r = E_SUCCESS;
3245
3246         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3247         String key(pJsBridge->GetName());
3248
3249         r = __pJsBridgeList->Add(key, pJsBridge);
3250         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3251
3252         return E_SUCCESS;
3253 }
3254
3255
3256 result
3257 _WebImpl::RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3258 {
3259         result r = E_SUCCESS;
3260
3261         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3262         String key(pJsBridge->GetName());
3263
3264         r = __pJsBridgeList->Remove(key);
3265         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3266
3267         return E_SUCCESS;
3268 }
3269
3270
3271 IJavaScriptBridge*
3272 _WebImpl::FindJsInterface(const IJsonValue* pValue) const
3273 {
3274         result r = E_SUCCESS;
3275
3276         IJsonValue* pJsonValue = null;
3277         IJavaScriptBridge* pJsBridge = null;
3278
3279         String key(L"name");
3280
3281         const JsonObject* pJsonObject = dynamic_cast< const JsonObject* >(pValue);
3282         SysTryReturn(NID_WEB_CTRL, pJsonObject, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. Json text must be Json Object type." , GetErrorMessage(E_INVALID_ARG));
3283
3284         r = pJsonObject->GetValue(&key, pJsonValue);
3285         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS && pJsonValue, null, r, "[%s] Propagating.", GetErrorMessage(r));
3286
3287         JsonString* pBridgeName = dynamic_cast< JsonString* >(pJsonValue);
3288         SysTryReturn(NID_WEB_CTRL, pBridgeName, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. name key is missing." , GetErrorMessage(E_INVALID_ARG));
3289
3290         r = __pJsBridgeList->GetValue(static_cast< String >(*pBridgeName), pJsBridge);
3291         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3292
3293         return pJsBridge;
3294 }
3295
3296
3297 ILoadingListener*
3298 _WebImpl::GetLoadingListener(void) const
3299 {
3300         return __pUserLoadingListener;
3301 }
3302
3303
3304 IWebUiEventListener*
3305 _WebImpl::GetUiEventListener(void) const
3306 {
3307         return __pUserUiListener;
3308 }
3309
3310
3311 IWebUiEventListenerF*
3312 _WebImpl::GetUiEventListenerF(void) const
3313 {
3314         return __pUserUiListenerF;
3315 }
3316
3317
3318 IWebKeypadEventListener*
3319 _WebImpl::GetWebKeypadEventListener(void) const
3320 {
3321         return __pUserKeypadEventListener;
3322 }
3323
3324
3325 ITextSearchListener*
3326 _WebImpl::GetTextSearchListener(void) const
3327 {
3328         return __pTextSearchListener;
3329 }
3330
3331
3332 void
3333 _WebImpl::SetEventListenerCallback(void) const
3334 {
3335         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3336         if (pWebNativeNode)
3337         {
3338                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3339                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3340
3341                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3342                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3343
3344                 Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
3345                 SysAssertf(pSmartData, "Failed to request");
3346
3347                 Ewk_View_Smart_Class *pSmart = const_cast<Ewk_View_Smart_Class*>(pSmartData->api);
3348                 SysAssertf(pSmart, "Failed to request");
3349
3350                 pSmart->popup_menu_show = OnSelectBoxRequested;
3351                 pSmart->popup_menu_hide = OnSelectBoxClosed;
3352                 pSmart->popup_menu_update = OnSelectBoxUpdateRequested;
3353
3354                 pSmart->input_picker_show = OnDatePickerProviderRequested;
3355                 pSmart->input_picker_color_request = OnColorPickerProviderRequested;
3356                 pSmart->input_picker_color_dismiss = OnColorPickerProviderDismissed;
3357
3358                 evas_object_data_set(pWebNativeNode, WEB_CTRL, this);
3359
3360                 // add loading event callbacks for ILoadingListener
3361                 evas_object_smart_callback_add(pWebNativeNode, "create,window", OnWebWindowCreateRequested, this);
3362                 evas_object_smart_callback_add(pWebNativeNode, "close,window", OnWebWindowClosedRequested, this);
3363
3364                 evas_object_smart_callback_add(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested, this);
3365                 evas_object_smart_callback_add(pWebNativeNode, "load,started", OnLoadingStarted, this);
3366                 evas_object_smart_callback_add(pWebNativeNode, "load,finished", OnLoadingCompleted, this);
3367                 evas_object_smart_callback_add(pWebNativeNode, "load,progress", OnEstimatedProgress, this);
3368                 evas_object_smart_callback_add(pWebNativeNode, "load,progress,finished", OnProgressCompleted, this);
3369                 evas_object_smart_callback_add(pWebNativeNode, "load,stop", OnLoadingCanceled, this);
3370                 evas_object_smart_callback_add(pWebNativeNode, "load,error", OnLoadingErrorOccurred, this);
3371                 evas_object_smart_callback_add(pWebNativeNode, "title,changed", OnPageTitleReceived, this);
3372                 evas_object_smart_callback_add(pWebNativeNode, "load,committed", OnLoadingCommitted, this);
3373
3374                 evas_object_smart_callback_add(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest, this);
3375
3376                 evas_object_smart_callback_add(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3377
3378                 evas_object_smart_callback_add(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged, this);
3379                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened, this);
3380                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed, this);
3381
3382                 evas_object_smart_callback_add(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested, this);
3383                 evas_object_smart_callback_add(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled, this);
3384
3385                 evas_object_smart_callback_add(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested, this);
3386
3387                 ewk_view_javascript_alert_callback_set(pWebNativeNode, OnScriptAlertRequested, const_cast< _WebImpl* >(this));
3388                 ewk_view_javascript_prompt_callback_set(pWebNativeNode, OnScriptPromptRequested, const_cast< _WebImpl* >(this));
3389                 ewk_view_javascript_confirm_callback_set(pWebNativeNode, OnScriptConfirmRequested, const_cast< _WebImpl* >(this));
3390
3391                 evas_object_smart_callback_add(pWebNativeNode, "policy,response,decide", OnWebDataReceived, this);
3392
3393                 evas_object_smart_callback_add(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested, this);
3394                 evas_object_smart_callback_add(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested, this);
3395                 evas_object_smart_callback_add(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted, this);
3396
3397                 evas_object_smart_callback_add(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested, this);
3398                 evas_object_smart_callback_add(pWebNativeNode, "notification,show", OnNotificationShow, this);
3399                 evas_object_smart_callback_add(pWebNativeNode, "notification,cancel", OnNotificationCancel, this);
3400
3401                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested, this);
3402                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered, this);
3403                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested, this);
3404
3405                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested, this);
3406                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered, this);
3407                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested, this);
3408                 evas_object_smart_callback_add(pWebNativeNode, "text,found", OnTextFound, this);
3409
3410                 evas_object_smart_callback_add(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered, this);
3411                 evas_object_smart_callback_add(pWebNativeNode, "icon,received", OnFaviconReceived, this);
3412
3413                 evas_object_smart_callback_add(pWebNativeNode, "text,style,state", OnWebPageBlockSelected, this);
3414                 evas_object_smart_callback_add(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation, this);
3415
3416                 ewk_view_open_panel_callback_set(pWebNativeNode, OnSelectUploadFile, const_cast< _WebImpl* >(this));
3417                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3418                 SysAssertf(pContext, "Failed to get webkit instance.");
3419                 ewk_context_did_start_download_callback_set(pContext, OnDidStartDownloadCallback, const_cast< _WebImpl* >(this));
3420                 ewk_context_vibration_client_callbacks_set(pContext, OnVibrationRequested, OnVibrationCanceled, const_cast< _WebImpl* >(this));
3421                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, OnApplicationCachePermissionRequested, const_cast< _WebImpl* >(this));
3422
3423                 evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained, this);
3424         }
3425 }
3426
3427
3428 void
3429 _WebImpl::RemoveEventListenerCallback(void) const
3430 {
3431         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3432         if (pWebNativeNode)
3433         {
3434                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3435                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3436
3437                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3438                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3439
3440                 evas_object_smart_callback_del(pWebNativeNode, "create,window", OnWebWindowCreateRequested);
3441                 evas_object_smart_callback_del(pWebNativeNode, "close,window", OnWebWindowClosedRequested);
3442
3443                 evas_object_smart_callback_del(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested);
3444                 evas_object_smart_callback_del(pWebNativeNode, "load,started", OnLoadingStarted);
3445                 evas_object_smart_callback_del(pWebNativeNode, "load,finished", OnLoadingCompleted);
3446                 evas_object_smart_callback_del(pWebNativeNode, "load,progress", OnEstimatedProgress);
3447                 evas_object_smart_callback_del(pWebNativeNode, "load,progress,finished", OnProgressCompleted);
3448                 evas_object_smart_callback_del(pWebNativeNode, "load,stop", OnLoadingCanceled);
3449                 evas_object_smart_callback_del(pWebNativeNode, "load,error", OnLoadingErrorOccurred);
3450                 evas_object_smart_callback_del(pWebNativeNode, "title,changed", OnPageTitleReceived);
3451
3452                 evas_object_smart_callback_del(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest);
3453
3454                 evas_object_smart_callback_del_full(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3455
3456                 evas_object_smart_callback_del(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged);
3457                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened);
3458                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed);
3459
3460                 evas_object_smart_callback_del(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested);
3461                 evas_object_smart_callback_del(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled);
3462
3463                 evas_object_smart_callback_del(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested);
3464
3465                 ewk_view_javascript_alert_callback_set(null, null, null);
3466                 ewk_view_javascript_prompt_callback_set(null, null, null);
3467                 ewk_view_javascript_confirm_callback_set(null, null, null);
3468
3469                 evas_object_smart_callback_del(pWebNativeNode, "policy,response,decide", OnWebDataReceived);
3470
3471                 evas_object_smart_callback_del(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested);
3472                 evas_object_smart_callback_del(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested);
3473                 evas_object_smart_callback_del(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted);
3474
3475                 evas_object_smart_callback_del(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested);
3476                 evas_object_smart_callback_del(pWebNativeNode, "notification,show", OnNotificationShow);
3477                 evas_object_smart_callback_del(pWebNativeNode, "notification,cancel", OnNotificationCancel);
3478                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested);
3479                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered);
3480                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested);
3481
3482                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested);
3483                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered);
3484                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested);
3485
3486                 evas_object_smart_callback_del(pWebNativeNode, "text,found", OnTextFound);
3487
3488                 evas_object_smart_callback_del(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered);
3489                 evas_object_smart_callback_del(pWebNativeNode, "icon,received", OnFaviconReceived);
3490
3491                 evas_object_smart_callback_del(pWebNativeNode, "text,style,state", OnWebPageBlockSelected);
3492                 evas_object_smart_callback_del(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation);
3493
3494                 ewk_view_open_panel_callback_set(null, null, null);
3495                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3496                 SysAssertf(pContext, "Failed to get webkit instance.");
3497                 ewk_context_vibration_client_callbacks_set(pContext, null, null, null);
3498                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, null, null);
3499
3500                 evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained);
3501         }
3502 }
3503
3504
3505 result
3506 _WebImpl::SetBlockSelectionPosition(const Point& startPoint)
3507 {
3508         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3509
3510         Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
3511         SysAssertf(pSmartData, "Failed to request");
3512
3513         Point absPoint(__pWebCore->GetAbsoluteCoordinate(startPoint));
3514
3515         Eina_Bool ret = pSmartData->api->text_selection_down(pSmartData, absPoint.x, absPoint.y);
3516         if (ret)
3517         {
3518                 pSmartData->api->text_selection_up(pSmartData, absPoint.x, absPoint.y);
3519
3520                 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(__pWebCore->GetWebNativeNode(), absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
3521                 SysTryReturnResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "Failed to get hit test.");
3522
3523                 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
3524
3525                 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false))
3526                 {
3527                         ewk_view_command_execute(pWebNativeNode, "SelectWord", 0);
3528                 }
3529                 else
3530                 {
3531                         Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
3532                         char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
3533                         if(pValue)
3534                         {
3535                                 ewk_view_command_execute(pWebNativeNode, "SelectWord", 0);
3536                         }
3537                 }
3538         }
3539
3540         SysTryReturnResult(NID_WEB_CTRL, GetTextFromBlock().GetLength() > 0, E_INVALID_ARG, "Failed to set text selection up.");
3541
3542         return E_SUCCESS;
3543 }
3544
3545
3546 result
3547 _WebImpl::SetBlockSelectionPosition(const FloatPoint& startPoint)
3548 {
3549         return SetBlockSelectionPosition(_CoordinateSystemUtils::ConvertToInteger(startPoint));
3550 }
3551
3552
3553 void
3554 _WebImpl::ReleaseBlock(void)
3555 {
3556         ewk_view_text_selection_range_clear(__pWebCore->GetWebNativeNode());
3557 }
3558
3559
3560 void
3561 _WebImpl::GetBlockRange(Point& startPoint, Point& endPoint) const
3562 {
3563         FloatPoint tempStartPoint;
3564         FloatPoint tempEndPoint;
3565
3566         GetBlockRange(tempStartPoint, tempEndPoint);
3567
3568         startPoint = _CoordinateSystemUtils::ConvertToInteger(tempStartPoint);
3569         endPoint = _CoordinateSystemUtils::ConvertToInteger(tempEndPoint);
3570 }
3571
3572
3573 void
3574 _WebImpl::GetBlockRange(FloatPoint& startPoint, FloatPoint& endPoint) const
3575 {
3576         Eina_Rectangle leftHandle;
3577         Eina_Rectangle rightHandle;
3578
3579         ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
3580
3581         startPoint.x = _CoordinateSystemUtils::ConvertToFloat(leftHandle.x);
3582         startPoint.y = _CoordinateSystemUtils::ConvertToFloat(leftHandle.y);
3583         endPoint.x = _CoordinateSystemUtils::ConvertToFloat(rightHandle.x + rightHandle.w);
3584         endPoint.y = _CoordinateSystemUtils::ConvertToFloat(rightHandle.y + rightHandle.h);
3585
3586         if ((endPoint.x != 0.0f) && (endPoint.y != 0.0f))
3587         {
3588                 startPoint = __pWebCore->GetRelativeCoordinate(startPoint);
3589                 endPoint = __pWebCore->GetRelativeCoordinate(endPoint);
3590         }
3591 }
3592
3593
3594 Bitmap*
3595 _WebImpl::GetFaviconN(void) const
3596 {
3597         result r = E_SUCCESS;
3598
3599         Evas_Object* pView = __pWebCore->GetWebNativeNode();
3600
3601         Evas* pEvas = evas_object_evas_get(pView);
3602         Ewk_Context* pContext = ewk_view_context_get(pView);
3603         SysAssertf(pEvas && pContext, "Failed to request");
3604
3605         const char* pUrl = ewk_view_url_get(pView);
3606
3607         Tizen::Graphics::BufferInfo bufferInfo;
3608         Tizen::Base::ByteBuffer byteBuffer;
3609
3610         std::unique_ptr<Bitmap> pBitmapImage(new (std::nothrow) Bitmap());
3611         SysTryReturn(NID_WEB_CTRL, pBitmapImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3612
3613         Evas_Object* pFavicon = ewk_context_icon_database_icon_object_add(pContext, pUrl, pEvas);
3614         if (!pFavicon)
3615         {
3616                 return null;
3617         }
3618
3619         r = _Utility::GetPixelBufferFromEvasObject(pFavicon,  bufferInfo);
3620         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3621
3622         const Dimension dimension(bufferInfo.width, bufferInfo.height);
3623
3624         r = byteBuffer.Construct((byte*)bufferInfo.pPixels, 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
3625         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3626
3627         r = pBitmapImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
3628         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3629
3630         return pBitmapImage.release();
3631
3632 }
3633
3634
3635 void
3636 _WebImpl::ScrollBy(const Tizen::Graphics::Point& diff)
3637 {
3638         ewk_view_scroll_by(__pWebCore->GetWebNativeNode(), diff.x, diff.y);
3639 }
3640
3641
3642 void
3643 _WebImpl::ScrollTo(const Tizen::Graphics::Point& dest)
3644 {
3645         ewk_view_scroll_set(__pWebCore->GetWebNativeNode(), dest.x, dest.y);
3646 }
3647
3648
3649 Point
3650 _WebImpl::GetScrollPosition(void) const
3651 {
3652         Point position;
3653
3654         ewk_view_scroll_pos_get(__pWebCore->GetWebNativeNode(), &position.x, &position.y);
3655
3656         return position;
3657 }
3658
3659
3660 Dimension
3661 _WebImpl::GetPageSize(void) const
3662 {
3663         Evas_Coord width = 0;
3664         Evas_Coord height = 0;
3665
3666         ewk_view_contents_size_get(__pWebCore->GetWebNativeNode(), &width, &height);
3667
3668         Dimension size(static_cast< int >(width), static_cast< int >(height));
3669
3670         return size;
3671 }
3672
3673
3674 void
3675 _WebImpl::SetLoadingErrorOccurred(bool arg)
3676 {
3677         __isLoadingErrorOccurred = arg;
3678 }
3679
3680
3681 bool
3682 _WebImpl::IsLoadingErrorOccurred(void) const
3683 {
3684         return __isLoadingErrorOccurred;
3685 }
3686
3687
3688 void
3689 _WebImpl::SetRedirectRequested(bool arg)
3690 {
3691         __isRedirectRequested = arg;
3692 }
3693
3694
3695 bool
3696 _WebImpl::IsRedirectRequested(void) const
3697 {
3698         return __isRedirectRequested;
3699 }
3700
3701
3702 void
3703 _WebImpl::SetPolicyDecision(DecisionPolicy policy)
3704 {
3705         __policy = policy;
3706 }
3707
3708
3709 DecisionPolicy
3710 _WebImpl::GetPolicyDecision(void) const
3711 {
3712         return __policy;
3713 }
3714
3715
3716 void
3717 _WebImpl::SetCertificateRequested(bool arg)
3718 {
3719         __isCertificateRequested = arg;
3720 }
3721
3722
3723 bool
3724 _WebImpl::IsCertificateRequested(void) const
3725 {
3726         return __isCertificateRequested;
3727 }
3728
3729
3730 bool
3731 _WebImpl::IsCertificateConfirmed(void) const
3732 {
3733         return __isCertificateConfirmed;
3734 }
3735
3736
3737 void
3738 _WebImpl::SetOrientationChanged(bool arg)
3739 {
3740         __isOrientationChanged = arg;
3741 }
3742
3743
3744 bool
3745 _WebImpl::IsOrientationChanged(void) const
3746 {
3747         return __isOrientationChanged;
3748 }
3749
3750
3751 result
3752 _WebImpl::LaunchAppControl(const IEventArg& arg)
3753 {
3754         result r = E_SUCCESS;
3755
3756         IEventArg* pArg = const_cast< IEventArg* >(&arg);
3757         _WebEventArg* pWebEventArg = dynamic_cast< _WebEventArg* >(pArg);
3758         SysTryReturnResult(NID_WEB_CTRL, pWebEventArg, E_INVALID_ARG, "Type casting failed. argument must be IEventArg type.");
3759
3760         String operationId(L"");
3761         String uriPattern(pWebEventArg->GetEventMessage());
3762         SysLog(NID_WEB_CTRL, "The current value of web event type is %d", pWebEventArg->GetEventType());
3763
3764         switch (pWebEventArg->GetEventType())
3765         {
3766         case WEB_EVENT_REQUEST_RTSP:
3767         {
3768                 String ext;
3769                 String mimeType;
3770                 int uriLength = uriPattern.GetLength();
3771                 int index;
3772
3773                 operationId = L"http://tizen.org/appcontrol/operation/view";
3774
3775                 r = uriPattern.LastIndexOf(L".", uriLength - 1, index);
3776                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3777
3778                 r = uriPattern.SubString(index + 1, ext);
3779                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3780
3781                 r = _AppControlManager::GetMimeFromExt(ext, mimeType);
3782                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3783
3784                 r = _AppControlImpl::FindAndStart(operationId, &uriPattern, &mimeType, null, null, null);
3785                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3786
3787                 return r;
3788         }
3789         case WEB_EVENT_REQUEST_TEL:
3790         {
3791                 operationId = L"http://tizen.org/appcontrol/operation/dial";
3792                 break;
3793         }
3794         case WEB_EVENT_REQUEST_EMAIL:
3795         //fall through
3796         case WEB_EVENT_REQUEST_SMS:
3797         //fall through
3798         case WEB_EVENT_REQUEST_MMS:
3799         {
3800                 operationId = L"http://tizen.org/appcontrol/operation/compose";
3801                 break;
3802         }
3803         case WEB_EVENT_REQUEST_UNKNOWN:
3804         {
3805                 operationId = L"http://tizen.org/appcontrol/operation/view";
3806                 break;
3807         }
3808         default:
3809                 SysAssert(false);
3810                 break;
3811         }
3812
3813         r = _AppControlImpl::FindAndStart(operationId, &uriPattern, null, null, null, null);
3814         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3815
3816         return r;
3817 }
3818
3819
3820 result
3821 _WebImpl::SetFullScreenKeypad(void)
3822 {
3823         result r = E_SUCCESS;
3824
3825         std::unique_ptr<Keypad> pKeypad(new (std::nothrow) Keypad());
3826         SysTryReturnResult(NID_WEB_CTRL, pKeypad.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
3827
3828         r = pKeypad->Construct(KEYPAD_STYLE_NORMAL, 100);
3829         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3830
3831         String text(ewk_view_focused_input_element_value_get(__pWebCore->GetWebNativeNode()));
3832         pKeypad->SetText(text);
3833
3834         r = pKeypad->SetShowState(true);
3835         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3836
3837         r = pKeypad->Show();
3838         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3839
3840         pKeypad->AddTextEventListener(*this);
3841
3842         __pKeypad = std::move(pKeypad);
3843
3844         return E_SUCCESS;
3845 }
3846
3847
3848 void
3849 _WebImpl::RemoveFullScreenKeypad(void)
3850 {
3851         __pKeypad->RemoveTextEventListener(*this);
3852
3853         __pKeypad.reset();
3854 }
3855
3856
3857 bool
3858 _WebImpl::IsFooterVisible(void) const
3859 {
3860         return __isFooterVisible;
3861 }
3862
3863
3864 void
3865 _WebImpl::SetFooterVisibleState(bool isFooterVisible)
3866 {
3867         __isFooterVisible = isFooterVisible;
3868 }
3869
3870
3871 bool
3872 _WebImpl::IsKeypadVisible(void) const
3873 {
3874         return __isKeypadVisible;
3875 }
3876
3877
3878 void
3879 _WebImpl::SetKeypadVisibleState(bool isKeypadVisible)
3880 {
3881         __isKeypadVisible = isKeypadVisible;
3882 }
3883
3884
3885 bool 
3886 _WebImpl::IsKeypadOpened(void) const
3887 {
3888         return __isKeypadOpened;
3889 }
3890
3891 void 
3892 _WebImpl::SetKeypadOpened(bool isKeypadOpened)
3893 {
3894         __isKeypadOpened = isKeypadOpened;
3895 }
3896
3897
3898 Rectangle
3899 _WebImpl::GetPreviousKeypadBounds(void) const
3900 {
3901         return __keypadBounds;
3902 }
3903
3904
3905 void 
3906 _WebImpl::SetPreviousKeypadBounds(Rectangle& bounds)
3907 {
3908         __keypadBounds = bounds;
3909 }
3910
3911
3912 void
3913 _WebImpl::OnTextValueChangeCanceled(const Control& source)
3914 {
3915         RemoveFullScreenKeypad();
3916 }
3917
3918
3919 void
3920 _WebImpl::OnTextValueChanged(const Control& source)
3921 {
3922         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(__pKeypad->GetText()));
3923
3924         ewk_view_focused_input_element_value_set(__pWebCore->GetWebNativeNode(), pText.get());
3925
3926         RemoveFullScreenKeypad();
3927 }
3928
3929
3930 result
3931 _WebImpl::OnHandleJavaScriptRequestByEventArg(const IEventArg& arg)
3932 {
3933         const _JsBridgeArg* pEventArg = dynamic_cast< const _JsBridgeArg* >(&arg);
3934         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. arg is not _JsBridgeArg object.");
3935
3936         std::unique_ptr<IJsonValue> pJsonValue(JsonParser::ParseN(*(pEventArg->GetJsonData())));
3937         SysTryReturn(NID_WEB_JSON, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3938
3939         IJavaScriptBridge* pJsInterface = FindJsInterface(pJsonValue.get());
3940         SysTryReturnResult(NID_WEB_CTRL, pJsInterface, E_OBJ_NOT_FOUND, "JsInterface instance is not available.");
3941
3942         pJsInterface->HandleJavaScriptRequestN(pJsonValue.release());
3943
3944         return E_SUCCESS;
3945 }
3946
3947
3948 result
3949 _WebImpl::OnHandleLoadingEvent(const IEventArg& arg)
3950 {
3951         result r = E_SUCCESS;
3952
3953         const _LoadingEventArg* pEventArg = dynamic_cast< const _LoadingEventArg* >(&arg);
3954         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
3955
3956         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
3957
3958         ILoadingListener* pLoadingListner = GetLoadingListener();
3959         SysTryReturnResult(NID_WEB_CTRL, pLoadingListner, E_SYSTEM, "A system error has been occurred. Loading listener was not set or null.");
3960
3961         switch (pEventArg->GetEventType())
3962         {
3963         case WEB_EVENT_LOADINGLISTENER_STARTED:
3964         {
3965                 pLoadingListner->OnLoadingStarted();
3966                 break;
3967         }
3968
3969         case WEB_EVENT_LOADINGLISTENER_PROGRESS:
3970         {
3971                 const Integer* pProgressPercentage = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS));
3972                 SysTryReturn(NID_WEB_CTRL, pProgressPercentage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3973
3974                 pLoadingListner->OnEstimatedProgress(pProgressPercentage->ToInt());
3975                 break;
3976         }
3977
3978         case WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED:
3979         {
3980                 const String* pPageTitle = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::PAGE_TITLE));
3981                 SysTryReturn(NID_WEB_CTRL, pPageTitle, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3982
3983                 pLoadingListner->OnPageTitleReceived(*pPageTitle);
3984                 break;
3985         }
3986
3987         case WEB_EVENT_LOADINGLISTENER_CANCELED:
3988         {
3989                 pLoadingListner->OnLoadingCanceled();
3990                 break;
3991         }
3992
3993         case WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED:
3994         {
3995                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_TYPE));
3996                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3997
3998                 const String* pErrorMessage = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_MESSAGE));
3999                 SysTryReturn(NID_WEB_CTRL, pErrorMessage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4000
4001                 LoadingErrorType errorType = ConvertErrorCode(pErrorType->ToInt());
4002
4003                 pLoadingListner->OnLoadingErrorOccurred(errorType, *pErrorMessage);
4004                 break;
4005         }
4006
4007         case WEB_EVENT_LOADINGLISTENER_COMPLETED:
4008         {
4009                 pLoadingListner->OnLoadingCompleted();
4010                 break;
4011         }
4012
4013         case WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED:
4014         {
4015                 pLoadingListner->OnHttpAuthenticationCanceled();
4016                 break;
4017         }
4018
4019         case WEB_EVENT_LOADINGLISTENER_FAVICON_RECEIVED:
4020         {
4021                 std::unique_ptr<Bitmap> pFavicon(GetFaviconN());
4022                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4023
4024                 if (pFavicon.get())
4025                 {
4026                         pLoadingListner->OnFaviconReceived(*pFavicon.get());
4027                 }
4028                 break;
4029         }
4030
4031         default:
4032         {
4033                 SysAssert(false);
4034         }
4035         }
4036
4037         return r;
4038 }
4039
4040
4041 result
4042 _WebImpl::OnHandleWebDownloadEvent(const IEventArg& arg)
4043 {
4044         result r = E_SUCCESS;
4045
4046         const _WebDownloadEventArg* pEventArg = dynamic_cast< const _WebDownloadEventArg* >(&arg);
4047         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4048
4049         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4050
4051         IWebDownloadListener* pWebDownloadListener = __pWebDownloadHandler->GetDownloadListener();
4052         SysTryReturnResult(NID_WEB_CTRL, pWebDownloadListener, E_SYSTEM, "A system error has been occurred. Web Downloading listener was not set or null.");
4053
4054         switch (pEventArg->GetEventType())
4055         {
4056         case WEB_EVENT_WEBDOWNLOADLISTENER_DATA_RECEIVED:
4057         {
4058                 const ByteBuffer* pChunk = dynamic_cast< const ByteBuffer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::CHUNKED_DATA));
4059                 SysTryReturn(NID_WEB_CTRL, pChunk, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4060
4061                 pWebDownloadListener->OnWebChunkedDataReceived(*pChunk);
4062                 break;
4063         }
4064
4065         case WEB_EVENT_WEBDOWNLOADLISTENER_COMPLETED:
4066         {
4067                 pWebDownloadListener->OnWebDataDownloadCompleted();
4068                 break;
4069         }
4070
4071         case WEB_EVENT_WEBDOWNLOADLISTENER_FAILED:
4072         {
4073                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::ERROR_TYPE));
4074                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4075
4076                 LoadingErrorType errorType = static_cast < LoadingErrorType >(pErrorType->ToInt());
4077
4078                 pWebDownloadListener->OnWebDownloadFailed(errorType);
4079                 break;
4080         }
4081
4082         default:
4083         {
4084                 SysAssert(false);
4085         }
4086         }
4087
4088         return r;
4089 }
4090
4091
4092 result
4093 _WebImpl::OnHandleWebUiEvent(const IEventArg& arg)
4094 {
4095         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4096         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4097
4098         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4099
4100         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListener, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4101
4102         switch (pEventArg->GetEventType())
4103         {
4104         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED:
4105         {
4106                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4107
4108                 Point* pStartPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4109                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4110
4111                 Point* pEndPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4112                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4113
4114                 __pUserUiListener->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4115                 break;
4116         }
4117
4118         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED:
4119         {
4120                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4121
4122                 __pUserUiListener->OnWebPageShowRequested(*pWeb);
4123                 break;
4124         }
4125
4126         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED:
4127         {
4128                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4129
4130                 __pUserUiListener->OnWebWindowCloseRequested(*pWeb);
4131                 break;
4132         }
4133
4134         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED:
4135         {
4136                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4137
4138                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4139                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4140
4141                 __pUserUiListener->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4142                 break;
4143         }
4144
4145         default:
4146         {
4147                 SysAssert(false);
4148         }
4149         }
4150
4151         return E_SUCCESS;
4152 }
4153
4154
4155 result
4156 _WebImpl::OnHandleWebUiEventF(const IEventArg& arg)
4157 {
4158         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4159         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4160
4161         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4162
4163         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListenerF, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4164
4165         switch (pEventArg->GetEventType())
4166         {
4167         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED_FLOAT:
4168         {
4169                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4170
4171                 FloatPoint* pStartPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4172                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4173
4174                 FloatPoint* pEndPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4175                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4176
4177                 __pUserUiListenerF->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4178                 break;
4179         }
4180
4181         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED_FLOAT:
4182         {
4183                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4184
4185                 __pUserUiListenerF->OnWebPageShowRequested(*pWeb);
4186                 break;
4187         }
4188
4189         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED_FLOAT:
4190         {
4191                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4192
4193                 __pUserUiListenerF->OnWebWindowCloseRequested(*pWeb);
4194                 break;
4195         }
4196
4197         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED_FLOAT:
4198         {
4199                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4200
4201                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4202                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4203
4204                 __pUserUiListenerF->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4205                 break;
4206         }
4207
4208         default:
4209         {
4210                 SysAssert(false);
4211         }
4212         }
4213
4214         return E_SUCCESS;
4215 }
4216
4217
4218 result
4219 _WebImpl::OnHandleTextSearchEvent(const IEventArg& arg)
4220 {
4221         result r = E_SUCCESS;
4222
4223         const _TextSearchEventArg* pEventArg = dynamic_cast< const _TextSearchEventArg* >(&arg);
4224         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4225
4226         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4227
4228         ITextSearchListener* pTextSearchListner = GetTextSearchListener();
4229         SysTryReturnResult(NID_WEB_CTRL, pTextSearchListner, E_SYSTEM, "A system error has been occurred. Web text search listener was not set or null.");
4230
4231         switch (pEventArg->GetEventType())
4232         {
4233         case WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND:
4234         {
4235                 Integer* pTotalCount= dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::TOTAL_COUNT)));
4236                 SysTryReturn(NID_WEB_CTRL, pTotalCount, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4237
4238                 Integer* pCurrentOrdinal = dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL)));
4239                 SysTryReturn(NID_WEB_CTRL, pCurrentOrdinal, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4240
4241                 pTextSearchListner->OnTextFound(pTotalCount->ToInt(), pCurrentOrdinal->ToInt());
4242                 break;
4243         }
4244
4245         default:
4246         {
4247                 SysAssert(false);
4248         }
4249         }
4250
4251         return r;
4252 }
4253
4254
4255 result
4256 _WebImpl::VibrationRequested(uint64_t duration)
4257 {
4258         result r = E_SUCCESS;
4259
4260         __pVibrator.reset();
4261
4262         std::unique_ptr<_VibratorImpl> pVibrator(new (std::nothrow) _VibratorImpl);
4263         SysTryReturnResult(NID_WEB_CTRL, pVibrator.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4264
4265         r = pVibrator->Construct();
4266         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4267
4268         __pVibrator = std::move(pVibrator);
4269
4270         IntensityDurationVibrationPattern pattern = {static_cast< int >(duration), -1};
4271
4272         r = __pVibrator->Start(&pattern, 1, 1);
4273         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4274
4275         return E_SUCCESS;
4276 }
4277
4278
4279 void
4280 _WebImpl::VibrationCanceled(void)
4281 {
4282         __pVibrator.reset();
4283 }
4284
4285
4286 result
4287 _WebImpl::HttpAuthenticationRequested(Ewk_Auth_Challenge* pChallenge)
4288 {
4289         result r = E_SUCCESS;
4290
4291         String host(ewk_auth_challenge_url_get(pChallenge));
4292         String realm(ewk_auth_challenge_realm_get(pChallenge));
4293
4294         __pAuthChallenge.reset();
4295
4296         std::unique_ptr<AuthenticationChallenge> pAuthChallenge(new (std::nothrow) AuthenticationChallenge());
4297         SysTryReturnResult(NID_WEB_CTRL, pAuthChallenge, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4298
4299         _AuthenticationChallengeImpl* pAuthImpl = _AuthenticationChallengeImpl::GetInstance(pAuthChallenge.get());
4300         SysTryReturn(NID_WEB_CTRL, pAuthImpl,  GetLastResult(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4301
4302         pAuthImpl->SetAuthenticationChallengeHandler(pChallenge);
4303         pAuthImpl->SetWebEvasObject(__pWebCore->GetWebNativeNode());
4304
4305         __pAuthChallenge = std::move(pAuthChallenge);
4306
4307         ewk_auth_challenge_suspend(pChallenge);
4308         if (__pUserLoadingListener && __pUserLoadingListener->OnHttpAuthenticationRequestedN(host, realm, *__pAuthChallenge.get()))
4309         {
4310                 __pAuthChallenge.release();
4311         }
4312         else
4313         {
4314                 r = ShowAuthenticationPopup(host, realm, __pAuthChallenge.get());
4315                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4316         }
4317
4318         return E_SUCCESS;
4319 }
4320
4321
4322 result
4323 _WebImpl::ShowAuthenticationPopup(const String& host, const String& realm, AuthenticationChallenge* pAuthChallenge)
4324 {
4325         result r = E_SUCCESS;
4326
4327         std::unique_ptr<_AuthConfirmPopup> pAuthPopup(new (std::nothrow) _AuthConfirmPopup());
4328         SysTryReturnResult(NID_WEB_CTRL, pAuthPopup, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4329
4330         r = pAuthPopup->Construct(host, realm, pAuthChallenge);
4331         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4332
4333         __pAuthPopup = std::move(pAuthPopup);
4334
4335         int modalResult = 0;
4336
4337         __pAuthPopup->SetOwner(&GetPublic());
4338         
4339         r = __pAuthPopup->ShowAndWait(modalResult);
4340         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4341
4342 CATCH:
4343         __pAuthPopup.reset();
4344
4345         return r;
4346 }
4347
4348
4349 result
4350 _WebImpl::ShowCertificateConfirmPopup(_CertificatePopupMode userConfirmMode, Ewk_Certificate_Policy_Decision* pPolicy)
4351 {
4352         result r = E_SUCCESS;
4353
4354         std::unique_ptr<_CertificateConfirmPopup> pCertConfirmPopup(new (std::nothrow) _CertificateConfirmPopup());
4355         SysTryReturnResult(NID_WEB_CTRL, pCertConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4356
4357         r = pCertConfirmPopup->Construct(userConfirmMode, pPolicy);
4358         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4359
4360         __pCertConfirmPopup = std::move(pCertConfirmPopup);
4361
4362         int modalResult = 0;
4363
4364         __pCertConfirmPopup->SetOwner(&GetPublic());
4365         
4366         r = __pCertConfirmPopup->ShowAndWait(modalResult);
4367         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4368
4369         if (userConfirmMode == CERTIFICATE_POPUP_MODE_USER_CONFIRM)
4370         {
4371                 __isCertificateConfirmed = __pCertConfirmPopup->GetConfirmResult();
4372         }
4373
4374 CATCH:
4375         __pCertConfirmPopup.reset();
4376
4377         return r;
4378 }
4379
4380 result
4381 _WebImpl::ShowUserConfirmPopup(_UserConfirmMode userConfirmMode, void* pPolicy)
4382 {
4383         result r = E_SUCCESS;
4384
4385         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4386         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4387
4388         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, true);
4389         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4390
4391         __pUserConfirmPopup = std::move(pUserConfirmPopup);
4392
4393         int modalResult = 0;
4394
4395         __pUserConfirmPopup->SetOwner(&GetPublic());
4396         
4397         r = __pUserConfirmPopup->ShowAndWait(modalResult);
4398         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4399         
4400 CATCH:
4401         __pUserConfirmPopup.reset();
4402
4403         return r;
4404 }
4405
4406 result
4407 _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPolicy, String msg)
4408 {
4409         result r = E_SUCCESS;
4410
4411         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4412         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4413
4414         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, false, msg);
4415         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4416
4417         __pUserConfirmPopup = std::move(pUserConfirmPopup);
4418
4419         __pUserConfirmPopup->SetOwner(&GetPublic());
4420
4421         r = __pUserConfirmPopup->ShowPopup();
4422         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4423
4424         __pUserConfirmPopup.release();
4425
4426         return E_SUCCESS;
4427
4428 CATCH:
4429         __pUserConfirmPopup.reset();
4430
4431         return r;
4432 }
4433
4434
4435 _Form*
4436 _WebImpl::GetParentFormCore(_Control* pControlCore)
4437 {
4438         String parentName;
4439         _Form* pFormCore = null;
4440
4441         _Control* pParentControlCore = dynamic_cast< _Control* >(pControlCore->GetParent());
4442         if (!pParentControlCore)
4443         {
4444                 return null;
4445         }
4446
4447         pFormCore = dynamic_cast< _Form* >(pParentControlCore);
4448         if (pFormCore)
4449         {
4450                 return pFormCore;
4451         }
4452
4453         return GetParentFormCore(pParentControlCore);
4454 }
4455
4456
4457 bool 
4458 _WebImpl::OnFocusGained(const _ControlImpl& source)
4459 {
4460         return true;
4461 }
4462
4463
4464 bool 
4465 _WebImpl::OnFocusLost(const _ControlImpl& source)
4466 {
4467         if(IsKeypadVisible() == true)
4468         {
4469                 SetKeypadOpened(true);
4470
4471                 SetKeypadVisibleState(false);
4472         }
4473
4474         evas_object_focus_set(__pWebCore->GetWebNativeNode(), EINA_FALSE);
4475
4476         return true;
4477 }
4478
4479
4480 bool
4481 _WebImpl::HasValidNativeNode(void) const
4482 {
4483         if (__pWebCore && __pWebCore->GetWebNativeNode())
4484         {
4485                 return true;
4486         }
4487
4488         return false;
4489 }
4490
4491
4492 result
4493 _WebImpl::OnPreAttachedToMainTree(void)
4494 {
4495         result r = E_SUCCESS;
4496
4497         r = __pWebCore->InitializeWebNativeNode();
4498         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4499
4500         r = InitializeSetting();
4501         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4502
4503         r = _ContainerImpl::OnPreAttachedToMainTree();
4504         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4505
4506         return E_SUCCESS;
4507 }
4508
4509
4510 void
4511 _WebImpl::OnChangeLayout(_ControlOrientation orientation)
4512 {
4513         _ContainerImpl::OnChangeLayout(orientation);
4514
4515         if (__pColorPicker.get())
4516         {
4517                 __pColorPicker->ChangeLayout(orientation);
4518         }
4519
4520         __isOrientationChanged = true;
4521 }
4522
4523
4524 void
4525 _WebImpl::OnAncestorVisibleStateChanged(const _Control& control)
4526 {
4527         if (IsVisible() == true)
4528         {
4529                 ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
4530         }
4531         else
4532         {
4533                 ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
4534         }
4535 }
4536
4537
4538 _WebDataHandler*
4539 _WebImpl::GetDownloadHandler(void) const
4540 {
4541         return __pWebDownloadHandler.get();
4542 }
4543
4544
4545 Eina_Bool
4546 _WebImpl::HideColorPicker(void)
4547 {
4548         __pColorPicker.reset();
4549
4550         return EINA_TRUE;
4551 }
4552
4553
4554 result
4555 _WebImpl::ShowColorPicker(int red, int green, int blue, int alpha, Color& color)
4556 {
4557         result r = E_SUCCESS;
4558
4559         std::unique_ptr<_InputPickerPopup> pColorHadler(new (std::nothrow) _InputPickerPopup());
4560         SysTryReturnResult(NID_WEB_CTRL, pColorHadler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4561
4562         Tizen::Graphics::Color colorVal(static_cast< byte >(red), static_cast< byte >(green), static_cast< byte >(blue), static_cast< byte >(alpha));
4563
4564         r = pColorHadler->Construct(colorVal, this);
4565         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4566
4567         __pColorPicker = std::move(pColorHadler);
4568
4569         r = __pColorPicker->ShowPopup();
4570         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4571
4572         color = __pColorPicker->GetColor();
4573
4574         return E_SUCCESS;
4575
4576 CATCH:
4577         __pColorPicker.reset();
4578
4579         return r;
4580 }
4581
4582
4583 result
4584 _WebImpl::ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue, String& dateStr)
4585 {
4586         result r = E_SUCCESS;
4587
4588         std::unique_ptr<_InputPickerPopup> pInputPicker(new (std::nothrow) _InputPickerPopup());
4589         SysTryReturnResult(NID_WEB_CTRL, pInputPicker.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4590
4591         r = pInputPicker->Construct(String(inputValue), inputType, this);
4592         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4593
4594         __pDatePicker = std::move(pInputPicker);
4595
4596         r = __pDatePicker->ShowPopup();
4597         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4598
4599         dateStr = __pDatePicker->GetDate();
4600
4601 CATCH:
4602         __pDatePicker.reset();
4603
4604         return r;
4605 }
4606
4607
4608 _WebImpl*
4609 _WebImpl::GetInstance(Web* pWeb)
4610 {
4611         return dynamic_cast< _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
4612 }
4613
4614
4615 const _WebImpl*
4616 _WebImpl::GetInstance(const Web* pWeb)
4617 {
4618         return dynamic_cast< const _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
4619 }
4620
4621
4622 int 
4623 _WebImpl::SearchHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
4624 {
4625         int checkReturn = 0;
4626         _DatabaseImpl db;
4627         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
4628
4629         String table;
4630         if( checkmime == true)
4631         {
4632                 table = CUSTOM_CONTENT_TABLE_NAME;
4633         }
4634         else
4635         {
4636                 table = CUSTOM_PROTOCOL_TABLE_NAME;
4637         }
4638         
4639         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
4640         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
4641         String target(ewk_custom_handlers_data_target_get(pHandlerData));
4642
4643         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
4644         
4645         result r = db.Construct(handlerPath, "r+", null);
4646         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
4647
4648         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select allow From " + table + L" Where baseUrl = '" + baseUri + L"' AND url = '" + uri + L"' AND mime = '" + target + L"'"));
4649         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4650
4651         if(pEnum.get())
4652         {
4653                 r = pEnum->MoveNext();
4654                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
4655                 r = pEnum->GetIntAt(0, checkReturn);
4656                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
4657         }
4658         else
4659         {
4660                 checkReturn = 2;
4661         }
4662
4663         return checkReturn;
4664 }
4665
4666
4667 result 
4668 _WebImpl::UnregistrationHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
4669 {
4670         int checkId = 0;
4671         _DatabaseImpl db;
4672         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
4673
4674         String table;
4675         if( checkmime == true)
4676         {
4677                 table = CUSTOM_CONTENT_TABLE_NAME;
4678         }
4679         else
4680         {
4681                 table = CUSTOM_PROTOCOL_TABLE_NAME;
4682         }
4683
4684         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
4685         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
4686         String target(ewk_custom_handlers_data_target_get(pHandlerData));
4687         
4688         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
4689         
4690         result r = db.Construct(handlerPath, "r+", null);
4691         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4692
4693         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"'"));
4694         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4695
4696         if(pEnum.get())
4697         {
4698                 r = pEnum->MoveNext();
4699                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4700                 r = pEnum->GetIntAt(0, checkId);
4701                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4702                 
4703                 std::unique_ptr<DbStatement> pDeleteStmt(db.CreateStatementN(L"Delete From " + table + L" Where id = (?)"));
4704                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4705
4706                 r = pDeleteStmt->BindInt(0, checkId);
4707                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4708                 
4709                 db.BeginTransaction();
4710                 
4711                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pDeleteStmt));
4712                 
4713                 db.CommitTransaction();
4714         }
4715
4716         return E_SUCCESS;
4717 }
4718
4719
4720 const Tizen::Base::String 
4721 _WebImpl::GetProtocolFromUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri)
4722 {
4723         if (originUri == L"" || currentUri == L"")
4724         {
4725                 return L"";
4726         }
4727
4728         result r = E_SUCCESS;
4729         String baseUri;
4730         _DatabaseImpl db;
4731         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
4732         String originReplace(originUri);
4733         String table(CUSTOM_PROTOCOL_TABLE_NAME);
4734         int found = 0;
4735         int foundQuery = 0;
4736
4737         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
4738         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4739         
4740         r = currentUri.SubString(0, found + 1, baseUri);
4741         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4742                 
4743         r = db.Construct(handlerPath, "r+", null);
4744         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4745         
4746         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select mime, url, allow From " + table + L" Where baseUrl = '" + baseUri + "'"));
4747         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, L"", GetLastResult(), "[%s] Propagating.", GetErrorMessage(r));
4748
4749         if(pEnum.get())
4750         {
4751                 while (pEnum->MoveNext() == E_SUCCESS)
4752                 {                       
4753                         String protocol;
4754                         String queryUrl;
4755                         int allow;
4756                         String originScheme;
4757
4758                         r = pEnum->GetStringAt(0, protocol);
4759                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4760                 
4761                         r = pEnum->GetStringAt(1, queryUrl);
4762                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4763                         
4764                         r = pEnum->GetIntAt(2, allow);
4765                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4766
4767                         if (allow == 0)
4768                         {
4769                                 break;
4770                         }
4771
4772                         String protocolScheme(protocol + L":");
4773                         
4774                         r = originReplace.SubString(0, protocolScheme.GetLength(), originScheme);
4775                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4776                                                 
4777                         if ((originReplace.GetLength() >= protocolScheme.GetLength()) && originScheme.Equals(protocolScheme, false))
4778                         {
4779                                 if (queryUrl.IndexOf(L"%s", 0, foundQuery) == E_SUCCESS)
4780                                 {
4781                                         r = originReplace.Replace(originScheme, "");
4782                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4783                                         
4784                                         queryUrl.Replace("%s", originReplace, 0);
4785                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4786
4787                                         return queryUrl;
4788                                 }
4789                         }               
4790                 }
4791         }
4792         
4793         return L"";
4794 }
4795
4796
4797 const Tizen::Base::String 
4798 _WebImpl::GetRedirectUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri, const Tizen::Base::String& mime)
4799 {
4800         if (originUri == L"" || currentUri == L"" || mime == L"")
4801         {
4802                 return L"";
4803         }
4804
4805         result r = E_SUCCESS;
4806         String baseUri;
4807         String contentUrl;
4808         String originUrlStr = originUri;
4809         const String replaceStr = L"%s";
4810         _DatabaseImpl db;
4811         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
4812         String table(CUSTOM_CONTENT_TABLE_NAME);
4813         int allow = 0;
4814         int found = 0;
4815         
4816         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
4817         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4818                 
4819         r = currentUri.SubString(0, found + 1, baseUri);
4820         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4821                 
4822         r = db.Construct(handlerPath, "r+", null);
4823         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4824
4825         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select allow, url From " + table + L" Where baseUrl = '" + baseUri + "' AND mime = '" + mime + L"'"));
4826         
4827         if (pEnum.get())
4828         {
4829                 r = pEnum->MoveNext();
4830                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4831                 r = pEnum->GetIntAt(0, allow);
4832                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4833                 r = pEnum->GetStringAt(1, contentUrl);
4834                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4835                         
4836                 if (allow == 0)
4837                 {
4838                         return L"";
4839                 }
4840                 else
4841                 {
4842                         if (contentUrl != L"")
4843                         {
4844                                 r = contentUrl.Replace(replaceStr, originUrlStr, 0);
4845                                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
4846
4847                                 return contentUrl;
4848                         }
4849                 }
4850         }
4851         
4852         return L"";
4853 }
4854
4855
4856 }}} // Tizen::Web::Controls