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