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