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