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