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