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