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