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