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