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