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