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