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