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