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