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