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