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