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