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