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