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