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