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