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