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