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