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