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