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