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