Fix for focus issue
[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                 pImpl->SetPreviousKeypadBounds(rect);
1673         }
1674         else
1675         {
1676                 result r = pImpl->SetFullScreenKeypad();
1677                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1678         }
1679 }
1680
1681
1682 void
1683 OnWebKeypadOpened(void* pUserData, Evas_Object* pView, void* pEventInfo)
1684 {
1685         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1686         SysAssertf(pImpl, "Failed to request");
1687
1688         pImpl->SetKeypadVisibleState(true);
1689
1690         _FormImpl* pFormImpl = pImpl->GetParentFormImpl(dynamic_cast< _ControlImpl* >(pImpl));
1691         if (pFormImpl)
1692         {
1693                 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1694                 SysAssertf(pXformer, "Failed to get CoordinateTransformer");
1695
1696                 pFormImpl->DeflateClientRectHeight(pXformer->TransformVertical(pImpl->GetPreviousKeypadBounds().height));
1697
1698                 if (pFormImpl->HasFooter())
1699                 {
1700                         pFormImpl->GetCore().SetKeypadShowState(true);
1701                         pFormImpl->Draw();
1702                 }
1703         }
1704
1705         if (pImpl->GetWebKeypadEventListener())
1706         {
1707                 pImpl->GetWebKeypadEventListener()->OnWebKeypadOpened(*static_cast< Web* >(&pImpl->GetPublic()));
1708         }
1709 }
1710
1711
1712 void
1713 OnWebKeypadClosed(void* pUserData, Evas_Object* pView, void* pEventInfo)
1714 {
1715         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1716         SysAssertf(pImpl, "Failed to request");
1717
1718         _FormImpl* pFormImpl = pImpl->GetParentFormImpl(dynamic_cast< _ControlImpl* >(pImpl));
1719         if (pFormImpl)
1720         {
1721                 pFormImpl->DeflateClientRectHeight(0);
1722
1723                 if (pFormImpl->HasFooter())
1724                 {
1725                         pFormImpl->GetCore().SetKeypadShowState(false);
1726                         pFormImpl->Draw();
1727                 }
1728         }
1729
1730         if (pImpl->GetWebKeypadEventListener())
1731         {
1732                 pImpl->GetWebKeypadEventListener()->OnWebKeypadClosed(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1733         }
1734
1735         pImpl->SetKeypadVisibleState(false);
1736 }
1737
1738
1739 void
1740 OnWindowObjectFocusLost(void* pUserData, Evas_Object* pWin, void* pEvent_info)
1741 {
1742         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1743         SysAssertf(pImpl, "Failed to request");
1744
1745         pImpl->SetWinFocusLost(true);
1746 }
1747
1748
1749 void
1750 OnWindowObjectFocusGained(void* pUserData, Evas_Object* pWin, void* pEvent_info)
1751 {
1752         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1753         SysAssertf(pImpl, "Failed to request");
1754
1755         if (pImpl->IsVisible() == true && pImpl->IsFocused() == true)
1756         {
1757                 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
1758                 SysAssertf(pWebCore, "Failed to get Web core object");
1759
1760                 if (pImpl->IsWinFocusLost() == true)
1761                 {
1762                         Ewk_Settings* pSettings = ewk_view_settings_get(pWebCore->GetWebNativeNode());
1763                         SysAssertf(pSettings, "Failed to get settings instance.");
1764
1765                         if (ewk_settings_clear_text_selection_automatically_get(pSettings) == EINA_FALSE)
1766                         {
1767                                 ewk_settings_clear_text_selection_automatically_set(pSettings, EINA_TRUE);
1768
1769                                 evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
1770                         }
1771                         else if (pImpl->IsKeypadOpened() == true)
1772                         {
1773                                 evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
1774                         }
1775                 }
1776         }
1777
1778         pImpl->SetWinFocusLost(false);
1779 }
1780
1781
1782 void
1783 OnWebNativeNodeFocusGained(void* pUserData, Evas* pCanvas, Evas_Object* pView, void* pEventInfo)
1784 {
1785         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1786         SysAssertf(pImpl, "Failed to request");
1787
1788         if (pImpl->IsKeypadOpened() == true)
1789         {
1790                 pImpl->SetKeypadOpened(false);
1791         }
1792 }
1793
1794
1795 void
1796 OnWebNativeNodeFocusLost(void* pUserData, Evas* pCanvas, Evas_Object* pView, void* pEventInfo)
1797 {
1798         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1799         SysAssertf(pImpl, "Failed to request");
1800
1801         _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
1802         SysAssertf(pWebCore, "Failed to get Web core object");
1803
1804         Eina_Rectangle leftHandle;
1805         Eina_Rectangle rightHandle;
1806
1807         EINA_RECTANGLE_SET(&leftHandle, 0, 0, 0, 0);
1808         EINA_RECTANGLE_SET(&rightHandle, 0, 0, 0, 0);
1809
1810         if (pImpl->IsWinFocusLost() == true && ewk_view_text_selection_range_get(pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle))
1811         {
1812                 Ewk_Settings* pSettings = ewk_view_settings_get(pWebCore->GetWebNativeNode());
1813                 SysAssertf(pSettings, "Failed to get settings instance.");
1814
1815                 ewk_settings_clear_text_selection_automatically_set(pSettings, EINA_FALSE);
1816         }
1817
1818
1819
1820 Eina_Bool
1821 OnColorPickerProviderRequested(Ewk_View_Smart_Data* pSmartData, int red, int green, int blue, int alpha)
1822 {
1823         SysAssertf(pSmartData, "invalid smartdata");
1824         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1825         SysAssertf(pWebImpl, "Failed to get Impl");
1826
1827         result r = E_SUCCESS;
1828
1829         if (pWebImpl->GetColorpicker())
1830         {
1831                 return EINA_FALSE;
1832         }
1833
1834         Color color;
1835
1836         r = pWebImpl->ShowColorPicker(red, green, blue, alpha, color);
1837         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1838
1839         byte r1, g1, b1, a1;
1840         color.GetColorComponents(r1, g1, b1, a1);
1841         ewk_view_color_picker_color_set(pSmartData->self, r1, g1, b1, a1);
1842
1843         return EINA_TRUE;
1844 }
1845
1846
1847 Eina_Bool
1848 OnColorPickerProviderDismissed(Ewk_View_Smart_Data* pSmartData)
1849 {
1850         SysAssertf(pSmartData, "invalid smartdata");
1851
1852         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1853         SysAssertf(pWebImpl, "Failed to get Impl");
1854
1855         return pWebImpl->HideColorPicker();
1856 }
1857
1858
1859 Eina_Bool
1860 OnDatePickerProviderRequested(Ewk_View_Smart_Data* pSmartData, Ewk_Input_Type inputType, const char* inputValue)
1861 {
1862         SysAssertf(pSmartData, "Failed to request");
1863         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1864         SysAssertf(pWebImpl, "Failed to get Impl");
1865
1866         result r = E_SUCCESS;
1867
1868         if (pWebImpl->GetDatepicker())
1869         {
1870                 ewk_view_focused_input_element_value_set(pSmartData->self, inputValue);
1871
1872                 return EINA_FALSE;
1873         }
1874
1875         String dateStr;
1876
1877         r = pWebImpl->ShowDatePicker(inputType, inputValue, dateStr);
1878         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1879
1880         std::unique_ptr<char[]> pDateStr(_StringConverter::CopyToCharArrayN(dateStr));
1881         SysTryReturn(NID_WEB_CTRL, pDateStr.get(), EINA_FALSE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1882
1883         ewk_view_focused_input_element_value_set(pSmartData->self, pDateStr.get());
1884
1885         return EINA_TRUE;
1886 }
1887
1888
1889 Eina_Bool
1890 OnSelectBoxRequested(Ewk_View_Smart_Data* pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, double pageScaleFactor, Eina_List* pItems, int selectedIndex)
1891 {
1892         SysAssertf(pSmartData, "Failed to request");
1893
1894         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1895         SysAssertf(pWebImpl, "Failed to get Impl");
1896
1897         result r = pWebImpl->ShowSelectBoxPopup(false, L"", pItems, pSmartData->self, selectedIndex);
1898         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1899
1900         return EINA_TRUE;
1901 }
1902
1903
1904 Eina_Bool
1905 OnMultiSelectBoxRequested(Ewk_View_Smart_Data* pSmartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Eina_List* pItems)
1906 {
1907         SysAssertf(pSmartData, "Failed to request");
1908
1909         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1910         SysAssertf(pWebImpl, "Failed to get Impl");
1911
1912         result r = pWebImpl->ShowSelectBoxPopup(true, L"", pItems, pSmartData->self, 0);
1913         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1914
1915         return EINA_TRUE;
1916 }
1917
1918
1919 Eina_Bool
1920 OnSelectBoxClosed(Ewk_View_Smart_Data* pSmartData)
1921 {
1922         SysAssertf(pSmartData, "invalid smartdata");
1923
1924         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1925         SysAssertf(pWebImpl, "Failed to get Impl");
1926
1927         result r = pWebImpl->ClearSelectBoxPopup();
1928         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1929
1930         return EINA_TRUE;
1931 }
1932
1933
1934 Eina_Bool
1935 OnSelectBoxUpdateRequested(Ewk_View_Smart_Data *pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, Eina_List* pItems, int selectedIndex)
1936 {
1937         SysAssertf(pSmartData, "invalid smartdata");
1938
1939         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1940         SysAssertf(pWebImpl, "Failed to get Impl");
1941
1942         result r = pWebImpl->UpdateSelectBoxPopup(pItems, selectedIndex, false);
1943         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1944
1945         return EINA_TRUE;
1946 }
1947
1948
1949 Eina_Bool
1950 OnFormDataCandidateShow(Ewk_View_Smart_Data *pSmartData, int x, int y, int w, int h)
1951 {
1952         SysAssertf(pSmartData, "Failed to request");
1953
1954         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1955         SysAssertf(pWebImpl, "Failed to get Impl");
1956
1957         Rectangle windowRect(x, y, w, h);
1958         result r = pWebImpl->ShowFormDataWindow(windowRect, pSmartData->self);
1959         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1960
1961         return EINA_TRUE;
1962 }
1963
1964
1965 Eina_Bool
1966 OnFormDataCandidateHide(Ewk_View_Smart_Data *pSmartData)
1967 {
1968         SysAssertf(pSmartData, "Failed to request");
1969
1970         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1971         SysAssertf(pWebImpl, "Failed to get Impl");
1972
1973         if (pWebImpl->IsFormDataWindowVisible())
1974         {
1975                 pWebImpl->HideFormDataWindow();
1976         }
1977
1978         return EINA_TRUE;
1979 }
1980
1981
1982 Eina_Bool
1983 OnFormDataCandidateUpdate(Ewk_View_Smart_Data *pSmartData, Eina_List *pDataList)
1984 {
1985         SysAssertf(pSmartData, "Failed to request");
1986
1987         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1988         SysAssertf(pWebImpl, "Failed to get Impl");
1989
1990         pWebImpl->SetFormDataList(pDataList);
1991
1992         return EINA_TRUE;
1993 }
1994
1995
1996 Eina_Bool
1997 OnFormDataCandidateIsShowing(Ewk_View_Smart_Data *pSmartData)
1998 {
1999         SysAssertf(pSmartData, "Failed to request");
2000
2001         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
2002         SysAssertf(pWebImpl, "Failed to get Impl");
2003
2004         if (pWebImpl->IsFormDataWindowVisible())
2005         {
2006                 return EINA_TRUE;
2007         }
2008         else
2009         {
2010                 return EINA_FALSE;
2011         }
2012 }
2013
2014
2015 void
2016 OnCookiesPolicyGot(Ewk_Cookie_Accept_Policy policy, Ewk_Web_Error *pError, void *pUserData)
2017 {
2018         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
2019         SysAssertf(pPresenter && !pError, "Failed to request");
2020
2021         bool ret = EINA_TRUE;
2022
2023         switch (policy)
2024         {
2025         case EWK_COOKIE_ACCEPT_POLICY_ALWAYS:
2026                 //fall through
2027         case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY:
2028                 ret = EINA_TRUE;
2029                 break;
2030
2031         case EWK_COOKIE_ACCEPT_POLICY_NEVER:
2032                 //fall through
2033                 ret = EINA_FALSE;
2034                 break;
2035
2036         default:
2037                 SysAssert(false);
2038         }
2039
2040         SysLog(NID_WEB_CTRL, "The current value of policy is %d", ret);
2041
2042         pPresenter->EndAsyncProcess(ret);
2043 }
2044
2045
2046 void
2047 OnScriptExecuted(Evas_Object* pView, const char* pResult, void* pUserData)
2048 {
2049         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
2050         SysAssertf(pPresenter, "Failed to request");
2051
2052         String result(pResult);
2053         SysLog(NID_WEB_CTRL, "result : %ls", result.GetPointer());
2054
2055         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, WEB_CTRL));
2056         _WebManager* pWebManager = _WebManager::GetInstance();
2057         if (pWebManager->IsValidCallback(reinterpret_cast< int >(pImpl), reinterpret_cast< int >(pPresenter)))
2058         {
2059                 pPresenter->EndAsyncProcess(result);
2060         }
2061 }
2062
2063
2064 void
2065 OnTextFound(void* pUserData, Evas_Object* pView, void* pEventInfo)
2066 {
2067         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
2068         SysAssertf(pImpl, "Failed to request");
2069
2070         int* pTotalCount = reinterpret_cast< int* >(pEventInfo);
2071         SysLog(NID_WEB_CTRL, "The current value of totalCount is %d", *pTotalCount);
2072
2073         _WebPresenter* pWebPresenter = pImpl->GetSearchPresenter();
2074
2075         if (pWebPresenter)
2076         {
2077                 pWebPresenter->EndAsyncProcess(*pTotalCount);
2078         }
2079         else
2080         {
2081                 if (pImpl->GetTextSearchListener())
2082                 {
2083                         result r = E_SUCCESS;
2084
2085                         int ordinal = 0;
2086
2087                         if (*pTotalCount > 0)
2088                         {
2089                                 ordinal = pImpl->GetAsyncSearchOrdinal();
2090                                 pImpl->SetAsyncSearchResult(*pTotalCount);
2091                         }
2092
2093                         if (pImpl->GetPendingAsyncSearchCount() > 0)
2094                         {
2095                                 return;
2096                         }
2097
2098                         std::unique_ptr<Integer> pCount(new (std::nothrow) Integer(*pTotalCount));
2099                         std::unique_ptr<Integer> pOrdinal(new (std::nothrow) Integer(ordinal));
2100                         std::unique_ptr<_TextSearchEventArg> pEventArg(new (std::nothrow) _TextSearchEventArg(WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND));
2101                         SysTryReturnVoidResult(NID_WEB_CTRL, pCount.get() && pOrdinal.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2102
2103                         r = pEventArg->SetEventInfo(_TextSearchEventArg::TOTAL_COUNT, *pCount.get());
2104                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2105                         pCount.release();
2106
2107                         r = pEventArg->SetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL, *pOrdinal.get());
2108                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2109                         pOrdinal.release();
2110
2111                         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
2112                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2113                         pEventArg.release();
2114                 }
2115         }
2116 }
2117
2118
2119 class _JsBridgeHashCodeProvider
2120         : public Tizen::Base::Collection::IHashCodeProviderT< Tizen::Base::String >
2121 {
2122 public:
2123         _JsBridgeHashCodeProvider(){}
2124         virtual ~_JsBridgeHashCodeProvider(void) {}
2125
2126
2127         int GetHashCode(const Tizen::Base::String& obj) const
2128         {
2129                 return obj.GetHashCode();
2130         }
2131
2132 };
2133
2134
2135 //Comparer implementation
2136 class _JsBridgeComparer
2137         : public Tizen::Base::Collection::IComparerT< Tizen::Base::String >
2138 {
2139 public:
2140         _JsBridgeComparer(){}
2141         virtual ~_JsBridgeComparer(void) {}
2142
2143
2144         result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
2145         {
2146                 if (obj1 == obj2)
2147                 {
2148                         cmp = 0;
2149                 }
2150                 else
2151                 {
2152                         cmp = 1;
2153                 }
2154
2155                 return E_SUCCESS;
2156         }
2157
2158 };
2159
2160
2161 _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
2162         : _ContainerImpl(pWeb, pCore)
2163         , __isFooterVisible(false)
2164         , __isKeypadVisible(false)
2165         , __isKeypadOpened(false)
2166         , __isWinFocusLost(false)
2167         , __isLoadingErrorOccurred(false)
2168         , __isRedirectRequested(false)
2169         , __isCertificateRequested(false)
2170         , __isCertificateConfirmed(false)
2171         , __isFormDataVisible(false)
2172         , __keypadBounds(0, 0, 0, 0)
2173         , __pWebCore(null)
2174         , __pUserLoadingListener(null)
2175         , __pUserUiListener(null)
2176         , __pUserUiListenerF(null)
2177         , __pUserKeypadEventListener(null)
2178         , __pTextSearchListener(null)
2179         , __pKeypad(null)
2180         , __pJsBridgeList(null)
2181         , __pJsProvider(null)
2182         , __pJsComparer(null)
2183         , __pWebDownloadHandler(null)
2184         , __pWebEvent(null)
2185         , __pAuthChallenge(null)
2186         , __pAuthPopup(null)
2187         , __pUserMediaConfirmPopup(null)
2188         , __pContentHandlerConfirmPopup(null)
2189         , __pProtocolHandlerConfirmPopup(null)
2190         , __pGeolocationConfirmPopup(null)
2191         , __pNotificationConfirmPopup(null)
2192         , __pScriptAlertConfirmPopup(null)
2193         , __pScriptConfirmPopup(null)
2194         , __pAppCacheConfirmPopup(null)
2195         , __pDbQuotaConfirmPopup(null)
2196         , __pLocalFsQuotaConfirmPopup(null)
2197         , __pIndexedDbQuotaConfirmPopup(null)
2198         , __pPromptPopup(null)
2199         , __pCertConfirmPopup(null)
2200         , __pSelectBox(null)
2201         , __pDatePicker(null)
2202         , __pColorPicker(null)
2203         , __pFormDataWindow(null)
2204         , __pVibrator(null)
2205         , __policy(WEB_DECISION_CONTINUE)
2206         , __defaultUserAgent(L"")
2207         , __pFormDataList(null)
2208         , __popupClosed(false)
2209 {
2210         __textSearch.__searchAll = false;
2211         __textSearch.__searchForward = true;
2212         __textSearch.__caseSensitive = false;
2213         __textSearch.__pending = 0;
2214         __textSearch.__currentIndex = 1;
2215         __textSearch.__totalCount = -1;
2216         __textSearch.__text = L"";
2217 }
2218
2219
2220 _WebImpl::~_WebImpl()
2221 {
2222         _WebManager* pWebManager = _WebManager::GetInstance();
2223         SysTryCatch(NID_WEB_CTRL, pWebManager, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2224
2225         pWebManager->RemoveWeb(reinterpret_cast< int >(this));
2226         pWebManager->RemoveActiveWeb(this);
2227
2228 CATCH:
2229         RemoveEventListenerCallback();
2230
2231         ClearCertificateDb();
2232 }
2233
2234
2235 _WebImpl*
2236 _WebImpl::CreateWebImplN(Web* pControl, const Rectangle& bounds)
2237 {
2238         result r = E_SUCCESS;
2239
2240         r = GET_SIZE_INFO(Web).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
2241         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2242
2243         _Web* pCore = _Web::CreateWebN();
2244         SysTryReturn(NID_WEB_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2245
2246         _WebImpl* pImpl = new (std::nothrow) _WebImpl(pControl, pCore);
2247
2248         r = CheckConstruction(pCore, pImpl);
2249         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2250
2251         r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Web), bounds, pCore->GetOrientation());
2252         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2253
2254         r = pImpl->Construct();
2255         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2256
2257         return pImpl;
2258
2259 CATCH:
2260         delete pImpl;
2261
2262         return null;
2263 }
2264
2265
2266 _WebImpl*
2267 _WebImpl::CreateWebImplN(Web* pControl, const FloatRectangle& bounds)
2268 {
2269         result r = E_SUCCESS;
2270
2271         r = GET_SIZE_INFO(Web).CheckInitialSizeValidF(FloatDimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
2272         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2273
2274         _Web* pCore = _Web::CreateWebN();
2275         SysTryReturn(NID_WEB_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2276
2277         _WebImpl* pImpl = new (std::nothrow) _WebImpl(pControl, pCore);
2278
2279         r = CheckConstruction(pCore, pImpl);
2280         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2281
2282         r = pImpl->InitializeBoundsPropertiesF(GET_SIZE_INFO(Web), bounds, pCore->GetOrientation());
2283         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2284
2285         r = pImpl->Construct();
2286         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2287
2288         return pImpl;
2289
2290 CATCH:
2291         delete pImpl;
2292
2293         return null;
2294 }
2295
2296
2297 result
2298 _WebImpl::Construct(void)
2299 {
2300         result r = E_SUCCESS;
2301
2302         r = __mutex.Create();
2303         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2304
2305         r = __textSearch.__searchQueue.Construct();
2306         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2307
2308         r = __webNotificationList.Construct();
2309         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2310
2311         r = InitJsBridgeList();
2312         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2313
2314         r = InitWebEvent();
2315         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2316
2317         __pWebCore = dynamic_cast< _Web* >(&(GetCore()));
2318         SysTryReturnResult(NID_WEB_CTRL, __pWebCore, E_SYSTEM, "A system error has been occurred. Failed to get web control");
2319
2320         return E_SUCCESS;
2321 }
2322
2323
2324 result
2325 _WebImpl::InitializeSetting(void)
2326 {
2327         result r = E_SUCCESS;
2328
2329         WebSetting* pWebSetting = __pWebCore->GetSetting();
2330         _WebSettingImpl* pWebSettingImpl = _WebSettingImpl::GetInstance(pWebSetting);
2331
2332         SetCookieEnabled(pWebSettingImpl->IsCookieEnabled());
2333         SetPrivateBrowsingEnabled(pWebSettingImpl->IsPrivateBrowsingEnabled());
2334
2335         __defaultUserAgent = pWebSettingImpl->GetUserAgent();
2336
2337         r = SetSetting(*pWebSetting);
2338         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2339
2340         SetEventListenerCallback();
2341
2342         return E_SUCCESS;
2343 }
2344
2345
2346 bool
2347 _WebImpl::IsLayoutable(void) const
2348 {
2349         return true;
2350 }
2351
2352
2353 result
2354 _WebImpl::InitWebEvent(void)
2355 {
2356         __pWebEvent = std::unique_ptr<_WebEvent>(new (std::nothrow) _WebEvent());
2357         SysTryReturnResult(NID_WEB_CTRL, __pWebEvent.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
2358
2359         return __pWebEvent->Construct(*this);
2360 }
2361
2362
2363 _WebEvent*
2364 _WebImpl::GetWebEvent(void) const
2365 {
2366         return __pWebEvent.get();
2367 }
2368
2369
2370 Eina_Hash*
2371 _WebImpl::ConvertToSlpHeaderN(const HttpHeader& header) const
2372 {
2373         Eina_Hash* pHttpHeader = null;
2374
2375         std::unique_ptr<IList> pFieldNameList(header.GetFieldNamesN());
2376         if (pFieldNameList.get())
2377         {
2378                 pHttpHeader = eina_hash_string_small_new(FreeCharArray);
2379                 SysTryReturn(NID_WEB_CTRL, pHttpHeader, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2380                 
2381                 int count = pFieldNameList->GetCount();
2382
2383                 for (int i = 0; i < count; i++)
2384                 {
2385                         String* pFieldName = dynamic_cast< String* >(pFieldNameList->GetAt(i));
2386                         SysTryCatch(NID_WEB_CTRL, pFieldName, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2387
2388                         std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(*pFieldName));
2389                         SysTryCatch(NID_WEB_CTRL, pKey.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2390
2391                         std::unique_ptr<IEnumerator> pFieldValueEnum(header.GetFieldValuesN(*pFieldName));
2392                         SysTryCatch(NID_WEB_CTRL, pFieldValueEnum.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2393                         
2394                         while (pFieldValueEnum->MoveNext() == E_SUCCESS)
2395                         {
2396                                 Eina_Bool ret = false;
2397
2398                                 String* pFieldValue = dynamic_cast< String* >(pFieldValueEnum->GetCurrent());
2399                                 SysTryCatch(NID_WEB_CTRL, pFieldValue, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2400
2401                                 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pFieldValue));
2402                                 SysTryCatch(NID_WEB_CTRL, pValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2403
2404                                 ret = eina_hash_add(pHttpHeader, pKey.get(), pValue.release());
2405                                 SysTryCatch(NID_WEB_CTRL, ret == EINA_TRUE, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2406                         }
2407                 }
2408         }
2409         return pHttpHeader;
2410
2411 CATCH:
2412         eina_hash_free(pHttpHeader);
2413
2414         return null;
2415 }
2416
2417
2418 result
2419 _WebImpl::LoadUrl(const String& url) const
2420 {
2421         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2422         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2423
2424         ewk_view_url_set(__pWebCore->GetWebNativeNode(), pUrl.get());
2425
2426         return E_SUCCESS;
2427 }
2428
2429
2430 result 
2431 _WebImpl::LoadUrl(const String& url, const HttpHeader& header)
2432 {
2433         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2434         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2435         
2436         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
2437
2438         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_GET, pHttpHeader, null);
2439
2440         eina_hash_free(pHttpHeader);
2441
2442         return E_SUCCESS;
2443 }
2444
2445
2446 result
2447 _WebImpl::LoadUrlWithPostRequest(const String& url, const HttpHeader& header, const ByteBuffer& body) const
2448 {
2449         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
2450         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2451
2452         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
2453
2454         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_POST, pHttpHeader, reinterpret_cast< const char* >(body.GetPointer()));
2455
2456         eina_hash_free(pHttpHeader);
2457
2458         return E_SUCCESS;
2459 }
2460
2461
2462 result
2463 _WebImpl::LoadData(const String& baseUrl, const ByteBuffer& content, const String& mime, const String& encoding) const
2464 {
2465         SysTryReturnResult(NID_WEB_CTRL, content.GetLimit() > 0, E_INVALID_ARG, "The content buffer is empty.");
2466
2467         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(baseUrl));
2468         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
2469         std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(encoding));
2470         SysTryReturn(NID_WEB_CTRL, pUrl.get() && pMime.get() && pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2471
2472         ewk_view_contents_set(__pWebCore->GetWebNativeNode(), reinterpret_cast< const char* >(content.GetPointer()), content.GetLimit(), pMime.get(), pEncoding.get(), pUrl.get());
2473
2474         return E_SUCCESS;
2475 }
2476
2477
2478 void
2479 _WebImpl::Pause(void)
2480 {
2481         ewk_view_suspend(__pWebCore->GetWebNativeNode());
2482 }
2483
2484
2485 void
2486 _WebImpl::Resume(void)
2487 {
2488         ewk_view_resume(__pWebCore->GetWebNativeNode());
2489 }
2490
2491
2492 result
2493 _WebImpl::ShowSelectBoxPopup(bool isMultiSelect, const String& title, Eina_List* pItems, Evas_Object* pWebView, int selectedIndex)
2494 {
2495         __pSelectBox.reset();
2496
2497         SysTryReturnResult(NID_WEB_CTRL, eina_list_count(pItems) > 0, E_SYSTEM, "ItemCount is invalid.");
2498
2499         result r = E_SUCCESS;
2500
2501         std::unique_ptr<_SelectBox> pSelectBox(new (std::nothrow) _SelectBox());
2502         SysTryReturnResult(NID_WEB_CTRL, pSelectBox.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
2503
2504         r = pSelectBox->Construct(isMultiSelect, title, DEFAULT_LIST_ITEM_COUNT, pWebView);
2505         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2506
2507         r = pSelectBox->UpdateList(pItems, selectedIndex, false, false);
2508         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2509
2510         __pSelectBox = std::move(pSelectBox);
2511
2512         return __pSelectBox->ShowPopup();
2513 }
2514
2515
2516 result
2517 _WebImpl::UpdateSelectBoxPopup(Eina_List* pItems, int selectedIndex, bool isGroupedList)
2518 {
2519         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2520
2521         return __pSelectBox->UpdateList(pItems, selectedIndex, true, isGroupedList);
2522 }
2523
2524
2525 result
2526 _WebImpl::ClearSelectBoxPopup(void)
2527 {
2528         SysTryReturnResult(NID_WEB_CTRL, __pSelectBox.get(), E_SYSTEM, "SlectBox instance does not exist.");
2529
2530         __pSelectBox.reset();
2531
2532         Resume();
2533
2534         return E_SUCCESS;
2535 }
2536
2537
2538 _InputPickerPopup*
2539 _WebImpl::GetDatepicker(void)
2540 {
2541         _InputPickerPopup* pInputPicker =null;
2542         if (__pDatePicker)
2543         {
2544                 pInputPicker =  __pDatePicker.get();
2545         }
2546         return pInputPicker;
2547 }
2548
2549
2550 _InputPickerPopup*
2551 _WebImpl::GetColorpicker(void)
2552 {
2553         _InputPickerPopup* pInputPicker =null;
2554         if (__pColorPicker)
2555         {
2556                 pInputPicker =  __pColorPicker.get();
2557         }
2558         return pInputPicker;
2559 }
2560
2561
2562 bool
2563 _WebImpl::CanGoBack(void) const
2564 {
2565         return static_cast< bool >(ewk_view_back_possible(__pWebCore->GetWebNativeNode()));
2566 }
2567
2568
2569 bool
2570 _WebImpl::CanGoForward(void) const
2571 {
2572         return static_cast< bool >(ewk_view_forward_possible(__pWebCore->GetWebNativeNode()));
2573 }
2574
2575
2576 void
2577 _WebImpl::GoBack(void) const
2578 {
2579         ewk_view_back(__pWebCore->GetWebNativeNode());
2580 }
2581
2582
2583 void
2584 _WebImpl::GoForward(void) const
2585 {
2586         ewk_view_forward(__pWebCore->GetWebNativeNode());
2587 }
2588
2589
2590 Tizen::Base::String
2591 _WebImpl::GetUrl(void) const
2592 {
2593         return ewk_view_url_get(__pWebCore->GetWebNativeNode());
2594 }
2595
2596
2597 Tizen::Base::String
2598 _WebImpl::GetTitle(void) const
2599 {
2600         return ewk_view_title_get(__pWebCore->GetWebNativeNode());
2601 }
2602
2603
2604 void
2605 _WebImpl::StopLoading(void) const
2606 {
2607         ewk_view_stop(__pWebCore->GetWebNativeNode());
2608 }
2609
2610
2611 void
2612 _WebImpl::Reload(void) const
2613 {
2614         ewk_view_reload(__pWebCore->GetWebNativeNode());
2615 }
2616
2617
2618 String*
2619 _WebImpl::EvaluateJavascriptN(const String& scriptCode)
2620 {
2621         Evas_Object* pView = __pWebCore->GetWebNativeNode();
2622         if (!pView)
2623         {
2624                 return null;
2625         }
2626         
2627         std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
2628         SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2629
2630         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
2631         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2632
2633         ewk_view_script_execute(pView, pScript.get(), OnScriptExecuted, pPresenter.get());
2634
2635         String* pResult = new (std::nothrow) String(L"");
2636         SysTryReturn(NID_WEB_CTRL, pResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2637
2638         pPresenter->WaitAsyncProcess(*pResult);
2639
2640         return pResult;
2641 }
2642
2643
2644 result
2645 _WebImpl::SetZoomLevel(float level)
2646 {
2647         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);
2648
2649         ewk_view_scale_set(__pWebCore->GetWebNativeNode(), static_cast< double >(level), 0, 0);
2650
2651         return E_SUCCESS;
2652 }
2653
2654
2655 float
2656 _WebImpl::GetZoomLevel(void) const
2657 {
2658         return static_cast< float >(ewk_view_scale_get(__pWebCore->GetWebNativeNode()));
2659 }
2660
2661
2662 const PageNavigationList*
2663 _WebImpl::GetBackForwardListN(void) const
2664 {
2665         Evas_Object* pView = __pWebCore->GetWebNativeNode();
2666         if (!pView)
2667         {
2668                 return null;
2669         }
2670
2671         result r = E_SUCCESS;
2672
2673         _PageNavigationListImpl* pNavigationListImpl = null;
2674         _HistoryItemImpl* pHistoryItemImpl = null;
2675
2676         std::unique_ptr<PageNavigationList> pNavigationList;
2677         std::unique_ptr<ArrayList, AllElementsDeleter> pHistoryList;
2678
2679         int backCount = 0;
2680         int forwardCount = 0;
2681
2682         String url(L"");
2683         String title(L"");
2684
2685         Ewk_History* pEwkHistoryList = ewk_view_history_get(pView);
2686         SysTryReturn(NID_WEB_CTRL, pEwkHistoryList, null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get full history.", GetErrorMessage(E_SYSTEM));
2687
2688         Ewk_History_Item* pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, 0);
2689         SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_DATA_NOT_FOUND, "[%s] There is no history.", GetErrorMessage(E_DATA_NOT_FOUND));
2690
2691         pNavigationList = std::unique_ptr<PageNavigationList>(new (std::nothrow) PageNavigationList());
2692         SysTryCatch(NID_WEB_CTRL, pNavigationList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2693
2694         pNavigationListImpl = _PageNavigationListImpl::GetInstance(pNavigationList.get());
2695         SysTryCatch(NID_WEB_CTRL, pNavigationListImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2696
2697         pHistoryList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
2698         SysTryCatch(NID_WEB_CTRL, pHistoryList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2699
2700         r = pHistoryList->Construct();
2701         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2702
2703         backCount = ewk_history_back_list_length_get(pEwkHistoryList);
2704         forwardCount = ewk_history_forward_list_length_get(pEwkHistoryList);
2705         SysLog(NID_WEB_CTRL, "The current value of backCount is %d, forwardCount is %d", backCount, forwardCount);
2706
2707         for (int i = -backCount; i < forwardCount + 1; i++)
2708         {
2709                 std::unique_ptr<HistoryItem> pHistoryItem(new (std::nothrow) HistoryItem());
2710                 SysTryCatch(NID_WEB_CTRL, pHistoryItem.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2711
2712                 pHistoryItemImpl = _HistoryItemImpl::GetInstance(pHistoryItem.get());
2713                 SysTryCatch(NID_WEB_CTRL, pHistoryItemImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2714
2715                 pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, i);
2716                 SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2717
2718                 url = ewk_history_item_uri_get(pEwkItem);
2719                 title = ewk_history_item_title_get(pEwkItem);
2720                 SysSecureLog(NID_WEB_CTRL, "The current value of url is %s, title is %s", url.GetPointer(), title.GetPointer());
2721
2722                 pHistoryItemImpl->SetHistoryItem(url, title);
2723
2724                 r = pHistoryList->Add(*pHistoryItem.get());
2725                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2726                 pHistoryItem.release();
2727         }
2728
2729         pNavigationListImpl->SetPageNavigationList(pHistoryList.release(), backCount);
2730
2731         ewk_history_free(pEwkHistoryList);
2732
2733         return pNavigationList.release();
2734
2735 CATCH:
2736         ewk_history_free(pEwkHistoryList);
2737
2738         return null;
2739 }
2740
2741
2742 bool
2743 _WebImpl::SearchText(const String& text, bool searchForward)
2744 {
2745         Evas_Object* pView = __pWebCore->GetWebNativeNode();
2746         if (!pView)
2747         {
2748                 return false;
2749         }
2750
2751         result r = E_SUCCESS;
2752
2753         Ewk_Find_Options condition = static_cast< Ewk_Find_Options >(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2754
2755         if (!searchForward)
2756         {
2757             condition = static_cast < Ewk_Find_Options >(condition | EWK_FIND_OPTIONS_BACKWARDS);
2758         }
2759
2760         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
2761         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2762
2763         r = SynchronizeSearch(SEARCH_SYNC, pView, condition, text, searchForward, false, pPresenter.get());
2764         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
2765
2766         int result = 0;
2767         pPresenter->WaitAsyncProcess(result);
2768
2769         return static_cast < bool >(result);
2770 }
2771
2772
2773 result
2774 _WebImpl::SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive)
2775 {
2776         Evas_Object* pView = __pWebCore->GetWebNativeNode();
2777         if (!pView)
2778         {
2779                 return E_SUCCESS;
2780         }
2781
2782         result r = E_SUCCESS;
2783
2784         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2785
2786         if (!caseSensitive)
2787         {
2788             condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2789         }
2790
2791         r = SynchronizeSearch(SEARCH_ALL_ASYNC, pView, condition, text, true, caseSensitive);
2792         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2793
2794         return E_SUCCESS;
2795 }
2796
2797
2798 result
2799 _WebImpl::SearchNextAsync(bool searchForward)
2800 {
2801         Evas_Object* pView = __pWebCore->GetWebNativeNode();
2802         if (!pView)
2803         {
2804                 return E_SUCCESS;
2805         }
2806
2807         SysTryReturnResult(NID_WEB_CTRL, __textSearch.__searchAll && __textSearch.__totalCount > -1, E_INVALID_OPERATION, "The SearchTextAllAsync() method is not called or completed.");
2808         SysTryReturnResult(NID_WEB_CTRL, (searchForward && __textSearch.__currentIndex < __textSearch.__totalCount) || (!searchForward && __textSearch.__currentIndex > 1)
2809                 , E_OBJ_NOT_FOUND,  "The Next instance is not available.");
2810
2811         result r = E_SUCCESS;
2812
2813         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2814
2815         if (!__textSearch.__caseSensitive)
2816         {
2817                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2818         }
2819
2820         if (!searchForward)
2821         {
2822                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_BACKWARDS);
2823         }
2824
2825         r = SynchronizeSearch(SEARCH_NEXT_ASYNC, pView, condition, __textSearch.__text, searchForward);
2826         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2827
2828         return E_SUCCESS;
2829 }
2830
2831
2832 result
2833 _WebImpl::SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Options condition, const Tizen::Base::String& text, bool searchForward, bool caseSensitive,  _WebPresenter* pWebPresenter)
2834 {
2835         MutexGuard lock(__mutex);
2836
2837         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(text));
2838         SysTryReturn(NID_WEB_CTRL, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2839
2840         switch (type)
2841         {
2842         case SEARCH_SYNC:
2843                 if (__textSearch.__searchAll)
2844                 {
2845                         DisableAsyncSearch();
2846
2847                         __textSearch.__searchQueue.Enqueue(this);
2848                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2849
2850                         ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2851                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2852                 }
2853                 else
2854                 {
2855                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2856
2857                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2858                 }
2859                 break;
2860
2861         case SEARCH_ALL_ASYNC:
2862                 __textSearch.__searchAll = true;
2863                 __textSearch.__text = text;
2864                 __textSearch.__searchForward = true;
2865                 __textSearch.__caseSensitive = caseSensitive;
2866                 __textSearch.__totalCount = -1;
2867                 __textSearch.__currentIndex = 1;
2868
2869                 __textSearch.__searchQueue.Enqueue(this);
2870                 __textSearch.__searchQueue.Enqueue(this);
2871
2872                 ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2873                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2874                 break;
2875
2876         case SEARCH_NEXT_ASYNC:
2877                 __textSearch.__searchForward = searchForward;
2878
2879                 CalculateAsyncSearchOrdinal();
2880
2881                 __textSearch.__searchQueue.Enqueue(this);
2882
2883                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2884                 break;
2885
2886         default:
2887                 SysAssert(false);
2888         }
2889
2890         return E_SUCCESS;
2891 }
2892
2893
2894 void
2895 _WebImpl::SetAsyncSearchResult(int totalCount)
2896 {
2897         __textSearch.__totalCount = totalCount;
2898 }
2899
2900
2901 _WebPresenter*
2902 _WebImpl::GetSearchPresenter(void)
2903 {
2904         MutexGuard lock(__mutex);
2905
2906         return dynamic_cast< _WebPresenter* >(__textSearch.__searchQueue.Dequeue());
2907 }
2908
2909
2910  int
2911  _WebImpl::GetPendingAsyncSearchCount(void) const
2912 {
2913         return __textSearch.__searchQueue.GetCount();
2914 }
2915
2916
2917 void
2918 _WebImpl::CalculateAsyncSearchOrdinal(void)
2919 {
2920         if (__textSearch.__searchForward)
2921         {
2922                 __textSearch.__currentIndex++;
2923         }
2924         else
2925         {
2926                 __textSearch.__currentIndex--;
2927         }
2928 }
2929
2930
2931  int
2932  _WebImpl::GetAsyncSearchOrdinal(void) const
2933 {
2934         return __textSearch.__currentIndex;
2935 }
2936
2937
2938  void
2939  _WebImpl::DisableAsyncSearch(void)
2940 {
2941         __textSearch.__searchAll = false;
2942 }
2943
2944
2945 result
2946 _WebImpl::SetSetting(const WebSetting& setting)
2947 {
2948         if (__pWebCore->GetWebNativeNode())
2949         {
2950                 Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2951                 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2952                 SysAssertf(pContext && pSettings, "Failed to get webkit instance.");
2953
2954                 std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(setting.GetDefaultTextEncoding()));
2955                 SysTryReturn(NID_WEB_CTRL, pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2956
2957                 ewk_settings_default_encoding_set(pSettings, pEncoding.get());
2958
2959                 switch (setting.GetCacheControl())
2960                 {
2961                 case WEB_CACHE_VALIDATED:
2962                         ewk_context_cache_disabled_set(pContext, EINA_FALSE);
2963                         break;
2964
2965                 case WEB_CACHE_IGNORE:
2966                         ewk_context_cache_disabled_set(pContext, EINA_TRUE);
2967                         break;
2968
2969                 default:
2970                         SysAssert(false);
2971                 }
2972
2973                 if (setting.GetInputStyle() == INPUT_STYLE_OVERLAY)
2974                 {
2975                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_TRUE);
2976                 }
2977                 else
2978                 {
2979                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_FALSE);
2980                 }
2981
2982                 ewk_settings_font_default_size_set(pSettings, static_cast< Eina_Bool >(setting.GetFontSize()));
2983
2984                 ewk_settings_javascript_enabled_set(pSettings, static_cast< Eina_Bool >(setting.IsJavascriptEnabled()));
2985
2986                 ewk_settings_loads_images_automatically_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoImageLoadEnabled()));
2987
2988                 if (__defaultUserAgent != setting.GetUserAgent())
2989                 {
2990                         std::unique_ptr<char[]> pAgent(_StringConverter::CopyToCharArrayN(setting.GetUserAgent()));
2991                         SysTryReturn(NID_WEB_CTRL, pAgent.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2992
2993                         ewk_view_user_agent_set(__pWebCore->GetWebNativeNode(), pAgent.get());
2994                 }
2995
2996                 ewk_settings_auto_fitting_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoFittingEnabled()));
2997
2998                 ewk_settings_scripts_window_open_set(pSettings,  static_cast< Eina_Bool >(setting.IsJavaScriptPopupEnabled()));
2999
3000                 ewk_settings_form_candidate_data_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoFormDataShowEnabled()));
3001
3002                 ewk_settings_autofill_password_form_enabled_set(pSettings,  static_cast< Eina_Bool >(setting.IsAutoLoginFormFillEnabled()));
3003         }
3004
3005         _WebSettingImpl* pWebSettingImpl = _WebSettingImpl::GetInstance(__pWebCore->GetSetting());
3006
3007         pWebSettingImpl->SetCertificateErrorHandlingMode(setting.GetCertificateErrorHandlingMode());
3008         pWebSettingImpl->SetDefaultTextEncoding(setting.GetDefaultTextEncoding());
3009         pWebSettingImpl->SetCacheControl(setting.GetCacheControl());
3010         pWebSettingImpl->SetFontSize(setting.GetFontSize());
3011         pWebSettingImpl->SetJavascriptEnabled(setting.IsJavascriptEnabled());
3012         pWebSettingImpl->SetAutoImageLoadEnabled(setting.IsAutoImageLoadEnabled());
3013         pWebSettingImpl->SetInputStyle(setting.GetInputStyle());
3014         pWebSettingImpl->SetUserAgent(setting.GetUserAgent());
3015         pWebSettingImpl->SetAutoFittingEnabled(setting.IsAutoFittingEnabled());
3016         pWebSettingImpl->SetJavaScriptPopupEnabled(setting.IsJavaScriptPopupEnabled());
3017         pWebSettingImpl->SetGeolocationEnabled(setting.IsGeolocationEnabled());
3018         pWebSettingImpl->SetAutoFormDataShowEnabled(setting.IsAutoFormDataShowEnabled());
3019         pWebSettingImpl->SetAutoLoginFormFillEnabled(setting.IsAutoLoginFormFillEnabled());
3020
3021         return E_SUCCESS;
3022 }
3023
3024
3025 WebSetting
3026 _WebImpl::GetSetting(void) const
3027 {
3028         return *__pWebCore->GetSetting();
3029 }
3030
3031
3032 const HitElementResult*
3033 _WebImpl::GetElementByPointN(const Point& point) const
3034 {
3035         return GetElementByPointN(_CoordinateSystemUtils::ConvertToFloat(point));
3036 }
3037
3038
3039 const HitElementResult*
3040 _WebImpl::GetElementByPointN(const FloatPoint& point) const
3041 {
3042         Evas_Object* pView = __pWebCore->GetWebNativeNode();
3043         if (!pView)
3044         {
3045                 return null;
3046         }
3047
3048         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));
3049
3050         result r = E_SUCCESS;
3051
3052         _HitElementResultImpl* pHitElementResultImpl = null;
3053
3054         std::unique_ptr<HitElementResult> pHitElementResult;
3055         std::unique_ptr<Bitmap> pImage;
3056         std::unique_ptr<HashMap, AllElementsDeleter> pAttributeMap;
3057
3058         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(point)));
3059
3060         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pView, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
3061         SysTryReturn(NID_WEB_CTRL, pEwkHitTest, null, E_SYSTEM, "[%s] Failed to get hit test.", GetErrorMessage(E_SYSTEM));
3062
3063         Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
3064         Ewk_Hit_Test_Result_Context context = ewk_hit_test_result_context_get(pEwkHitTest);
3065         String url(ewk_hit_test_link_uri_get(pEwkHitTest));
3066         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
3067         String nodeValue(ewk_hit_test_node_value_get(pEwkHitTest));
3068
3069         SysSecureLog(NID_WEB_CTRL, "The current value of url is %ls, tag is %ls, value is %ls", url.GetPointer(), tagName.GetPointer(), nodeValue.GetPointer());
3070
3071         pHitElementResult = std::unique_ptr<HitElementResult>(new (std::nothrow) HitElementResult());
3072         SysTryCatch(NID_WEB_CTRL, pHitElementResult.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3073
3074         pHitElementResultImpl = _HitElementResultImpl::GetInstance(pHitElementResult.get());
3075         SysTryCatch(NID_WEB_CTRL, pHitElementResultImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3076
3077         if (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
3078         {
3079                 ByteBuffer buf;
3080                 Image image;
3081                 ImageFormat format;
3082
3083                 int imageLength = ewk_hit_test_image_buffer_length_get(pEwkHitTest);
3084                 void* pImageBuffer = ewk_hit_test_image_buffer_get(pEwkHitTest);
3085                 const char* pExtension = ewk_hit_test_image_file_name_extension_get(pEwkHitTest);
3086                 SysLog(NID_WEB_CTRL, "The current value of imageBuffer is %u, bufferLength is %d, extension is %s", pImageBuffer, imageLength, pExtension);
3087
3088                 r = buf.Construct(imageLength);
3089                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3090
3091                 r = buf.SetArray(reinterpret_cast< byte* >(pImageBuffer), 0, imageLength);
3092                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3093
3094                 buf.Rewind();
3095
3096 //              ToDo : webkit doesn't support types such as IMG_FORMAT_WBMP and IMG_FORMAT_TIFF
3097 //              webkit support types such as ico and vp8 additionally
3098                 if (strcmp(pExtension, "gif") == 0)
3099                 {
3100                         format = IMG_FORMAT_GIF;
3101                 }
3102                 else if (strcmp(pExtension, "jpg") == 0)
3103                 {
3104                         format = IMG_FORMAT_JPG;
3105                 }
3106                 else if (strcmp(pExtension, "png") == 0)
3107                 {
3108                         format = IMG_FORMAT_PNG;
3109                 }
3110                 else if (strcmp(pExtension, "bmp") == 0)
3111                 {
3112                         format = IMG_FORMAT_BMP;
3113                 }
3114                 else
3115                 {
3116                         SysLogException(NID_WEB_CTRL, E_UNSUPPORTED_FORMAT, "[%s] The %s format is not supported", GetErrorMessage(E_UNSUPPORTED_FORMAT), pExtension);
3117                         goto CATCH;
3118                 }
3119
3120                 r = image.Construct();
3121                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3122
3123                 pImage = std::unique_ptr<Bitmap>(image.DecodeN(buf, format, BITMAP_PIXEL_FORMAT_RGB565));
3124                 SysTryCatch(NID_WEB_CTRL, pImage.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3125         }
3126
3127         if (pAttrHash)
3128         {
3129                 pAttributeMap = std::unique_ptr<HashMap, AllElementsDeleter>(new (std::nothrow) HashMap());
3130                 SysTryCatch(NID_WEB_CTRL, pAttributeMap.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3131
3132                 r = pAttributeMap->Construct(eina_hash_population(pAttrHash));
3133                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3134
3135                 eina_hash_foreach(pAttrHash, AddHttpAttributeData, pAttributeMap.get());
3136                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3137         }
3138
3139         pHitElementResultImpl->SetHitElementResult(pAttributeMap.release(), pImage.release(), tagName, nodeValue, url);
3140
3141         ewk_hit_test_free(pEwkHitTest);
3142
3143         return pHitElementResult.release();
3144
3145 CATCH:
3146         ewk_hit_test_free(pEwkHitTest);
3147
3148         return null;
3149 }
3150
3151
3152 bool
3153 _WebImpl::IsLoading(void) const
3154 {
3155         double percent = ewk_view_load_progress_get(__pWebCore->GetWebNativeNode());
3156
3157         if (Double::Compare(percent, 0.0) > 0 && Double::Compare(percent, 1.0) < 0)
3158         {
3159                 return true;
3160         }
3161         else
3162         {
3163                 return false;
3164         }
3165 }
3166
3167
3168 String
3169 _WebImpl::GetTextFromBlock(void) const
3170 {
3171         return ewk_view_text_selection_text_get(__pWebCore->GetWebNativeNode());
3172 }
3173
3174
3175 bool
3176 _WebImpl::IsPrivateBrowsingEnabled(void) const
3177 {
3178         if (__pWebCore->GetWebNativeNode() == null)
3179         {
3180                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsPrivateBrowsingEnabled();
3181         }
3182
3183         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
3184         SysAssertf(pSettings, "Failed to get webkit instance.");
3185
3186         return static_cast< bool >(ewk_settings_private_browsing_enabled_get(pSettings));
3187 }
3188
3189
3190 void
3191 _WebImpl::SetPrivateBrowsingEnabled(bool enable)
3192 {
3193         if (__pWebCore->GetWebNativeNode() == null)
3194         {
3195                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetPrivateBrowsingEnabled(enable);
3196                 return;
3197         }
3198
3199         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
3200         SysAssertf(pSettings, "Failed to get webkit instance.");
3201
3202         ewk_settings_private_browsing_enabled_set(pSettings, static_cast< Eina_Bool >(enable));
3203 }
3204
3205
3206 void
3207 _WebImpl::ClearHistory(void)
3208 {
3209         ewk_view_back_forward_list_clear(__pWebCore->GetWebNativeNode());
3210 }
3211
3212
3213 void
3214 _WebImpl::ClearCache(void)
3215 {
3216         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3217
3218         ewk_context_cache_clear(pContext);
3219 }
3220
3221
3222 void
3223 _WebImpl::ClearCookie(void)
3224 {
3225         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3226         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3227
3228         ewk_cookie_manager_cookies_clear(pCookieManager);
3229 }
3230
3231
3232 void
3233 _WebImpl::ClearFormData(void)
3234 {
3235         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3236
3237         ewk_context_form_candidate_data_clear(pContext);
3238 }
3239
3240
3241 void
3242 _WebImpl::ClearLoginFormData(void)
3243 {
3244         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3245
3246         ewk_context_form_password_data_clear(pContext);
3247 }
3248
3249
3250 bool
3251 _WebImpl::IsCookieEnabled(void) const
3252 {
3253         if (__pWebCore->GetWebNativeNode() == null)
3254         {
3255                 return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsCookieEnabled();
3256         }
3257
3258         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3259         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3260         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3261
3262         std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
3263         SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3264
3265         ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, pPresenter.get());
3266
3267         bool result = false;
3268         pPresenter->WaitAsyncProcess(result);
3269
3270         return result;
3271 }
3272
3273
3274 void
3275 _WebImpl::SetCookieEnabled(bool enable)
3276 {
3277         if (__pWebCore->GetWebNativeNode() == null)
3278         {
3279                 _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetCookiEnabled(enable);
3280
3281                 return;
3282         }
3283
3284         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
3285         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
3286         SysAssertf(pCookieManager, "Failed to get webkit instance.");
3287
3288         if (enable)
3289         {
3290                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_ALWAYS);
3291         }
3292         else
3293         {
3294                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_NEVER);
3295                 ewk_cookie_manager_cookies_clear(pCookieManager);
3296         }
3297 }
3298
3299
3300 result 
3301 _WebImpl::SavePageAsPdf(const String& filePath, const Dimension* pSize) const
3302 {
3303         result r = E_SUCCESS;
3304
3305         std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
3306         SysTryReturn(NID_WEB_CTRL, pFilePath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3307
3308         String dirPath;
3309         String fileExtension = File::GetFileExtension(filePath);
3310         int pathLength = filePath.GetLength();
3311         int index = 0;
3312
3313         SysTryReturnResult(NID_WEB_CTRL, fileExtension.Equals("pdf", false), E_INVALID_ARG, "Invalid argument(s) is used. File extension is not pdf.");
3314
3315         r = filePath.LastIndexOf(L"/", pathLength - 1, index);
3316         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3317         r = filePath.SubString(0, index + 1, dirPath);
3318         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
3319
3320         std::unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(dirPath));
3321         SysTryReturnResult(NID_WEB_CTRL, access(pDirPath.get(), W_OK) == 0, E_INACCESSIBLE_PATH, "Directory permission is read-only.");
3322
3323         if (pSize)
3324         {
3325                 SysTryReturnResult(NID_WEB_CTRL, pSize->width > 0 && pSize->height > 0, E_INVALID_ARG, "Invalid argument(s) is used. Size of pdf file is invalid.");
3326
3327                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), pSize->width, pSize->height, pFilePath.get());
3328         }
3329         else
3330         {
3331                 Evas_Coord contentsWidth;
3332                 Evas_Coord contentsHeight;
3333
3334                 ewk_view_contents_size_get(__pWebCore->GetWebNativeNode(), &contentsWidth, &contentsHeight);
3335                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), contentsWidth, contentsHeight, pFilePath.get());
3336         }
3337
3338         return E_SUCCESS;
3339 }
3340
3341
3342 bool
3343 _WebImpl::IsMimeSupported(const String& mime) const
3344 {
3345         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
3346         SysTryReturn(NID_WEB_CTRL, pMime.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3347
3348         return static_cast< bool >(ewk_frame_can_show_mime_type(ewk_view_main_frame_get(__pWebCore->GetWebNativeNode()), pMime.get()));
3349 }
3350
3351
3352 void
3353 _WebImpl::SetLoadingListener(ILoadingListener* pLoadingListener)
3354 {
3355         __pUserLoadingListener = const_cast< ILoadingListener* >(pLoadingListener);
3356 }
3357
3358
3359 void
3360 _WebImpl::SetWebUiEventListener(IWebUiEventListener* pUiEventListener)
3361 {
3362         __pUserUiListener = pUiEventListener;
3363 }
3364
3365
3366 void
3367 _WebImpl::SetWebUiEventListenerF(IWebUiEventListenerF* pUiEventListener)
3368 {
3369         __pUserUiListenerF = pUiEventListener;
3370 }
3371
3372
3373 void
3374 _WebImpl::SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener)
3375 {
3376         __pUserKeypadEventListener = pKeypadEventListener;
3377 }
3378
3379
3380 void
3381 _WebImpl::SetDownloadListener(IWebDownloadListener* pDownLoadListener)
3382 {
3383         if (__pWebDownloadHandler.get() == null)
3384         {
3385                 __pWebDownloadHandler = std::unique_ptr<_WebDataHandler>(new (std::nothrow) _WebDataHandler());
3386                 SysTryReturnVoidResult(NID_WEB_CTRL, __pWebDownloadHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3387         }
3388
3389         __pWebDownloadHandler->SetDownloadListener(pDownLoadListener);
3390         __pWebDownloadHandler->SetWebEvent(__pWebEvent.get());
3391 }
3392
3393
3394 void
3395 _WebImpl::SetTextSearchListener(ITextSearchListener* pTextSearchListener)
3396 {
3397         __pTextSearchListener = pTextSearchListener;
3398 }
3399
3400
3401 void
3402 _WebImpl::SetScrollEnabled(bool enable)
3403 {
3404         _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->SetScrollEnabled(enable);
3405 }
3406
3407
3408 bool
3409 _WebImpl::IsScrollEnabled(void) const
3410 {
3411         return _WebSettingImpl::GetInstance(__pWebCore->GetSetting())->IsScrollEnabled();
3412 }
3413
3414
3415 result
3416 _WebImpl::InitJsBridgeList(void)
3417 {
3418         result r = E_SUCCESS;
3419
3420         __pJsProvider = std::unique_ptr<_JsBridgeHashCodeProvider>(new (std::nothrow) _JsBridgeHashCodeProvider());
3421         SysTryReturnResult(NID_WEB_CTRL, __pJsProvider.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3422
3423         __pJsComparer = std::unique_ptr<_JsBridgeComparer>(new (std::nothrow) _JsBridgeComparer());
3424         SysTryReturnResult(NID_WEB_CTRL, __pJsComparer.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3425
3426         std::unique_ptr<HashMapT< String, IJavaScriptBridge* > > pJsBridgeList(new (std::nothrow) HashMapT< String, IJavaScriptBridge* >);
3427         SysTryReturnResult(NID_WEB_CTRL, pJsBridgeList.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3428
3429         r = pJsBridgeList->Construct(0, 0, *__pJsProvider.get(), *__pJsComparer.get());
3430         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3431
3432         __pJsBridgeList = std::move(pJsBridgeList);
3433
3434         return E_SUCCESS;
3435 }
3436
3437
3438 result
3439 _WebImpl::AddJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3440 {
3441         result r = E_SUCCESS;
3442
3443         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3444         String key(pJsBridge->GetName());
3445
3446         r = __pJsBridgeList->Add(key, pJsBridge);
3447         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3448
3449         return E_SUCCESS;
3450 }
3451
3452
3453 result
3454 _WebImpl::RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge)
3455 {
3456         result r = E_SUCCESS;
3457
3458         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
3459         String key(pJsBridge->GetName());
3460
3461         r = __pJsBridgeList->Remove(key);
3462         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3463
3464         return E_SUCCESS;
3465 }
3466
3467
3468 IJavaScriptBridge*
3469 _WebImpl::FindJsInterface(const IJsonValue* pValue) const
3470 {
3471         result r = E_SUCCESS;
3472
3473         IJsonValue* pJsonValue = null;
3474         IJavaScriptBridge* pJsBridge = null;
3475
3476         String key(L"name");
3477
3478         const JsonObject* pJsonObject = dynamic_cast< const JsonObject* >(pValue);
3479         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));
3480
3481         r = pJsonObject->GetValue(&key, pJsonValue);
3482         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS && pJsonValue, null, r, "[%s] Propagating.", GetErrorMessage(r));
3483
3484         JsonString* pBridgeName = dynamic_cast< JsonString* >(pJsonValue);
3485         SysTryReturn(NID_WEB_CTRL, pBridgeName, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. name key is missing." , GetErrorMessage(E_INVALID_ARG));
3486
3487         r = __pJsBridgeList->GetValue(static_cast< String >(*pBridgeName), pJsBridge);
3488         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3489
3490         return pJsBridge;
3491 }
3492
3493
3494 ILoadingListener*
3495 _WebImpl::GetLoadingListener(void) const
3496 {
3497         return __pUserLoadingListener;
3498 }
3499
3500
3501 IWebUiEventListener*
3502 _WebImpl::GetUiEventListener(void) const
3503 {
3504         return __pUserUiListener;
3505 }
3506
3507
3508 IWebUiEventListenerF*
3509 _WebImpl::GetUiEventListenerF(void) const
3510 {
3511         return __pUserUiListenerF;
3512 }
3513
3514
3515 IWebKeypadEventListener*
3516 _WebImpl::GetWebKeypadEventListener(void) const
3517 {
3518         return __pUserKeypadEventListener;
3519 }
3520
3521
3522 ITextSearchListener*
3523 _WebImpl::GetTextSearchListener(void) const
3524 {
3525         return __pTextSearchListener;
3526 }
3527
3528
3529 void
3530 _WebImpl::SetEventListenerCallback(void) const
3531 {
3532         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3533         if (pWebNativeNode)
3534         {
3535                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3536                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3537
3538                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3539                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3540
3541                 Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
3542                 SysAssertf(pSmartData, "Failed to request");
3543
3544                 Ewk_View_Smart_Class *pSmart = const_cast<Ewk_View_Smart_Class*>(pSmartData->api);
3545                 SysAssertf(pSmart, "Failed to request");
3546
3547                 pSmart->popup_menu_show = OnSelectBoxRequested;
3548                 pSmart->multiple_popup_menu_show = OnMultiSelectBoxRequested;
3549                 pSmart->popup_menu_hide = OnSelectBoxClosed;
3550                 pSmart->popup_menu_update = OnSelectBoxUpdateRequested;
3551
3552                 pSmart->input_picker_show = OnDatePickerProviderRequested;
3553                 pSmart->input_picker_color_request = OnColorPickerProviderRequested;
3554                 pSmart->input_picker_color_dismiss = OnColorPickerProviderDismissed;
3555
3556                 pSmart->formdata_candidate_show = OnFormDataCandidateShow;
3557                 pSmart->formdata_candidate_hide = OnFormDataCandidateHide;
3558                 pSmart->formdata_candidate_update_data = OnFormDataCandidateUpdate;
3559                 pSmart->formdata_candidate_is_showing = OnFormDataCandidateIsShowing;
3560
3561                 evas_object_data_set(pWebNativeNode, WEB_CTRL, this);
3562
3563                 // add loading event callbacks for ILoadingListener
3564                 evas_object_smart_callback_add(pWebNativeNode, "create,window", OnWebWindowCreateRequested, this);
3565                 evas_object_smart_callback_add(pWebNativeNode, "close,window", OnWebWindowClosedRequested, this);
3566
3567                 evas_object_smart_callback_add(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested, this);
3568                 evas_object_smart_callback_add(pWebNativeNode, "load,started", OnLoadingStarted, this);
3569                 evas_object_smart_callback_add(pWebNativeNode, "load,finished", OnLoadingCompleted, this);
3570                 evas_object_smart_callback_add(pWebNativeNode, "load,progress", OnEstimatedProgress, this);
3571                 evas_object_smart_callback_add(pWebNativeNode, "load,progress,finished", OnProgressCompleted, this);
3572                 evas_object_smart_callback_add(pWebNativeNode, "load,stop", OnLoadingCanceled, this);
3573                 evas_object_smart_callback_add(pWebNativeNode, "load,error", OnLoadingErrorOccurred, this);
3574                 evas_object_smart_callback_add(pWebNativeNode, "title,changed", OnPageTitleReceived, this);
3575                 evas_object_smart_callback_add(pWebNativeNode, "load,committed", OnLoadingCommitted, this);
3576
3577                 evas_object_smart_callback_add(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest, this);
3578
3579                 evas_object_smart_callback_add(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3580                 evas_object_smart_callback_add(pWinObject, "focus,out", OnWindowObjectFocusLost, this);
3581
3582                 evas_object_smart_callback_add(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged, this);
3583                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened, this);
3584                 evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed, this);
3585
3586                 evas_object_smart_callback_add(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested, this);
3587                 evas_object_smart_callback_add(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled, this);
3588
3589                 evas_object_smart_callback_add(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested, this);
3590
3591                 ewk_view_javascript_alert_callback_set(pWebNativeNode, OnScriptAlertRequested, const_cast< _WebImpl* >(this));
3592                 ewk_view_javascript_prompt_callback_set(pWebNativeNode, OnScriptPromptRequested, const_cast< _WebImpl* >(this));
3593                 ewk_view_javascript_confirm_callback_set(pWebNativeNode, OnScriptConfirmRequested, const_cast< _WebImpl* >(this));
3594
3595                 evas_object_smart_callback_add(pWebNativeNode, "policy,response,decide", OnWebDataReceived, this);
3596
3597                 evas_object_smart_callback_add(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested, this);
3598                 evas_object_smart_callback_add(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested, this);
3599                 evas_object_smart_callback_add(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted, this);
3600
3601                 evas_object_smart_callback_add(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested, this);
3602                 evas_object_smart_callback_add(pWebNativeNode, "notification,show", OnNotificationShow, this);
3603                 evas_object_smart_callback_add(pWebNativeNode, "notification,cancel", OnNotificationCancel, this);
3604
3605                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested, this);
3606                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered, this);
3607                 evas_object_smart_callback_add(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested, this);
3608
3609                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested, this);
3610                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered, this);
3611                 evas_object_smart_callback_add(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested, this);
3612                 evas_object_smart_callback_add(pWebNativeNode, "text,found", OnTextFound, this);
3613
3614                 evas_object_smart_callback_add(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered, this);
3615                 evas_object_smart_callback_add(pWebNativeNode, "icon,received", OnFaviconReceived, this);
3616
3617                 evas_object_smart_callback_add(pWebNativeNode, "magnifier,hide", OnWebPageBlockSelected, this);
3618
3619                 evas_object_smart_callback_add(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered, this);
3620                 evas_object_smart_callback_add(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited, this);
3621
3622                 evas_object_smart_callback_add(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested, this);
3623                 evas_object_smart_callback_add(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested, this);
3624
3625                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3626                 SysAssertf(pContext, "Failed to get webkit instance.");
3627                 ewk_context_did_start_download_callback_set(pContext, OnDidStartDownloadCallback, const_cast< _WebImpl* >(this));
3628                 ewk_context_vibration_client_callbacks_set(pContext, OnVibrationRequested, OnVibrationCanceled, const_cast< _WebImpl* >(this));
3629
3630                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, OnApplicationCachePermissionRequested, const_cast< _WebImpl* >(this));
3631                 ewk_view_exceeded_indexed_database_quota_callback_set(pWebNativeNode, OnIndexedDatabaseQuotaExceeded, const_cast< _WebImpl* >(this));
3632                 ewk_view_exceeded_database_quota_callback_set(pWebNativeNode, OnDatabaseQuotaExceeded, const_cast< _WebImpl* >(this));
3633                 ewk_view_exceeded_local_file_system_quota_callback_set(pWebNativeNode, OnLocalFileSystemQuotaExceeded, const_cast< _WebImpl* >(this));
3634
3635                 evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained, this);
3636                 evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_OUT, OnWebNativeNodeFocusLost, this);
3637         }
3638 }
3639
3640
3641 void
3642 _WebImpl::RemoveEventListenerCallback(void) const
3643 {
3644         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
3645         if (pWebNativeNode)
3646         {
3647                 _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
3648                 SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
3649
3650                 Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
3651                 SysAssertf(pWinObject, "Failed to get Ui window evas object");
3652
3653                 evas_object_smart_callback_del(pWebNativeNode, "create,window", OnWebWindowCreateRequested);
3654                 evas_object_smart_callback_del(pWebNativeNode, "close,window", OnWebWindowClosedRequested);
3655
3656                 evas_object_smart_callback_del(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested);
3657                 evas_object_smart_callback_del(pWebNativeNode, "load,started", OnLoadingStarted);
3658                 evas_object_smart_callback_del(pWebNativeNode, "load,finished", OnLoadingCompleted);
3659                 evas_object_smart_callback_del(pWebNativeNode, "load,progress", OnEstimatedProgress);
3660                 evas_object_smart_callback_del(pWebNativeNode, "load,progress,finished", OnProgressCompleted);
3661                 evas_object_smart_callback_del(pWebNativeNode, "load,stop", OnLoadingCanceled);
3662                 evas_object_smart_callback_del(pWebNativeNode, "load,error", OnLoadingErrorOccurred);
3663                 evas_object_smart_callback_del(pWebNativeNode, "title,changed", OnPageTitleReceived);
3664                 evas_object_smart_callback_del(pWebNativeNode, "load,committed", OnLoadingCommitted);
3665
3666                 evas_object_smart_callback_del(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest);
3667
3668                 evas_object_smart_callback_del_full(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
3669                 evas_object_smart_callback_del_full(pWinObject, "focus,out", OnWindowObjectFocusLost, this);
3670
3671                 evas_object_smart_callback_del(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged);
3672                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened);
3673                 evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed);
3674
3675                 evas_object_smart_callback_del(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested);
3676                 evas_object_smart_callback_del(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled);
3677
3678                 evas_object_smart_callback_del(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested);
3679
3680                 ewk_view_javascript_alert_callback_set(pWebNativeNode, null, null);
3681                 ewk_view_javascript_prompt_callback_set(pWebNativeNode, null, null);
3682                 ewk_view_javascript_confirm_callback_set(pWebNativeNode, null, null);
3683
3684                 evas_object_smart_callback_del(pWebNativeNode, "policy,response,decide", OnWebDataReceived);
3685
3686                 evas_object_smart_callback_del(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested);
3687                 evas_object_smart_callback_del(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested);
3688                 evas_object_smart_callback_del(pWebNativeNode, "usermedia,permission,request", OnGetUserMediaPermissionRequsted);
3689
3690                 evas_object_smart_callback_del(pWebNativeNode, "notification,permission,request", OnNotificationPermissionRequested);
3691                 evas_object_smart_callback_del(pWebNativeNode, "notification,show", OnNotificationShow);
3692                 evas_object_smart_callback_del(pWebNativeNode, "notification,cancel", OnNotificationCancel);
3693                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,registration,requested", OnProtocolHandlerRegistrationRequested);
3694                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,isregistered", OnIsProtocolHandlerRegistered);
3695                 evas_object_smart_callback_del(pWebNativeNode, "protocolhandler,unregistration,requested", OnProtocolHandlerUnregistrationRequested);
3696
3697                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,registration,requested", OnContentHandlerRegistrationRequested);
3698                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,isregistered", OnIsContentHandlerRegistered);
3699                 evas_object_smart_callback_del(pWebNativeNode, "contenthandler,unregistration,requested", OnContentHandlerUnregistrationRequested);
3700
3701                 evas_object_smart_callback_del(pWebNativeNode, "text,found", OnTextFound);
3702
3703                 evas_object_smart_callback_del(pWebNativeNode, "touchmove,handled", OnWebPreventDefaultTriggered);
3704                 evas_object_smart_callback_del(pWebNativeNode, "icon,received", OnFaviconReceived);
3705
3706                 evas_object_smart_callback_del(pWebNativeNode, "magnifier,hide", OnWebPageBlockSelected);
3707
3708                 evas_object_smart_callback_del(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered);
3709                 evas_object_smart_callback_del(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited);
3710
3711                 evas_object_smart_callback_del(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested);
3712                 evas_object_smart_callback_del(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested);
3713
3714                 Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
3715                 SysAssertf(pContext, "Failed to get webkit instance.");
3716                 ewk_context_vibration_client_callbacks_set(pContext, null, null, null);
3717
3718                 ewk_view_application_cache_permission_callback_set(pWebNativeNode, null, null);
3719                 ewk_view_exceeded_indexed_database_quota_callback_set(pWebNativeNode, null, null);
3720                 ewk_view_exceeded_database_quota_callback_set(pWebNativeNode, null, null);
3721                 ewk_view_exceeded_local_file_system_quota_callback_set(pWebNativeNode, null, null);
3722
3723                 evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained);
3724                 evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_OUT, OnWebNativeNodeFocusLost);
3725         }
3726 }
3727
3728
3729 void
3730 _WebImpl::ClearCertificateDb(void)
3731 {
3732         result r = E_SUCCESS;
3733
3734         String certificatePath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
3735         String table(CERTIFICATE_TABLE_NAME);
3736         _DatabaseImpl db;
3737
3738         r = db.Construct(certificatePath, "r+", null);
3739         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
3740
3741         db.BeginTransaction();
3742
3743         r = db.ExecuteSql(L"Delete From " + table, true);
3744         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3745
3746         db.CommitTransaction();
3747
3748         return;
3749
3750 CATCH:
3751         db.RollbackTransaction();
3752 }
3753
3754
3755 result
3756 _WebImpl::SetBlockSelectionPosition(const Point& startPoint)
3757 {
3758         return SetBlockSelectionPosition(_CoordinateSystemUtils::ConvertToFloat(startPoint));
3759 }
3760
3761
3762 result
3763 _WebImpl::SetBlockSelectionPosition(const FloatPoint& startPoint)
3764 {
3765         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
3766         if (!pWebview)
3767         {
3768                 return E_SUCCESS;
3769         }
3770
3771         Ewk_View_Smart_Data* pSmartData = reinterpret_cast< Ewk_View_Smart_Data* >(evas_object_smart_data_get(pWebview));
3772         SysAssertf(pSmartData && pSmartData->api, "Failed to get webkit instance.");
3773         Point absPoint(_CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(startPoint)));
3774
3775         Eina_Bool ret = pSmartData->api->text_selection_down(pSmartData, absPoint.x, absPoint.y);
3776         if (ret)
3777         {
3778                 pSmartData->api->text_selection_up(pSmartData, absPoint.x, absPoint.y);
3779
3780                 Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(pWebview, absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
3781                 SysTryReturnResult(NID_WEB_CTRL, pEwkHitTest, E_SYSTEM, "Failed to get hit test.");
3782
3783                 String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
3784
3785                 Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
3786                 char* pValue = reinterpret_cast< char* >(eina_hash_find(pAttrHash, "contenteditable"));
3787                 if (tagName.Equals(L"INPUT", false) || tagName.Equals(L"TEXTAREA", false) || pValue)
3788                 {
3789                         ewk_view_command_execute(pWebview, "SelectWord", 0);
3790                         evas_object_smart_callback_call(pWebview, "magnifier,hide", NULL);
3791                 }
3792         }
3793
3794         SysTryReturnResult(NID_WEB_CTRL, GetTextFromBlock().GetLength() > 0, E_INVALID_ARG, "Failed to set text selection up.");
3795
3796         return E_SUCCESS;
3797 }
3798
3799
3800 void
3801 _WebImpl::ReleaseBlock(void)
3802 {
3803         ewk_view_text_selection_range_clear(__pWebCore->GetWebNativeNode());
3804 }
3805
3806
3807 void
3808 _WebImpl::GetBlockRange(Point& startPoint, Point& endPoint) const
3809 {
3810         FloatPoint tempStartPoint;
3811         FloatPoint tempEndPoint;
3812
3813         GetBlockRange(tempStartPoint, tempEndPoint);
3814
3815         startPoint = _CoordinateSystemUtils::ConvertToInteger(tempStartPoint);
3816         endPoint = _CoordinateSystemUtils::ConvertToInteger(tempEndPoint);
3817 }
3818
3819
3820 void
3821 _WebImpl::GetBlockRange(FloatPoint& startPoint, FloatPoint& endPoint) const
3822 {
3823         Eina_Rectangle leftHandle;
3824         Eina_Rectangle rightHandle;
3825
3826         EINA_RECTANGLE_SET(&leftHandle, 0, 0, 0, 0);
3827         EINA_RECTANGLE_SET(&rightHandle, 0, 0, 0, 0);
3828
3829         ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
3830
3831         startPoint.x = _CoordinateSystemUtils::ConvertToFloat(leftHandle.x);
3832         startPoint.y = _CoordinateSystemUtils::ConvertToFloat(leftHandle.y);
3833         endPoint.x = _CoordinateSystemUtils::ConvertToFloat(rightHandle.x + rightHandle.w);
3834         endPoint.y = _CoordinateSystemUtils::ConvertToFloat(rightHandle.y + rightHandle.h);
3835
3836         if ((endPoint.x != 0.0f) && (endPoint.y != 0.0f))
3837         {
3838                 startPoint = __pWebCore->GetRelativeCoordinate(startPoint);
3839                 endPoint = __pWebCore->GetRelativeCoordinate(endPoint);
3840         }
3841 }
3842
3843
3844 Bitmap*
3845 _WebImpl::GetFaviconN(void) const
3846 {
3847         result r = E_SUCCESS;
3848
3849         Evas_Object* pView = __pWebCore->GetWebNativeNode();
3850         Ewk_Context* pContext = ewk_view_context_get(pView);
3851         const char* pUrl = ewk_view_url_get(pView);
3852         Evas* pEvas = evas_object_evas_get(pView);
3853
3854         Evas_Object* pFavicon = ewk_context_icon_database_icon_object_add(pContext, pUrl, pEvas);
3855         if (!pFavicon)
3856         {
3857                 return null;
3858         }
3859
3860         Tizen::Graphics::BufferInfo bufferInfo;
3861
3862         r = _Utility::GetPixelBufferFromEvasObject(pFavicon,  bufferInfo);
3863         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3864
3865         const Dimension dimension(bufferInfo.width, bufferInfo.height);
3866         Tizen::Base::ByteBuffer byteBuffer;
3867         
3868         r = byteBuffer.Construct((byte*)bufferInfo.pPixels, 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
3869         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3870
3871         std::unique_ptr<Bitmap> pImage(new (std::nothrow) Bitmap());
3872         SysTryReturn(NID_WEB_CTRL, pImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3873
3874         r = pImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
3875         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3876
3877         return pImage.release();
3878
3879 }
3880
3881
3882 void
3883 _WebImpl::ScrollBy(const Tizen::Graphics::Point& diff)
3884 {
3885         ewk_view_scroll_by(__pWebCore->GetWebNativeNode(), diff.x, diff.y);
3886 }
3887
3888
3889 void
3890 _WebImpl::ScrollTo(const Tizen::Graphics::Point& dest)
3891 {
3892         ewk_view_scroll_set(__pWebCore->GetWebNativeNode(), dest.x, dest.y);
3893 }
3894
3895
3896 Point
3897 _WebImpl::GetScrollPosition(void) const
3898 {
3899         Point position;
3900
3901         ewk_view_scroll_pos_get(__pWebCore->GetWebNativeNode(), &position.x, &position.y);
3902
3903         return position;
3904 }
3905
3906
3907 Dimension
3908 _WebImpl::GetPageSize(void) const
3909 {
3910         Evas_Coord width = 0;
3911         Evas_Coord height = 0;
3912
3913         ewk_view_contents_size_get(__pWebCore->GetWebNativeNode(), &width, &height);
3914
3915         Dimension size(static_cast< int >(width), static_cast< int >(height));
3916
3917         return size;
3918 }
3919
3920
3921 result
3922 _WebImpl::AddHttpHeaderField(const String& name, const String& value)
3923 {
3924         SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing.");
3925
3926         std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(name));
3927         SysTryReturn(NID_WEB_CTRL, pName.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3928
3929         std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(value));
3930
3931         ewk_view_custom_header_add(__pWebCore->GetWebNativeNode(), pName.get(), pValue.get());
3932
3933         return E_SUCCESS;
3934 }
3935
3936
3937 result
3938 _WebImpl::RemoveHttpHeaderField(const String& name)
3939 {
3940         SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing.");
3941
3942         std::unique_ptr<char[]> pName(_StringConverter::CopyToCharArrayN(name));
3943         SysTryReturn(NID_WEB_CTRL, pName.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3944
3945         ewk_view_custom_header_remove(__pWebCore->GetWebNativeNode(), pName.get());
3946
3947         return E_SUCCESS;
3948 }
3949
3950
3951 void
3952 _WebImpl::SetLoadingErrorOccurred(bool arg)
3953 {
3954         __isLoadingErrorOccurred = arg;
3955 }
3956
3957
3958 bool
3959 _WebImpl::IsLoadingErrorOccurred(void) const
3960 {
3961         return __isLoadingErrorOccurred;
3962 }
3963
3964
3965 void
3966 _WebImpl::SetRedirectRequested(bool arg)
3967 {
3968         __isRedirectRequested = arg;
3969 }
3970
3971
3972 bool
3973 _WebImpl::IsRedirectRequested(void) const
3974 {
3975         return __isRedirectRequested;
3976 }
3977
3978
3979 void
3980 _WebImpl::SetPolicyDecision(DecisionPolicy policy)
3981 {
3982         __policy = policy;
3983 }
3984
3985
3986 DecisionPolicy
3987 _WebImpl::GetPolicyDecision(void) const
3988 {
3989         return __policy;
3990 }
3991
3992
3993 void
3994 _WebImpl::SetCertificateRequested(bool arg)
3995 {
3996         __isCertificateRequested = arg;
3997 }
3998
3999
4000 bool
4001 _WebImpl::IsCertificateRequested(void) const
4002 {
4003         return __isCertificateRequested;
4004 }
4005
4006
4007 void
4008 _WebImpl::SetCertificateConfirmed(bool arg)
4009 {
4010         __isCertificateConfirmed = arg;
4011 }
4012
4013
4014 bool
4015 _WebImpl::IsCertificateConfirmed(void) const
4016 {
4017         return __isCertificateConfirmed;
4018 }
4019
4020
4021 result
4022 _WebImpl::SetFullScreenKeypad(void)
4023 {
4024         result r = E_SUCCESS;
4025
4026         std::unique_ptr<Keypad> pKeypad(new (std::nothrow) Keypad());
4027         SysTryReturnResult(NID_WEB_CTRL, pKeypad.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4028
4029         r = pKeypad->Construct(KEYPAD_STYLE_NORMAL, 100);
4030         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4031
4032         String text(ewk_view_focused_input_element_value_get(__pWebCore->GetWebNativeNode()));
4033         pKeypad->SetText(text);
4034
4035         r = pKeypad->SetShowState(true);
4036         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4037
4038         r = pKeypad->Show();
4039         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4040
4041         pKeypad->AddTextEventListener(*this);
4042
4043         __pKeypad = std::move(pKeypad);
4044
4045         return E_SUCCESS;
4046 }
4047
4048
4049 void
4050 _WebImpl::RemoveFullScreenKeypad(void)
4051 {
4052         __pKeypad->RemoveTextEventListener(*this);
4053
4054         __pKeypad.reset();
4055 }
4056
4057
4058 bool
4059 _WebImpl::IsFooterVisible(void) const
4060 {
4061         return __isFooterVisible;
4062 }
4063
4064
4065 void
4066 _WebImpl::SetFooterVisibleState(bool isFooterVisible)
4067 {
4068         __isFooterVisible = isFooterVisible;
4069 }
4070
4071
4072 bool
4073 _WebImpl::IsKeypadVisible(void) const
4074 {
4075         return __isKeypadVisible;
4076 }
4077
4078
4079 void
4080 _WebImpl::SetKeypadVisibleState(bool isKeypadVisible)
4081 {
4082         __isKeypadVisible = isKeypadVisible;
4083 }
4084
4085
4086 bool 
4087 _WebImpl::IsKeypadOpened(void) const
4088 {
4089         return __isKeypadOpened;
4090 }
4091
4092 void 
4093 _WebImpl::SetKeypadOpened(bool isKeypadOpened)
4094 {
4095         __isKeypadOpened = isKeypadOpened;
4096 }
4097
4098
4099 bool
4100 _WebImpl::IsWinFocusLost(void) const
4101 {
4102         return __isWinFocusLost;
4103 }
4104
4105
4106 void
4107 _WebImpl::SetWinFocusLost(bool isWinFocusLost)
4108 {
4109         __isWinFocusLost = isWinFocusLost;
4110 }
4111
4112
4113 Rectangle
4114 _WebImpl::GetPreviousKeypadBounds(void) const
4115 {
4116         return __keypadBounds;
4117 }
4118
4119
4120 void 
4121 _WebImpl::SetPreviousKeypadBounds(Rectangle& bounds)
4122 {
4123         __keypadBounds = bounds;
4124 }
4125
4126
4127 void
4128 _WebImpl::OnTextValueChangeCanceled(const Control& source)
4129 {
4130         RemoveFullScreenKeypad();
4131 }
4132
4133
4134 void
4135 _WebImpl::OnTextValueChanged(const Control& source)
4136 {
4137         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(__pKeypad->GetText()));
4138
4139         ewk_view_focused_input_element_value_set(__pWebCore->GetWebNativeNode(), pText.get());
4140
4141         RemoveFullScreenKeypad();
4142 }
4143
4144
4145 result
4146 _WebImpl::OnHandleJavaScriptRequestByEventArg(const IEventArg& arg)
4147 {
4148         const _JsBridgeArg* pEventArg = dynamic_cast< const _JsBridgeArg* >(&arg);
4149         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. arg is not _JsBridgeArg object.");
4150
4151         std::unique_ptr<IJsonValue> pJsonValue(JsonParser::ParseN(*(pEventArg->GetJsonData())));
4152         SysTryReturn(NID_WEB_JSON, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4153
4154         IJavaScriptBridge* pJsInterface = FindJsInterface(pJsonValue.get());
4155         SysTryReturnResult(NID_WEB_CTRL, pJsInterface, E_OBJ_NOT_FOUND, "JsInterface instance is not available.");
4156
4157         pJsInterface->HandleJavaScriptRequestN(pJsonValue.release());
4158
4159         return E_SUCCESS;
4160 }
4161
4162
4163 result
4164 _WebImpl::OnHandleLoadingEvent(const IEventArg& arg)
4165 {
4166         result r = E_SUCCESS;
4167
4168         const _LoadingEventArg* pEventArg = dynamic_cast< const _LoadingEventArg* >(&arg);
4169         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4170
4171         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4172
4173         ILoadingListener* pLoadingListner = GetLoadingListener();
4174         SysTryReturnResult(NID_WEB_CTRL, pLoadingListner, E_SYSTEM, "A system error has been occurred. Loading listener was not set or null.");
4175
4176         switch (pEventArg->GetEventType())
4177         {
4178         case WEB_EVENT_LOADINGLISTENER_STARTED:
4179         {
4180                 pLoadingListner->OnLoadingStarted();
4181                 break;
4182         }
4183
4184         case WEB_EVENT_LOADINGLISTENER_PROGRESS:
4185         {
4186                 const Integer* pProgressPercentage = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS));
4187                 SysTryReturn(NID_WEB_CTRL, pProgressPercentage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4188
4189                 pLoadingListner->OnEstimatedProgress(pProgressPercentage->ToInt());
4190                 break;
4191         }
4192
4193         case WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED:
4194         {
4195                 const String* pPageTitle = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::PAGE_TITLE));
4196                 SysTryReturn(NID_WEB_CTRL, pPageTitle, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4197
4198                 pLoadingListner->OnPageTitleReceived(*pPageTitle);
4199                 break;
4200         }
4201
4202         case WEB_EVENT_LOADINGLISTENER_CANCELED:
4203         {
4204                 pLoadingListner->OnLoadingCanceled();
4205                 break;
4206         }
4207
4208         case WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED:
4209         {
4210                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_TYPE));
4211                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4212
4213                 const String* pErrorMessage = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_MESSAGE));
4214                 SysTryReturn(NID_WEB_CTRL, pErrorMessage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4215
4216                 LoadingErrorType errorType = ConvertErrorCode(pErrorType->ToInt());
4217
4218                 pLoadingListner->OnLoadingErrorOccurred(errorType, *pErrorMessage);
4219                 break;
4220         }
4221
4222         case WEB_EVENT_LOADINGLISTENER_COMPLETED:
4223         {
4224                 pLoadingListner->OnLoadingCompleted();
4225                 break;
4226         }
4227
4228         case WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED:
4229         {
4230                 pLoadingListner->OnHttpAuthenticationCanceled();
4231                 break;
4232         }
4233
4234         case WEB_EVENT_LOADINGLISTENER_FAVICON_RECEIVED:
4235         {
4236                 std::unique_ptr<Bitmap> pFavicon(GetFaviconN());
4237                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4238
4239                 if (pFavicon.get())
4240                 {
4241                         pLoadingListner->OnFaviconReceived(*pFavicon.get());
4242                 }
4243                 break;
4244         }
4245
4246         default:
4247         {
4248                 SysAssert(false);
4249         }
4250         }
4251
4252         return r;
4253 }
4254
4255
4256 result
4257 _WebImpl::OnHandleWebDownloadEvent(const IEventArg& arg)
4258 {
4259         result r = E_SUCCESS;
4260
4261         const _WebDownloadEventArg* pEventArg = dynamic_cast< const _WebDownloadEventArg* >(&arg);
4262         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4263
4264         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4265
4266         IWebDownloadListener* pWebDownloadListener = __pWebDownloadHandler->GetDownloadListener();
4267         SysTryReturnResult(NID_WEB_CTRL, pWebDownloadListener, E_SYSTEM, "A system error has been occurred. Web Downloading listener was not set or null.");
4268
4269         switch (pEventArg->GetEventType())
4270         {
4271         case WEB_EVENT_WEBDOWNLOADLISTENER_DATA_RECEIVED:
4272         {
4273                 const ByteBuffer* pChunk = dynamic_cast< const ByteBuffer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::CHUNKED_DATA));
4274                 SysTryReturn(NID_WEB_CTRL, pChunk, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4275
4276                 pWebDownloadListener->OnWebChunkedDataReceived(*pChunk);
4277                 break;
4278         }
4279
4280         case WEB_EVENT_WEBDOWNLOADLISTENER_COMPLETED:
4281         {
4282                 pWebDownloadListener->OnWebDataDownloadCompleted();
4283                 break;
4284         }
4285
4286         case WEB_EVENT_WEBDOWNLOADLISTENER_FAILED:
4287         {
4288                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::ERROR_TYPE));
4289                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4290
4291                 LoadingErrorType errorType = static_cast < LoadingErrorType >(pErrorType->ToInt());
4292
4293                 pWebDownloadListener->OnWebDownloadFailed(errorType);
4294                 break;
4295         }
4296
4297         default:
4298         {
4299                 SysAssert(false);
4300         }
4301         }
4302
4303         return r;
4304 }
4305
4306
4307 result
4308 _WebImpl::OnHandleWebUiEvent(const IEventArg& arg)
4309 {
4310         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4311         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4312
4313         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4314
4315         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListener, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4316
4317         switch (pEventArg->GetEventType())
4318         {
4319         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED:
4320         {
4321                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4322
4323                 Point* pStartPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4324                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4325
4326                 Point* pEndPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4327                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4328
4329                 __pUserUiListener->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4330                 break;
4331         }
4332
4333         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED:
4334         {
4335                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4336
4337                 __pUserUiListener->OnWebPageShowRequested(*pWeb);
4338                 break;
4339         }
4340
4341         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED:
4342         {
4343                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4344
4345                 __pUserUiListener->OnWebWindowCloseRequested(*pWeb);
4346                 break;
4347         }
4348
4349         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED:
4350         {
4351                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4352
4353                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4354                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4355
4356                 __pUserUiListener->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4357                 break;
4358         }
4359
4360         default:
4361         {
4362                 SysAssert(false);
4363         }
4364         }
4365
4366         return E_SUCCESS;
4367 }
4368
4369
4370 result
4371 _WebImpl::OnHandleWebUiEventF(const IEventArg& arg)
4372 {
4373         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
4374         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4375
4376         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4377
4378         SysTryReturnResult(NID_WEB_CTRL, __pUserUiListenerF, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
4379
4380         switch (pEventArg->GetEventType())
4381         {
4382         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED_FLOAT:
4383         {
4384                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4385
4386                 FloatPoint* pStartPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
4387                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4388
4389                 FloatPoint* pEndPoint = const_cast< FloatPoint* >(dynamic_cast< const FloatPoint* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
4390                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4391
4392                 __pUserUiListenerF->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
4393                 break;
4394         }
4395
4396         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED_FLOAT:
4397         {
4398                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4399
4400                 __pUserUiListenerF->OnWebPageShowRequested(*pWeb);
4401                 break;
4402         }
4403
4404         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED_FLOAT:
4405         {
4406                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4407
4408                 __pUserUiListenerF->OnWebWindowCloseRequested(*pWeb);
4409                 break;
4410         }
4411
4412         case WEB_EVENT_WEBUIEVENTLISTENER_PREVENT_DEFAULT_TRIGGERED_FLOAT:
4413         {
4414                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
4415
4416                 Boolean* pTrigger = const_cast< Boolean* >(dynamic_cast< const Boolean* >(pEventArg->GetEventInfo(_WebUiEventArg::PREVENT_DEFAULT)));
4417                 SysTryReturn(NID_WEB_CTRL, pTrigger, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4418
4419                 __pUserUiListenerF->OnWebPreventDefaultTriggered(*pWeb, pTrigger->ToBool());
4420                 break;
4421         }
4422
4423         default:
4424         {
4425                 SysAssert(false);
4426         }
4427         }
4428
4429         return E_SUCCESS;
4430 }
4431
4432
4433 result
4434 _WebImpl::OnHandleTextSearchEvent(const IEventArg& arg)
4435 {
4436         result r = E_SUCCESS;
4437
4438         const _TextSearchEventArg* pEventArg = dynamic_cast< const _TextSearchEventArg* >(&arg);
4439         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
4440
4441         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
4442
4443         ITextSearchListener* pTextSearchListner = GetTextSearchListener();
4444         SysTryReturnResult(NID_WEB_CTRL, pTextSearchListner, E_SYSTEM, "A system error has been occurred. Web text search listener was not set or null.");
4445
4446         switch (pEventArg->GetEventType())
4447         {
4448         case WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND:
4449         {
4450                 Integer* pTotalCount= dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::TOTAL_COUNT)));
4451                 SysTryReturn(NID_WEB_CTRL, pTotalCount, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4452
4453                 Integer* pCurrentOrdinal = dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL)));
4454                 SysTryReturn(NID_WEB_CTRL, pCurrentOrdinal, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4455
4456                 pTextSearchListner->OnTextFound(pTotalCount->ToInt(), pCurrentOrdinal->ToInt());
4457                 break;
4458         }
4459
4460         default:
4461         {
4462                 SysAssert(false);
4463         }
4464         }
4465
4466         return r;
4467 }
4468
4469
4470 result
4471 _WebImpl::VibrationRequested(uint64_t duration)
4472 {
4473         result r = E_SUCCESS;
4474
4475         __pVibrator.reset();
4476
4477         std::unique_ptr<_VibratorImpl> pVibrator(new (std::nothrow) _VibratorImpl);
4478         SysTryReturnResult(NID_WEB_CTRL, pVibrator.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
4479
4480         r = pVibrator->Construct();
4481         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4482
4483         __pVibrator = std::move(pVibrator);
4484
4485         IntensityDurationVibrationPattern pattern = {static_cast< int >(duration), -1};
4486
4487         r = __pVibrator->Start(&pattern, 1, 1);
4488         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4489
4490         return E_SUCCESS;
4491 }
4492
4493
4494 void
4495 _WebImpl::VibrationCanceled(void)
4496 {
4497         __pVibrator.reset();
4498 }
4499
4500
4501 result
4502 _WebImpl::HttpAuthenticationRequested(Ewk_Auth_Challenge* pChallenge)
4503 {
4504         result r = E_SUCCESS;
4505
4506         String host(ewk_auth_challenge_url_get(pChallenge));
4507         String realm(ewk_auth_challenge_realm_get(pChallenge));
4508
4509         __pAuthChallenge.reset();
4510
4511         std::unique_ptr<AuthenticationChallenge> pAuthChallenge(new (std::nothrow) AuthenticationChallenge());
4512         SysTryReturnResult(NID_WEB_CTRL, pAuthChallenge, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4513
4514         _AuthenticationChallengeImpl* pAuthImpl = _AuthenticationChallengeImpl::GetInstance(pAuthChallenge.get());
4515         SysTryReturn(NID_WEB_CTRL, pAuthImpl,  GetLastResult(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
4516
4517         pAuthImpl->SetAuthenticationChallengeHandler(pChallenge);
4518         pAuthImpl->SetWebEvasObject(__pWebCore->GetWebNativeNode());
4519
4520         __pAuthChallenge = std::move(pAuthChallenge);
4521
4522         ewk_auth_challenge_suspend(pChallenge);
4523         if (__pUserLoadingListener && __pUserLoadingListener->OnHttpAuthenticationRequestedN(host, realm, *__pAuthChallenge.get()))
4524         {
4525                 __pAuthChallenge.release();
4526         }
4527         else
4528         {
4529                 r = ShowAuthenticationPopup(host, realm, __pAuthChallenge.get());
4530                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4531         }
4532
4533         return E_SUCCESS;
4534 }
4535
4536
4537 result
4538 _WebImpl::ShowAuthenticationPopup(const String& host, const String& realm, AuthenticationChallenge* pAuthChallenge)
4539 {
4540         result r = E_SUCCESS;
4541
4542         std::unique_ptr<_AuthConfirmPopup> pAuthPopup(new (std::nothrow) _AuthConfirmPopup());
4543         SysTryReturnResult(NID_WEB_CTRL, pAuthPopup, E_OUT_OF_MEMORY, "Memory Allocation failed.");
4544
4545         r = pAuthPopup->Construct(host, realm, pAuthChallenge);
4546         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4547
4548         __pAuthPopup = std::move(pAuthPopup);
4549
4550         int modalResult = 0;
4551
4552         r = __pAuthPopup->ShowAndWait(modalResult);
4553         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4554
4555 CATCH:
4556         if (__pAuthPopup)
4557         {
4558                 __pAuthPopup.reset();
4559         }
4560
4561         return r;
4562 }
4563
4564
4565 result
4566 _WebImpl::ShowCertificateConfirmPopup(_CertificatePopupMode userConfirmMode, Ewk_Certificate_Policy_Decision* pPolicy)
4567 {
4568         result r = E_SUCCESS;
4569
4570         std::unique_ptr<_CertificateConfirmPopup> pCertConfirmPopup(new (std::nothrow) _CertificateConfirmPopup());
4571         SysTryReturnResult(NID_WEB_CTRL, pCertConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4572
4573         r = pCertConfirmPopup->Construct(userConfirmMode, pPolicy);
4574         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4575
4576         __pCertConfirmPopup = std::move(pCertConfirmPopup);
4577
4578         int modalResult = 0;
4579
4580         r = __pCertConfirmPopup->ShowAndWait(modalResult);
4581         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4582
4583         if (__pCertConfirmPopup.get() && userConfirmMode == CERTIFICATE_POPUP_MODE_USER_CONFIRM)
4584         {
4585                 __isCertificateConfirmed = __pCertConfirmPopup->GetConfirmResult();
4586         }
4587
4588 CATCH:
4589         if (__pCertConfirmPopup.get())
4590         {
4591                 __pCertConfirmPopup.reset();
4592         }
4593
4594         return r;
4595 }
4596
4597
4598 result
4599 _WebImpl::ShowPromptPopup(String msg, String defVal)
4600 {
4601         result r = E_SUCCESS;
4602
4603         std::unique_ptr< _PromptPopup > pPromptPopup(new (std::nothrow) _PromptPopup());
4604         SysTryReturnResult(NID_WEB_CTRL, pPromptPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4605
4606         r = pPromptPopup->Construct(msg, defVal, __pWebCore->GetWebNativeNode(), this);
4607         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4608
4609         __pPromptPopup = std::move(pPromptPopup);
4610
4611         r = __pPromptPopup->ShowPopup();
4612         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
4613
4614         return E_SUCCESS;
4615
4616 CATCH:
4617         __pPromptPopup.reset();
4618
4619         return r;
4620
4621 }
4622
4623
4624 result
4625 _WebImpl::ShowUserConfirmPopup(_UserConfirmMode userConfirmMode, void* pPolicy, String msg)
4626 {
4627         result r = E_SUCCESS;
4628
4629         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4630         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4631
4632         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, this, true, msg);
4633         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4634
4635         int modalResult = 0;
4636
4637         switch(userConfirmMode)
4638         {
4639         case USER_CONTENT_HANDLER:
4640         {
4641                 __pContentHandlerConfirmPopup = std::move(pUserConfirmPopup);
4642
4643                 r = __pContentHandlerConfirmPopup->ShowAndWait(modalResult);
4644                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pContentHandlerConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4645
4646                 __pContentHandlerConfirmPopup.reset();
4647
4648                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4649
4650                 break;
4651         }
4652         case USER_PROTOCOL_HANDLER:
4653         {
4654                 __pProtocolHandlerConfirmPopup = std::move(pUserConfirmPopup);
4655
4656                 r = __pProtocolHandlerConfirmPopup->ShowAndWait(modalResult);
4657                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pProtocolHandlerConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4658
4659                 __pProtocolHandlerConfirmPopup.reset();
4660
4661                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4662
4663                 break;
4664         }
4665         case USER_CONFIRM_APP_CACHE:
4666         {
4667                 __pAppCacheConfirmPopup = std::move(pUserConfirmPopup);
4668
4669                 r = __pAppCacheConfirmPopup->ShowAndWait(modalResult);
4670                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pAppCacheConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4671
4672                 __pAppCacheConfirmPopup.reset();
4673
4674                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4675
4676                 break;
4677         }
4678         case USER_CONFIRM_DB_QUOTA_EXCEDED:
4679         {
4680                 __pDbQuotaConfirmPopup = std::move(pUserConfirmPopup);
4681
4682                 r = __pDbQuotaConfirmPopup->ShowAndWait(modalResult);
4683                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pDbQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4684
4685                 __pDbQuotaConfirmPopup.reset();
4686
4687                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4688
4689                 break;
4690         }
4691         case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
4692         {
4693                 __pLocalFsQuotaConfirmPopup = std::move(pUserConfirmPopup);
4694
4695                 r = __pLocalFsQuotaConfirmPopup->ShowAndWait(modalResult);
4696                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pLocalFsQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4697
4698                 __pLocalFsQuotaConfirmPopup.reset();
4699
4700                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4701
4702                 break;
4703         }
4704         case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
4705         {
4706                 __pIndexedDbQuotaConfirmPopup = std::move(pUserConfirmPopup);
4707
4708                 r = __pIndexedDbQuotaConfirmPopup->ShowAndWait(modalResult);
4709                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pIndexedDbQuotaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4710
4711                 __pIndexedDbQuotaConfirmPopup.reset();
4712
4713                 ewk_view_resume(__pWebCore->GetWebNativeNode());
4714
4715                 break;
4716         }
4717         default:
4718                 break;
4719         }
4720 CATCH:
4721                 return r;
4722 }
4723
4724
4725 result
4726 _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPolicy, String msg)
4727 {
4728         result r = E_SUCCESS;
4729
4730         std::unique_ptr<_UserConfirmPopup> pUserConfirmPopup(new (std::nothrow) _UserConfirmPopup());
4731         SysTryReturnResult(NID_WEB_CTRL, pUserConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
4732
4733         r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, this, false, msg);
4734         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4735
4736         switch(userConfirmMode)
4737         {
4738         case USER_CONFIRM_USERMEDIA:
4739         {
4740                 __pUserMediaConfirmPopup.reset();
4741
4742                 __pUserMediaConfirmPopup = std::move(pUserConfirmPopup);
4743
4744                 r = __pUserMediaConfirmPopup->ShowPopup();
4745                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pUserMediaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4746
4747                 break;
4748         }
4749         case USER_CONFIRM_GEOLOCATION:
4750         {
4751                 __pGeolocationConfirmPopup.reset();
4752
4753                 __pGeolocationConfirmPopup = std::move(pUserConfirmPopup);
4754
4755                 r = __pGeolocationConfirmPopup->ShowPopup();
4756                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pGeolocationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4757
4758                 break;
4759         }
4760         case USER_CONFIRM_NOTIFICATION:
4761         {
4762                 __pNotificationConfirmPopup.reset();
4763
4764                 __pNotificationConfirmPopup = std::move(pUserConfirmPopup);
4765
4766                 r = __pNotificationConfirmPopup->ShowPopup();
4767                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pNotificationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4768
4769                 break;
4770         }
4771         case USER_SCRIPT_ALERT:
4772         {
4773                 __pScriptAlertConfirmPopup.reset();
4774
4775                 __pScriptAlertConfirmPopup = std::move(pUserConfirmPopup);
4776
4777                 r = __pScriptAlertConfirmPopup->ShowPopup();
4778                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptAlertConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4779
4780                 break;
4781         }
4782         case USER_SCRIPT_CONFIRM:
4783         {
4784                 __pScriptConfirmPopup.reset();
4785
4786                 __pScriptConfirmPopup = std::move(pUserConfirmPopup);
4787
4788                 r = __pScriptConfirmPopup->ShowPopup();
4789                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
4790
4791                 break;
4792         }
4793         default:
4794                 break;
4795         }
4796
4797         return E_SUCCESS;
4798
4799 CATCH:
4800         return r;
4801 }
4802
4803
4804 _FormImpl*
4805 _WebImpl::GetParentFormImpl(_ControlImpl* pControlImpl)
4806 {
4807         String parentName;
4808         _FormImpl* pFormImpl = null;
4809
4810         _ControlImpl* pParentControlImpl = dynamic_cast< _ControlImpl* >(pControlImpl->GetParent());
4811         if (!pParentControlImpl)
4812         {
4813                 return null;
4814         }
4815
4816         pFormImpl = dynamic_cast< _FormImpl* >(pParentControlImpl);
4817         if (pFormImpl)
4818         {
4819                 return pFormImpl;
4820         }
4821
4822         return GetParentFormImpl(pParentControlImpl);
4823 }
4824
4825
4826 bool 
4827 _WebImpl::OnFocusGained(const _ControlImpl& source)
4828 {
4829         return false;
4830 }
4831
4832
4833 bool 
4834 _WebImpl::OnFocusLost(const _ControlImpl& source)
4835 {
4836         Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
4837         if (!pWebview)
4838         {
4839                 return false;
4840         }
4841
4842         if(IsKeypadVisible() == true)
4843         {
4844                 SetKeypadOpened(true);
4845         }
4846
4847         return false;
4848 }
4849
4850
4851 bool
4852 _WebImpl::HasValidNativeNode(void) const
4853 {
4854         if (__pWebCore && __pWebCore->GetWebNativeNode())
4855         {
4856                 return true;
4857         }
4858
4859         return false;
4860 }
4861
4862
4863 result
4864 _WebImpl::OnPreAttachedToMainTree(void)
4865 {
4866         result r = E_SUCCESS;
4867
4868         if (IsVisible() == true)
4869         {
4870                 _WebManager* pWebManager = _WebManager::GetInstance();
4871                 pWebManager->SetActiveWeb(this);
4872         }
4873
4874         r = _ContainerImpl::OnPreAttachedToMainTree();
4875         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4876
4877         if (!HasValidNativeNode())
4878         {
4879                 r = __pWebCore->InitializeWebNativeNode();
4880                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4881
4882                 _ControlManager* pControlManager = _ControlManager::GetInstance();
4883                 SysTryReturnResult(NID_WEB_CTRL, pControlManager, E_SYSTEM, "Failed to get the ControlManager instance.");
4884                 OnChangeLayout(pControlManager->GetScreenRotation());
4885
4886                 r = InitializeSetting();
4887                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4888
4889                 _WebManager* pWebManager = _WebManager::GetInstance();
4890                 pWebManager->AddWeb(reinterpret_cast< int >(this));
4891         }
4892
4893         return E_SUCCESS;
4894 }
4895
4896
4897 result
4898 _WebImpl::OnDetachingFromMainTree(void)
4899 {
4900         result r = E_SUCCESS;
4901
4902         _WebManager* pWebManager = _WebManager::GetInstance();
4903         pWebManager->RemoveActiveWeb(this);
4904
4905         r = _ContainerImpl::OnDetachingFromMainTree();
4906         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
4907
4908         return E_SUCCESS;
4909 }
4910
4911
4912 void
4913 _WebImpl::OnChangeLayout(_ControlRotation rotation)
4914 {
4915         int degree = 0;
4916
4917         switch (rotation)
4918         {
4919                 case _CONTROL_ROTATION_0:
4920                         degree =  0;
4921                         break;
4922                 case _CONTROL_ROTATION_90:
4923                         degree =  90;
4924                         break;
4925                 case _CONTROL_ROTATION_180:
4926                         degree =  180;
4927                         break;
4928                 case _CONTROL_ROTATION_270:
4929                         degree =  -90;
4930                         break;
4931                 default:
4932                         SysAssert(false);
4933         }
4934         ewk_view_orientation_send(__pWebCore->GetWebNativeNode(), degree);
4935 }
4936
4937
4938 void
4939 _WebImpl::OnChangeLayout(_ControlOrientation orientation)
4940 {
4941         _ContainerImpl::OnChangeLayout(orientation);
4942
4943         if (__pColorPicker.get())
4944         {
4945                 __pColorPicker->ChangeLayout(orientation);
4946         }
4947
4948         HideFormDataWindow();
4949
4950         std::unique_ptr< IEnumerator > pEnum(__webNotificationList.GetEnumeratorN());
4951         _WebNotification* pWebNotification = null;
4952
4953         while (pEnum->MoveNext() == E_SUCCESS)
4954         {
4955                 pWebNotification = static_cast< _WebNotification* >(pEnum->GetCurrent());
4956                 pWebNotification->OnChangeLayout();
4957         }
4958 }
4959
4960
4961 void
4962 _WebImpl::OnAncestorVisibleStateChanged(const _Control& control)
4963 {
4964         _WebManager* pWebManager = _WebManager::GetInstance();
4965         if (IsVisible() == true)
4966         {
4967                 pWebManager->SetActiveWeb(this);
4968                 ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_VISIBLE, false);
4969         }
4970         else
4971         {
4972                 pWebManager->RemoveActiveWeb(this);
4973                 ewk_view_page_visibility_state_set(__pWebCore->GetWebNativeNode(), EWK_PAGE_VISIBILITY_STATE_HIDDEN, false);
4974         }
4975 }
4976
4977
4978 void
4979 _WebImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
4980 {
4981         _ContainerImpl::OnUserEventReceivedN(requestId, pArgs);
4982         
4983         switch (requestId)
4984         {
4985         case ID_CERTIFICATE_CONFIRM_POPUP_CLOSE:
4986                 __pCertConfirmPopup.reset();
4987                 break;
4988         case ID_PROMPT_POPUP_CLOSE:
4989                 __pPromptPopup.reset();
4990                 break;
4991         case ID_USER_CONFIRM_USERMEDIA_CLOSE:
4992                 __pUserMediaConfirmPopup.reset();
4993                 break;
4994         case ID_USER_CONFIRM_GEOLOCATION_CLOSE:
4995                 __pGeolocationConfirmPopup.reset();
4996                 break;
4997         case ID_USER_CONFIRM_NOTIFICATION_CLOSE:
4998                 __pNotificationConfirmPopup.reset();
4999                 break;
5000         case ID_USER_SCRIPT_ALERT_CLOSE:
5001                 __pScriptAlertConfirmPopup.reset();
5002                 break;
5003         case ID_USER_SCRIPT_CONFIRM_CLOSE:
5004                 __pScriptConfirmPopup.reset();
5005                 break;
5006         default:
5007                 break;
5008         }
5009
5010         Resume();
5011 }
5012
5013
5014 _WebDataHandler*
5015 _WebImpl::GetDownloadHandler(void) const
5016 {
5017         return __pWebDownloadHandler.get();
5018 }
5019
5020
5021 Eina_Bool
5022 _WebImpl::HideColorPicker(void)
5023 {
5024         __pColorPicker.reset();
5025
5026         Resume();
5027
5028         return EINA_TRUE;
5029 }
5030
5031
5032 result
5033 _WebImpl::ShowColorPicker(int red, int green, int blue, int alpha, Color& color)
5034 {
5035         result r = E_SUCCESS;
5036
5037         std::unique_ptr<_InputPickerPopup> pColorHadler(new (std::nothrow) _InputPickerPopup());
5038         SysTryReturnResult(NID_WEB_CTRL, pColorHadler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
5039
5040         Tizen::Graphics::Color colorVal(static_cast< byte >(red), static_cast< byte >(green), static_cast< byte >(blue), static_cast< byte >(alpha));
5041
5042         r = pColorHadler->Construct(colorVal, this);
5043         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5044
5045         __pColorPicker = std::move(pColorHadler);
5046
5047         r = __pColorPicker->ShowPopup();
5048         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5049
5050         if (__pColorPicker)
5051         {
5052                 color = __pColorPicker->GetColor();
5053         }
5054
5055 CATCH:
5056         if (__pColorPicker)
5057         {
5058                 __pColorPicker.reset();
5059                 Resume();
5060         }
5061
5062         return r;
5063 }
5064
5065
5066 result
5067 _WebImpl::ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue, String& dateStr)
5068 {
5069         result r = E_SUCCESS;
5070
5071         std::unique_ptr<_InputPickerPopup> pInputPicker(new (std::nothrow) _InputPickerPopup());
5072         SysTryReturnResult(NID_WEB_CTRL, pInputPicker.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
5073
5074         r = pInputPicker->Construct(String(inputValue), inputType, this);
5075         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5076
5077         __pDatePicker = std::move(pInputPicker);
5078
5079         r = __pDatePicker->ShowPopup();
5080         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
5081
5082         if (__pDatePicker)
5083         {
5084                 dateStr = __pDatePicker->GetDate();
5085         }
5086
5087 CATCH:
5088         if (__pDatePicker)
5089         {
5090                 __pDatePicker.reset();
5091                 Resume();
5092         }
5093
5094         return r;
5095 }
5096
5097
5098 _WebImpl*
5099 _WebImpl::GetInstance(Web* pWeb)
5100 {
5101         return dynamic_cast< _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
5102 }
5103
5104
5105 const _WebImpl*
5106 _WebImpl::GetInstance(const Web* pWeb)
5107 {
5108         return dynamic_cast< const _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
5109 }
5110
5111
5112 int 
5113 _WebImpl::SearchHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
5114 {
5115         int checkReturn = 0;
5116         _DatabaseImpl db;
5117         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5118
5119         String table;
5120         if( checkmime == true)
5121         {
5122                 table = CUSTOM_CONTENT_TABLE_NAME;
5123         }
5124         else
5125         {
5126                 table = CUSTOM_PROTOCOL_TABLE_NAME;
5127         }
5128         
5129         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
5130         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
5131         String target(ewk_custom_handlers_data_target_get(pHandlerData));
5132
5133         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
5134         
5135         result r = db.Construct(handlerPath, "r+", null);
5136         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5137
5138         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"'"));
5139         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5140
5141         if(pEnum.get())
5142         {
5143                 r = pEnum->MoveNext();
5144                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5145                 r = pEnum->GetIntAt(0, checkReturn);
5146                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, -1, r, "[%s] Propagating.", GetErrorMessage(r));
5147         }
5148         else
5149         {
5150                 checkReturn = 2;
5151         }
5152
5153         return checkReturn;
5154 }
5155
5156
5157 result 
5158 _WebImpl::UnregistrationHandler(Ewk_Custom_Handlers_Data* pHandlerData, bool checkmime)
5159 {
5160         int checkId = 0;
5161         _DatabaseImpl db;
5162         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5163
5164         String table;
5165         if( checkmime == true)
5166         {
5167                 table = CUSTOM_CONTENT_TABLE_NAME;
5168         }
5169         else
5170         {
5171                 table = CUSTOM_PROTOCOL_TABLE_NAME;
5172         }
5173
5174         String baseUri(ewk_custom_handlers_data_base_url_get(pHandlerData));
5175         String uri(ewk_custom_handlers_data_url_get(pHandlerData));
5176         String target(ewk_custom_handlers_data_target_get(pHandlerData));
5177         
5178         SysSecureLog(NID_WEB_CTRL, "BaseUrl : %s, Url : %s, mime : %s", baseUri.GetPointer(), uri.GetPointer(), target.GetPointer());
5179         
5180         result r = db.Construct(handlerPath, "r+", null);
5181         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5182
5183         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"'"));
5184         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5185
5186         if(pEnum.get())
5187         {
5188                 r = pEnum->MoveNext();
5189                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5190                 r = pEnum->GetIntAt(0, checkId);
5191                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5192                 
5193                 std::unique_ptr<DbStatement> pDeleteStmt(db.CreateStatementN(L"Delete From " + table + L" Where id = (?)"));
5194                 SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
5195
5196                 r = pDeleteStmt->BindInt(0, checkId);
5197                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5198                 
5199                 db.BeginTransaction();
5200                 
5201                 std::unique_ptr<DbEnumerator> pEnum(db.ExecuteStatementN(*pDeleteStmt));
5202                 
5203                 db.CommitTransaction();
5204         }
5205
5206         return E_SUCCESS;
5207 }
5208
5209
5210 const Tizen::Base::String 
5211 _WebImpl::GetProtocolFromUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri)
5212 {
5213         if (originUri == L"" || currentUri == L"")
5214         {
5215                 return L"";
5216         }
5217
5218         result r = E_SUCCESS;
5219         String baseUri;
5220         _DatabaseImpl db;
5221         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5222         String originReplace(originUri);
5223         String table(CUSTOM_PROTOCOL_TABLE_NAME);
5224         int found = 0;
5225         int foundQuery = 0;
5226
5227         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
5228         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5229         
5230         r = currentUri.SubString(0, found + 1, baseUri);
5231         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5232                 
5233         r = db.Construct(handlerPath, "r+", null);
5234         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5235         
5236         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select mime, url, allow From " + table + L" Where baseUrl = '" + baseUri + "'"));
5237         SysTryReturn(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, L"", GetLastResult(), "[%s] Propagating.", GetErrorMessage(r));
5238
5239         if(pEnum.get())
5240         {
5241                 while (pEnum->MoveNext() == E_SUCCESS)
5242                 {                       
5243                         String protocol;
5244                         String queryUrl;
5245                         int allow;
5246                         String originScheme;
5247
5248                         r = pEnum->GetStringAt(0, protocol);
5249                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5250                 
5251                         r = pEnum->GetStringAt(1, queryUrl);
5252                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5253                         
5254                         r = pEnum->GetIntAt(2, allow);
5255                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5256
5257                         if (allow == 0)
5258                         {
5259                                 break;
5260                         }
5261
5262                         String protocolScheme(protocol + L":");
5263                         
5264                         r = originReplace.SubString(0, protocolScheme.GetLength(), originScheme);
5265                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5266                                                 
5267                         if ((originReplace.GetLength() >= protocolScheme.GetLength()) && originScheme.Equals(protocolScheme, false))
5268                         {
5269                                 if (queryUrl.IndexOf(L"%s", 0, foundQuery) == E_SUCCESS)
5270                                 {
5271                                         r = originReplace.Replace(originScheme, "");
5272                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5273                                         
5274                                         queryUrl.Replace("%s", originReplace, 0);
5275                                         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5276
5277                                         return queryUrl;
5278                                 }
5279                         }               
5280                 }
5281         }
5282         
5283         return L"";
5284 }
5285
5286
5287 const Tizen::Base::String 
5288 _WebImpl::GetRedirectUri(const Tizen::Base::String& originUri, const Tizen::Base::String& currentUri, const Tizen::Base::String& mime)
5289 {
5290         if (originUri == L"" || currentUri == L"" || mime == L"")
5291         {
5292                 return L"";
5293         }
5294
5295         result r = E_SUCCESS;
5296         String baseUri;
5297         String contentUrl;
5298         String originUrlStr = originUri;
5299         const String replaceStr = L"%s";
5300         _DatabaseImpl db;
5301         String handlerPath(Tizen::App::App::GetInstance()->GetAppRootPath() + CUSTOM_DB_DIRECTORY_PATH + USER_CONFIRM_DB_NAME);
5302         String table(CUSTOM_CONTENT_TABLE_NAME);
5303         int allow = 0;
5304         int found = 0;
5305         
5306         r = currentUri.LastIndexOf(L"/", currentUri.GetLength()-1, found);
5307         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5308                 
5309         r = currentUri.SubString(0, found + 1, baseUri);
5310         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5311                 
5312         r = db.Construct(handlerPath, "r+", null);
5313         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5314
5315         std::unique_ptr<DbEnumerator> pEnum(db.QueryN(L"Select allow, url From " + table + L" Where baseUrl = '" + baseUri + "' AND mime = '" + mime + L"'"));
5316         
5317         if (pEnum.get())
5318         {
5319                 r = pEnum->MoveNext();
5320                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5321                 r = pEnum->GetIntAt(0, allow);
5322                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5323                 r = pEnum->GetStringAt(1, contentUrl);
5324                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5325                         
5326                 if (allow == 0)
5327                 {
5328                         return L"";
5329                 }
5330                 else
5331                 {
5332                         if (contentUrl != L"")
5333                         {
5334                                 r = contentUrl.Replace(replaceStr, originUrlStr, 0);
5335                                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, L"", r, "[%s] Propagating.", GetErrorMessage(r));
5336
5337                                 return contentUrl;
5338                         }
5339                 }
5340         }
5341         
5342         return L"";
5343 }
5344
5345
5346 void
5347 _WebImpl::SetFormDataList(Eina_List* pFormDataList)
5348 {
5349         __pFormDataList = pFormDataList;
5350 }
5351
5352
5353 bool
5354 _WebImpl::IsFormDataWindowVisible(void) const
5355 {
5356         return __isFormDataVisible;
5357 }
5358
5359
5360 result
5361 _WebImpl::ShowFormDataWindow(const Rectangle& windowRect, Evas_Object* pWebView)
5362 {
5363         Rectangle rect(_CoordinateSystemUtils::InverseTransform(Rectangle(windowRect.x, windowRect.y + windowRect.height, windowRect.width, windowRect.height)));
5364
5365         if (__isFormDataVisible)
5366         {
5367                 result r = __pFormDataWindow->UpdateList(__pFormDataList, rect);
5368                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5369         }
5370         else
5371         {
5372                 __pFormDataWindow.reset();
5373
5374                 std::unique_ptr<_FormDataWindow> pFormDataWindow( new (std::nothrow) _FormDataWindow());
5375                 SysTryReturnResult(NID_WEB_CTRL, pFormDataWindow.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
5376
5377                 result r = pFormDataWindow->Construct(rect, this, pWebView);
5378                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5379
5380                 r = pFormDataWindow->UpdateList(__pFormDataList, rect);
5381                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5382
5383                 r = pFormDataWindow->LaunchFormDataWindow();
5384                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
5385
5386                 __pFormDataWindow = std::move(pFormDataWindow);
5387                 __isFormDataVisible = true;
5388         }
5389
5390         return E_SUCCESS;
5391 }
5392
5393
5394 void
5395 _WebImpl::HideFormDataWindow(bool delWindow)
5396 {
5397         if (delWindow)
5398         {
5399                 __pFormDataWindow.reset();
5400         }
5401
5402         __isFormDataVisible = false;
5403 }
5404
5405
5406 void
5407 _WebImpl::ClearWebNotification(_WebNotification* pWebNotification)
5408 {
5409         __webNotificationList.Remove(*pWebNotification);
5410 }
5411
5412
5413 void
5414 _WebImpl::SetWebNotification(_WebNotification* pWebNotification)
5415 {
5416         __webNotificationList.Add(pWebNotification);
5417 }
5418
5419
5420 }}} // Tizen::Web::Controls