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