patch for rc20
[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         int itemCount = eina_list_count(pItems);
2607         int defaultCount = (itemCount < DEFAULT_LIST_ITEM_COUNT) ? itemCount : (isMultiSelect ? (DEFAULT_LIST_ITEM_COUNT - 1) : DEFAULT_LIST_ITEM_COUNT);
2608         r = pSelectBox->Construct(this, isMultiSelect, title, defaultCount, pWebView);
2609
2610         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2611
2612         r = pSelectBox->UpdateList(pItems, selectedIndex, false, false);
2613         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2614
2615         __pSelectBox = std::move(pSelectBox);
2616
2617         return __pSelectBox->ShowPopup();
2618 }
2619
2620
2621 result
2622 _WebImpl::UpdateSelectBoxPopup(Eina_List* pItems, int selectedIndex, bool isGroupedList)
2623 {
2624         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2625
2626         return __pSelectBox->UpdateList(pItems, selectedIndex, true, isGroupedList);
2627 }
2628
2629
2630 result
2631 _WebImpl::ClearSelectBoxPopup(void)
2632 {
2633         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2634
2635         __pSelectBox.reset();
2636
2637         Resume();
2638
2639         return E_SUCCESS;
2640 }
2641
2642
2643 _InputPickerPopup*
2644 _WebImpl::GetDatepicker(void)
2645 {
2646         _InputPickerPopup* pInputPicker =null;
2647         if (__pDatePicker)
2648         {
2649                 pInputPicker =  __pDatePicker.get();
2650         }
2651         return pInputPicker;
2652 }
2653
2654
2655 _InputPickerPopup*
2656 _WebImpl::GetColorpicker(void)
2657 {
2658         _InputPickerPopup* pInputPicker =null;
2659         if (__pColorPicker)
2660         {
2661                 pInputPicker =  __pColorPicker.get();
2662         }
2663         return pInputPicker;
2664 }
2665
2666
2667 bool
2668 _WebImpl::CanGoBack(void) const
2669 {
2670         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2671         if (!pWebview)
2672         {
2673                 return false;
2674         }
2675
2676         return static_cast< bool >(ewk_view_back_possible(pWebview));
2677 }
2678
2679
2680 bool
2681 _WebImpl::CanGoForward(void) const
2682 {
2683         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2684         if (!pWebview)
2685         {
2686                 return false;
2687         }
2688
2689         return static_cast< bool >(ewk_view_forward_possible(pWebview));
2690 }
2691
2692
2693 void
2694 _WebImpl::GoBack(void) const
2695 {
2696         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2697         if (!pWebview)
2698         {
2699                 return;
2700         }
2701
2702         ewk_view_back(pWebview);
2703 }
2704
2705
2706 void
2707 _WebImpl::GoForward(void) const
2708 {
2709         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2710         if (!pWebview)
2711         {
2712                 return;
2713         }
2714
2715         ewk_view_forward(pWebview);
2716 }
2717
2718
2719 Tizen::Base::String
2720 _WebImpl::GetUrl(void) const
2721 {
2722         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2723         if (!pWebview)
2724         {
2725                 return L"";
2726         }
2727
2728         return ewk_view_url_get(pWebview);
2729 }
2730
2731
2732 Tizen::Base::String
2733 _WebImpl::GetTitle(void) const
2734 {
2735         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2736         if (!pWebview)
2737         {
2738                 return L"";
2739         }
2740
2741         return ewk_view_title_get(pWebview);
2742 }
2743
2744
2745 void
2746 _WebImpl::StopLoading(void) const
2747 {
2748         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2749         if (!pWebview)
2750         {
2751                 return;
2752         }
2753
2754         ewk_view_stop(pWebview);
2755 }
2756
2757
2758 void
2759 _WebImpl::Reload(void) const
2760 {
2761         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2762         if (!pWebview)
2763         {
2764                 return;
2765         }
2766
2767         ewk_view_reload(pWebview);
2768 }
2769
2770
2771 String*
2772 _WebImpl::EvaluateJavascriptN(const String& scriptCode)
2773 {
2774         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2775         if (!pWebview)
2776         {
2777                 return null;
2778         }
2779         
2780         std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
2781         SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2782
2783         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
2784         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2785
2786         ewk_view_script_execute(pWebview, pScript.get(), OnScriptExecuted, pPresenter.get());
2787
2788         String* pResult = new (std::nothrow) String(L"");
2789         SysTryReturn(NID_WEB_CTRL, pResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2790
2791         pPresenter->WaitAsyncProcess(*pResult);
2792
2793         return pResult;
2794 }
2795
2796
2797 result
2798 _WebImpl::SetZoomLevel(float level)
2799 {
2800         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2801         if (!pWebview)
2802         {
2803                 return E_SUCCESS;
2804         }
2805
2806         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);
2807
2808         ewk_view_scale_set(pWebview, static_cast< double >(level), 0, 0);
2809
2810         return E_SUCCESS;
2811 }
2812
2813
2814 float
2815 _WebImpl::GetZoomLevel(void) const
2816 {
2817         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2818         if (!pWebview)
2819         {
2820                 return -1.0f;
2821         }
2822
2823         return static_cast< float >(ewk_view_scale_get(pWebview));
2824 }
2825
2826
2827 const PageNavigationList*
2828 _WebImpl::GetBackForwardListN(void) const
2829 {
2830         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2831         if (!pWebview)
2832         {
2833                 return null;
2834         }
2835
2836         result r = E_SUCCESS;
2837
2838         _PageNavigationListImpl* pNavigationListImpl = null;
2839         _HistoryItemImpl* pHistoryItemImpl = null;
2840
2841         std::unique_ptr<PageNavigationList> pNavigationList;
2842         std::unique_ptr<ArrayList, AllElementsDeleter> pHistoryList;
2843
2844         int backCount = 0;
2845         int forwardCount = 0;
2846
2847         String url(L"");
2848         String title(L"");
2849
2850         Ewk_History* pEwkHistoryList = ewk_view_history_get(pWebview);
2851         SysTryReturn(NID_WEB_CTRL, pEwkHistoryList, null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get full history.", GetErrorMessage(E_SYSTEM));
2852
2853         Ewk_History_Item* pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, 0);
2854         SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_DATA_NOT_FOUND, "[%s] There is no history.", GetErrorMessage(E_DATA_NOT_FOUND));
2855
2856         pNavigationList = std::unique_ptr<PageNavigationList>(new (std::nothrow) PageNavigationList());
2857         SysTryCatch(NID_WEB_CTRL, pNavigationList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2858
2859         pNavigationListImpl = _PageNavigationListImpl::GetInstance(pNavigationList.get());
2860         SysTryCatch(NID_WEB_CTRL, pNavigationListImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2861
2862         pHistoryList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
2863         SysTryCatch(NID_WEB_CTRL, pHistoryList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2864
2865         r = pHistoryList->Construct();
2866         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2867
2868         backCount = ewk_history_back_list_length_get(pEwkHistoryList);
2869         forwardCount = ewk_history_forward_list_length_get(pEwkHistoryList);
2870         SysLog(NID_WEB_CTRL, "The current value of backCount is %d, forwardCount is %d", backCount, forwardCount);
2871
2872         for (int i = -backCount; i < forwardCount + 1; i++)
2873         {
2874                 std::unique_ptr<HistoryItem> pHistoryItem(new (std::nothrow) HistoryItem());
2875                 SysTryCatch(NID_WEB_CTRL, pHistoryItem.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2876
2877                 pHistoryItemImpl = _HistoryItemImpl::GetInstance(pHistoryItem.get());
2878                 SysTryCatch(NID_WEB_CTRL, pHistoryItemImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2879
2880                 pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, i);
2881                 SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2882
2883                 url = ewk_history_item_uri_get(pEwkItem);
2884                 title = ewk_history_item_title_get(pEwkItem);
2885                 SysSecureLog(NID_WEB_CTRL, "The current value of url is %s, title is %s", url.GetPointer(), title.GetPointer());
2886
2887                 pHistoryItemImpl->SetHistoryItem(url, title);
2888
2889                 r = pHistoryList->Add(*pHistoryItem.get());
2890                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2891                 pHistoryItem.release();
2892         }
2893
2894         pNavigationListImpl->SetPageNavigationList(pHistoryList.release(), backCount);
2895
2896         ewk_history_free(pEwkHistoryList);
2897
2898         return pNavigationList.release();
2899
2900 CATCH:
2901         ewk_history_free(pEwkHistoryList);
2902
2903         return null;
2904 }
2905
2906
2907 bool
2908 _WebImpl::SearchText(const String& text, bool searchForward)
2909 {
2910         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2911         if (!pWebview)
2912         {
2913                 return false;
2914         }
2915
2916         result r = E_SUCCESS;
2917
2918         Ewk_Find_Options condition = static_cast< Ewk_Find_Options >(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2919
2920         if (!searchForward)
2921         {
2922             condition = static_cast < Ewk_Find_Options >(condition | EWK_FIND_OPTIONS_BACKWARDS);
2923         }
2924
2925         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
2926         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2927
2928         r = SynchronizeSearch(SEARCH_SYNC, pWebview, condition, text, searchForward, false, pPresenter.get());
2929         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2930
2931         int result = 0;
2932         pPresenter->WaitAsyncProcess(result);
2933
2934         return static_cast < bool >(result);
2935 }
2936
2937
2938 result
2939 _WebImpl::SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive)
2940 {
2941         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2942         if (!pWebview)
2943         {
2944                 return E_SUCCESS;
2945         }
2946
2947         result r = E_SUCCESS;
2948
2949         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2950
2951         if (!caseSensitive)
2952         {
2953             condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2954         }
2955
2956         r = SynchronizeSearch(SEARCH_ALL_ASYNC, pWebview, condition, text, true, caseSensitive);
2957         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2958
2959         return E_SUCCESS;
2960 }
2961
2962
2963 result
2964 _WebImpl::SearchNextAsync(bool searchForward)
2965 {
2966         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
2967         if (!pWebview)
2968         {
2969                 return E_SUCCESS;
2970         }
2971
2972         SysTryReturnResult(NID_WEB_CTRL, __textSearch.__searchAll && __textSearch.__totalCount > -1, E_INVALID_OPERATION, "The SearchTextAllAsync() method is not called or completed.");
2973         SysTryReturnResult(NID_WEB_CTRL, (searchForward && __textSearch.__currentIndex < __textSearch.__totalCount) || (!searchForward && __textSearch.__currentIndex > 1)
2974                 , E_OBJ_NOT_FOUND,  "The Next instance is not available.");
2975
2976         result r = E_SUCCESS;
2977
2978         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2979
2980         if (!__textSearch.__caseSensitive)
2981         {
2982                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2983         }
2984
2985         if (!searchForward)
2986         {
2987                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_BACKWARDS);
2988         }
2989
2990         r = SynchronizeSearch(SEARCH_NEXT_ASYNC, pWebview, condition, __textSearch.__text, searchForward);
2991         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2992
2993         return E_SUCCESS;
2994 }
2995
2996
2997 result
2998 _WebImpl::SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Options condition, const Tizen::Base::String& text, bool searchForward, bool caseSensitive,  _WebPresenter* pWebPresenter)
2999 {
3000         MutexGuard lock(__mutex);
3001
3002         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(text));
3003         SysTryReturn(NID_WEB_CTRL, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3004
3005         switch (type)
3006         {
3007         case SEARCH_SYNC:
3008                 if (__textSearch.__searchAll)
3009                 {
3010                         DisableAsyncSearch();
3011
3012                         __textSearch.__searchQueue.Enqueue(this);
3013                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
3014
3015                         ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
3016                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
3017                 }
3018                 else
3019                 {
3020                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
3021
3022                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
3023                 }
3024                 break;
3025
3026         case SEARCH_ALL_ASYNC:
3027                 __textSearch.__searchAll = true;
3028                 __textSearch.__text = text;
3029                 __textSearch.__searchForward = true;
3030                 __textSearch.__caseSensitive = caseSensitive;
3031                 __textSearch.__totalCount = -1;
3032                 __textSearch.__currentIndex = 1;
3033
3034                 __textSearch.__searchQueue.Enqueue(this);
3035                 __textSearch.__searchQueue.Enqueue(this);
3036
3037                 ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
3038                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
3039                 break;
3040
3041         case SEARCH_NEXT_ASYNC:
3042                 __textSearch.__searchForward = searchForward;
3043
3044                 CalculateAsyncSearchOrdinal();
3045
3046                 __textSearch.__searchQueue.Enqueue(this);
3047
3048                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
3049                 break;
3050
3051         default:
3052                 SysAssert(false);
3053         }
3054
3055         return E_SUCCESS;
3056 }
3057
3058
3059 void
3060 _WebImpl::SetAsyncSearchResult(int totalCount)
3061 {
3062         __textSearch.__totalCount = totalCount;
3063 }
3064
3065
3066 _WebPresenter*
3067 _WebImpl::GetSearchPresenter(void)
3068 {
3069         MutexGuard lock(__mutex);
3070
3071         return dynamic_cast< _WebPresenter* >(__textSearch.__searchQueue.Dequeue());
3072 }
3073
3074
3075  int
3076  _WebImpl::GetPendingAsyncSearchCount(void) const
3077 {
3078         return __textSearch.__searchQueue.GetCount();
3079 }
3080
3081
3082 void
3083 _WebImpl::CalculateAsyncSearchOrdinal(void)
3084 {
3085         if (__textSearch.__searchForward)
3086         {
3087                 __textSearch.__currentIndex++;
3088         }
3089         else
3090         {
3091                 __textSearch.__currentIndex--;
3092         }
3093 }
3094
3095
3096  int
3097  _WebImpl::GetAsyncSearchOrdinal(void) const
3098 {
3099         return __textSearch.__currentIndex;
3100 }
3101
3102
3103  void
3104  _WebImpl::DisableAsyncSearch(void)
3105 {
3106         __textSearch.__searchAll = false;
3107 }
3108
3109
3110 result
3111 _WebImpl::SetSetting(const WebSetting& setting)
3112 {
3113         if (__pWebCore->GetWebNativeNode())
3114         {
3115                 Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3116                 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
3117                 SysAssertf(pContext && pSettings, "Failed to get webkit instance.");
3118
3119                 std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(setting.GetDefaultTextEncoding()));
3120                 SysTryReturn(NID_WEB_CTRL, pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3121
3122                 ewk_settings_default_encoding_set(pSettings, pEncoding.get());
3123
3124                 switch (setting.GetCacheControl())
3125                 {
3126                 case WEB_CACHE_VALIDATED:
3127                         ewk_context_cache_disabled_set(pContext, EINA_FALSE);
3128                         break;
3129
3130                 case WEB_CACHE_IGNORE:
3131                         ewk_context_cache_disabled_set(pContext, EINA_TRUE);
3132                         break;
3133
3134                 default:
3135                         SysAssert(false);
3136                 }
3137
3138                 if (setting.GetInputStyle() == INPUT_STYLE_OVERLAY)
3139                 {
3140                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_TRUE);
3141                 }
3142                 else
3143                 {
3144                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_FALSE);
3145                 }
3146
3147                 ewk_settings_font_default_size_set(pSettings, static_cast< Eina_Bool >(setting.GetFontSize()));
3148
3149                 ewk_settings_javascript_enabled_set(pSettings, static_cast< Eina_Bool >(setting.IsJavascriptEnabled()));
3150
3151                 ewk_settings_loads_images_automatically_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoImageLoadEnabled()));
3152
3153                 if (__defaultUserAgent != setting.GetUserAgent())
3154                 {
3155                         std::unique_ptr<char[]> pAgent(_StringConverter::CopyToCharArrayN(setting.GetUserAgent()));
3156                         SysTryReturn(NID_WEB_CTRL, pAgent.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3157
3158                         ewk_view_user_agent_set(__pWebCore->GetWebNativeNode(), pAgent.get());
3159                 }
3160
3161                 ewk_settings_auto_fitting_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoFittingEnabled()));
3162
3163                 ewk_settings_scripts_window_open_set(pSettings,  static_cast< Eina_Bool >(setting.IsJavaScriptPopupEnabled()));
3164
3165                 ewk_settings_form_candidate_data_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoFormDataShowEnabled()));
3166
3167                 ewk_settings_autofill_password_form_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoLoginFormFillEnabled()));
3168         }
3169
3170         _WebSettingImpl* pWebSettingImpl = _WebSettingImpl::GetInstance(__pWebCore->GetSetting());
3171
3172         pWebSettingImpl->SetCertificateErrorHandlingMode(setting.GetCertificateErrorHandlingMode());
3173         pWebSettingImpl->SetDefaultTextEncoding(setting.GetDefaultTextEncoding());
3174         pWebSettingImpl->SetCacheControl(setting.GetCacheControl());
3175         pWebSettingImpl->SetFontSize(setting.GetFontSize());
3176         pWebSettingImpl->SetJavascriptEnabled(setting.IsJavascriptEnabled());
3177         pWebSettingImpl->SetAutoImageLoadEnabled(setting.IsAutoImageLoadEnabled());
3178         pWebSettingImpl->SetInputStyle(setting.GetInputStyle());
3179         pWebSettingImpl->SetUserAgent(setting.GetUserAgent());
3180         pWebSettingImpl->SetAutoFittingEnabled(setting.IsAutoFittingEnabled());
3181         pWebSettingImpl->SetJavaScriptPopupEnabled(setting.IsJavaScriptPopupEnabled());
3182         pWebSettingImpl->SetGeolocationEnabled(setting.IsGeolocationEnabled());
3183         pWebSettingImpl->SetAutoFormDataShowEnabled(setting.IsAutoFormDataShowEnabled());
3184         pWebSettingImpl->SetAutoLoginFormFillEnabled(setting.IsAutoLoginFormFillEnabled());
3185
3186         return E_SUCCESS;
3187 }
3188
3189
3190 WebSetting
3191 _WebImpl::GetSetting(void) const
3192 {
3193         return *__pWebCore->GetSetting();
3194 }
3195
3196
3197 const HitElementResult*
3198 _WebImpl::GetElementByPointN(const Point& point) const
3199 {
3200         return GetElementByPointN(_CoordinateSystemUtils::ConvertToFloat(point));
3201 }
3202
3203
3204 const HitElementResult*
3205 _WebImpl::GetElementByPointN(const FloatPoint& point) const
3206 {
3207         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3208         if (!pWebview)
3209         {
3210                 return null;
3211         }
3212
3213         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));
3214
3215         result r = E_SUCCESS;
3216
3217         _HitElementResultImpl* pHitElementResultImpl = null;
3218
3219         std::unique_ptr<HitElementResult> pHitElementResult;
3220         std::unique_ptr<Bitmap> pImage;
3221         std::unique_ptr<HashMap, AllElementsDeleter> pAttributeMap;
3222
3223         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(point)));
3224
3225         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pWebview, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
3226         SysTryReturn(NID_WEB_CTRL, pEwkHitTest, null, E_SYSTEM, "[%s] Failed to get hit test.", GetErrorMessage(E_SYSTEM));
3227
3228         Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
3229         Ewk_Hit_Test_Result_Context context = ewk_hit_test_result_context_get(pEwkHitTest);
3230         String url(ewk_hit_test_link_uri_get(pEwkHitTest));
3231         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
3232         String nodeValue(ewk_hit_test_node_value_get(pEwkHitTest));
3233
3234         SysSecureLog(NID_WEB_CTRL, "The current value of url is %ls, tag is %ls, value is %ls", url.GetPointer(), tagName.GetPointer(), nodeValue.GetPointer());
3235
3236         pHitElementResult = std::unique_ptr<HitElementResult>(new (std::nothrow) HitElementResult());
3237         SysTryCatch(NID_WEB_CTRL, pHitElementResult.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3238
3239         pHitElementResultImpl = _HitElementResultImpl::GetInstance(pHitElementResult.get());
3240         SysTryCatch(NID_WEB_CTRL, pHitElementResultImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3241
3242         if (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
3243         {
3244                 ByteBuffer buf;
3245                 Image image;
3246                 ImageFormat format;
3247
3248                 int imageLength = ewk_hit_test_image_buffer_length_get(pEwkHitTest);
3249                 void* pImageBuffer = ewk_hit_test_image_buffer_get(pEwkHitTest);
3250                 const char* pExtension = ewk_hit_test_image_file_name_extension_get(pEwkHitTest);
3251                 SysLog(NID_WEB_CTRL, "The current value of imageBuffer is %u, bufferLength is %d, extension is %s", pImageBuffer, imageLength, pExtension);
3252
3253                 r = buf.Construct(imageLength);
3254                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3255
3256                 r = buf.SetArray(reinterpret_cast< byte* >(pImageBuffer), 0, imageLength);
3257                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3258
3259                 buf.Rewind();
3260
3261 //              ToDo : webkit doesn't support types such as IMG_FORMAT_WBMP and IMG_FORMAT_TIFF
3262 //              webkit support types such as ico and vp8 additionally
3263                 if (strcmp(pExtension, "gif") == 0)
3264                 {
3265                         format = IMG_FORMAT_GIF;
3266                 }
3267                 else if (strcmp(pExtension, "jpg") == 0)
3268                 {
3269                         format = IMG_FORMAT_JPG;
3270                 }
3271                 else if (strcmp(pExtension, "png") == 0)
3272                 {
3273                         format = IMG_FORMAT_PNG;
3274                 }
3275                 else if (strcmp(pExtension, "bmp") == 0)
3276                 {
3277                         format = IMG_FORMAT_BMP;
3278                 }
3279                 else
3280                 {
3281                         SysLogException(NID_WEB_CTRL, E_UNSUPPORTED_FORMAT, "[%s] The %s format is not supported", GetErrorMessage(E_UNSUPPORTED_FORMAT), pExtension);
3282                         goto CATCH;
3283                 }
3284
3285                 r = image.Construct();
3286                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3287
3288                 pImage = std::unique_ptr<Bitmap>(image.DecodeN(buf, format, BITMAP_PIXEL_FORMAT_RGB565));
3289                 SysTryCatch(NID_WEB_CTRL, pImage.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3290         }
3291
3292         if (pAttrHash)
3293         {
3294                 pAttributeMap = std::unique_ptr<HashMap, AllElementsDeleter>(new (std::nothrow) HashMap());
3295                 SysTryCatch(NID_WEB_CTRL, pAttributeMap.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3296
3297                 r = pAttributeMap->Construct(eina_hash_population(pAttrHash));
3298                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3299
3300                 eina_hash_foreach(pAttrHash, AddHttpAttributeData, pAttributeMap.get());
3301                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3302         }
3303
3304         pHitElementResultImpl->SetHitElementResult(pAttributeMap.release(), pImage.release(), tagName, nodeValue, url);
3305
3306         ewk_hit_test_free(pEwkHitTest);
3307
3308         return pHitElementResult.release();
3309
3310 CATCH:
3311         ewk_hit_test_free(pEwkHitTest);
3312
3313         return null;
3314 }
3315
3316
3317 bool
3318 _WebImpl::IsLoading(void) const
3319 {
3320         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3321         if (!pWebview)
3322         {
3323                 return false;
3324         }
3325
3326         double percent = ewk_view_load_progress_get(pWebview);
3327
3328         if (Double::Compare(percent, 0.0) > 0 && Double::Compare(percent, 1.0) < 0)
3329         {
3330                 return true;
3331         }
3332         else
3333         {
3334                 return false;
3335         }
3336 }
3337
3338
3339 String
3340 _WebImpl::GetTextFromBlock(void) const
3341 {
3342         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3343         if (!pWebview)
3344         {
3345                 return L"";
3346         }
3347
3348         return ewk_view_text_selection_text_get(pWebview);
3349 }
3350
3351
3352 bool
3353 _WebImpl::IsPrivateBrowsingEnabled(void) const
3354 {
3355         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3356         if (!pWebview)
3357         {
3358                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsPrivateBrowsingEnabled();
3359         }
3360
3361         Ewk_Settings* pSettings = ewk_view_settings_get(pWebview);
3362         SysAssertf(pSettings, "Failed to get webkit instance.");
3363
3364         return static_cast< bool >(ewk_settings_private_browsing_enabled_get(pSettings));
3365 }
3366
3367
3368 void
3369 _WebImpl::SetPrivateBrowsingEnabled(bool enable)
3370 {
3371         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3372         if (!pWebview)
3373         {
3374                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetPrivateBrowsingEnabled(enable);
3375
3376                 return;
3377         }
3378
3379         Ewk_Settings* pSettings = ewk_view_settings_get(pWebview);
3380         SysAssertf(pSettings, "Failed to get webkit instance.");
3381
3382         ewk_settings_private_browsing_enabled_set(pSettings, static_cast< Eina_Bool >(enable));
3383 }
3384
3385
3386 void
3387 _WebImpl::ClearHistory(void)
3388 {
3389         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3390         if (!pWebview)
3391         {
3392                 return;
3393         }
3394
3395         ewk_view_back_forward_list_clear(pWebview);
3396 }
3397
3398
3399 void
3400 _WebImpl::ClearCache(void)
3401 {
3402         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3403         if (!pWebview)
3404         {
3405                 return;
3406         }
3407
3408         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3409
3410         ewk_context_cache_clear(pContext);
3411 }
3412
3413
3414 void
3415 _WebImpl::ClearCookie(void)
3416 {
3417         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3418         if (!pWebview)
3419         {
3420                 return;
3421         }
3422
3423         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3424         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3425
3426         ewk_cookie_manager_cookies_clear(pCookieManager);
3427 }
3428
3429
3430 void
3431 _WebImpl::ClearFormData(void)
3432 {
3433         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3434         if (!pWebview)
3435         {
3436                 return;
3437         }
3438
3439         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3440
3441         ewk_context_form_candidate_data_clear(pContext);
3442 }
3443
3444
3445 void
3446 _WebImpl::ClearLoginFormData(void)
3447 {
3448         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3449         if (!pWebview)
3450         {
3451                 return;
3452         }
3453
3454         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3455
3456         ewk_context_form_password_data_clear(pContext);
3457 }
3458
3459
3460 bool
3461 _WebImpl::IsCookieEnabled(void) const
3462 {
3463         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3464         if (!pWebview)
3465         {
3466                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsCookieEnabled();
3467         }
3468
3469         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3470         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3471         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3472
3473         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
3474         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3475
3476         ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, pPresenter.get());
3477
3478         bool result = false;
3479         pPresenter->WaitAsyncProcess(result);
3480
3481         return result;
3482 }
3483
3484
3485 void
3486 _WebImpl::SetCookieEnabled(bool enable)
3487 {
3488         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3489         if (!pWebview)
3490         {
3491                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetCookiEnabled(enable);
3492
3493                 return;
3494         }
3495
3496         Ewk_Context* pContext = ewk_view_context_get(pWebview);
3497         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3498         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3499
3500         if (enable)
3501         {
3502                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
3503         }
3504         else
3505         {
3506                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_NEVER);
3507                 ewk_cookie_manager_cookies_clear(pCookieManager);
3508         }
3509 }
3510
3511
3512 result 
3513 _WebImpl::SavePageAsPdf(const String& filePath, const Dimension* pSize) const
3514 {
3515         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3516         if (!pWebview)
3517         {
3518                 return E_SUCCESS;
3519         }
3520
3521         result r = E_SUCCESS;
3522
3523         std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
3524         SysTryReturn(NID_WEB_CTRL, pFilePath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3525
3526         String dirPath;
3527         String fileExtension = File::GetFileExtension(filePath);
3528         int pathLength = filePath.GetLength();
3529         int index = 0;
3530
3531         SysTryReturnResult(NID_WEB_CTRL, fileExtension.Equals("pdf", false), E_INVALID_ARG, "Invalid argument(s) is used. File extension is not pdf.");
3532
3533         r = filePath.LastIndexOf(L"/", pathLength - 1, index);
3534         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3535         r = filePath.SubString(0, index + 1, dirPath);
3536         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3537
3538         std::unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(dirPath));
3539         SysTryReturnResult(NID_WEB_CTRL, access(pDirPath.get(), W_OK) == 0, E_INACCESSIBLE_PATH, "Directory permission is read-only.");
3540
3541         if (pSize)
3542         {
3543                 SysTryReturnResult(NID_WEB_CTRL, pSize->width > 0 && pSize->height > 0, E_INVALID_ARG, "Invalid argument(s) is used. Size of pdf file is invalid.");
3544
3545                 ewk_view_contents_pdf_get(pWebview, pSize->width, pSize->height, pFilePath.get());
3546         }
3547         else
3548         {
3549                 Evas_Coord contentsWidth;
3550                 Evas_Coord contentsHeight;
3551
3552                 ewk_view_contents_size_get(pWebview, &contentsWidth, &contentsHeight);
3553                 ewk_view_contents_pdf_get(pWebview, contentsWidth, contentsHeight, pFilePath.get());
3554         }
3555
3556         return E_SUCCESS;
3557 }
3558
3559
3560 bool
3561 _WebImpl::IsMimeSupported(const String& mime) const
3562 {
3563         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3564         if (!pWebview)
3565         {
3566                 return false;
3567         }
3568
3569         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
3570         SysTryReturn(NID_WEB_CTRL, pMime.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3571
3572         return static_cast< bool >(ewk_frame_can_show_mime_type(ewk_view_main_frame_get(pWebview), pMime.get()));
3573 }
3574
3575
3576 void
3577 _WebImpl::SetLoadingListener(ILoadingListener* pLoadingListener)
3578 {
3579         __pUserLoadingListener = const_cast< ILoadingListener* >(pLoadingListener);
3580 }
3581
3582
3583 void
3584 _WebImpl::SetWebUiEventListener(IWebUiEventListener* pUiEventListener)
3585 {
3586         __pUserUiListener = pUiEventListener;
3587 }
3588
3589
3590 void
3591 _WebImpl::SetWebUiEventListenerF(IWebUiEventListenerF* pUiEventListener)
3592 {
3593         __pUserUiListenerF = pUiEventListener;
3594 }
3595
3596
3597 void
3598 _WebImpl::SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener)
3599 {
3600         __pUserKeypadEventListener = pKeypadEventListener;
3601 }
3602
3603
3604 void
3605 _WebImpl::SetDownloadListener(IWebDownloadListener* pDownLoadListener)
3606 {
3607         if (__pWebDownloadHandler.get() == null)
3608         {
3609                 __pWebDownloadHandler = std::unique_ptr<_WebDataHandler>(new (std::nothrow) _WebDataHandler());
3610                 SysTryReturnVoidResult(NID_WEB_CTRL, __pWebDownloadHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3611         }
3612
3613         __pWebDownloadHandler->SetDownloadListener(pDownLoadListener);
3614         __pWebDownloadHandler->SetWebEvent(__pWebEvent.get());
3615 }
3616
3617
3618 void
3619 _WebImpl::SetTextSearchListener(ITextSearchListener* pTextSearchListener)
3620 {
3621         __pTextSearchListener = pTextSearchListener;
3622 }
3623
3624
3625 void
3626 _WebImpl::SetScrollEnabled(bool enable)
3627 {
3628         _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetScrollEnabled(enable);
3629 }
3630
3631
3632 bool
3633 _WebImpl::IsScrollEnabled(void) const
3634 {
3635         return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled();
3636 }
3637
3638
3639 result
3640 _WebImpl::InitJsBridgeList(void)
3641 {
3642         result r = E_SUCCESS;
3643
3644         __pJsProvider = std::unique_ptr<_JsBridgeHashCodeProvider>(new (std::nothrow) _JsBridgeHashCodeProvider());
3645         SysTryReturnResult(NID_WEB_CTRL, __pJsProvider.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3646
3647         __pJsComparer = std::unique_ptr<_JsBridgeComparer>(new (std::nothrow) _JsBridgeComparer());
3648         SysTryReturnResult(NID_WEB_CTRL, __pJsComparer.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3649
3650         std::unique_ptr<HashMapT< String, IJavaScriptBridge* > > pJsBridgeList(new (std::nothrow) HashMapT< String, IJavaScriptBridge* >);
3651         SysTryReturnResult(NID_WEB_CTRL, pJsBridgeList.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3652
3653         r = pJsBridgeList->Construct(0, 0, *__pJsProvider.get(), *__pJsComparer.get());
3654         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3655
3656         __pJsBridgeList = std::move(pJsBridgeList);
3657
3658         return E_SUCCESS;
3659 }
3660
3661
3662 result
3663 _WebImpl::AddJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3664 {
3665         result r = E_SUCCESS;
3666
3667         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3668         String key(pJsBridge->GetName());
3669
3670         r = __pJsBridgeList->Add(key, pJsBridge);
3671         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3672
3673         return E_SUCCESS;
3674 }
3675
3676
3677 result
3678 _WebImpl::RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3679 {
3680         result r = E_SUCCESS;
3681
3682         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3683         String key(pJsBridge->GetName());
3684
3685         r = __pJsBridgeList->Remove(key);
3686         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3687
3688         return E_SUCCESS;
3689 }
3690
3691
3692 IJavaScriptBridge*
3693 _WebImpl::FindJsInterface(const IJsonValue* pValue) const
3694 {
3695         result r = E_SUCCESS;
3696
3697         IJsonValue* pJsonValue = null;
3698         IJavaScriptBridge* pJsBridge = null;
3699
3700         String key(L"name");
3701
3702         const JsonObject* pJsonObject = dynamic_cast< const JsonObject* >(pValue);
3703         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));
3704
3705         r = pJsonObject->GetValue(&key, pJsonValue);
3706         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS && pJsonValue, null, r, "[%s] Propagating.", GetErrorMessage(r));
3707
3708         JsonString* pBridgeName = dynamic_cast< JsonString* >(pJsonValue);
3709         SysTryReturn(NID_WEB_CTRL, pBridgeName, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. name key is missing." , GetErrorMessage(E_INVALID_ARG));
3710
3711         r = __pJsBridgeList->GetValue(static_cast< String >(*pBridgeName), pJsBridge);
3712         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3713
3714         return pJsBridge;
3715 }
3716
3717
3718 ILoadingListener*
3719 _WebImpl::GetLoadingListener(void) const
3720 {
3721         return __pUserLoadingListener;
3722 }
3723
3724
3725 IWebUiEventListener*
3726 _WebImpl::GetUiEventListener(void) const
3727 {
3728         return __pUserUiListener;
3729 }
3730
3731
3732 IWebUiEventListenerF*
3733 _WebImpl::GetUiEventListenerF(void) const
3734 {
3735         return __pUserUiListenerF;
3736 }
3737
3738
3739 IWebKeypadEventListener*
3740 _WebImpl::GetWebKeypadEventListener(void) const
3741 {
3742         return __pUserKeypadEventListener;
3743 }
3744
3745
3746 ITextSearchListener*
3747 _WebImpl::GetTextSearchListener(void) const
3748 {
3749         return __pTextSearchListener;
3750 }
3751
3752
3753 void
3754 _WebImpl::SetEventListenerCallback(void) const
3755 {
3756         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3757         if (pWebNativeNode)
3758         {
3759                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3760                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3761
3762                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3763                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3764
3765                 Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
3766                 SysAssertf(pSmartData, "Failed to request");
3767
3768                 Ewk_View_Smart_Class *pSmart = const_cast<Ewk_View_Smart_Class*>(pSmartData->api);
3769                 SysAssertf(pSmart, "Failed to request");
3770
3771                 pSmart->popup_menu_show = OnSelectBoxRequested;
3772                 pSmart->multiple_popup_menu_show = OnMultiSelectBoxRequested;
3773                 pSmart->popup_menu_hide = OnSelectBoxClosed;
3774                 pSmart->popup_menu_update = OnSelectBoxUpdateRequested;
3775
3776                 pSmart->input_picker_show = OnDatePickerProviderRequested;
3777                 pSmart->input_picker_color_request = OnColorPickerProviderRequested;
3778                 pSmart->input_picker_color_dismiss = OnColorPickerProviderDismissed;
3779
3780                 pSmart->formdata_candidate_show = OnFormDataCandidateShow;
3781                 pSmart->formdata_candidate_hide = OnFormDataCandidateHide;
3782                 pSmart->formdata_candidate_update_data = OnFormDataCandidateUpdate;
3783                 pSmart->formdata_candidate_is_showing = OnFormDataCandidateIsShowing;
3784
3785                 evas_object_data_set(pWebNativeNode, WEB_CTRL, this);
3786
3787                 // add loading event callbacks for ILoadingListener
3788                 evas_object_smart_callback_add(pWebNativeNode, "create,window", OnWebWindowCreateRequested, this);
3789                 evas_object_smart_callback_add(pWebNativeNode, "close,window", OnWebWindowClosedRequested, this);
3790
3791                 evas_object_smart_callback_add(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested, this);
3792                 evas_object_smart_callback_add(pWebNativeNode, "load,started", OnLoadingStarted, this);
3793                 evas_object_smart_callback_add(pWebNativeNode, "load,finished", OnLoadingCompleted, this);
3794                 evas_object_smart_callback_add(pWebNativeNode, "load,progress", OnEstimatedProgress, this);
3795                 evas_object_smart_callback_add(pWebNativeNode, "load,progress,finished", OnProgressCompleted, this);
3796                 evas_object_smart_callback_add(pWebNativeNode, "load,stop", OnLoadingCanceled, this);
3797                 evas_object_smart_callback_add(pWebNativeNode, "load,error", OnLoadingErrorOccurred, this);
3798                 evas_object_smart_callback_add(pWebNativeNode, "title,changed", OnPageTitleReceived, this);
3799                 evas_object_smart_callback_add(pWebNativeNode, "load,committed", OnLoadingCommitted, this);
3800
3801                 evas_object_smart_callback_add(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest, this);
3802
3803                 evas_object_smart_callback_add(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3804                 evas_object_smart_callback_add(pWinObject, "focus,out", OnWindowObjectFocusLost, this);
3805
3806                 evas_object_smart_callback_add(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged, this);
3807                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened, this);
3808                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed, this);
3809
3810                 evas_object_smart_callback_add(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested, this);
3811                 evas_object_smart_callback_add(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled, this);
3812
3813                 evas_object_smart_callback_add(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested, this);
3814
3815                 ewk_view_javascript_alert_callback_set(pWebNativeNode, OnScriptAlertRequested, const_cast< _WebImpl* >(this));
3816                 ewk_view_javascript_prompt_callback_set(pWebNativeNode, OnScriptPromptRequested, const_cast< _WebImpl* >(this));
3817                 ewk_view_javascript_confirm_callback_set(pWebNativeNode, OnScriptConfirmRequested, const_cast< _WebImpl* >(this));
3818                 ewk_view_before_unload_confirm_panel_callback_set(pWebNativeNode, OnBeforeUnloadConfirmRequested, const_cast< _WebImpl* >(this));
3819
3820                 evas_object_smart_callback_add(pWebNativeNode, "policy,response,decide", OnWebDataReceived, this);
3821
3822                 evas_object_smart_callback_add(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested, this);
3823                 evas_object_smart_callback_add(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested, this);
3824                 evas_object_smart_callback_add(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted, this);
3825
3826                 evas_object_smart_callback_add(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested, this);
3827                 evas_object_smart_callback_add(pWebNativeNode, "notification,show", OnNotificationShow, this);
3828                 evas_object_smart_callback_add(pWebNativeNode, "notification,cancel", OnNotificationCancel, this);
3829
3830                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested, this);
3831                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered, this);
3832                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested, this);
3833
3834                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested, this);
3835                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered, this);
3836                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested, this);
3837                 evas_object_smart_callback_add(pWebNativeNode, "text,found", OnTextFound, this);
3838
3839                 evas_object_smart_callback_add(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered, this);
3840                 evas_object_smart_callback_add(pWebNativeNode, "icon,received", OnFaviconReceived, this);
3841
3842                 evas_object_smart_callback_add(pWebNativeNode, "magnifier,hide", OnWebPageBlockSelected, this);
3843
3844                 evas_object_smart_callback_add(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered, this);
3845                 evas_object_smart_callback_add(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited, this);
3846
3847                 evas_object_smart_callback_add(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested, this);
3848                 evas_object_smart_callback_add(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested, this);
3849
3850                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3851                 SysAssertf(pContext, "Failed to get webkit instance.");
3852                 ewk_context_did_start_download_callback_set(pContext, OnDidStartDownloadCallback, const_cast< _WebImpl* >(this));
3853                 ewk_context_vibration_client_callbacks_set(pContext, OnVibrationRequested, OnVibrationCanceled, const_cast< _WebImpl* >(this));
3854
3855                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, OnApplicationCachePermissionRequested, const_cast< _WebImpl* >(this));
3856                 ewk_view_exceeded_indexed_database_quota_callback_set(pWebNativeNode, OnIndexedDatabaseQuotaExceeded, const_cast< _WebImpl* >(this));
3857                 ewk_view_exceeded_database_quota_callback_set(pWebNativeNode, OnDatabaseQuotaExceeded, const_cast< _WebImpl* >(this));
3858                 ewk_view_exceeded_local_file_system_quota_callback_set(pWebNativeNode, OnLocalFileSystemQuotaExceeded, const_cast< _WebImpl* >(this));
3859
3860                 evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained, this);
3861                 evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_OUT, OnWebNativeNodeFocusLost, this);
3862         }
3863 }
3864
3865
3866 void
3867 _WebImpl::RemoveEventListenerCallback(void) const
3868 {
3869         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3870         if (pWebNativeNode)
3871         {
3872                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3873                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3874
3875                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3876                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3877
3878                 evas_object_smart_callback_del(pWebNativeNode, "create,window", OnWebWindowCreateRequested);
3879                 evas_object_smart_callback_del(pWebNativeNode, "close,window", OnWebWindowClosedRequested);
3880
3881                 evas_object_smart_callback_del(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested);
3882                 evas_object_smart_callback_del(pWebNativeNode, "load,started", OnLoadingStarted);
3883                 evas_object_smart_callback_del(pWebNativeNode, "load,finished", OnLoadingCompleted);
3884                 evas_object_smart_callback_del(pWebNativeNode, "load,progress", OnEstimatedProgress);
3885                 evas_object_smart_callback_del(pWebNativeNode, "load,progress,finished", OnProgressCompleted);
3886                 evas_object_smart_callback_del(pWebNativeNode, "load,stop", OnLoadingCanceled);
3887                 evas_object_smart_callback_del(pWebNativeNode, "load,error", OnLoadingErrorOccurred);
3888                 evas_object_smart_callback_del(pWebNativeNode, "title,changed", OnPageTitleReceived);
3889                 evas_object_smart_callback_del(pWebNativeNode, "load,committed", OnLoadingCommitted);
3890
3891                 evas_object_smart_callback_del(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest);
3892
3893                 evas_object_smart_callback_del_full(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3894                 evas_object_smart_callback_del_full(pWinObject, "focus,out", OnWindowObjectFocusLost, this);
3895
3896                 evas_object_smart_callback_del(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged);
3897                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened);
3898                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed);
3899
3900                 evas_object_smart_callback_del(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested);
3901                 evas_object_smart_callback_del(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled);
3902
3903                 evas_object_smart_callback_del(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested);
3904
3905                 ewk_view_javascript_alert_callback_set(pWebNativeNode, null, null);
3906                 ewk_view_javascript_prompt_callback_set(pWebNativeNode, null, null);
3907                 ewk_view_javascript_confirm_callback_set(pWebNativeNode, null, null);
3908                 ewk_view_before_unload_confirm_panel_callback_set(pWebNativeNode, null, null);
3909
3910                 evas_object_smart_callback_del(pWebNativeNode, "policy,response,decide", OnWebDataReceived);
3911
3912                 evas_object_smart_callback_del(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested);
3913                 evas_object_smart_callback_del(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested);
3914                 evas_object_smart_callback_del(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted);
3915
3916                 evas_object_smart_callback_del(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested);
3917                 evas_object_smart_callback_del(pWebNativeNode, "notification,show", OnNotificationShow);
3918                 evas_object_smart_callback_del(pWebNativeNode, "notification,cancel", OnNotificationCancel);
3919                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested);
3920                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered);
3921                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested);
3922
3923                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested);
3924                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered);
3925                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested);
3926
3927                 evas_object_smart_callback_del(pWebNativeNode, "text,found", OnTextFound);
3928
3929                 evas_object_smart_callback_del(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered);
3930                 evas_object_smart_callback_del(pWebNativeNode, "icon,received", OnFaviconReceived);
3931
3932                 evas_object_smart_callback_del(pWebNativeNode, "magnifier,hide", OnWebPageBlockSelected);
3933
3934                 evas_object_smart_callback_del(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered);
3935                 evas_object_smart_callback_del(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited);
3936
3937                 evas_object_smart_callback_del(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested);
3938                 evas_object_smart_callback_del(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested);
3939
3940                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3941                 SysAssertf(pContext, "Failed to get webkit instance.");
3942                 ewk_context_vibration_client_callbacks_set(pContext, null, null, null);
3943
3944                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, null, null);
3945                 ewk_view_exceeded_indexed_database_quota_callback_set(pWebNativeNode, null, null);
3946                 ewk_view_exceeded_database_quota_callback_set(pWebNativeNode, null, null);
3947                 ewk_view_exceeded_local_file_system_quota_callback_set(pWebNativeNode, null, null);
3948
3949                 evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained);
3950                 evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_OUT, OnWebNativeNodeFocusLost);
3951         }
3952 }
3953
3954
3955 result
3956 _WebImpl::SetBlockSelectionPosition(const Point& startPoint)
3957 {
3958         return SetBlockSelectionPosition(_CoordinateSystemUtils::ConvertToFloat(startPoint));
3959 }
3960
3961
3962 result
3963 _WebImpl::SetBlockSelectionPosition(const FloatPoint& startPoint)
3964 {
3965         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3966         if (!pWebview)
3967         {
3968                 return E_SUCCESS;
3969         }
3970
3971         Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pWebview));
3972         SysAssertf(pSmartData && pSmartData->api, "Failed to get webkit instance.");
3973         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(startPoint)));
3974
3975         Eina_Bool ret = pSmartData->api->text_selection_down(pSmartData, absPoint.x, absPoint.y);
3976         if (ret)
3977         {
3978                 pSmartData->api->text_selection_up(pSmartData, absPoint.x, absPoint.y);
3979
3980                 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pWebview, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
3981                 SysTryReturnResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "Failed to get hit test.");
3982
3983                 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
3984
3985                 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
3986                 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
3987                 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
3988                 {
3989                         ewk_view_command_execute(pWebview, "SelectWord", null);
3990                         evas_object_smart_callback_call(pWebview, "magnifier,hide", NULL);
3991                 }
3992         }
3993
3994         SysTryReturnResult(NID_WEB_CTRL, GetTextFromBlock().GetLength() > 0, E_INVALID_ARG, "Failed to set text selection up.");
3995
3996         return E_SUCCESS;
3997 }
3998
3999
4000 void
4001 _WebImpl::ReleaseBlock(void)
4002 {
4003         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4004         if (!pWebview)
4005         {
4006                 return;
4007         }
4008
4009         ewk_view_text_selection_range_clear(pWebview);
4010 }
4011
4012
4013 void
4014 _WebImpl::GetBlockRange(Point& startPoint, Point& endPoint) const
4015 {
4016         FloatPoint tempStartPoint;
4017         FloatPoint tempEndPoint;
4018
4019         GetBlockRange(tempStartPoint, tempEndPoint);
4020
4021         startPoint = _CoordinateSystemUtils::ConvertToInteger(tempStartPoint);
4022         endPoint = _CoordinateSystemUtils::ConvertToInteger(tempEndPoint);
4023 }
4024
4025
4026 void
4027 _WebImpl::GetBlockRange(FloatPoint& startPoint, FloatPoint& endPoint) const
4028 {
4029         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4030         if (!pWebview)
4031         {
4032                 startPoint.x = startPoint.y = endPoint.x = endPoint.y = 0.0f;
4033                 
4034         }
4035
4036         Eina_Rectangle leftHandle;
4037         Eina_Rectangle rightHandle;
4038
4039         EINA_RECTANGLE_SET(&leftHandle, 0, 0, 0, 0);
4040         EINA_RECTANGLE_SET(&rightHandle, 0, 0, 0, 0);
4041
4042         ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
4043
4044         startPoint.x = _CoordinateSystemUtils::ConvertToFloat(leftHandle.x);
4045         startPoint.y = _CoordinateSystemUtils::ConvertToFloat(leftHandle.y);
4046         endPoint.x = _CoordinateSystemUtils::ConvertToFloat(rightHandle.x + rightHandle.w);
4047         endPoint.y = _CoordinateSystemUtils::ConvertToFloat(rightHandle.y + rightHandle.h);
4048
4049         if ((endPoint.x != 0.0f) && (endPoint.y != 0.0f))
4050         {
4051                 startPoint = __pWebCore->GetRelativeCoordinate(startPoint);
4052                 endPoint = __pWebCore->GetRelativeCoordinate(endPoint);
4053         }
4054 }
4055
4056
4057 Bitmap*
4058 _WebImpl::GetFaviconN(void) const
4059 {
4060         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4061         if (!pWebview)
4062         {
4063                 return null;
4064         }
4065
4066         result r = E_SUCCESS;
4067
4068         Ewk_Context* pContext = ewk_view_context_get(pWebview);
4069         const char* pUrl = ewk_view_url_get(pWebview);
4070         Evas* pEvas = evas_object_evas_get(pWebview);
4071
4072         Evas_Object* pFavicon = ewk_context_icon_database_icon_object_add(pContext, pUrl, pEvas);
4073         if (!pFavicon)
4074         {
4075                 return null;
4076         }
4077
4078         Tizen::Graphics::BufferInfo bufferInfo;
4079
4080         r = _Utility::GetPixelBufferFromEvasObject(pFavicon,  bufferInfo);
4081         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
4082
4083         const Dimension dimension(bufferInfo.width, bufferInfo.height);
4084         Tizen::Base::ByteBuffer byteBuffer;
4085         
4086         r = byteBuffer.Construct((byte*)bufferInfo.pPixels, 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
4087         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
4088
4089         std::unique_ptr<Bitmap> pImage(new (std::nothrow) Bitmap());
4090         SysTryReturn(NID_WEB_CTRL, pImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
4091
4092         r = pImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
4093         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
4094
4095         return pImage.release();
4096
4097 }
4098
4099
4100 void
4101 _WebImpl::ScrollBy(const Tizen::Graphics::Point& diff)
4102 {
4103         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4104         if (!pWebview)
4105         {
4106                 return;
4107         }
4108
4109         ewk_view_scroll_by(pWebview, diff.x, diff.y);
4110 }
4111
4112
4113 void
4114 _WebImpl::ScrollTo(const Tizen::Graphics::Point& dest)
4115 {
4116         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4117         if (!pWebview)
4118         {
4119                 return;
4120         }
4121
4122         ewk_view_scroll_set(pWebview, dest.x, dest.y);
4123 }
4124
4125
4126 Point
4127 _WebImpl::GetScrollPosition(void) const
4128 {
4129         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4130         if (!pWebview)
4131         {
4132                 return Point(0, 0);
4133         }
4134
4135         Point position;
4136
4137         ewk_view_scroll_pos_get(pWebview, &position.x, &position.y);
4138
4139         return position;
4140 }
4141
4142
4143 Dimension
4144 _WebImpl::GetPageSize(void) const
4145 {
4146         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4147         if (!pWebview)
4148         {
4149                 return Dimension(0, 0);
4150         }
4151
4152         Evas_Coord width = 0;
4153         Evas_Coord height = 0;
4154
4155         ewk_view_contents_size_get(pWebview, &width, &height);
4156
4157         Dimension size(static_cast< int >(width), static_cast< int >(height));
4158
4159         return size;
4160 }
4161
4162
4163 void
4164 _WebImpl::SetLoadingErrorOccurred(bool arg)
4165 {
4166         __isLoadingErrorOccurred = arg;
4167 }
4168
4169
4170 bool
4171 _WebImpl::IsLoadingErrorOccurred(void) const
4172 {
4173         return __isLoadingErrorOccurred;
4174 }
4175
4176
4177 void
4178 _WebImpl::SetRedirectRequested(bool arg)
4179 {
4180         __isRedirectRequested = arg;
4181 }
4182
4183
4184 bool
4185 _WebImpl::IsRedirectRequested(void) const
4186 {
4187         return __isRedirectRequested;
4188 }
4189
4190
4191 void
4192 _WebImpl::SetPolicyDecision(DecisionPolicy policy)
4193 {
4194         __policy = policy;
4195 }
4196
4197
4198 DecisionPolicy
4199 _WebImpl::GetPolicyDecision(void) const
4200 {
4201         return __policy;
4202 }
4203
4204
4205 void
4206 _WebImpl::SetCertificateRequested(bool arg)
4207 {
4208         __isCertificateRequested = arg;
4209 }
4210
4211
4212 bool
4213 _WebImpl::IsCertificateRequested(void) const
4214 {
4215         return __isCertificateRequested;
4216 }
4217
4218
4219 void
4220 _WebImpl::SetCertificateConfirmed(bool arg)
4221 {
4222         __isCertificateConfirmed = arg;
4223 }
4224
4225
4226 bool
4227 _WebImpl::IsCertificateConfirmed(void) const
4228 {
4229         return __isCertificateConfirmed;
4230 }
4231
4232
4233 result
4234 _WebImpl::SetFullScreenKeypad(void)
4235 {
4236         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4237         if (!pWebview)
4238         {
4239                 return E_SUCCESS;
4240         }
4241
4242         result r = E_SUCCESS;
4243
4244         std::unique_ptr<Keypad> pKeypad(new (std::nothrow) Keypad());
4245         SysTryReturnResult(NID_WEB_CTRL, pKeypad.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4246
4247         r = pKeypad->Construct(KEYPAD_STYLE_NORMAL, 100);
4248         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4249
4250         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pWebCore->GetTouchPosition())));
4251
4252         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pWebview, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
4253         SysTryReturnResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "Failed to get hit test.");
4254
4255         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
4256         if (tagName.Equals(L"INPUT", false))
4257         {
4258                 String text(ewk_view_focused_input_element_value_get(pWebview));
4259                 pKeypad->SetText(text);
4260         }
4261         else
4262         {
4263                 String* pText = EvaluateJavascriptN(L"document.activeElement.value");
4264                 SysTryReturnResult(NID_WEB_CTRL, pText, E_OUT_OF_MEMORY, "Memory allocation failed.");
4265                 pKeypad->SetText(*pText);
4266         }
4267
4268         r = pKeypad->SetShowState(true);
4269         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4270
4271         r = pKeypad->Show();
4272         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4273
4274         pKeypad->AddTextEventListener(*this);
4275
4276         __pKeypad = std::move(pKeypad);
4277
4278         return E_SUCCESS;
4279 }
4280
4281
4282 void
4283 _WebImpl::RemoveFullScreenKeypad(void)
4284 {
4285         __pKeypad->RemoveTextEventListener(*this);
4286
4287         __pKeypad.reset();
4288 }
4289
4290
4291 bool
4292 _WebImpl::IsFooterVisible(void) const
4293 {
4294         return __isFooterVisible;
4295 }
4296
4297
4298 void
4299 _WebImpl::SetFooterVisibleState(bool isFooterVisible)
4300 {
4301         __isFooterVisible = isFooterVisible;
4302 }
4303
4304
4305 bool
4306 _WebImpl::IsKeypadVisible(void) const
4307 {
4308         return __isKeypadVisible;
4309 }
4310
4311
4312 void
4313 _WebImpl::SetKeypadVisibleState(bool isKeypadVisible)
4314 {
4315         __isKeypadVisible = isKeypadVisible;
4316 }
4317
4318
4319 bool 
4320 _WebImpl::IsKeypadOpened(void) const
4321 {
4322         return __isKeypadOpened;
4323 }
4324
4325 void 
4326 _WebImpl::SetKeypadOpened(bool isKeypadOpened)
4327 {
4328         __isKeypadOpened = isKeypadOpened;
4329 }
4330
4331
4332 bool
4333 _WebImpl::IsWinFocusLost(void) const
4334 {
4335         return __isWinFocusLost;
4336 }
4337
4338
4339 void
4340 _WebImpl::SetWinFocusLost(bool isWinFocusLost)
4341 {
4342         __isWinFocusLost = isWinFocusLost;
4343 }
4344
4345
4346 Rectangle
4347 _WebImpl::GetPreviousKeypadBounds(void) const
4348 {
4349         return __keypadBounds;
4350 }
4351
4352
4353 void 
4354 _WebImpl::SetPreviousKeypadBounds(Rectangle& bounds)
4355 {
4356         __keypadBounds = bounds;
4357 }
4358
4359
4360 void
4361 _WebImpl::OnTextValueChangeCanceled(const Control& source)
4362 {
4363         RemoveFullScreenKeypad();
4364 }
4365
4366
4367 void
4368 _WebImpl::OnTextValueChanged(const Control& source)
4369 {
4370         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4371         if (!pWebview)
4372         {
4373                 return;
4374         }
4375
4376         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(__pKeypad->GetText()));
4377         SysTryReturnVoidResult(NID_WEB_CTRL, pText.get(), E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
4378
4379         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(__pWebCore->GetTouchPosition())));
4380
4381         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pWebview, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
4382         SysTryReturnVoidResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "[E_SYSTEM] Failed to get hit test.");
4383
4384         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
4385         if (tagName.Equals(L"INPUT", false))
4386         {
4387                 ewk_view_focused_input_element_value_set(__pWebCore->GetWebNativeNode(), pText.get());
4388         }
4389         else
4390         {
4391                 ewk_view_command_execute(pWebview, "SelectAll", null);
4392                 ewk_view_command_execute(pWebview, "Delete", null);
4393                 ewk_view_command_execute(pWebview, "InsertText", pText.get());
4394         }
4395
4396         RemoveFullScreenKeypad();
4397 }
4398
4399
4400 result
4401 _WebImpl::OnHandleJavaScriptRequestByEventArg(const IEventArg& arg)
4402 {
4403         const _JsBridgeArg* pEventArg = dynamic_cast< const _JsBridgeArg* >(&arg);
4404         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. arg is not _JsBridgeArg object.");
4405
4406         std::unique_ptr<IJsonValue> pJsonValue(JsonParser::ParseN(*(pEventArg->GetJsonData())));
4407         SysTryReturn(NID_WEB_JSON, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4408
4409         IJavaScriptBridge* pJsInterface = FindJsInterface(pJsonValue.get());
4410         SysTryReturnResult(NID_WEB_CTRL, pJsInterface, E_OBJ_NOT_FOUND, "JsInterface instance is not available.");
4411
4412         pJsInterface->HandleJavaScriptRequestN(pJsonValue.release());
4413
4414         return E_SUCCESS;
4415 }
4416
4417
4418 result
4419 _WebImpl::OnHandleLoadingEvent(const IEventArg& arg)
4420 {
4421         result r = E_SUCCESS;
4422
4423         const _LoadingEventArg* pEventArg = dynamic_cast< const _LoadingEventArg* >(&arg);
4424         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4425
4426         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4427
4428         ILoadingListener* pLoadingListner = GetLoadingListener();
4429         SysTryReturnResult(NID_WEB_CTRL, pLoadingListner, E_SYSTEM, "A system error has been occurred. Loading listener was not set or null.");
4430
4431         switch (pEventArg->GetEventType())
4432         {
4433         case WEB_EVENT_LOADINGLISTENER_STARTED:
4434         {
4435                 pLoadingListner->OnLoadingStarted();
4436                 break;
4437         }
4438
4439         case WEB_EVENT_LOADINGLISTENER_PROGRESS:
4440         {
4441                 const Integer* pProgressPercentage = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS));
4442                 SysTryReturn(NID_WEB_CTRL, pProgressPercentage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4443
4444                 pLoadingListner->OnEstimatedProgress(pProgressPercentage->ToInt());
4445                 break;
4446         }
4447
4448         case WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED:
4449         {
4450                 const String* pPageTitle = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::PAGE_TITLE));
4451                 SysTryReturn(NID_WEB_CTRL, pPageTitle, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4452
4453                 pLoadingListner->OnPageTitleReceived(*pPageTitle);
4454                 break;
4455         }
4456
4457         case WEB_EVENT_LOADINGLISTENER_CANCELED:
4458         {
4459                 pLoadingListner->OnLoadingCanceled();
4460                 break;
4461         }
4462
4463         case WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED:
4464         {
4465                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_TYPE));
4466                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4467
4468                 const String* pErrorMessage = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_MESSAGE));
4469                 SysTryReturn(NID_WEB_CTRL, pErrorMessage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4470
4471                 LoadingErrorType errorType = ConvertErrorCode(pErrorType->ToInt());
4472
4473                 pLoadingListner->OnLoadingErrorOccurred(errorType, *pErrorMessage);
4474                 break;
4475         }
4476
4477         case WEB_EVENT_LOADINGLISTENER_COMPLETED:
4478         {
4479                 pLoadingListner->OnLoadingCompleted();
4480                 break;
4481         }
4482
4483         case WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED:
4484         {
4485                 pLoadingListner->OnHttpAuthenticationCanceled();
4486                 break;
4487         }
4488
4489         case WEB_EVENT_LOADINGLISTENER_FAVICON_RECEIVED:
4490         {
4491                 std::unique_ptr<Bitmap> pFavicon(GetFaviconN());
4492                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4493
4494                 if (pFavicon.get())
4495                 {
4496                         pLoadingListner->OnFaviconReceived(*pFavicon.get());
4497                 }
4498                 break;
4499         }
4500
4501         default:
4502         {
4503                 SysAssert(false);
4504         }
4505         }
4506
4507         return r;
4508 }
4509
4510
4511 result
4512 _WebImpl::OnHandleWebDownloadEvent(const IEventArg& arg)
4513 {
4514         result r = E_SUCCESS;
4515
4516         const _WebDownloadEventArg* pEventArg = dynamic_cast< const _WebDownloadEventArg* >(&arg);
4517         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4518
4519         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4520
4521         IWebDownloadListener* pWebDownloadListener = __pWebDownloadHandler->GetDownloadListener();
4522         SysTryReturnResult(NID_WEB_CTRL, pWebDownloadListener, E_SYSTEM, "A system error has been occurred. Web Downloading listener was not set or null.");
4523
4524         switch (pEventArg->GetEventType())
4525         {
4526         case WEB_EVENT_WEBDOWNLOADLISTENER_DATA_RECEIVED:
4527         {
4528                 const ByteBuffer* pChunk = dynamic_cast< const ByteBuffer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::CHUNKED_DATA));
4529                 SysTryReturn(NID_WEB_CTRL, pChunk, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4530
4531                 pWebDownloadListener->OnWebChunkedDataReceived(*pChunk);
4532                 break;
4533         }
4534
4535         case WEB_EVENT_WEBDOWNLOADLISTENER_COMPLETED:
4536         {
4537                 pWebDownloadListener->OnWebDataDownloadCompleted();
4538                 break;
4539         }
4540
4541         case WEB_EVENT_WEBDOWNLOADLISTENER_FAILED:
4542         {
4543                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::ERROR_TYPE));
4544                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4545
4546                 LoadingErrorType errorType = static_cast < LoadingErrorType >(pErrorType->ToInt());
4547
4548                 pWebDownloadListener->OnWebDownloadFailed(errorType);
4549                 break;
4550         }
4551
4552         default:
4553         {
4554                 SysAssert(false);
4555         }
4556         }
4557
4558         return r;
4559 }
4560
4561
4562 result
4563 _WebImpl::OnHandleWebUiEvent(const IEventArg& arg)
4564 {
4565         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4566         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4567
4568         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4569
4570         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListener, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4571
4572         switch (pEventArg->GetEventType())
4573         {
4574         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED:
4575         {
4576                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4577
4578                 Point* pStartPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4579                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4580
4581                 Point* pEndPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4582                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4583
4584                 __pUserUiListener->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4585                 break;
4586         }
4587
4588         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED:
4589         {
4590                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4591
4592                 __pUserUiListener->OnWebPageShowRequested(*pWeb);
4593                 break;
4594         }
4595
4596         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED:
4597         {
4598                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4599
4600                 __pUserUiListener->OnWebWindowCloseRequested(*pWeb);
4601                 break;
4602         }
4603
4604         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED:
4605         {
4606                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4607
4608                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4609                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4610
4611                 __pUserUiListener->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4612                 break;
4613         }
4614
4615         default:
4616         {
4617                 SysAssert(false);
4618         }
4619         }
4620
4621         return E_SUCCESS;
4622 }
4623
4624
4625 result
4626 _WebImpl::OnHandleWebUiEventF(const IEventArg& arg)
4627 {
4628         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4629         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4630
4631         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4632
4633         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListenerF, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4634
4635         switch (pEventArg->GetEventType())
4636         {
4637         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED_FLOAT:
4638         {
4639                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4640
4641                 FloatPoint* pStartPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4642                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4643
4644                 FloatPoint* pEndPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4645                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4646
4647                 __pUserUiListenerF->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4648                 break;
4649         }
4650
4651         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED_FLOAT:
4652         {
4653                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4654
4655                 __pUserUiListenerF->OnWebPageShowRequested(*pWeb);
4656                 break;
4657         }
4658
4659         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED_FLOAT:
4660         {
4661                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4662
4663                 __pUserUiListenerF->OnWebWindowCloseRequested(*pWeb);
4664                 break;
4665         }
4666
4667         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED_FLOAT:
4668         {
4669                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4670
4671                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4672                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4673
4674                 __pUserUiListenerF->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4675                 break;
4676         }
4677
4678         default:
4679         {
4680                 SysAssert(false);
4681         }
4682         }
4683
4684         return E_SUCCESS;
4685 }
4686
4687
4688 result
4689 _WebImpl::OnHandleTextSearchEvent(const IEventArg& arg)
4690 {
4691         result r = E_SUCCESS;
4692
4693         const _TextSearchEventArg* pEventArg = dynamic_cast< const _TextSearchEventArg* >(&arg);
4694         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4695
4696         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4697
4698         ITextSearchListener* pTextSearchListner = GetTextSearchListener();
4699         SysTryReturnResult(NID_WEB_CTRL, pTextSearchListner, E_SYSTEM, "A system error has been occurred. Web text search listener was not set or null.");
4700
4701         switch (pEventArg->GetEventType())
4702         {
4703         case WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND:
4704         {
4705                 Integer* pTotalCount= dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::TOTAL_COUNT)));
4706                 SysTryReturn(NID_WEB_CTRL, pTotalCount, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4707
4708                 Integer* pCurrentOrdinal = dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL)));
4709                 SysTryReturn(NID_WEB_CTRL, pCurrentOrdinal, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4710
4711                 pTextSearchListner->OnTextFound(pTotalCount->ToInt(), pCurrentOrdinal->ToInt());
4712                 break;
4713         }
4714
4715         default:
4716         {
4717                 SysAssert(false);
4718         }
4719         }
4720
4721         return r;
4722 }
4723
4724
4725 result
4726 _WebImpl::VibrationRequested(uint64_t duration)
4727 {
4728         result r = E_SUCCESS;
4729
4730         __pVibrator.reset();
4731
4732         std::unique_ptr<Vibrator> pVibrator(new (std::nothrow) Vibrator());
4733         SysTryReturnResult(NID_WEB_CTRL, pVibrator.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4734
4735         r = pVibrator->Construct();
4736         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4737
4738         __pVibrator = std::move(pVibrator);
4739
4740         IntensityDurationVibrationPattern pattern = {static_cast< int >(duration), -1};
4741
4742         r = __pVibrator->Start(&pattern, 1);
4743         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4744
4745         return E_SUCCESS;
4746 }
4747
4748
4749 void
4750 _WebImpl::VibrationCanceled(void)
4751 {
4752         __pVibrator.reset();
4753 }
4754
4755
4756 result
4757 _WebImpl::HttpAuthenticationRequested(Ewk_Auth_Challenge* pChallenge)
4758 {
4759         result r = E_SUCCESS;
4760
4761         String host(ewk_auth_challenge_url_get(pChallenge));
4762         String realm(ewk_auth_challenge_realm_get(pChallenge));
4763
4764         std::unique_ptr<AuthenticationChallenge> pAuthChallenge(new (std::nothrow) AuthenticationChallenge());
4765         SysTryReturnResult(NID_WEB_CTRL, pAuthChallenge, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4766
4767         _AuthenticationChallengeImpl* pAuthImpl = _AuthenticationChallengeImpl::GetInstance(pAuthChallenge.get());
4768         SysTryReturn(NID_WEB_CTRL, pAuthImpl,  GetLastResult(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4769
4770         pAuthImpl->SetAuthenticationChallengeHandler(pChallenge);
4771         pAuthImpl->SetWebEvasObject(__pWebCore->GetWebNativeNode());
4772
4773         __pAuthChallenge = std::move(pAuthChallenge);
4774
4775         ewk_auth_challenge_suspend(pChallenge);
4776         if (__pUserLoadingListener && __pUserLoadingListener->OnHttpAuthenticationRequestedN(host, realm, *__pAuthChallenge.get()))
4777         {
4778                 __pAuthChallenge.release();
4779         }
4780         else
4781         {
4782                 r = ShowAuthenticationPopup(host, realm, __pAuthChallenge.get());
4783                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4784         }
4785
4786         return E_SUCCESS;
4787 }
4788
4789
4790 result
4791 _WebImpl::ShowAuthenticationPopup(const String& host, const String& realm, AuthenticationChallenge* pAuthChallenge)
4792 {
4793         result r = E_SUCCESS;
4794
4795         std::unique_ptr<_AuthConfirmPopup> pAuthPopup(new (std::nothrow) _AuthConfirmPopup());
4796         SysTryReturnResult(NID_WEB_CTRL, pAuthPopup, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4797
4798         r = pAuthPopup->Construct(host, realm, this);
4799         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4800
4801         __pAuthPopup = std::move(pAuthPopup);
4802
4803         r = __pAuthPopup->ShowPopup();
4804         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4805
4806         return E_SUCCESS;
4807 }
4808
4809
4810 result
4811 _WebImpl::ShowCertificateConfirmPopup(_CertificatePopupMode userConfirmMode, Ewk_Certificate_Policy_Decision* pPolicy)
4812 {
4813         result r = E_SUCCESS;
4814
4815         std::unique_ptr<_CertificateConfirmPopup> pCertConfirmPopup(new (std::nothrow) _CertificateConfirmPopup());
4816         SysTryReturnResult(NID_WEB_CTRL, pCertConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4817
4818         r = pCertConfirmPopup->Construct(userConfirmMode, pPolicy);
4819         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4820
4821         __pCertConfirmPopup = std::move(pCertConfirmPopup);
4822
4823         int modalResult = 0;
4824
4825         r = __pCertConfirmPopup->ShowAndWait(modalResult);
4826         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4827
4828         if (__pCertConfirmPopup.get() && userConfirmMode == CERTIFICATE_POPUP_MODE_USER_CONFIRM)
4829         {
4830                 __isCertificateConfirmed = __pCertConfirmPopup->GetConfirmResult();
4831         }
4832
4833 CATCH:
4834         if (__pCertConfirmPopup.get())
4835         {
4836                 __pCertConfirmPopup.reset();
4837         }
4838
4839         return r;
4840 }
4841
4842
4843 result
4844 _WebImpl::ShowPromptPopup(String msg, String defVal)
4845 {
4846         result r = E_SUCCESS;
4847
4848         std::unique_ptr< _PromptPopup > pPromptPopup(new (std::nothrow) _PromptPopup());
4849         SysTryReturnResult(NID_WEB_CTRL, pPromptPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4850
4851         r = pPromptPopup->Construct(msg, defVal, __pWebCore->GetWebNativeNode(), this);
4852         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4853
4854         __pPromptPopup = std::move(pPromptPopup);
4855
4856         r = __pPromptPopup->ShowPopup();
4857         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4858
4859         return E_SUCCESS;
4860
4861 CATCH:
4862         __pPromptPopup.reset();
4863
4864         return r;
4865
4866 }
4867
4868
4869 result
4870 _WebImpl::ShowUserConfirmPopup(_UserConfirmMode userConfirmMode, void* pPolicy, String msg)
4871 {
4872         result r = E_SUCCESS;
4873
4874         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4875         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4876
4877         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, this, true, msg);
4878         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4879
4880         int modalResult = 0;
4881
4882         switch(userConfirmMode)
4883         {
4884         case USER_CONTENT_HANDLER:
4885         {
4886                 __pContentHandlerConfirmPopup = std::move(pUserConfirmPopup);
4887
4888                 r = __pContentHandlerConfirmPopup->ShowAndWait(modalResult);
4889                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pContentHandlerConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4890
4891                 __pContentHandlerConfirmPopup.reset();
4892
4893                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4894
4895                 break;
4896         }
4897         case USER_PROTOCOL_HANDLER:
4898         {
4899                 __pProtocolHandlerConfirmPopup = std::move(pUserConfirmPopup);
4900
4901                 r = __pProtocolHandlerConfirmPopup->ShowAndWait(modalResult);
4902                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pProtocolHandlerConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4903
4904                 __pProtocolHandlerConfirmPopup.reset();
4905
4906                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4907
4908                 break;
4909         }
4910         case USER_CONFIRM_APP_CACHE:
4911         {
4912                 __pAppCacheConfirmPopup = std::move(pUserConfirmPopup);
4913
4914                 r = __pAppCacheConfirmPopup->ShowAndWait(modalResult);
4915                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pAppCacheConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4916
4917                 __pAppCacheConfirmPopup.reset();
4918
4919                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4920
4921                 break;
4922         }
4923         case USER_CONFIRM_DB_QUOTA_EXCEDED:
4924         {
4925                 __pDbQuotaConfirmPopup = std::move(pUserConfirmPopup);
4926
4927                 r = __pDbQuotaConfirmPopup->ShowAndWait(modalResult);
4928                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pDbQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4929
4930                 __pDbQuotaConfirmPopup.reset();
4931
4932                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4933
4934                 break;
4935         }
4936         case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
4937         {
4938                 __pLocalFsQuotaConfirmPopup = std::move(pUserConfirmPopup);
4939
4940                 r = __pLocalFsQuotaConfirmPopup->ShowAndWait(modalResult);
4941                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pLocalFsQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4942
4943                 __pLocalFsQuotaConfirmPopup.reset();
4944
4945                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4946
4947                 break;
4948         }
4949         case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
4950         {
4951                 __pIndexedDbQuotaConfirmPopup = std::move(pUserConfirmPopup);
4952
4953                 r = __pIndexedDbQuotaConfirmPopup->ShowAndWait(modalResult);
4954                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pIndexedDbQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4955
4956                 __pIndexedDbQuotaConfirmPopup.reset();
4957
4958                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4959
4960                 break;
4961         }
4962         default:
4963                 break;
4964         }
4965 CATCH:
4966                 return r;
4967 }
4968
4969
4970 result
4971 _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPolicy, String msg)
4972 {
4973         result r = E_SUCCESS;
4974
4975         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4976         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4977
4978         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, this, false, msg);
4979         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4980
4981         switch(userConfirmMode)
4982         {
4983         case USER_CONFIRM_USERMEDIA:
4984         {
4985                 __pUserMediaConfirmPopup.reset();
4986
4987                 __pUserMediaConfirmPopup = std::move(pUserConfirmPopup);
4988
4989                 r = __pUserMediaConfirmPopup->ShowPopup();
4990                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pUserMediaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4991
4992                 break;
4993         }
4994         case USER_CONFIRM_GEOLOCATION:
4995         {
4996                 __pGeolocationConfirmPopup.reset();
4997
4998                 __pGeolocationConfirmPopup = std::move(pUserConfirmPopup);
4999
5000                 r = __pGeolocationConfirmPopup->ShowPopup();
5001                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pGeolocationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
5002
5003                 break;
5004         }
5005         case USER_CONFIRM_NOTIFICATION:
5006         {
5007                 __pNotificationConfirmPopup.reset();
5008
5009                 __pNotificationConfirmPopup = std::move(pUserConfirmPopup);
5010
5011                 r = __pNotificationConfirmPopup->ShowPopup();
5012                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pNotificationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
5013
5014                 break;
5015         }
5016         case USER_SCRIPT_ALERT:
5017         {
5018                 __pScriptAlertConfirmPopup.reset();
5019
5020                 __pScriptAlertConfirmPopup = std::move(pUserConfirmPopup);
5021
5022                 r = __pScriptAlertConfirmPopup->ShowPopup();
5023                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptAlertConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
5024
5025                 break;
5026         }
5027         case USER_SCRIPT_CONFIRM:
5028         {
5029                 __pScriptConfirmPopup.reset();
5030
5031                 __pScriptConfirmPopup = std::move(pUserConfirmPopup);
5032
5033                 r = __pScriptConfirmPopup->ShowPopup();
5034                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
5035
5036                 break;
5037         }
5038         case USER_BEFORE_UNLOAD_CONFIRM:
5039         {
5040                 __pBeforeUnloadConfirmPopup.reset();
5041
5042                 __pBeforeUnloadConfirmPopup = std::move(pUserConfirmPopup);
5043
5044                 r = __pBeforeUnloadConfirmPopup->ShowPopup();
5045                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pBeforeUnloadConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
5046
5047                 break;
5048         }
5049         default:
5050                 break;
5051         }
5052
5053         return E_SUCCESS;
5054
5055 CATCH:
5056         return r;
5057 }
5058
5059
5060 _FormImpl*
5061 _WebImpl::GetParentFormImpl(_ControlImpl* pControlImpl)
5062 {
5063         String parentName;
5064         _FormImpl* pFormImpl = null;
5065
5066         _ControlImpl* pParentControlImpl = dynamic_cast< _ControlImpl* >(pControlImpl->GetParent());
5067         if (!pParentControlImpl)
5068         {
5069                 return null;
5070         }
5071
5072         pFormImpl = dynamic_cast< _FormImpl* >(pParentControlImpl);
5073         if (pFormImpl)
5074         {
5075                 return pFormImpl;
5076         }
5077
5078         return GetParentFormImpl(pParentControlImpl);
5079 }
5080
5081
5082 bool 
5083 _WebImpl::OnFocusGained(const _ControlImpl& source)
5084 {
5085         return false;
5086 }
5087
5088
5089 bool 
5090 _WebImpl::OnFocusLost(const _ControlImpl& source)
5091 {
5092         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
5093         if (!pWebview)
5094         {
5095                 return false;
5096         }
5097
5098         if(IsKeypadVisible() == true)
5099         {
5100                 SetKeypadOpened(true);
5101         }
5102
5103         return false;
5104 }
5105
5106
5107 bool
5108 _WebImpl::HasValidNativeNode(void) const
5109 {
5110         if (__pWebCore && __pWebCore->GetWebNativeNode())
5111         {
5112                 return true;
5113         }
5114
5115         return false;
5116 }
5117
5118
5119 result
5120 _WebImpl::OnPreAttachedToMainTree(void)
5121 {
5122         result r = E_SUCCESS;
5123
5124         r = _ContainerImpl::OnPreAttachedToMainTree();
5125         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5126
5127         if (!HasValidNativeNode())
5128         {
5129                 r = __pWebCore->InitializeWebNativeNode();
5130                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5131
5132                 _ControlManager* pControlManager = _ControlManager::GetInstance();
5133                 SysTryReturnResult(NID_WEB_CTRL, pControlManager, E_SYSTEM, "Failed to get the _ControlManager instance.");
5134                 OnChangeLayout(pControlManager->GetScreenRotation());
5135
5136                 r = InitializeSetting();
5137                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5138
5139                 _SettingInfoImpl::AddSettingEventListener(*this);
5140
5141                 _WebManager* pWebManager = _WebManager::GetInstance();
5142                 SysTryReturnResult(NID_WEB_CTRL, pWebManager, E_SYSTEM, "Failed to get the _WebManager instance.");
5143                 pWebManager->AddWeb(reinterpret_cast< int >(this));
5144         }
5145
5146         if (IsVisible() == true)
5147         {
5148                 _WebManager* pWebManager = _WebManager::GetInstance();
5149                 SysTryReturnResult(NID_WEB_CTRL, pWebManager, E_SYSTEM, "Failed to get the _WebManager instance.");
5150                 pWebManager->SetActiveWeb(this);
5151         }
5152
5153         return E_SUCCESS;
5154 }
5155
5156
5157 result
5158 _WebImpl::OnDetachingFromMainTree(void)
5159 {
5160         result r = E_SUCCESS;
5161
5162         r = _ContainerImpl::OnDetachingFromMainTree();
5163         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5164
5165         _WebManager* pWebManager = _WebManager::GetInstance();
5166         SysTryReturnResult(NID_WEB_CTRL, pWebManager, E_SYSTEM, "Failed to get the _WebManager instance.");
5167         pWebManager->RemoveActiveWeb(this);
5168
5169         return E_SUCCESS;
5170 }
5171
5172
5173 void
5174 _WebImpl::OnSettingChanged(String& key)
5175 {
5176         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
5177         if (!pWebview)
5178         {
5179                 return;
5180         }
5181
5182         if (key == L"http://tizen.org/setting/font.type")
5183         {
5184                 ewk_view_use_settings_font(pWebview);
5185         }
5186 }
5187
5188
5189 void
5190 _WebImpl::OnChangeLayout(_ControlRotation rotation)
5191 {
5192         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
5193         if (!pWebview)
5194         {
5195                 return;
5196         }
5197
5198         int degree = 0;
5199
5200         switch (rotation)
5201         {
5202                 case _CONTROL_ROTATION_0:
5203                         degree =  0;
5204                         break;
5205                 case _CONTROL_ROTATION_90:
5206                         degree =  -90;
5207                         break;
5208                 case _CONTROL_ROTATION_180:
5209                         degree =  180;
5210                         break;
5211                 case _CONTROL_ROTATION_270:
5212                         degree =  90;
5213                         break;
5214                 default:
5215                         SysAssert(false);
5216         }
5217         ewk_view_orientation_send(pWebview, degree);
5218 }
5219
5220
5221 void
5222 _WebImpl::OnChangeLayout(_ControlOrientation orientation)
5223 {
5224         _ContainerImpl::OnChangeLayout(orientation);
5225
5226         if (__pColorPicker.get())
5227         {
5228                 __pColorPicker->ChangeLayout(orientation);
5229         }
5230
5231         HideFormDataWindow();
5232
5233         std::unique_ptr< IEnumerator > pEnum(__webNotificationList.GetEnumeratorN());
5234         _WebNotification* pWebNotification = null;
5235
5236         while (pEnum->MoveNext() == E_SUCCESS)
5237         {
5238                 pWebNotification = static_cast< _WebNotification* >(pEnum->GetCurrent());
5239                 pWebNotification->OnChangeLayout();
5240         }
5241
5242         if (IsKeypadVisible())
5243         {
5244                 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
5245                 SysAssertf(pXformer, "Failed to get CoordinateTransformer");
5246
5247                 _FormImpl* pFormImpl = GetParentFormImpl(dynamic_cast< _ControlImpl* >(this));
5248                 pFormImpl->DeflateClientRectHeight(pXformer->TransformVertical(GetPreviousKeypadBounds().height));
5249         }
5250 }
5251
5252
5253 void
5254 _WebImpl::OnAncestorVisibleStateChanged(const _Control& control)
5255 {
5256         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
5257         if (!pWebview)
5258         {
5259                 return;
5260         }
5261
5262         _WebManager* pWebManager = _WebManager::GetInstance();
5263         SysTryReturnVoidResult(NID_WEB_CTRL, pWebManager, E_SYSTEM, "[E_SYSTEM] Failed to get the _WebManager instance.");
5264         if (IsVisible() == true)
5265         {
5266                 pWebManager->SetActiveWeb(this);
5267                 if (IsLoading())
5268                 {
5269 //                      ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, true);
5270                 }
5271                 else
5272                 {
5273 //                      ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
5274                 }
5275         }
5276         else
5277         {
5278                 pWebManager->RemoveActiveWeb(this);
5279                 if (IsLoading())
5280                 {
5281 //                      ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_HIDDEN, true);
5282                 }
5283                 else
5284                 {
5285 //                      ewk_view_page_visibility_state_set(pWebview, EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
5286                 }
5287         }
5288 }
5289
5290
5291 void
5292 _WebImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
5293 {
5294         _ContainerImpl::OnUserEventReceivedN(requestId, pArgs);
5295         
5296         switch (requestId)
5297         {
5298         case ID_AUTHENTICATION_CONFIRM_POPUP_CANCEL:
5299                 __pAuthPopup->RemoveAllControls();
5300                 __pAuthPopup.reset();
5301                 __pAuthChallenge->Cancel();
5302                 __pAuthChallenge.reset();
5303                 break;
5304         case ID_AUTHENTICATION_CONFIRM_POPUP_PROCESS:
5305                 __pAuthPopup->RemoveAllControls();
5306                 __pAuthPopup.reset();
5307                 if (pArgs)
5308                 {
5309                         std::unique_ptr<ArrayList, AllElementsDeleter> pAuthValue(reinterpret_cast< ArrayList* >(pArgs));
5310                         __pAuthChallenge->Process(*reinterpret_cast< String* >(pAuthValue->GetAt(0)),*reinterpret_cast< String* >(pAuthValue->GetAt(1)));
5311                 }
5312                 __pAuthChallenge.reset();
5313                 break;
5314         case ID_CERTIFICATE_CONFIRM_POPUP_CLOSE:
5315                 __pCertConfirmPopup.reset();
5316                 break;
5317         case ID_PROMPT_POPUP_CLOSE:
5318                 __pPromptPopup.reset();
5319                 break;
5320         case ID_USER_CONFIRM_USERMEDIA_CLOSE:
5321                 __pUserMediaConfirmPopup.reset();
5322                 break;
5323         case ID_USER_CONFIRM_GEOLOCATION_CLOSE:
5324                 __pGeolocationConfirmPopup.reset();
5325                 break;
5326         case ID_USER_CONFIRM_NOTIFICATION_CLOSE:
5327                 __pNotificationConfirmPopup.reset();
5328                 break;
5329         case ID_USER_SCRIPT_ALERT_CLOSE:
5330                 __pScriptAlertConfirmPopup.reset();
5331                 break;
5332         case ID_USER_SCRIPT_CONFIRM_CLOSE:
5333                 __pScriptConfirmPopup.reset();
5334                 break;
5335
5336         case ID_USER_BEFORE_UNLOAD_CONFIRM_CLOSE:
5337                 __pBeforeUnloadConfirmPopup.reset();
5338                 break;
5339
5340         case ID_USER_SCRIPT_SELECTBOX_CLOSE:
5341                 __pSelectBox.reset();
5342                 break;
5343         default:
5344                 break;
5345         }
5346
5347         Resume();
5348 }
5349
5350
5351 _WebDataHandler*
5352 _WebImpl::GetDownloadHandler(void) const
5353 {
5354         return __pWebDownloadHandler.get();
5355 }
5356
5357
5358 Eina_Bool
5359 _WebImpl::HideColorPicker(void)
5360 {
5361         __pColorPicker.reset();
5362
5363         Resume();
5364
5365         return EINA_TRUE;
5366 }
5367
5368
5369 result
5370 _WebImpl::ShowColorPicker(int red, int green, int blue, int alpha, Color& color)
5371 {
5372         result r = E_SUCCESS;
5373
5374         std::unique_ptr<_InputPickerPopup> pColorHadler(new (std::nothrow) _InputPickerPopup());
5375         SysTryReturnResult(NID_WEB_CTRL, pColorHadler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
5376
5377         Tizen::Graphics::Color colorVal(static_cast< byte >(red), static_cast< byte >(green), static_cast< byte >(blue), static_cast< byte >(alpha));
5378
5379         r = pColorHadler->Construct(colorVal, this);
5380         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5381
5382         __pColorPicker = std::move(pColorHadler);
5383
5384         int modalResult = 0;
5385         r = __pColorPicker->ShowAndWait(modalResult);
5386         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5387
5388         if (__pColorPicker)
5389         {
5390                 color = __pColorPicker->GetColor();
5391         }
5392
5393 CATCH:
5394         if (__pColorPicker)
5395         {
5396                 __pColorPicker.reset();
5397                 Resume();
5398         }
5399
5400         return r;
5401 }
5402
5403
5404 result
5405 _WebImpl::ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue, String& dateStr)
5406 {
5407         result r = E_SUCCESS;
5408
5409         std::unique_ptr<_InputPickerPopup> pInputPicker(new (std::nothrow) _InputPickerPopup());
5410         SysTryReturnResult(NID_WEB_CTRL, pInputPicker.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
5411
5412         r = pInputPicker->Construct(String(inputValue), inputType, this);
5413         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5414
5415         __pDatePicker = std::move(pInputPicker);
5416
5417         int modalResult = 0;
5418         r = __pDatePicker->ShowAndWait(modalResult);
5419         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5420
5421         if (__pDatePicker)
5422         {
5423                 dateStr = __pDatePicker->GetDate();
5424         }
5425
5426 CATCH:
5427         if (__pDatePicker)
5428         {
5429                 __pDatePicker.reset();
5430                 Resume();
5431         }
5432
5433         return r;
5434 }
5435
5436
5437 _WebImpl*
5438 _WebImpl::GetInstance(Web* pWeb)
5439 {
5440         return dynamic_cast< _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
5441 }
5442
5443
5444 const _WebImpl*
5445 _WebImpl::GetInstance(const Web* pWeb)
5446 {
5447         return dynamic_cast< const _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
5448 }
5449
5450
5451 int 
5452 _WebImpl::SearchHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
5453 {
5454         int checkReturn = 0;
5455         _DatabaseImpl db;
5456         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5457
5458         String table;
5459         if( checkmime == true)
5460         {
5461                 table = CUSTOM_CONTENT_TABLE_NAME;
5462         }
5463         else
5464         {
5465                 table = CUSTOM_PROTOCOL_TABLE_NAME;
5466         }
5467         
5468         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
5469         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
5470         String target(ewk_custom_handlers_data_target_get(pHandlerData));
5471
5472         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
5473         
5474         result r = db.Construct(handlerPath, "r+", null);
5475         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5476
5477         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"'"));
5478         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5479
5480         if(pEnum.get())
5481         {
5482                 r = pEnum->MoveNext();
5483                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5484                 r = pEnum->GetIntAt(0, checkReturn);
5485                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5486         }
5487         else
5488         {
5489                 checkReturn = 2;
5490         }
5491
5492         return checkReturn;
5493 }
5494
5495
5496 result 
5497 _WebImpl::UnregistrationHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
5498 {
5499         int checkId = 0;
5500         _DatabaseImpl db;
5501         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5502
5503         String table;
5504         if( checkmime == true)
5505         {
5506                 table = CUSTOM_CONTENT_TABLE_NAME;
5507         }
5508         else
5509         {
5510                 table = CUSTOM_PROTOCOL_TABLE_NAME;
5511         }
5512
5513         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
5514         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
5515         String target(ewk_custom_handlers_data_target_get(pHandlerData));
5516         
5517         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
5518         
5519         result r = db.Construct(handlerPath, "r+", null);
5520         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5521
5522         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"'"));
5523         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5524
5525         if(pEnum.get())
5526         {
5527                 r = pEnum->MoveNext();
5528                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5529                 r = pEnum->GetIntAt(0, checkId);
5530                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5531                 
5532                 std::unique_ptr<DbStatement> pDeleteStmt(db.CreateStatementN(L"Delete From " + table + L" Where id = (?)"));
5533                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5534
5535                 r = pDeleteStmt->BindInt(0, checkId);
5536                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5537                 
5538                 db.BeginTransaction();
5539                 
5540                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pDeleteStmt));
5541                 
5542                 db.CommitTransaction();
5543         }
5544
5545         return E_SUCCESS;
5546 }
5547
5548
5549 const Tizen::Base::String 
5550 _WebImpl::GetProtocolFromUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri)
5551 {
5552         if (originUri == L"" || currentUri == L"")
5553         {
5554                 return L"";
5555         }
5556
5557         result r = E_SUCCESS;
5558         String baseUri;
5559         _DatabaseImpl db;
5560         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5561         String originReplace(originUri);
5562         String table(CUSTOM_PROTOCOL_TABLE_NAME);
5563         int found = 0;
5564         int foundQuery = 0;
5565
5566         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
5567         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5568         
5569         r = currentUri.SubString(0, found + 1, baseUri);
5570         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5571                 
5572         r = db.Construct(handlerPath, "r+", null);
5573         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5574         
5575         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select mime, url, allow From " + table + L" Where baseUrl = '" + baseUri + "'"));
5576         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, L"", GetLastResult(), "[%s] Propagating.", GetErrorMessage(r));
5577
5578         if(pEnum.get())
5579         {
5580                 while (pEnum->MoveNext() == E_SUCCESS)
5581                 {                       
5582                         String protocol;
5583                         String queryUrl;
5584                         int allow;
5585                         String originScheme;
5586
5587                         r = pEnum->GetStringAt(0, protocol);
5588                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5589                 
5590                         r = pEnum->GetStringAt(1, queryUrl);
5591                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5592                         
5593                         r = pEnum->GetIntAt(2, allow);
5594                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5595
5596                         if (allow == 0)
5597                         {
5598                                 break;
5599                         }
5600
5601                         String protocolScheme(protocol + L":");
5602                         
5603                         r = originReplace.SubString(0, protocolScheme.GetLength(), originScheme);
5604                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5605                                                 
5606                         if ((originReplace.GetLength() >= protocolScheme.GetLength()) && originScheme.Equals(protocolScheme, false))
5607                         {
5608                                 if (queryUrl.IndexOf(L"%s", 0, foundQuery) == E_SUCCESS)
5609                                 {
5610                                         r = originReplace.Replace(originScheme, "");
5611                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5612                                         
5613                                         queryUrl.Replace("%s", originReplace, 0);
5614                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5615
5616                                         return queryUrl;
5617                                 }
5618                         }               
5619                 }
5620         }
5621         
5622         return L"";
5623 }
5624
5625
5626 const Tizen::Base::String 
5627 _WebImpl::GetRedirectUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri, const Tizen::Base::String& mime)
5628 {
5629         if (originUri == L"" || currentUri == L"" || mime == L"")
5630         {
5631                 return L"";
5632         }
5633
5634         result r = E_SUCCESS;
5635         String baseUri;
5636         String contentUrl;
5637         String originUrlStr = originUri;
5638         const String replaceStr = L"%s";
5639         _DatabaseImpl db;
5640         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5641         String table(CUSTOM_CONTENT_TABLE_NAME);
5642         int allow = 0;
5643         int found = 0;
5644         
5645         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
5646         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5647                 
5648         r = currentUri.SubString(0, found + 1, baseUri);
5649         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5650                 
5651         r = db.Construct(handlerPath, "r+", null);
5652         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5653
5654         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select allow, url From " + table + L" Where baseUrl = '" + baseUri + "' AND mime = '" + mime + L"'"));
5655         
5656         if (pEnum.get())
5657         {
5658                 r = pEnum->MoveNext();
5659                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5660                 r = pEnum->GetIntAt(0, allow);
5661                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5662                 r = pEnum->GetStringAt(1, contentUrl);
5663                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5664                         
5665                 if (allow == 0)
5666                 {
5667                         return L"";
5668                 }
5669                 else
5670                 {
5671                         if (contentUrl != L"")
5672                         {
5673                                 r = contentUrl.Replace(replaceStr, originUrlStr, 0);
5674                                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5675
5676                                 return contentUrl;
5677                         }
5678                 }
5679         }
5680         
5681         return L"";
5682 }
5683
5684
5685 void
5686 _WebImpl::SetFormDataList(Eina_List* pFormDataList)
5687 {
5688         __pFormDataList = pFormDataList;
5689 }
5690
5691
5692 bool
5693 _WebImpl::IsFormDataWindowVisible(void) const
5694 {
5695         return __isFormDataVisible;
5696 }
5697
5698
5699 result
5700 _WebImpl::ShowFormDataWindow(const Rectangle& windowRect, Evas_Object* pWebView)
5701 {
5702         Rectangle rect(_CoordinateSystemUtils::InverseTransform(Rectangle(windowRect.x, windowRect.y + windowRect.height, windowRect.width, windowRect.height)));
5703
5704         if (__isFormDataVisible)
5705         {
5706                 result r = __pFormDataWindow->UpdateList(__pFormDataList, rect);
5707                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5708         }
5709         else
5710         {
5711                 __pFormDataWindow.reset();
5712
5713                 std::unique_ptr<_FormDataWindow> pFormDataWindow( new (std::nothrow) _FormDataWindow());
5714                 SysTryReturnResult(NID_WEB_CTRL, pFormDataWindow.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5715
5716                 result r = pFormDataWindow->Construct(rect, this, pWebView);
5717                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5718
5719                 r = pFormDataWindow->UpdateList(__pFormDataList, rect);
5720                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5721
5722                 r = pFormDataWindow->LaunchFormDataWindow();
5723                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5724
5725                 __pFormDataWindow = std::move(pFormDataWindow);
5726                 __isFormDataVisible = true;
5727         }
5728
5729         return E_SUCCESS;
5730 }
5731
5732
5733 void
5734 _WebImpl::HideFormDataWindow(bool delWindow)
5735 {
5736         if (delWindow)
5737         {
5738                 __pFormDataWindow.reset();
5739         }
5740
5741         __isFormDataVisible = false;
5742 }
5743
5744
5745 void
5746 _WebImpl::ClearWebNotification(_WebNotification* pWebNotification)
5747 {
5748         __webNotificationList.Remove(*pWebNotification);
5749 }
5750
5751
5752 void
5753 _WebImpl::SetWebNotification(_WebNotification* pWebNotification)
5754 {
5755         __webNotificationList.Add(pWebNotification);
5756 }
5757
5758
5759 }}} // Tizen::Web::Controls