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