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