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