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