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