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