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