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