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