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