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