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