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