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