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