Tizen 2.1 base
[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_Evas.h>
25 #include <elm_config.h>
26 #include <elm_win.h>
27 #include <EWebKit2.h>
28 #include <ewk_popup_menu_item.h>
29 #include <libsoup/soup-status.h>
30 #include <FAppApp.h>
31 #include <FAppAppControl.h>
32 #include <FAppIAppControlListener.h>
33 #include <FBaseColAllElementsDeleter.h>
34 #include <FBaseColHashMapT.h>
35 #include <FBaseRtMutex.h>
36 #include <FBaseRtMutexGuard.h>
37 #include <FBaseSysLog.h>
38 #include <FBaseUtilUri.h>
39 #include <FCntDownloadRequest.h>
40 #include <FGrpColor.h>
41 #include <FGrpPoint.h>
42 #include <FGrpRectangle.h>
43 #include <FIoDbEnumerator.h>
44 #include <FIoDbStatement.h>
45 #include <FIoFile.h>
46 #include <FMediaImage.h>
47 #include <FMediaImageTypes.h>
48 #include <FNetHttpHttpHeader.h>
49 #include <FUiControl.h>
50 #include <FUiCtrlKeypad.h>
51 #include <FWebCtrlHitElementResult.h>
52 #include <FWebCtrlITextSearchListener.h>
53 #include <FWebCtrlIWebDownloadListener.h>
54 #include <FWebCtrlIWebUiEventListener.h>
55 #include <FWebCtrlIWebKeypadEventListener.h>
56 #include <FWebCtrlIJavaScriptBridge.h>
57 #include <FWebCtrlPageNavigationList.h>
58 #include <FWebCtrlAuthenticationChallenge.h>
59 #include <FWebCtrlWeb.h>
60 #include <FWebCtrlWebSetting.h>
61 #include <FWebHistoryItem.h>
62 #include <FWebJsonJsonObject.h>
63 #include <FWebJsonJsonParser.h>
64 #include <FWebJsonJsonString.h>
65 #include <FApp_AppControlImpl.h>
66 #include <FApp_AppControlManager.h>
67 #include <FApp_AppInfo.h>
68 #include <FApp_AppManagerImpl.h>
69 #include <FBase_StringConverter.h>
70 #include <FCnt_DownloadManagerImpl.h>
71 #include <FGrp_CoordinateSystem.h>
72 #include <FIo_DatabaseImpl.h>
73 #include <FIo_NormalFile.h>
74 #include <FUi_Control.h>
75 #include <FUi_EcoreEvasMgr.h>
76 #include <FUi_EcoreEvas.h>
77 #include <FUi_ResourceSizeInfo.h>
78 #include <FUi_Window.h>
79 #include <FUiAnim_EflNode.h>
80 #include <FUiAnim_VisualElement.h>
81 #include <FUiCtrl_FooterImpl.h>
82 #include <FUiCtrl_Form.h>
83 #include "FWeb_HistoryItemImpl.h"
84 #include "FWebCtrl_AppControlListener.h"
85 #include "FWebCtrl_AuthConfirmPopup.h"
86 #include "FWebCtrl_AuthenticationChallengeImpl.h"
87 #include "FWebCtrl_GeolocationConfirmPopup.h"
88 #include "FWebCtrl_GeolocationPermissionManagerImpl.h"
89 #include "FWebCtrl_HitElementResultImpl.h"
90 #include "FWebCtrl_InputPickerPopup.h"
91 #include "FWebCtrl_PageNavigationListImpl.h"
92 #include "FWebCtrl_PromptPopup.h"
93 #include "FWebCtrl_SelectBox.h"
94 #include "FWebCtrl_Utility.h"
95 #include "FWebCtrl_Web.h"
96 #include "FWebCtrl_WebDataHandler.h"
97 #include "FWebCtrl_WebEvent.h"
98 #include "FWebCtrl_WebEventArg.h"
99 #include "FWebCtrl_WebImpl.h"
100 #include "FWebCtrl_WebPresenter.h"
101 #include "FWebCtrl_WebSettingImpl.h"
102
103
104 using namespace Tizen::App;
105 using namespace Tizen::Base;
106 using namespace Tizen::Base::Collection;
107 using namespace Tizen::Base::Runtime;
108 using namespace Tizen::Base::Utility;
109 using namespace Tizen::Content;
110 using namespace Tizen::Graphics;
111 using namespace Tizen::Io;
112 using namespace Tizen::Media;
113 using namespace Tizen::Net::Http;
114 using namespace Tizen::Ui;
115 using namespace Tizen::Ui::Animations;
116 using namespace Tizen::Ui::Controls;
117 using namespace Tizen::Web::Json;
118
119
120 namespace Tizen { namespace Web { namespace Controls
121 {
122
123
124 static const char WEB_CTRL[] = "webcontrol";
125 static const char PARENT_WEB_CTRL[] = "parentwebcontrol";
126
127
128 static const float MIN_ZOOM_LEVEL = 0.3;
129 static const float MAX_ZOOM_LEVEL = 2;
130
131
132 static const int REDIRECTION_HEADER_GROUP = 300;
133
134
135 static const int MAX_TEXT_MATCH = pow(2, 31) - 1;
136
137
138 static const int PORTRAIT_KEYPAD_HEIGHT = 444;
139 static const int LANDSCAPE_KEYPAD_HEIGHT = 316;
140
141
142 Eina_Bool
143 AddHttpHeaderData(const Eina_Hash* pHash, const void* pKey, void* pValue, void* pUserData)
144 {
145         result r = E_SUCCESS;
146
147         String key(reinterpret_cast< const char* >(pKey));
148         String value(reinterpret_cast< char* >(pValue));
149
150         SysLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", key.GetPointer(), value.GetPointer());
151
152         r = reinterpret_cast< HttpHeader* >(pUserData)->AddField(key, value);
153         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         return EINA_TRUE;
156 }
157
158
159 Eina_Bool
160 AddHttpAttributeData(const Eina_Hash* pHash, const void* pKey, void* pValue, void* pUserData)
161 {
162         result r = E_SUCCESS;
163
164         std::unique_ptr<String> pAttrKey(new (std::nothrow) String(reinterpret_cast< char* >(const_cast< void* >(pKey))));
165         std::unique_ptr<String> pAttrValue(new (std::nothrow) String(reinterpret_cast< char* >(pValue)));
166         SysTryReturn(NID_WEB_CTRL, pAttrKey.get() && pAttrValue.get(), EINA_FALSE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
167
168         SysLog(NID_WEB_CTRL, "The current value of key is %ls, value is %ls", pAttrKey->GetPointer(), pAttrValue->GetPointer());
169
170         r = reinterpret_cast< HashMap* >(pUserData)->Add(*pAttrKey, *pAttrValue);
171         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
172         pAttrKey.release();
173         pAttrValue.release();
174
175         return EINA_TRUE;
176 }
177
178
179 void FreeCharArray(void* pData)
180 {
181         delete[] reinterpret_cast<char*>(pData);
182 }
183
184
185 result
186 FireLoadingErrorOccurredEvent(_WebImpl* pImpl, int code, const char* pDescription)
187 {
188         result r = E_SUCCESS;
189
190         std::unique_ptr<Integer> pErrorCode(new (std::nothrow) Integer(code));
191         std::unique_ptr<String> pErrorDescription(new (std::nothrow) String(pDescription));
192         std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED));
193         SysTryReturn(NID_WEB_CTRL, pErrorCode.get() && pErrorDescription.get() && pEventArg.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
194
195         r = pEventArg->SetEventInfo(_LoadingEventArg::ERROR_TYPE, *pErrorCode.get());
196         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
197         pErrorCode.release();
198
199         r = pEventArg->SetEventInfo(_LoadingEventArg::ERROR_MESSAGE, *pErrorDescription.get());
200         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
201         pErrorDescription.release();
202
203         r = pImpl->GetWebEvent()->FireAsync(*pEventArg);
204         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
205         pEventArg.release();
206
207         return E_SUCCESS;
208 }
209
210
211 Eina_Bool
212 OnScriptAlertRequested(Evas_Object* pView, const char* pMessage, void* pUserData)
213 {
214         SysLog(NID_WEB_CTRL, "The current value of message is %s", pMessage);
215
216         result r = E_SUCCESS;
217
218         String msg(pMessage);
219
220         MessageBox messageBox;
221         r = messageBox.Construct(L"", msg, MSGBOX_STYLE_OK);
222         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
223
224         int modalResult = 0;
225         r = messageBox.ShowAndWait(modalResult);
226         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
227
228         ewk_view_javascript_alert_reply(pView);
229
230         return EINA_TRUE;
231 }
232
233
234 Eina_Bool
235 OnScriptConfirmRequested(Evas_Object* pView, const char* pMessage, void* pUserData)
236 {
237         SysLog(NID_WEB_CTRL, "The current value of message is %s", pMessage);
238
239         result r = E_SUCCESS;
240
241         String msg(pMessage);
242
243         MessageBox messageBox;
244         r = messageBox.Construct(L"", msg, MSGBOX_STYLE_OKCANCEL);
245         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
246
247         int modalResult = 0;
248         r = messageBox.ShowAndWait(modalResult);
249         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
250
251         if (modalResult == MSGBOX_RESULT_OK)
252         {
253                 ewk_view_javascript_confirm_reply(pView, EINA_TRUE);
254         }
255         else
256         {
257                 ewk_view_javascript_confirm_reply(pView, EINA_FALSE);
258         }
259
260         return EINA_TRUE;
261 }
262
263
264 Eina_Bool
265 OnScriptPromptRequested(Evas_Object* pView, const char* pMessage, const char* pDefaultValue, void* pUserData)
266 {
267         SysLog(NID_WEB_CTRL, "The current value of message is %s, defaulValue is %s", pMessage, pDefaultValue);
268
269         result r = E_SUCCESS;
270
271         String msg(pMessage);
272         String defVal(pDefaultValue);
273
274         int modalResult = -1;
275         _PromptPopup pPromptPopup;
276
277         r = pPromptPopup.Construct(msg, defVal);
278         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
279
280         pPromptPopup.ShowAndWait(modalResult);
281
282         if (modalResult)
283         {
284                 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(pPromptPopup.GetPromptText()));
285                 SysTryReturn(NID_WEB_CTRL, pResult.get(), EINA_FALSE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
286
287                 ewk_view_javascript_prompt_reply(pView, pResult.get());
288         }
289         else
290         {
291                 ewk_view_javascript_prompt_reply(pView, null);
292         }
293
294         return EINA_TRUE;
295 }
296
297
298 void
299 OnCertificateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
300 {
301         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
302         Ewk_Certificate_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Certificate_Policy_Decision* >(pEventInfo);
303         SysAssertf(pImpl && pPolicy, "Failed to request");
304
305         SysLog(NID_WEB_CTRL, "url : %s, pem : %s, error : %d", ewk_certificate_policy_decision_url_get(pPolicy), ewk_certificate_policy_decision_certificate_pem_get(pPolicy), ewk_certificate_policy_decision_error_get(pPolicy));
306
307         ewk_certificate_policy_decision_allowed_set(pPolicy, EINA_TRUE);
308
309         if (pImpl->GetLoadingListener())
310         {
311 //              ToDo : If certificate check works properly, remove annotation.
312 //              r = FireLoadingErrorOccurredEvent(pImpl, 999, "Invalid certificate.");
313 //              SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
314         }
315 }
316
317
318 void
319 OnHttpAuthenticationRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
320 {
321         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
322         Ewk_Auth_Challenge* pChallenge = reinterpret_cast< Ewk_Auth_Challenge* >(pEventInfo);
323         SysAssertf(pImpl && pChallenge, "Failed to request");
324
325         result r = E_SUCCESS;
326
327         r = pImpl->HttpAuthenticationRequested(pChallenge);
328         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
329
330         return;
331
332 CATCH:
333         ewk_auth_challenge_credential_cancel(pChallenge);
334         evas_object_smart_callback_call(pView, "authentication,canceled", NULL);
335 }
336
337
338 void
339 OnHttpAuthenticationCanceled(void* pUserData, Evas_Object* pView, void* pEventInfo)
340 {
341         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
342         SysAssertf(pImpl , "Failed to request");
343
344         if (pImpl->GetLoadingListener())
345         {
346                 result r = E_SUCCESS;
347
348                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED));
349                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
350
351                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
352                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
353                 pEventArg.release();
354         }
355 }
356
357
358 void
359 OnGeolocationPermissionRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
360 {
361         _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
362         Ewk_Geolocation_Permission_Data* pPermissionData = reinterpret_cast< Ewk_Geolocation_Permission_Data* >(pEventInfo);
363         SysAssertf(pImpl && pPermissionData, "Failed to request");
364
365         Ewk_Geolocation_Permission_Request permissionRequest = ewk_geolocation_permission_request_get(pPermissionData);
366
367         if (pImpl->GetSetting().IsGeolocationEnabled())
368         {
369                 result r = E_SUCCESS;
370
371                 std::unique_ptr<DbEnumerator> pEnum;
372
373                 String geolocationPath(Tizen::App::App::GetInstance()->GetAppRootPath() + GEOLOCATION_DIRECTORY_PATH + GEOLOCATION_DB_NAME);
374                 String table(GEOLOCATION_TABLE_NAME);
375                 _DatabaseImpl db;
376
377                 const Ewk_Security_Origin* pOrigin = ewk_geolocation_permission_request_origin_get(pPermissionData);
378                 String origin = _GeolocationPermissionManagerImpl::CreateOrigin(pOrigin);
379
380                 r = db.Construct(geolocationPath, "r", null);
381                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
382
383                 pEnum = std::unique_ptr<DbEnumerator>(db.QueryN(L"Select permission From " + table + L" Where origin = '" + origin + L"'"));
384                 if (pEnum.get())
385                 {
386                         r = pEnum->MoveNext();
387                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
388
389                         int permission = 0;
390                         r = pEnum->GetIntAt(0, permission);
391                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
392
393                         SysLog(NID_WEB_CTRL, "The current value of permission is %d", permission);
394
395                         ewk_geolocation_permission_request_allow_set(permissionRequest, static_cast < Eina_Bool >(permission));
396                 }
397                 else
398                 {
399                         r = pImpl->ShowGeolocationPopup(pPermissionData);
400                         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
401                 }
402
403                 return;
404         }
405
406 CATCH:
407         ewk_geolocation_permission_request_allow_set(permissionRequest, EINA_FALSE);
408 }
409
410
411 void
412 OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
413 {
414         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
415         Ewk_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Policy_Decision* >(pEventInfo);
416         SysAssertf(pImpl && pPolicy, "Failed to request");
417
418         String url(ewk_policy_decision_url_get(pPolicy));
419         SysLog(NID_WEB_CTRL, "The current value of url is %ls", url.GetPointer());
420
421         if (url == L"about:blank")
422         {
423                 ewk_policy_decision_use(pPolicy);
424                 return;
425         }
426
427         if (pImpl->GetLoadingListener() && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy))
428                 && !pImpl->IsRedirectRequested())
429         {
430                 if (pImpl->GetTextSearchListener())
431                 {
432                         pImpl->DisableAsyncSearch();
433                 }
434         
435                 WebNavigationType navigationType = WEB_NAVIGATION_OTHER;
436                 Ewk_Policy_Navigation_Type ewkNavigationType = ewk_policy_decision_navigation_type_get(pPolicy);
437
438                 switch (ewkNavigationType)
439                 {
440                 case EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED:
441                         navigationType = WEB_NAVIGATION_LINK_CLICKED;
442                         break;
443                 case EWK_POLICY_NAVIGATION_TYPE_FORM_SUBMITTED:
444                         navigationType = WEB_NAVIGATION_FORM_SUBMITTED;
445                         break;
446                 case EWK_POLICY_NAVIGATION_TYPE_BACK_FORWARD:
447                         navigationType = WEB_NAVIGATION_BACKFORWARD;
448                         break;
449                 case EWK_POLICY_NAVIGATION_TYPE_RELOAD:
450                         navigationType = WEB_NAVIGATION_RELOAD;
451                         break;
452                 case EWK_POLICY_NAVIGATION_TYPE_FORM_RESUBMITTED:
453                         navigationType = WEB_NAVIGATION_FORM_RESUBMITTED;
454                         break;
455                 case EWK_POLICY_NAVIGATION_TYPE_OTHER:
456                         navigationType = WEB_NAVIGATION_OTHER;
457                         break;
458                 default:
459                         SysAssert(false);
460                 }
461
462                 if (pImpl->GetLoadingListener()->OnLoadingRequested(url, navigationType))
463                 {
464                         ewk_policy_decision_ignore(pPolicy);
465
466                         return;
467                 }
468         }
469
470         String uriScheme(ewk_policy_decision_scheme_get(pPolicy));
471         SysLog(NID_WEB_CTRL, "The current value of scheme is %ls", uriScheme.GetPointer());
472
473         if ((uriScheme != L"http") && (uriScheme != L"https") && (uriScheme != L"file"))
474         {
475                 ewk_policy_decision_ignore(pPolicy);
476
477                 result r = E_SUCCESS;
478
479                 _WebEventType eventType = WEB_EVENT_REQUEST_UNKNOWN;
480
481                 if (uriScheme == L"rtsp")
482                 {
483                         eventType = WEB_EVENT_REQUEST_RTSP;
484                 }
485                 else if (uriScheme == L"mailto")
486                 {
487                         eventType = WEB_EVENT_REQUEST_EMAIL;
488                 }
489                 else if (uriScheme == L"tel")
490                 {
491                         eventType = WEB_EVENT_REQUEST_TEL;
492                 }
493                 else if (uriScheme == L"sms" || uriScheme == L"smsto" )
494                 {
495                         eventType = WEB_EVENT_REQUEST_SMS;
496                 }
497                 else if (uriScheme == L"mms" || uriScheme == L"mmsto" )
498                 {
499                         eventType = WEB_EVENT_REQUEST_MMS;
500                 }
501
502                 std::unique_ptr<_WebEventArg> pEventArg(new _WebEventArg(eventType, url));
503                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
504
505                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
506                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
507                 pEventArg.release();
508
509                 return;
510         }
511
512         ewk_policy_decision_use(pPolicy);
513 }
514
515
516 void
517 OnLoadingStarted(void* pUserData, Evas_Object* pView, void* pEventInfo)
518 {
519         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
520         SysAssertf(pImpl, "Failed to request");
521
522         if (pImpl->GetLoadingListener())
523         {
524                 result r = E_SUCCESS;
525
526                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_STARTED));
527                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
528
529                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
530                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
531                 pEventArg.release();
532         }
533 }
534
535
536 void
537 OnPageTitleReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
538 {
539         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
540         char* pTitle = reinterpret_cast< char* >(pEventInfo);
541         SysAssertf(pImpl, "Failed to request");
542
543         SysLog(NID_WEB_CTRL, "The current value of title is %s", pTitle);
544
545         if (pImpl->GetLoadingListener())
546         {
547                 result r = E_SUCCESS;
548
549                 std::unique_ptr<String> pPageTitle(new (std::nothrow) String(pTitle));
550                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED));
551                 SysTryReturnVoidResult(NID_WEB_CTRL, pPageTitle.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
552
553                 r = pEventArg->SetEventInfo(_LoadingEventArg::PAGE_TITLE, *pPageTitle.get());
554                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
555                 pPageTitle.release();
556
557                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
558                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
559                 pEventArg.release();
560         }
561 }
562
563
564 void
565 OnEstimatedProgress(void* pUserData, Evas_Object* pView, void* pEventInfo)
566 {
567         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
568         double* pProgress = reinterpret_cast< double* >(pEventInfo);
569         SysAssertf(pImpl, "Failed to request");
570
571         SysLog(NID_WEB_CTRL, "The current value of progress is %lf", *pProgress);
572
573         if (pImpl->GetLoadingListener())
574         {
575                 result r = E_SUCCESS;
576
577                 std::unique_ptr<Integer> pProgressPercentage(new (std::nothrow) Integer(static_cast< int >(*pProgress * 100)));
578                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_PROGRESS));
579                 SysTryReturnVoidResult(NID_WEB_CTRL, pProgressPercentage.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
580
581                 r = pEventArg->SetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS, *pProgressPercentage.get());
582                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
583                 pProgressPercentage.release();
584
585                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
586                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
587                 pEventArg.release();
588         }
589 }
590
591
592 void
593 OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
594 {
595         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
596         Ewk_Policy_Decision* pPolicy = reinterpret_cast< Ewk_Policy_Decision* >(pEventInfo);
597         SysAssertf(pImpl && pPolicy, "Failed to request");
598
599         result r = E_SUCCESS;
600
601         const char* pUrl = ewk_policy_decision_url_get(pPolicy);
602         int code = ewk_policy_decision_response_status_code_get(pPolicy);
603         String mime(ewk_policy_decision_response_mime_get(pPolicy));
604         SysLog(NID_WEB_CTRL, "url : %s, mime : %ls, code : %d", pUrl, mime.GetPointer(), code);
605
606         ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
607         if (pLoadingListener && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy)))
608         {
609                 const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
610
611                 DecisionPolicy policy;
612                 HttpHeader httpHeader;
613
614                 if (code >= REDIRECTION_HEADER_GROUP && code < REDIRECTION_HEADER_GROUP + 100)
615                 {
616                         pImpl->SetRedirectRequested(true);
617                         mime = L"";
618                 }
619
620                 eina_hash_foreach(pHeader, AddHttpHeaderData, &httpHeader);
621                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
622
623                 policy = pLoadingListener->OnWebDataReceived(mime, httpHeader);
624                 pImpl->SetPolicyDecision(policy);
625         }
626
627         switch (pImpl->GetPolicyDecision())
628         {
629         case WEB_DECISION_CONTINUE:
630         {
631                 if (pImpl->IsMimeSupported(mime) || mime == L"")
632                 {
633                         break;
634                 }
635                 
636                 else
637                 {
638                         SysLog(NID_WEB_CTRL, "Lauch native app to handle the mime");
639
640                         ewk_policy_decision_ignore(pPolicy);
641
642                         AppControl* pAppControl = null;
643                         _SelectBox selectBox;
644                         int appCount = 0;
645                         int selectedIndex = 0;
646
647                         std::unique_ptr<IList, AllElementsDeleter> pList(_AppManagerImpl::FindAppControlsN(NULL, NULL, &mime, NULL));
648
649                         if (pList.get())
650                         {
651                                 appCount = pList->GetCount();
652                         }
653
654                         r = selectBox.Construct(false, L"", appCount+1); //+1 for Downloader
655                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
656
657                         selectBox.AddListItem(L"Download", _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
658                         for (int i = 0; i < appCount; i++)
659                         {
660                                 pAppControl = dynamic_cast< AppControl* >(pList->GetAt(i));
661                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppControl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
662
663                                 String text = pAppControl->GetAppName();
664                                 SysLog(NID_WEB_CTRL, "AppName : %S", text.GetPointer());
665
666                                 selectBox.AddListItem(text, _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
667                         }
668                         selectBox.ShowAndWait(selectedIndex);
669
670                         if (selectedIndex == 0) //download
671                         {
672                                 RequestId reqId = 0;
673                                 DownloadRequest request(pUrl);
674
675                                 _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
676                                 SysTryReturnVoidResult(NID_WEB_CTRL, pManagerImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
677
678                                 r = pManagerImpl->Start(request, reqId);
679                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
680                         }
681                         else if (selectedIndex != -1) // -1 for cancel
682                         {
683                                 String path("path");
684                                 String pathVal(pUrl);
685
686                                 HashMap dataList;
687                                 r = dataList.Construct();
688                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
689
690                                 r = dataList.Add(path, pathVal);
691                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
692
693                                 pAppControl = dynamic_cast< AppControl* >(pList->GetAt(selectedIndex));
694                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAppControl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
695
696                                 _AppControlImpl* pAcImpl = _AppControlImpl::GetInstance(*pAppControl);
697                                 SysTryReturnVoidResult(NID_WEB_CTRL, pAcImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
698
699                                 r = pAcImpl->Start(null, null, &dataList, null);
700                                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
701                         }
702
703                         return;
704                 }
705                 break;
706         }
707         case WEB_DECISION_DOWNLOAD:
708         {
709                 ewk_policy_decision_ignore(pPolicy);
710
711                 _WebDataHandler* pDownloadHandler = pImpl->GetDownloadHandler();
712                 SysTryReturnVoidResult(NID_WEB_CTRL, pDownloadHandler, E_SYSTEM, "[%s] A system error has been occurred. Failed to get DownloadHandler.", GetErrorMessage(E_SYSTEM));
713
714                 Ewk_Context* pContext = ewk_view_context_get(pView);
715                 SysAssertf(pContext, "Failed to get webkit instance.");
716
717                 pDownloadHandler->StartDownload(pUrl);
718
719                 return;
720         }
721         case WEB_DECISION_IGNORE:
722         {
723                 ewk_policy_decision_ignore(pPolicy);
724
725                 return;
726         }
727         default:
728         {
729                 SysAssert(false);
730         }
731         }
732
733         ewk_policy_decision_use(pPolicy);
734
735         return;
736
737 CATCH:
738         ewk_policy_decision_ignore(pPolicy);
739 }
740
741
742 void
743 OnProgressCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
744 {
745         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
746         SysAssertf(pImpl, "Failed to request");
747
748         if (pImpl->IsRedirectRequested())
749         {
750                 pImpl->SetRedirectRequested(false);
751         }
752
753         if (pImpl->IsLoadingErrorOccurred())
754         {
755                 pImpl->SetLoadingErrorOccurred(false);
756                 evas_object_smart_callback_call(pView, "load,finished", NULL);
757         }
758 }
759
760
761 void
762 OnLoadingErrorOccurred(void* pUserData, Evas_Object* pView, void* pEventInfo)
763 {
764         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
765         Ewk_Error* pErrorData = reinterpret_cast< Ewk_Error* >(pEventInfo);
766         SysAssertf(pImpl && pErrorData, "Failed to request");
767
768         int code = ewk_error_code_get(pErrorData);
769         const char* pDescription = ewk_error_description_get(pErrorData);
770
771         SysLog(NID_WEB_CTRL, "The current value of code is %d, description is %s", code, pDescription);
772
773         pImpl->SetLoadingErrorOccurred(true);
774         switch (code)
775         {
776         case EWK_ERROR_CODE_FRAMELOADINTERRUPTEDBYPOLICYCHANGE:
777                 //fall through
778         case EWK_ERROR_CODE_PLUGINWILLHANDLELOAD:
779                 break;
780
781         case EWK_ERROR_NETWORK_STATUS_CANCELLED:
782                 evas_object_smart_callback_call(pView, "load,stop", NULL);
783                 break;
784
785         default:
786                 if (pImpl->GetLoadingListener())
787                 {
788                         result r = E_SUCCESS;
789
790                         r = FireLoadingErrorOccurredEvent(pImpl, code, pDescription);
791                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
792                 }
793                 break;
794         }
795 }
796
797
798 void
799 OnLoadingCanceled(void* pUserData, Evas_Object* pView, void* pEventInfo)
800 {
801         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
802         SysAssertf(pImpl, "Failed to request");
803
804         if (pImpl->GetLoadingListener())
805         {
806                 result r = E_SUCCESS;
807
808                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_CANCELED));
809                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
810
811                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
812                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
813                 pEventArg.release();
814         }
815
816 }
817
818
819 void
820 OnLoadingCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
821 {
822         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
823         SysAssertf(pImpl, "Failed to request");
824
825         if (pImpl->GetLoadingListener())
826         {
827                 result r = E_SUCCESS;
828
829                 std::unique_ptr<_LoadingEventArg> pEventArg(new (std::nothrow) _LoadingEventArg(WEB_EVENT_LOADINGLISTENER_COMPLETED));
830                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
831
832                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
833                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
834                 pEventArg.release();
835         }
836
837 }
838
839
840 void
841 OnLoadingCommitted(void* pUserData, Evas_Object* pView, void* pEventInfo)
842 {
843         evas_object_focus_set(pView, EINA_FALSE);
844 }
845
846
847 void
848 OnDidStartDownloadCallback(const char* pUrl, void* pUserData)
849 {
850         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
851         SysAssertf(pUrl && pImpl != null, "Failed to request");
852
853         SysLog(NID_WEB_CTRL, "The current value of url is %s", pUrl);
854 }
855
856
857 void
858 OnWebPageShowRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
859 {
860         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
861         SysAssertf(pImpl, "Failed to request");
862
863         if (pImpl->GetUiEventListener())
864         {
865                 result r = E_SUCCESS;
866
867                 std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED));
868                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
869
870                 r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
871                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
872                 pEventArg.release();
873         }
874 }
875
876
877 void
878 OnWebWindowCreateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
879 {
880         _WebImpl* pParentImpl = reinterpret_cast< _WebImpl* >(pUserData);
881         Evas_Object** pChildView = reinterpret_cast< Evas_Object** >(pEventInfo);
882         SysAssertf(pParentImpl && pChildView, "Failed to request");
883
884         IWebUiEventListener* pUserUiListener = pParentImpl->GetUiEventListener();
885         if (pUserUiListener)
886         {
887                 Web* pWeb = pUserUiListener->OnWebWindowCreateRequested();
888                 if (pWeb)
889                 {
890                         _WebImpl* pChildImpl = _WebImpl::GetInstance(pWeb);
891                         SysTryReturnVoidResult(NID_WEB_CTRL, pChildImpl, E_SYSTEM, "[%s] A system error has been occurred. Failed to get ChildImpl object.", GetErrorMessage(E_SYSTEM));
892
893                         *pChildView = dynamic_cast< _Web* >(&pChildImpl->GetCore())->GetWebNativeNode();
894                         evas_object_data_set(*pChildView, PARENT_WEB_CTRL, pParentImpl);
895                 }
896         }
897 }
898
899
900 void
901 OnWebWindowClosedRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
902 {
903         _WebImpl* pChildImpl = reinterpret_cast< _WebImpl* >(pUserData);
904         _WebImpl* pParentImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, PARENT_WEB_CTRL));
905         SysAssertf(pChildImpl && pParentImpl, "Failed to request");
906
907         if (pParentImpl->GetUiEventListener())
908         {
909                 result r = E_SUCCESS;
910
911                 std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED));
912                 SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
913
914                 r = pChildImpl->GetWebEvent()->FireAsync(*pEventArg.get());
915                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
916                 pEventArg.release();
917         }
918 }
919
920
921 Eina_Bool
922 OnSelectUploadFile(Evas_Object* pView, Eina_Bool multipleFile, Eina_List* pAcceptTypes, const char* pCapture, void* pUserData)
923 {
924         Eina_Bool ret = EINA_FALSE;
925         Eina_List* pSelectedFileNames = null;
926         String isMultipleSelection(L"single");
927
928         if (multipleFile)
929         {
930                 isMultipleSelection.Append(L"multiple");
931         }
932
933         std::unique_ptr<_MediaSelectionListener> pMediaListener(new (std::nothrow) _MediaSelectionListener());
934         SysTryCatch(NID_WEB_CTRL, pMediaListener.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
935
936         {
937                 int itemCount = eina_list_count(pAcceptTypes);
938                 String fileType = L"all";
939
940                 if (itemCount == 1)
941                 {
942                         String item((char*)eina_list_nth(pAcceptTypes, 0));
943                         if (item.StartsWith("image/",0))
944                         {
945                                 fileType = L"image";
946                         }
947                         else if (item.StartsWith("audio/",0))
948                         {
949                                 fileType = L"audio";
950                         }
951                         else if (item.StartsWith("video/",0))
952                         {
953                                 fileType = L"video";
954                         }
955                 }
956
957                 HashMap dataList;
958                 result r = dataList.Construct();
959                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
960
961                 String mode(L"selectionType");
962                 r = dataList.Add(mode, isMultipleSelection);
963                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
964
965                 String type(L"type");
966                 r = dataList.Add(type, fileType);
967                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
968
969                 std::unique_ptr<AppControl> pMediaAppControl(_AppManagerImpl::FindAppControlN(L"tizen.filemanager", L"http://tizen.org/appcontrol/operation/pick"));
970                 SysTryCatch(NID_WEB_CTRL, pMediaAppControl.get(), r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
971
972                 _AppControlImpl* pMediaAppControlImpl = _AppControlImpl::GetInstance(*pMediaAppControl);
973                 r = pMediaAppControlImpl->Start(null, null, &dataList, pMediaListener.get());
974                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
975
976                 while (true)
977                 {
978                         if (pMediaListener->IsSelectionCompleted())
979                         {
980                                 const ArrayList* pSelectedFiles = pMediaListener->GetSelectedFiles();
981                                 SysTryCatch(NID_WEB_CTRL, pSelectedFiles, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
982
983                                 int fileCount = pSelectedFiles->GetCount();
984
985                                 for (int i = 0; i < fileCount; i++)
986                                 {
987                                         String* pFile = (String*)pSelectedFiles->GetAt(i);
988                                         SysTryCatch(NID_WEB_CTRL, pFile, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
989
990                                         std::unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(*pFile));
991                                         SysTryCatch(NID_WEB_CTRL, pByteBuf.get(), r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
992
993                                         pSelectedFileNames = eina_list_append(pSelectedFileNames, strdup((const char*)pByteBuf->GetPointer()));
994                                 }
995
996                                 ret = EINA_TRUE;
997                                 break;
998                         }
999
1000                         ecore_main_loop_iterate();
1001                 }
1002
1003                 ewk_view_open_panel_reply(pView, pSelectedFileNames, ret);
1004                 return ret;
1005         }
1006
1007 CATCH:
1008         ewk_view_open_panel_reply(pView, null, ret);
1009         eina_list_free(pSelectedFileNames);
1010         return ret;
1011 }
1012
1013
1014 void
1015 OnHandleJavaScriptRequest(void* pUserData, Evas_Object* pView, void* pEventInfo)
1016 {
1017         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1018         char* pJsonText = reinterpret_cast< char* >(pEventInfo);
1019         SysAssertf(pImpl && pJsonText, "Failed to request");
1020
1021         result r = E_SUCCESS;
1022
1023         SysLog(NID_WEB_CTRL, "The current value of jsontext is %s", pJsonText);
1024
1025         std::unique_ptr<_JsBridgeArg> pEventArg(new (std::nothrow) _JsBridgeArg());
1026         SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1027
1028         r = pEventArg->Construct(pJsonText);
1029         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1030
1031         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1032         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1033         pEventArg.release();
1034 }
1035
1036
1037 void
1038 OnWebKeypadStateChanged(void* pUserData, Evas_Object* pView, void* pEventInfo)
1039 {
1040         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1041         Eina_Rectangle* pEinaRect = reinterpret_cast< Eina_Rectangle* >(pEventInfo);
1042         SysAssertf(pImpl && pEinaRect, "Failed to request");
1043
1044         if (pImpl->GetSetting().GetInputStyle() == INPUT_STYLE_OVERLAY)
1045         {
1046                 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
1047                 SysAssertf(pXformer, "Failed to get CoordinateTransformer");
1048
1049                 Rectangle rect(pEinaRect->x, pEinaRect->y, pEinaRect->w, pEinaRect->h);
1050
1051                 if (rect.height == 0)
1052                 {
1053                         return;
1054                 }
1055
1056                 _Form* pFormCore = pImpl->GetParentFormCore(dynamic_cast< _Control* >(&pImpl->GetCore()));
1057                 SysAssertf(pFormCore != null, "Failed to get FormCore");
1058
1059                 if (pFormCore->HasFooter() && pFormCore->IsFooterVisible())
1060                 {
1061                         pImpl->SetFooterVisibleState(true);
1062                         pFormCore->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, false);
1063                 }
1064
1065                 if (pImpl->GetWebKeypadEventListener())
1066                 {
1067                         if (pImpl->IsKeypadVisible() == true)
1068                         {
1069                                 if ((pImpl->GetPreviousOrientation() == pFormCore->GetOrientation()) && (pImpl->GetKeypadHeight() != rect.height))
1070                                 {
1071                                         pFormCore->DeflateClientRectHeight(pXformer->TransformVertical(rect.height));
1072                                         pImpl->GetWebKeypadEventListener()->OnWebKeypadBoundsChanged(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1073                                 }
1074                         }
1075                         else
1076                         {
1077                                 pFormCore->DeflateClientRectHeight(pXformer->TransformVertical(rect.height));
1078                                 pImpl->GetWebKeypadEventListener()->OnWebKeypadWillOpen(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1079                         }
1080                 }
1081                 pImpl->SetKeypadVisibleState(true);
1082                 pImpl->SetPreviousOrientation(pFormCore->GetOrientation());
1083                 pImpl->SetKeypadHeight(rect.height);
1084         }
1085         else
1086         {
1087                 result r = pImpl->SetFullScreenKeypad();
1088                 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1089         }
1090 }
1091
1092
1093 void
1094 OnWebKeypadOpened(void* pUserData, Evas_Object* pView, void* pEventInfo)
1095 {
1096         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1097         SysAssertf(pImpl, "Failed to request");
1098
1099         if (pImpl->GetWebKeypadEventListener())
1100         {
1101                 pImpl->GetWebKeypadEventListener()->OnWebKeypadOpened(*static_cast< Web* >(&pImpl->GetPublic()));
1102         }
1103 }
1104
1105
1106 void
1107 OnWebKeypadClosed(void* pUserData, Evas_Object* pView, void* pEventInfo)
1108 {
1109         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1110         SysAssertf(pImpl, "Failed to request");
1111
1112         _Form* pFormCore = pImpl->GetParentFormCore(dynamic_cast< _Control* >(&pImpl->GetCore()));
1113         SysAssertf(pFormCore != null, "Failed to get FormCore");
1114
1115         if (pFormCore->HasFooter() && pImpl->IsFooterVisible())
1116         {
1117                 pImpl->SetFooterVisibleState(false);
1118                 pFormCore->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
1119         }
1120
1121         pFormCore->DeflateClientRectHeight(0);
1122
1123         if (pImpl->GetWebKeypadEventListener())
1124         {
1125                 pImpl->GetWebKeypadEventListener()->OnWebKeypadClosed(*dynamic_cast< Web* >(&pImpl->GetPublic()));
1126         }
1127
1128         pImpl->SetKeypadVisibleState(false);
1129 }
1130
1131
1132 void
1133 OnWindowObjectFocusGained(void *pUserData, Evas_Object *pWin, void *pEvent_info)
1134 {
1135         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1136         SysAssertf(pImpl, "Failed to request");
1137
1138         if (pImpl->IsKeypadOpened() == true)
1139         {
1140                 _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
1141                 SysAssertf(pWebCore, "Failed to get Web core object");
1142
1143                 evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
1144
1145                 pImpl->SetKeypadOpened(false);
1146         }
1147 }
1148
1149
1150 void
1151 OnWebNativeNodeFocusGained(void *pUserData, Evas *pCanvas, Evas_Object* pView, void* pEventInfo)
1152 {
1153         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1154         SysAssertf(pImpl, "Failed to request");
1155
1156         if (pImpl->IsKeypadOpened() == true)
1157         {
1158                 pImpl->SetKeypadOpened(false);
1159         }
1160
1161
1162
1163 Eina_Bool
1164 OnColorPickerProviderRequested(Ewk_View_Smart_Data *pSmartData, int red, int green, int blue, int alpha)
1165 {
1166         SysAssertf(pSmartData, "invalid smartdata");
1167         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1168         SysAssertf(pWebImpl, "Failed to get Impl");
1169
1170         result r = E_SUCCESS;
1171
1172         if (pWebImpl->GetColorpicker())
1173         {
1174                 return EINA_FALSE;
1175         }
1176
1177         Color color;
1178
1179         r = pWebImpl->ShowColorPicker(red, green, blue, alpha, color);
1180         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1181
1182         byte r1, g1, b1, a1;
1183         color.GetColorComponents(r1, g1, b1, a1);
1184         ewk_view_color_picker_color_set(pSmartData->self, r1, g1, b1, a1);
1185
1186         return EINA_TRUE;
1187 }
1188
1189
1190 Eina_Bool
1191 OnColorPickerProviderDismissed(Ewk_View_Smart_Data *pSmartData)
1192 {
1193         SysAssertf(pSmartData, "invalid smartdata");
1194
1195         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1196         SysAssertf(pWebImpl, "Failed to get Impl");
1197
1198         return pWebImpl->HideColorPicker();
1199 }
1200
1201
1202 Eina_Bool
1203 OnDatePickerProviderRequested(Ewk_View_Smart_Data *pSmartData, Ewk_Input_Type inputType, const char* inputValue)
1204 {
1205         SysAssertf(pSmartData, "Failed to request");
1206         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1207         SysAssertf(pWebImpl, "Failed to get Impl");
1208
1209         result r = E_SUCCESS;
1210
1211         if (pWebImpl->GetDatepicker())
1212         {
1213                 ewk_view_focused_input_element_value_set(pSmartData->self, inputValue);
1214
1215                 return EINA_FALSE;
1216         }
1217
1218         String dateStr;
1219
1220         r = pWebImpl->ShowDatePicker(inputType, inputValue, dateStr);
1221         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Memory allocation failed.", GetErrorMessage(r));
1222
1223         std::unique_ptr<char[]> pDateStr(_StringConverter::CopyToCharArrayN(dateStr));
1224         SysTryReturn(NID_WEB_CTRL, pDateStr.get(), EINA_FALSE, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1225
1226         ewk_view_focused_input_element_value_set(pSmartData->self, pDateStr.get());
1227
1228         return EINA_TRUE;
1229 }
1230
1231
1232 Eina_Bool
1233 OnSelectBoxRequested(Ewk_View_Smart_Data *pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, double pageScaleFactor, Eina_List* pItems, int selectedIndex)
1234 {
1235         SysAssertf(pSmartData, "Failed to request");
1236
1237         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1238         SysAssertf(pWebImpl, "Failed to get Impl");
1239
1240         result r = E_SUCCESS;
1241
1242         std::unique_ptr<_SelectBox> pSelectBox(new (std::nothrow) _SelectBox());
1243         SysTryReturn(NID_WEB_CTRL, pSelectBox.get(), EINA_FALSE, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1244
1245         //Create list required for selectBox
1246         int itemCount = eina_list_count(pItems);
1247         SysTryReturn(NID_WEB_CTRL, itemCount > 0, EINA_FALSE , E_SYSTEM, "[%s] ItemCount is invalid.", GetErrorMessage(E_SYSTEM));
1248
1249         r = pSelectBox->Construct(false, L"", itemCount, pSmartData->self);
1250         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1251
1252         r = pSelectBox->UpdateList(pItems, selectedIndex, false, false);
1253         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1254
1255         pWebImpl->SetSelectBox(pSelectBox.release());
1256
1257         pWebImpl->GetSelectBox()->Show();
1258
1259         return EINA_TRUE;
1260 }
1261
1262
1263 Eina_Bool
1264 OnSelectBoxClosed(Ewk_View_Smart_Data *pSmartData)
1265 {
1266         SysAssertf(pSmartData, "invalid smartdata");
1267
1268         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1269         SysAssertf(pWebImpl, "Failed to get Impl");
1270
1271         Eina_Bool ret = EINA_TRUE;
1272
1273         _SelectBox* pSelectBox = pWebImpl->GetSelectBox();
1274
1275         if (pSelectBox)
1276         {
1277                 pWebImpl->DeleteSelectBox();
1278         }
1279         else
1280         {
1281                 ret = EINA_FALSE;
1282         }
1283
1284         return ret;
1285 }
1286
1287
1288 Eina_Bool
1289 OnSelectBoxUpdateRequested(Ewk_View_Smart_Data *pSmartData, Eina_Rectangle rect, Ewk_Text_Direction textDirection, Eina_List* pItems, int selectedIndex)
1290 {
1291         SysAssertf(pSmartData, "invalid smartdata");
1292
1293         _WebImpl* pWebImpl = reinterpret_cast<_WebImpl*>(evas_object_data_get(pSmartData->self, WEB_CTRL));
1294         SysAssertf(pWebImpl, "Failed to get Impl");
1295
1296         _SelectBox* pSelectBox = pWebImpl->GetSelectBox();
1297
1298         Eina_Bool ret = EINA_FALSE;
1299
1300         if (pSelectBox)
1301         {
1302                 result r = pSelectBox->UpdateList(pItems, selectedIndex, true, false);
1303                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
1304
1305                 ret = EINA_TRUE;
1306         }
1307
1308         return ret;
1309 }
1310
1311
1312 void
1313 OnCookiesPolicyGot(Ewk_Cookie_Accept_Policy policy, Ewk_Web_Error *pError, void *pUserData)
1314 {
1315         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
1316         SysAssertf(pPresenter && !pError, "Failed to request");
1317
1318         bool ret = EINA_TRUE;
1319
1320         switch (policy)
1321         {
1322         case EWK_COOKIE_ACCEPT_POLICY_ALWAYS:
1323                 //fall through
1324         case EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY:
1325                 ret = EINA_TRUE;
1326                 break;
1327
1328         case EWK_COOKIE_ACCEPT_POLICY_NEVER:
1329                 //fall through
1330                 ret = EINA_FALSE;
1331                 break;
1332
1333         default:
1334                 SysAssert(false);
1335         }
1336
1337         SysLog(NID_WEB_CTRL, "The current value of policy is %d", ret);
1338
1339         pPresenter->EndAsyncProcess(ret);
1340 }
1341
1342
1343 void
1344 OnScriptExecuted(Evas_Object* pView, const char* pResult, void* pUserData)
1345 {
1346         _WebPresenter* pPresenter = reinterpret_cast< _WebPresenter* >(pUserData);
1347         SysAssertf(pPresenter, "Failed to request");
1348
1349         String result(pResult);
1350         SysLog(NID_WEB_CTRL, "result : %ls", result.GetPointer());
1351
1352         pPresenter->EndAsyncProcess(result);
1353 }
1354
1355
1356 void
1357 OnTextFound(void* pUserData, Evas_Object* pView, void* pEventInfo)
1358 {
1359         _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
1360         SysAssertf(pImpl, "Failed to request");
1361
1362         int* pTotalCount = reinterpret_cast< int* >(pEventInfo);
1363         SysLog(NID_WEB_CTRL, "The current value of totalCount is %d", *pTotalCount);
1364
1365         _WebPresenter* pWebPresenter = pImpl->GetSearchPresenter();
1366
1367         if (pWebPresenter)
1368         {
1369                 pWebPresenter->EndAsyncProcess(*pTotalCount);
1370         }
1371         else
1372         {
1373                 if (pImpl->GetTextSearchListener())
1374                 {
1375                         result r = E_SUCCESS;
1376
1377                         int ordinal = 0;
1378
1379                         if (*pTotalCount > 0)
1380                         {
1381                                 ordinal = pImpl->GetAsyncSearchOrdinal();
1382                                 pImpl->SetAsyncSearchResult(*pTotalCount);
1383                         }
1384
1385                         if (pImpl->GetPendingAsyncSearchCount() > 0)
1386                         {
1387                                 return;
1388                         }
1389
1390                         std::unique_ptr<Integer> pCount(new (std::nothrow) Integer(*pTotalCount));
1391                         std::unique_ptr<Integer> pOrdinal(new (std::nothrow) Integer(ordinal));
1392                         std::unique_ptr<_TextSearchEventArg> pEventArg(new (std::nothrow) _TextSearchEventArg(WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND));
1393                         SysTryReturnVoidResult(NID_WEB_CTRL, pCount.get() && pOrdinal.get() && pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1394
1395                         r = pEventArg->SetEventInfo(_TextSearchEventArg::TOTAL_COUNT, *pCount.get());
1396                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1397                         pCount.release();
1398
1399                         r = pEventArg->SetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL, *pOrdinal.get());
1400                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1401                         pOrdinal.release();
1402
1403                         r = pImpl->GetWebEvent()->FireAsync(*pEventArg.get());
1404                         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
1405                         pEventArg.release();
1406                 }
1407         }
1408 }
1409
1410
1411 class _JsBridgeHashCodeProvider
1412         : public Tizen::Base::Collection::IHashCodeProviderT< Tizen::Base::String >
1413 {
1414 public:
1415         _JsBridgeHashCodeProvider(){}
1416         virtual ~_JsBridgeHashCodeProvider(void) {}
1417
1418
1419         int GetHashCode(const Tizen::Base::String& obj) const
1420         {
1421                 return obj.GetHashCode();
1422         }
1423
1424 };
1425
1426
1427 //Comparer implementation
1428 class _JsBridgeComparer
1429         : public Tizen::Base::Collection::IComparerT< Tizen::Base::String >
1430 {
1431 public:
1432         _JsBridgeComparer(){}
1433         virtual ~_JsBridgeComparer(void) {}
1434
1435
1436         result Compare(const Tizen::Base::String& obj1, const Tizen::Base::String& obj2, int& cmp) const
1437         {
1438                 if (obj1 == obj2)
1439                 {
1440                         cmp = 0;
1441                 }
1442                 else
1443                 {
1444                         cmp = 1;
1445                 }
1446
1447                 return E_SUCCESS;
1448         }
1449
1450 };
1451
1452
1453 _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
1454         : _ContainerImpl(pWeb, pCore)
1455         , __isFooterVisible(false)
1456         , __isKeypadVisible(false)
1457         , __isKeypadOpened(false)
1458         , __isLoadingErrorOccurred(false)
1459         , __isRedirectRequested(false)
1460         , __keypadHeight(0)
1461         , __pWebCore(null)
1462         , __pUserLoadingListener(null)
1463         , __pUserUiListener(null)
1464         , __pUserKeypadEventListener(null)
1465         , __pTextSearchListener(null)
1466         , __pKeypad(null)
1467         , __pWebSetting(null)
1468         , __pJsBridgeList(null)
1469         , __pJsProvider(null)
1470         , __pJsComparer(null)
1471         , __pWebDownloadHandler(null)
1472         , __pWebEvent(null)
1473         , __pAuthChallenge(null)
1474         , __pAuthPopup(null)
1475         , __pGeolocationPopup(null)
1476         , __orientation(_CONTROL_ORIENTATION_PORTRAIT)
1477         , __pSelectBox(null)
1478         , __pDatePicker(null)
1479         , __pColorPicker(null)
1480         , __policy(WEB_DECISION_CONTINUE)
1481 {
1482         __textSearch.__searchAll = false;
1483         __textSearch.__searchForward = true;
1484         __textSearch.__caseSensitive = false;
1485         __textSearch.__pending = 0;
1486         __textSearch.__currentIndex = 1;
1487         __textSearch.__totalCount -1;
1488         __textSearch.__text = L"";
1489 }
1490
1491
1492 _WebImpl::~_WebImpl()
1493 {
1494         RemoveEventListenerCallback();
1495 }
1496
1497 _WebImpl*
1498 _WebImpl::CreateWebImplN(Web* pControl, const Rectangle& bounds)
1499 {
1500         result r = E_SUCCESS;
1501
1502         r = GET_SIZE_INFO(Web).CheckInitialSizeValid(Dimension(bounds.width, bounds.height), _CONTROL_ORIENTATION_PORTRAIT);
1503         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1504
1505         _Web* pCore = _Web::CreateWebN();
1506         SysTryReturn(NID_WEB_CTRL, pCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1507
1508         _WebImpl* pImpl = new (std::nothrow) _WebImpl(pControl, pCore);
1509
1510         r = CheckConstruction(pCore, pImpl);
1511         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
1512
1513         r = pImpl->InitializeBoundsProperties(GET_SIZE_INFO(Web), bounds, pCore->GetOrientation());
1514         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1515
1516         r = pImpl->Construct();
1517         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1518
1519         return pImpl;
1520
1521 CATCH:
1522         delete pImpl;
1523
1524         return null;
1525 }
1526
1527
1528 result
1529 _WebImpl::Construct(void)
1530 {
1531         result r = E_SUCCESS;
1532
1533         r = __mutex.Create();
1534         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1535
1536         r = __textSearch.__searchQueue.Construct();
1537         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1538
1539         __pWebSetting = std::unique_ptr<WebSetting>(new (std::nothrow) WebSetting());
1540         SysTryReturn(NID_WEB_CTRL, __pWebSetting.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1541
1542         r = InitJsBridgeList();
1543         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1544
1545         r = InitWebEvent();
1546         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1547
1548         __pWebCore = dynamic_cast< _Web* >(&(GetCore()));
1549         SysTryReturnResult(NID_WEB_CTRL, __pWebCore, E_SYSTEM, "A system error has been occurred. Failed to get web control");
1550
1551         __pWebCore->SetWebSettingImpl(_WebSettingImpl::GetInstance(__pWebSetting.get()));
1552
1553         return E_SUCCESS;
1554 }
1555
1556
1557 result
1558 _WebImpl::InitializeSetting(void)
1559 {
1560         result r = E_SUCCESS;
1561
1562         r = SetSetting(*__pWebSetting.get());
1563         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
1564
1565         SetCookieEnabled(_WebSettingImpl::GetInstance(__pWebSetting.get())->IsCookieEnabled());
1566         SetPrivateBrowsingEnabled(_WebSettingImpl::GetInstance(__pWebSetting.get())->IsPrivateBrowsingEnabled());
1567         SetZoomLevel(_WebSettingImpl::GetInstance(__pWebSetting.get())->GetZoomLevel());
1568
1569         SetEventListenerCallback();
1570
1571         _Form* pFormCore = GetParentFormCore(dynamic_cast< _Control* >(&this->GetCore()));
1572         SysAssertf(pFormCore != null, "Failed to get FormCore");
1573
1574         SetPreviousOrientation(pFormCore->GetOrientation());
1575
1576         return E_SUCCESS;
1577 }
1578
1579
1580 bool
1581 _WebImpl::IsLayoutable(void) const
1582 {
1583         return true;
1584 }
1585
1586
1587 result
1588 _WebImpl::InitWebEvent(void)
1589 {
1590         __pWebEvent = std::unique_ptr<_WebEvent>(new (std::nothrow) _WebEvent());
1591         SysTryReturnResult(NID_WEB_CTRL, __pWebEvent.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
1592
1593         return __pWebEvent->Construct(*this);
1594 }
1595
1596
1597 _WebEvent*
1598 _WebImpl::GetWebEvent(void) const
1599 {
1600         return __pWebEvent.get();
1601 }
1602
1603
1604 Eina_Hash*
1605 _WebImpl::ConvertToSlpHeaderN(const HttpHeader& header) const
1606 {
1607         Eina_Hash* pHttpHeader = null;
1608
1609         std::unique_ptr<IList> pFieldNameList(header.GetFieldNamesN());
1610         if (pFieldNameList.get())
1611         {
1612                 pHttpHeader = eina_hash_string_small_new(FreeCharArray);
1613                 SysTryReturn(NID_WEB_CTRL, pHttpHeader, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1614                 
1615                 int count = pFieldNameList->GetCount();
1616
1617                 for (int i = 0; i < count; i++)
1618                 {
1619                         String* pFieldName = dynamic_cast< String* >(pFieldNameList->GetAt(i));
1620                         SysTryCatch(NID_WEB_CTRL, pFieldName, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1621
1622                         std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(*pFieldName));
1623                         SysTryCatch(NID_WEB_CTRL, pKey.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1624
1625                         std::unique_ptr<IEnumerator> pFieldValueEnum(header.GetFieldValuesN(*pFieldName));
1626                         SysTryCatch(NID_WEB_CTRL, pFieldValueEnum.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1627                         
1628                         while (pFieldValueEnum->MoveNext() == E_SUCCESS)
1629                         {
1630                                 Eina_Bool ret = false;
1631
1632                                 String* pFieldValue = dynamic_cast< String* >(pFieldValueEnum->GetCurrent());
1633                                 SysTryCatch(NID_WEB_CTRL, pFieldValue, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1634
1635                                 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pFieldValue));
1636                                 SysTryCatch(NID_WEB_CTRL, pValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1637
1638                                 ret = eina_hash_add(pHttpHeader, pKey.get(), pValue.release());
1639                                 SysTryCatch(NID_WEB_CTRL, ret == EINA_TRUE, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1640                         }
1641                 }
1642         }
1643         return pHttpHeader;
1644
1645 CATCH:
1646         eina_hash_free(pHttpHeader);
1647
1648         return null;
1649 }
1650
1651
1652 result
1653 _WebImpl::LoadUrl(const String& url) const
1654 {
1655         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
1656         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1657
1658         ewk_view_url_set(__pWebCore->GetWebNativeNode(), pUrl.get());
1659
1660         return E_SUCCESS;
1661 }
1662
1663
1664 result 
1665 _WebImpl::LoadUrl(const String& url, const HttpHeader& header)
1666 {
1667         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
1668         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1669         
1670         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
1671
1672         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_GET, pHttpHeader, null);
1673
1674         eina_hash_free(pHttpHeader);
1675
1676         return E_SUCCESS;
1677 }
1678
1679
1680 result
1681 _WebImpl::LoadUrlWithPostRequest(const String& url, const HttpHeader& header, const ByteBuffer& body) const
1682 {
1683
1684         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(url));
1685         SysTryReturn(NID_WEB_CTRL, pUrl.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1686
1687         Eina_Hash* pHttpHeader = ConvertToSlpHeaderN(header);
1688
1689         ewk_view_url_request_set(__pWebCore->GetWebNativeNode(), pUrl.get(), EWK_HTTP_METHOD_POST, pHttpHeader, reinterpret_cast< const char* >(body.GetPointer()));
1690
1691         eina_hash_free(pHttpHeader);
1692
1693         return E_SUCCESS;
1694 }
1695
1696
1697 result
1698 _WebImpl::LoadData(const String& baseUrl, const ByteBuffer& content, const String& mime, const String& encoding) const
1699 {
1700         std::unique_ptr<char[]> pUrl(_StringConverter::CopyToCharArrayN(baseUrl));
1701         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
1702         std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(encoding));
1703         SysTryReturn(NID_WEB_CTRL, pUrl.get() && pMime.get() && pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1704
1705         ewk_view_contents_set(__pWebCore->GetWebNativeNode(), reinterpret_cast< const char* >(content.GetPointer()), content.GetLimit(), pMime.get(), pEncoding.get(), pUrl.get());
1706
1707         return E_SUCCESS;
1708 }
1709
1710
1711 void
1712 _WebImpl::Pause(void)
1713 {
1714         ewk_view_suspend(__pWebCore->GetWebNativeNode());
1715 }
1716
1717
1718 void
1719 _WebImpl::Resume(void)
1720 {
1721         ewk_view_resume(__pWebCore->GetWebNativeNode());
1722 }
1723
1724
1725 void
1726 _WebImpl::SetSelectBox(_SelectBox* pSelectBox)
1727 {
1728         __pSelectBox = std::unique_ptr<_SelectBox>(pSelectBox);
1729 }
1730
1731
1732 _SelectBox*
1733 _WebImpl::GetSelectBox(void)
1734 {
1735         return __pSelectBox.get();
1736 }
1737
1738
1739 void
1740 _WebImpl::DeleteSelectBox(void)
1741 {
1742         _SelectBox* pSelectBox = __pSelectBox.release();
1743         delete pSelectBox;
1744 }
1745
1746
1747 _InputPickerPopup*
1748 _WebImpl::GetDatepicker(void)
1749 {
1750         _InputPickerPopup* pInputPicker =null;
1751         if (__pDatePicker)
1752         {
1753                 pInputPicker =  __pDatePicker.get();
1754         }
1755         return pInputPicker;
1756 }
1757
1758
1759 _InputPickerPopup*
1760 _WebImpl::GetColorpicker(void)
1761 {
1762         _InputPickerPopup* pInputPicker =null;
1763         if (__pColorPicker)
1764         {
1765                 pInputPicker =  __pColorPicker.get();
1766         }
1767         return pInputPicker;
1768 }
1769
1770
1771 bool
1772 _WebImpl::CanGoBack(void) const
1773 {
1774         return static_cast< bool >(ewk_view_back_possible(__pWebCore->GetWebNativeNode()));
1775 }
1776
1777
1778 bool
1779 _WebImpl::CanGoForward(void) const
1780 {
1781         return static_cast< bool >(ewk_view_forward_possible(__pWebCore->GetWebNativeNode()));
1782 }
1783
1784
1785 void
1786 _WebImpl::GoBack(void) const
1787 {
1788         ewk_view_back(__pWebCore->GetWebNativeNode());
1789 }
1790
1791
1792 void
1793 _WebImpl::GoForward(void) const
1794 {
1795         ewk_view_forward(__pWebCore->GetWebNativeNode());
1796 }
1797
1798
1799 Tizen::Base::String
1800 _WebImpl::GetUrl(void) const
1801 {
1802         return ewk_view_url_get(__pWebCore->GetWebNativeNode());
1803 }
1804
1805
1806 Tizen::Base::String
1807 _WebImpl::GetTitle(void) const
1808 {
1809         return ewk_view_title_get(__pWebCore->GetWebNativeNode());
1810 }
1811
1812
1813 void
1814 _WebImpl::StopLoading(void) const
1815 {
1816         ewk_view_stop(__pWebCore->GetWebNativeNode());
1817 }
1818
1819
1820 void
1821 _WebImpl::Reload(void) const
1822 {
1823         ewk_view_reload_bypass_cache(__pWebCore->GetWebNativeNode());
1824 }
1825
1826
1827 String*
1828 _WebImpl::EvaluateJavascriptN(const String& scriptCode) const
1829 {
1830         if (scriptCode.GetLength())
1831         {
1832                 std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
1833                 SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1834
1835                 _WebPresenter presenter;
1836                 presenter.InitAsyncProcess();
1837
1838                 ewk_view_script_execute(__pWebCore->GetWebNativeNode(), pScript.get(), OnScriptExecuted, &presenter);
1839
1840                 Tizen::Base::String* pResult = new (std::nothrow) Tizen::Base::String(L"");
1841                 SysTryReturn(NID_WEB_CTRL, pResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1842                 presenter.WaitAsyncProcess(*pResult);
1843
1844                 return pResult;
1845         }
1846
1847         return null;
1848 }
1849
1850
1851 result
1852 _WebImpl::SetZoomLevel(float level)
1853 {
1854         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);
1855
1856         ewk_view_scale_set(__pWebCore->GetWebNativeNode(), static_cast< double >(level), 0, 0);
1857
1858         return E_SUCCESS;
1859 }
1860
1861
1862 float
1863 _WebImpl::GetZoomLevel(void) const
1864 {
1865         return static_cast< float >(ewk_view_scale_get(__pWebCore->GetWebNativeNode()));
1866 }
1867
1868
1869 const PageNavigationList*
1870 _WebImpl::GetBackForwardListN(void) const
1871 {
1872         result r = E_SUCCESS;
1873
1874         _PageNavigationListImpl* pNavigationListImpl = null;
1875         _HistoryItemImpl* pHistoryItemImpl = null;
1876
1877         std::unique_ptr<PageNavigationList> pNavigationList;
1878         std::unique_ptr<ArrayList, AllElementsDeleter> pHistoryList;
1879
1880         int backCount = 0;
1881         int forwardCount = 0;
1882
1883         String url(L"");
1884         String title(L"");
1885
1886         Ewk_History* pEwkHistoryList = ewk_view_history_get(__pWebCore->GetWebNativeNode());
1887         SysTryReturn(NID_WEB_CTRL, pEwkHistoryList, null, E_SYSTEM, "[%s] A system error has been occurred. Failed to get full history.", GetErrorMessage(E_SYSTEM));
1888
1889         Ewk_History_Item* pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, 0);
1890         SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_DATA_NOT_FOUND, "[%s] There is no history.", GetErrorMessage(E_DATA_NOT_FOUND));
1891
1892         pNavigationList = std::unique_ptr<PageNavigationList>(new (std::nothrow) PageNavigationList());
1893         SysTryCatch(NID_WEB_CTRL, pNavigationList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1894
1895         pNavigationListImpl = _PageNavigationListImpl::GetInstance(pNavigationList.get());
1896         SysTryCatch(NID_WEB_CTRL, pNavigationListImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1897
1898         pHistoryList = std::unique_ptr<ArrayList, AllElementsDeleter>(new (std::nothrow) ArrayList());
1899         SysTryCatch(NID_WEB_CTRL, pHistoryList.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1900
1901         r = pHistoryList->Construct();
1902         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1903
1904         backCount = ewk_history_back_list_length_get(pEwkHistoryList);
1905         forwardCount = ewk_history_forward_list_length_get(pEwkHistoryList);
1906         SysLog(NID_WEB_CTRL, "The current value of backCount is %d, forwardCount is %d", backCount, forwardCount);
1907
1908         for (int i = -backCount; i < forwardCount + 1; i++)
1909         {
1910                 std::unique_ptr<HistoryItem> pHistoryItem(new (std::nothrow) HistoryItem());
1911                 SysTryCatch(NID_WEB_CTRL, pHistoryItem.get(), , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1912
1913                 pHistoryItemImpl = _HistoryItemImpl::GetInstance(pHistoryItem.get());
1914                 SysTryCatch(NID_WEB_CTRL, pHistoryItemImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1915
1916                 pEwkItem = ewk_history_nth_item_get(pEwkHistoryList, i);
1917                 SysTryCatch(NID_WEB_CTRL, pEwkItem, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
1918
1919                 url = ewk_history_item_uri_get(pEwkItem);
1920                 title = ewk_history_item_title_get(pEwkItem);
1921                 SysLog(NID_WEB_CTRL, "The current value of url is %s, title is %s", url.GetPointer(), title.GetPointer());
1922
1923                 pHistoryItemImpl->SetHistoryItem(url, title);
1924
1925                 r = pHistoryList->Add(*pHistoryItem.get());
1926                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1927                 pHistoryItem.release();
1928         }
1929
1930         pNavigationListImpl->SetPageNavigationList(pHistoryList.release(), backCount);
1931
1932         ewk_history_free(pEwkHistoryList);
1933
1934         return pNavigationList.release();
1935
1936 CATCH:
1937         ewk_history_free(pEwkHistoryList);
1938
1939         return null;
1940 }
1941
1942
1943 result 
1944 _WebImpl::AddCustomHeader(const HttpHeader& header)
1945 {
1946         std::unique_ptr<IList> pFieldNameList(header.GetFieldNamesN());
1947         if (pFieldNameList.get())
1948         {
1949                 int count = pFieldNameList->GetCount();
1950                 for (int i = 0; i < count; i++)
1951                 {
1952                         String* pFieldName = dynamic_cast< String* >(pFieldNameList->GetAt(i));
1953                         SysTryReturn(NID_WEB_CTRL, pFieldName, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1954
1955                         std::unique_ptr<char[]> pKey(_StringConverter::CopyToCharArrayN(*pFieldName));
1956                         SysTryReturn(NID_WEB_CTRL, pKey.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1957
1958                         std::unique_ptr<IEnumerator> pFieldValueEnum(header.GetFieldValuesN(*pFieldName));
1959                         SysTryReturn(NID_WEB_CTRL, pFieldValueEnum.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1960                         
1961                         while (pFieldValueEnum->MoveNext() == E_SUCCESS)
1962                         {
1963                                 String* pFieldValue = dynamic_cast< String* >(pFieldValueEnum->GetCurrent());
1964                                 SysTryReturn(NID_WEB_CTRL, pFieldValue, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1965
1966                                 std::unique_ptr<char[]> pValue(_StringConverter::CopyToCharArrayN(*pFieldValue));
1967                                 SysTryReturn(NID_WEB_CTRL, pValue.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1968
1969                                 ewk_view_custom_header_add(__pWebCore->GetWebNativeNode(), pKey.get(), pValue.get());
1970                         }
1971                 }
1972         }
1973         return E_SUCCESS;
1974 }
1975
1976
1977 void
1978 _WebImpl::RemoveAllCustomHeaders(void)
1979 {
1980 }
1981
1982
1983 bool
1984 _WebImpl::SearchText(const String& text, bool searchForward)
1985 {
1986         result r = E_SUCCESS;
1987
1988         Ewk_Find_Options condition = static_cast< Ewk_Find_Options >(EWK_FIND_OPTIONS_SHOW_HIGHLIGHT | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
1989
1990         if (!searchForward)
1991         {
1992             condition = static_cast < Ewk_Find_Options >(condition | EWK_FIND_OPTIONS_BACKWARDS);
1993         }
1994
1995         _WebPresenter presenter;
1996         presenter.InitAsyncProcess();
1997
1998         r = SynchronizeSearch(SEARCH_SYNC, __pWebCore->GetWebNativeNode(), condition, text, searchForward, false, &presenter);
1999         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2000
2001         int result = 0;
2002         presenter.WaitAsyncProcess(result);
2003
2004         return static_cast < bool >(result);
2005 }
2006
2007
2008 result
2009 _WebImpl::SearchTextAllAsync(const Tizen::Base::String& text, bool caseSensitive)
2010 {
2011         result r = E_SUCCESS;
2012
2013         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2014
2015         if (!caseSensitive)
2016         {
2017             condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2018         }
2019
2020         r = SynchronizeSearch(SEARCH_ALL_ASYNC, __pWebCore->GetWebNativeNode(), condition, text, true, caseSensitive);
2021         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2022
2023         return E_SUCCESS;
2024 }
2025
2026
2027 result
2028 _WebImpl::SearchNextAsync(bool searchForward)
2029 {
2030         SysTryReturnResult(NID_WEB_CTRL, __textSearch.__searchAll && __textSearch.__totalCount > -1, E_INVALID_OPERATION, "The SearchTextAllAsync() method is not called or completed.");
2031         SysTryReturnResult(NID_WEB_CTRL, (searchForward && __textSearch.__currentIndex < __textSearch.__totalCount) || (!searchForward && __textSearch.__currentIndex > 1)
2032                 , E_OBJ_NOT_FOUND,  "The Next instance is not available.");
2033
2034         result r = E_SUCCESS;
2035
2036         Ewk_Find_Options condition = EWK_FIND_OPTIONS_SHOW_HIGHLIGHT;
2037
2038         if (__textSearch.__caseSensitive)
2039         {
2040                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_CASE_INSENSITIVE);
2041         }
2042
2043         if (!searchForward)
2044         {
2045                 condition = static_cast <Ewk_Find_Options>(condition | EWK_FIND_OPTIONS_BACKWARDS);
2046         }
2047
2048         r = SynchronizeSearch(SEARCH_NEXT_ASYNC, __pWebCore->GetWebNativeNode(), condition, __textSearch.__text, searchForward);
2049         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2050
2051         return E_SUCCESS;
2052 }
2053
2054
2055 result
2056 _WebImpl::SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Options condition, const Tizen::Base::String& text, bool searchForward, bool caseSensitive,  _WebPresenter* pWebPresenter)
2057 {
2058         MutexGuard lock(__mutex);
2059
2060         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(text));
2061         SysTryReturn(NID_WEB_CTRL, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2062
2063         switch (type)
2064         {
2065         case SEARCH_SYNC:
2066                 if (__textSearch.__searchAll)
2067                 {
2068                         DisableAsyncSearch();
2069
2070                         __textSearch.__searchQueue.Enqueue(this);
2071                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2072
2073                         ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2074                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2075                 }
2076                 else
2077                 {
2078                         __textSearch.__searchQueue.Enqueue(pWebPresenter);
2079
2080                         ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2081                 }
2082                 break;
2083
2084         case SEARCH_ALL_ASYNC:
2085                 __textSearch.__searchAll = true;
2086                 __textSearch.__text = text;
2087                 __textSearch.__searchForward = true;
2088                 __textSearch.__caseSensitive = caseSensitive;
2089                 __textSearch.__totalCount = -1;
2090                 __textSearch.__currentIndex = 1;
2091
2092                 __textSearch.__searchQueue.Enqueue(this);
2093                 __textSearch.__searchQueue.Enqueue(this);
2094
2095                 ewk_view_text_find(pView, "", condition, MAX_TEXT_MATCH);
2096                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2097                 break;
2098
2099         case SEARCH_NEXT_ASYNC:
2100                 __textSearch.__searchForward = searchForward;
2101
2102                 CalculateAsyncSearchOrdinal();
2103
2104                 __textSearch.__searchQueue.Enqueue(this);
2105
2106                 ewk_view_text_find(pView, pText.get(), condition, MAX_TEXT_MATCH);
2107                 break;
2108
2109         default:
2110                 SysAssert(false);
2111         }
2112
2113         return E_SUCCESS;
2114 }
2115
2116
2117 void
2118 _WebImpl::SetAsyncSearchResult(int totalCount)
2119 {
2120         __textSearch.__totalCount = totalCount;
2121 }
2122
2123
2124 _WebPresenter*
2125 _WebImpl::GetSearchPresenter(void)
2126 {
2127         MutexGuard lock(__mutex);
2128
2129         return dynamic_cast< _WebPresenter* >(__textSearch.__searchQueue.Dequeue());
2130 }
2131
2132
2133  int
2134  _WebImpl::GetPendingAsyncSearchCount(void) const
2135 {
2136         return __textSearch.__searchQueue.GetCount();
2137 }
2138
2139
2140 void
2141 _WebImpl::CalculateAsyncSearchOrdinal(void)
2142 {
2143         if (__textSearch.__searchForward)
2144         {
2145                 __textSearch.__currentIndex++;
2146         }
2147         else
2148         {
2149                 __textSearch.__currentIndex--;
2150         }
2151 }
2152
2153
2154  int
2155  _WebImpl::GetAsyncSearchOrdinal(void) const
2156 {
2157         return __textSearch.__currentIndex;
2158 }
2159
2160
2161  void
2162  _WebImpl::DisableAsyncSearch(void)
2163 {
2164         __textSearch.__searchAll = false;
2165 }
2166
2167
2168 result
2169 _WebImpl::SetSetting(const WebSetting& setting)
2170 {
2171         if (__pWebCore->GetWebNativeNode())
2172         {
2173                 Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2174                 Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2175                 SysAssertf(pContext && pSettings, "Failed to get webkit instance.");
2176
2177                 std::unique_ptr<char[]> pEncoding(_StringConverter::CopyToCharArrayN(setting.GetDefaultTextEncoding()));
2178                 SysTryReturn(NID_WEB_CTRL, pEncoding.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2179
2180                 ewk_settings_default_encoding_set(pSettings, pEncoding.get());
2181
2182                 switch (setting.GetCacheControl())
2183                 {
2184                 case WEB_CACHE_VALIDATED:
2185                         ewk_context_cache_disabled_set(pContext, EINA_FALSE);
2186                         break;
2187
2188                 case WEB_CACHE_IGNORE:
2189                         ewk_context_cache_disabled_set(pContext, EINA_TRUE);
2190                         break;
2191
2192                 default:
2193                         SysAssert(false);
2194                 }
2195
2196                 if (setting.GetInputStyle() == INPUT_STYLE_OVERLAY)
2197                 {
2198                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_TRUE);
2199                 }
2200                 else
2201                 {
2202                         ewk_settings_default_keypad_enabled_set(pSettings, EINA_FALSE);
2203                 }
2204
2205                 ewk_settings_font_default_size_set(pSettings, static_cast< Eina_Bool >(setting.GetFontSize()));
2206
2207                 ewk_settings_javascript_enabled_set(pSettings, static_cast< Eina_Bool >(setting.IsJavascriptEnabled()));
2208
2209                 ewk_settings_loads_images_automatically_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoImageLoadEnabled()));
2210
2211                 std::unique_ptr<char[]> pAgent(_StringConverter::CopyToCharArrayN(setting.GetUserAgent()));
2212                 SysTryReturn(NID_WEB_CTRL, pAgent.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2213
2214                 ewk_view_user_agent_set(__pWebCore->GetWebNativeNode(), pAgent.get());
2215
2216                 ewk_settings_auto_fitting_set(pSettings, static_cast< Eina_Bool >(setting.IsAutoFittingEnabled()));
2217
2218                 ewk_settings_scripts_window_open_set(pSettings,  static_cast< Eina_Bool >(setting.IsJavaScriptPopupEnabled()));
2219
2220                 ewk_settings_show_ime_on_autofocus_set(pSettings, EINA_FALSE);
2221         }
2222
2223         __pWebSetting->SetDefaultTextEncoding(setting.GetDefaultTextEncoding());
2224         __pWebSetting->SetCacheControl(setting.GetCacheControl());
2225         __pWebSetting->SetFontSize(setting.GetFontSize());
2226         __pWebSetting->SetJavascriptEnabled(setting.IsJavascriptEnabled());
2227         __pWebSetting->SetAutoImageLoadEnabled(setting.IsAutoImageLoadEnabled());
2228         __pWebSetting->SetInputStyle(setting.GetInputStyle());
2229         __pWebSetting->SetUserAgent(setting.GetUserAgent());
2230         __pWebSetting->SetAutoFittingEnabled(setting.IsAutoFittingEnabled());
2231         __pWebSetting->SetJavaScriptPopupEnabled(setting.IsJavaScriptPopupEnabled());
2232         __pWebSetting->SetGeolocationEnabled(setting.IsGeolocationEnabled());
2233
2234         return E_SUCCESS;
2235 }
2236
2237
2238 WebSetting
2239 _WebImpl::GetSetting(void) const
2240 {
2241         return *__pWebSetting;
2242 }
2243
2244
2245 const HitElementResult*
2246 _WebImpl::GetElementByPointN(const Point& point) const
2247 {
2248         result r = E_SUCCESS;
2249
2250         _HitElementResultImpl* pHitElementResultImpl = null;
2251
2252         std::unique_ptr<HitElementResult> pHitElementResult;
2253         std::unique_ptr<Bitmap> pImage;
2254         std::unique_ptr<HashMap, AllElementsDeleter> pAttributeMap;
2255
2256         Point absPoint(__pWebCore->GetAbsoluteCoordinate(point));
2257
2258         Ewk_Hit_Test* pEwkHitTest = ewk_view_hit_test_new(__pWebCore->GetWebNativeNode(), absPoint.x, absPoint.y, EWK_HIT_TEST_MODE_ALL);
2259         SysTryReturn(NID_WEB_CTRL, pEwkHitTest, null, E_SYSTEM, "[%s] Failed to get hit test.", GetErrorMessage(E_SYSTEM));
2260
2261         Eina_Hash* pAttrHash = ewk_hit_test_attribute_hash_get(pEwkHitTest);
2262         Ewk_Hit_Test_Result_Context context = ewk_hit_test_result_context_get(pEwkHitTest);
2263         String url(ewk_hit_test_link_uri_get(pEwkHitTest));
2264         String tagName(ewk_hit_test_tag_name_get(pEwkHitTest));
2265         String nodeValue(ewk_hit_test_node_value_get(pEwkHitTest));
2266
2267         SysLog(NID_WEB_CTRL, "The current value of url is %ls, tag is %ls, value is %ls", url.GetPointer(), tagName.GetPointer(), nodeValue.GetPointer());
2268
2269         pHitElementResult = std::unique_ptr<HitElementResult>(new (std::nothrow) HitElementResult());
2270         SysTryCatch(NID_WEB_CTRL, pHitElementResult.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2271
2272         pHitElementResultImpl = _HitElementResultImpl::GetInstance(pHitElementResult.get());
2273         SysTryCatch(NID_WEB_CTRL, pHitElementResultImpl, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2274
2275         if (context & EWK_HIT_TEST_RESULT_CONTEXT_IMAGE)
2276         {
2277                 ByteBuffer buf;
2278                 Image image;
2279                 ImageFormat format;
2280
2281                 int imageLength = ewk_hit_test_image_buffer_length_get(pEwkHitTest);
2282                 void* pImageBuffer = ewk_hit_test_image_buffer_get(pEwkHitTest);
2283                 const char* pExtension = ewk_hit_test_image_file_name_extension_get(pEwkHitTest);
2284                 SysLog(NID_WEB_CTRL, "The current value of imageBuffer is %u, bufferLength is %d, extension is %s", pImageBuffer, imageLength, pExtension);
2285
2286                 r = buf.Construct(imageLength);
2287                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2288
2289                 r = buf.SetArray(reinterpret_cast< byte* >(pImageBuffer), 0, imageLength);
2290                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2291
2292                 buf.Rewind();
2293
2294 //              ToDo : webkit doesn't support types such as IMG_FORMAT_WBMP and IMG_FORMAT_TIFF
2295 //              webkit support types such as ico and vp8 additionally
2296                 if (strcmp(pExtension, "gif") == 0)
2297                 {
2298                         format = IMG_FORMAT_GIF;
2299                 }
2300                 else if (strcmp(pExtension, "jpg") == 0)
2301                 {
2302                         format = IMG_FORMAT_JPG;
2303                 }
2304                 else if (strcmp(pExtension, "png") == 0)
2305                 {
2306                         format = IMG_FORMAT_PNG;
2307                 }
2308                 else if (strcmp(pExtension, "bmp") == 0)
2309                 {
2310                         format = IMG_FORMAT_BMP;
2311                 }
2312                 else
2313                 {
2314                         SysLogException(NID_WEB_CTRL, E_UNSUPPORTED_FORMAT, "[%s] The %s format is not supported", GetErrorMessage(E_UNSUPPORTED_FORMAT), pExtension);
2315                         goto CATCH;
2316                 }
2317
2318                 r = image.Construct();
2319                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2320
2321                 pImage = std::unique_ptr<Bitmap>(image.DecodeN(buf, format, BITMAP_PIXEL_FORMAT_RGB565));
2322                 SysTryCatch(NID_WEB_CTRL, pImage.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2323         }
2324
2325         if (pAttrHash)
2326         {
2327                 pAttributeMap = std::unique_ptr<HashMap, AllElementsDeleter>(new (std::nothrow) HashMap());
2328                 SysTryCatch(NID_WEB_CTRL, pAttributeMap.get(), , E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2329
2330                 r = pAttributeMap->Construct(eina_hash_population(pAttrHash));
2331                 SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2332
2333                 eina_hash_foreach(pAttrHash, AddHttpAttributeData, pAttributeMap.get());
2334                 SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2335         }
2336
2337         pHitElementResultImpl->SetHitElementResult(pAttributeMap.release(), pImage.release(), tagName, nodeValue, url);
2338
2339         ewk_hit_test_free(pEwkHitTest);
2340
2341         return pHitElementResult.release();
2342
2343 CATCH:
2344         ewk_hit_test_free(pEwkHitTest);
2345
2346         return null;
2347 }
2348
2349
2350 bool
2351 _WebImpl::IsLoading(void) const
2352 {
2353         double percent = ewk_view_load_progress_get(__pWebCore->GetWebNativeNode());
2354
2355         if (Double::Compare(percent, 0.0) > 0 && Double::Compare(percent, 1.0) < 0)
2356         {
2357                 return true;
2358         }
2359         else
2360         {
2361                 return false;
2362         }
2363 }
2364
2365
2366 String
2367 _WebImpl::GetTextFromBlock(void) const
2368 {
2369         return ewk_view_text_selection_text_get(__pWebCore->GetWebNativeNode());
2370 }
2371
2372
2373 bool
2374 _WebImpl::IsPrivateBrowsingEnabled(void) const
2375 {
2376         if (__pWebCore->GetWebNativeNode() == null)
2377         {
2378                 return _WebSettingImpl::GetInstance(__pWebSetting.get())->IsPrivateBrowsingEnabled();
2379         }
2380
2381         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2382         SysAssertf(pSettings, "Failed to get webkit instance.");
2383
2384         return static_cast< bool >(ewk_settings_private_browsing_enabled_get(pSettings));
2385 }
2386
2387
2388 result
2389 _WebImpl::SetPrivateBrowsingEnabled(bool enable)
2390 {
2391         if (__pWebCore->GetWebNativeNode() == null)
2392         {
2393                 _WebSettingImpl::GetInstance(__pWebSetting.get())->SetPrivateBrowsingEnabled(enable);
2394                 return E_SUCCESS;
2395         }
2396
2397         Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
2398         SysAssertf(pSettings, "Failed to get webkit instance.");
2399
2400         ewk_settings_private_browsing_enabled_set(pSettings, static_cast< Eina_Bool >(enable));
2401
2402         return E_SUCCESS;
2403 }
2404
2405
2406 void
2407 _WebImpl::ClearCache(void)
2408 {
2409         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2410         SysAssertf(pContext, "Failed to get webkit instance.");
2411
2412         ewk_context_cache_clear(pContext);
2413 }
2414
2415
2416 void
2417 _WebImpl::ClearCookie(void)
2418 {
2419         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2420         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
2421         SysAssertf(pCookieManager, "Failed to get webkit instance.");
2422
2423         ewk_cookie_manager_cookies_clear(pCookieManager);
2424 }
2425
2426
2427 bool
2428 _WebImpl::IsCookieEnabled(void) const
2429 {
2430         if (__pWebCore->GetWebNativeNode() == null)
2431         {
2432                 return _WebSettingImpl::GetInstance(__pWebSetting.get())->IsCookieEnabled();
2433         }
2434
2435         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2436         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
2437         SysAssertf(pCookieManager, "Failed to get webkit instance.");
2438
2439         _WebPresenter presenter;
2440         presenter.InitAsyncProcess();
2441
2442         ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, &presenter);
2443
2444         bool result = false;
2445         presenter.WaitAsyncProcess(result);
2446
2447         return result;
2448 }
2449
2450
2451 void
2452 _WebImpl::SetCookieEnabled(bool enable)
2453 {
2454         if (__pWebCore->GetWebNativeNode() == null)
2455         {
2456                 _WebSettingImpl::GetInstance(__pWebSetting.get())->SetCookiEnabled(enable);
2457
2458                 return;
2459         }
2460
2461         Ewk_Context* pContext = ewk_view_context_get(__pWebCore->GetWebNativeNode());
2462         Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
2463         SysAssertf(pCookieManager, "Failed to get webkit instance.");
2464
2465         if (enable)
2466         {
2467                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_NO_THIRD_PARTY);
2468         }
2469         else
2470         {
2471                 ewk_cookie_manager_accept_policy_set(pCookieManager, EWK_COOKIE_ACCEPT_POLICY_NEVER);
2472                 ewk_cookie_manager_cookies_clear(pCookieManager);
2473         }
2474 }
2475
2476
2477 result 
2478 _WebImpl::SavePageAsPdf(const String& filePath, const Dimension* pSize) const
2479 {
2480         result r = E_SUCCESS;
2481
2482         std::unique_ptr<char[]> pFilePath(_StringConverter::CopyToCharArrayN(filePath));
2483         SysTryReturn(NID_WEB_CTRL, pFilePath.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2484
2485         String dirPath;
2486         String fileExtension = File::GetFileExtension(filePath);
2487         int pathLength = filePath.GetLength();
2488         int index = 0;
2489
2490         SysTryReturnResult(NID_WEB_CTRL, fileExtension.Equals("pdf", false), E_INVALID_ARG, "Invalid argument(s) is used. File extension is not pdf.");
2491
2492         r = filePath.LastIndexOf(L"/", pathLength - 1, index);
2493         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
2494         r = filePath.SubString(0, index + 1, dirPath);
2495         SysTryReturnResult(NID_WEB_CTRL, r == E_SUCCESS, E_INVALID_ARG, "Invalid argument(s) is used. Directory path is invalid.");
2496
2497         std::unique_ptr<char[]> pDirPath(_StringConverter::CopyToCharArrayN(dirPath));
2498         SysTryReturnResult(NID_WEB_CTRL, access(pDirPath.get(), W_OK) == 0, E_INACCESSIBLE_PATH, "Directory permission is read-only.");
2499
2500         if (pSize)
2501         {
2502                 SysTryReturnResult(NID_WEB_CTRL, pSize->width > 0 && pSize->height > 0, E_INVALID_ARG, "Invalid argument(s) is used. Size of pdf file is invalid.");
2503
2504                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), pSize->width, pSize->height, pFilePath.get());
2505         }
2506         else
2507         {
2508                 Evas_Coord contentsWidth;
2509                 Evas_Coord contentsHeight;
2510
2511                 ewk_view_contents_size_get(__pWebCore->GetWebNativeNode(), &contentsWidth, &contentsHeight);
2512                 ewk_view_contents_pdf_get(__pWebCore->GetWebNativeNode(), contentsWidth, contentsHeight, pFilePath.get());
2513         }
2514
2515         return E_SUCCESS;
2516 }
2517
2518
2519 bool
2520 _WebImpl::IsMimeSupported(const String& mime) const
2521 {
2522         std::unique_ptr<char[]> pMime(_StringConverter::CopyToCharArrayN(mime));
2523         SysTryReturn(NID_WEB_CTRL, pMime.get(), false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2524
2525         return static_cast< bool >(ewk_frame_can_show_mime_type(ewk_view_main_frame_get(__pWebCore->GetWebNativeNode()), pMime.get()));
2526 }
2527
2528
2529 void
2530 _WebImpl::SetLoadingListener(ILoadingListener* pLoadingListener)
2531 {
2532         __pUserLoadingListener = const_cast< ILoadingListener* >(pLoadingListener);
2533 }
2534
2535
2536 void
2537 _WebImpl::SetWebUiEventListener(IWebUiEventListener* pUiEventListener)
2538 {
2539         __pUserUiListener = pUiEventListener;
2540 }
2541
2542
2543 void
2544 _WebImpl::SetWebKeypadEventListener(IWebKeypadEventListener* pKeypadEventListener)
2545 {
2546         __pUserKeypadEventListener = pKeypadEventListener;
2547 }
2548
2549
2550 void
2551 _WebImpl::SetDownloadListener(IWebDownloadListener* pDownLoadListener)
2552 {
2553         if (__pWebDownloadHandler.get() == null)
2554         {
2555                 __pWebDownloadHandler = std::unique_ptr<_WebDataHandler>(new (std::nothrow) _WebDataHandler());
2556                 SysTryReturnVoidResult(NID_WEB_CTRL, __pWebDownloadHandler.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2557         }
2558
2559         __pWebDownloadHandler->SetDownloadListener(pDownLoadListener);
2560         __pWebDownloadHandler->SetWebEvent(__pWebEvent.get());
2561 }
2562
2563
2564 void
2565 _WebImpl::SetTextSearchListener(ITextSearchListener* pTextSearchListener)
2566 {
2567         __pTextSearchListener = pTextSearchListener;
2568 }
2569
2570
2571 result
2572 _WebImpl::SetScrollEnabled(bool enable)
2573 {
2574         _WebSettingImpl::GetInstance(__pWebSetting.get())->SetScrollEnabled(enable);
2575
2576         return E_SUCCESS;
2577 }
2578
2579
2580 bool
2581 _WebImpl::IsScrollEnabled(void) const
2582 {
2583         return _WebSettingImpl::GetInstance(__pWebSetting.get())->IsScrollEnabled();
2584 }
2585
2586
2587 result
2588 _WebImpl::InitJsBridgeList(void)
2589 {
2590         result r = E_SUCCESS;
2591
2592         __pJsProvider = std::unique_ptr<_JsBridgeHashCodeProvider>(new (std::nothrow) _JsBridgeHashCodeProvider());
2593         SysTryReturnResult(NID_WEB_CTRL, __pJsProvider.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
2594
2595         __pJsComparer = std::unique_ptr<_JsBridgeComparer>(new (std::nothrow) _JsBridgeComparer());
2596         SysTryReturnResult(NID_WEB_CTRL, __pJsComparer.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
2597
2598         std::unique_ptr<HashMapT< String, IJavaScriptBridge* > > pJsBridgeList(new (std::nothrow) HashMapT< String, IJavaScriptBridge* >);
2599         SysTryReturnResult(NID_WEB_CTRL, pJsBridgeList.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
2600
2601         r = pJsBridgeList->Construct(0, 0, *__pJsProvider.get(), *__pJsComparer.get());
2602         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2603
2604         __pJsBridgeList = std::move(pJsBridgeList);
2605
2606         return r;
2607 }
2608
2609
2610 result
2611 _WebImpl::AddJavaScriptBridge(const IJavaScriptBridge& jsBridge)
2612 {
2613         result r = E_SUCCESS;
2614
2615         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
2616         String key(pJsBridge->GetName());
2617
2618         r = __pJsBridgeList->Add(key, pJsBridge);
2619         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2620
2621         return r;
2622 }
2623
2624
2625 result
2626 _WebImpl::RemoveJavaScriptBridge(const IJavaScriptBridge& jsBridge)
2627 {
2628         result r = E_SUCCESS;
2629
2630         IJavaScriptBridge* pJsBridge = const_cast< IJavaScriptBridge* >(&jsBridge);
2631         String key(pJsBridge->GetName());
2632
2633         r = __pJsBridgeList->Remove(key);
2634         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
2635
2636         return r;
2637 }
2638
2639
2640 IJavaScriptBridge*
2641 _WebImpl::FindJsInterface(const IJsonValue* pValue) const
2642 {
2643         result r = E_SUCCESS;
2644
2645         IJsonValue* pJsonValue = null;
2646         IJavaScriptBridge* pJsBridge = null;
2647
2648         String key(L"name");
2649
2650         const JsonObject* pJsonObject = dynamic_cast< const JsonObject* >(pValue);
2651         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));
2652
2653         r = pJsonObject->GetValue(&key, pJsonValue);
2654         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS && pJsonValue, null, r, "[%s] Propagating.", GetErrorMessage(r));
2655
2656         JsonString* pBridgeName = dynamic_cast< JsonString* >(pJsonValue);
2657         SysTryReturn(NID_WEB_CTRL, pBridgeName, null, E_INVALID_ARG, "[%s] Invalid argument(s) is used. name key is missing." , GetErrorMessage(E_INVALID_ARG));
2658
2659         r = __pJsBridgeList->GetValue(static_cast< String >(*pBridgeName), pJsBridge);
2660         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
2661
2662         return pJsBridge;
2663 }
2664
2665
2666 ILoadingListener*
2667 _WebImpl::GetLoadingListener(void) const
2668 {
2669         return __pUserLoadingListener;
2670 }
2671
2672
2673 IWebUiEventListener*
2674 _WebImpl::GetUiEventListener(void) const
2675 {
2676         return __pUserUiListener;
2677 }
2678
2679
2680 IWebKeypadEventListener*
2681 _WebImpl::GetWebKeypadEventListener(void) const
2682 {
2683         return __pUserKeypadEventListener;
2684 }
2685
2686
2687 ITextSearchListener*
2688 _WebImpl::GetTextSearchListener(void) const
2689 {
2690         return __pTextSearchListener;
2691 }
2692
2693
2694 void
2695 _WebImpl::SetEventListenerCallback(void) const
2696 {
2697         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
2698         SysAssertf(pWebNativeNode, "Failed to get Web evas object");
2699
2700         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
2701         SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
2702
2703         Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
2704         SysAssertf(pWinObject, "Failed to get Ui window evas object");
2705
2706         Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
2707         SysAssertf(pSmartData, "Failed to request");
2708
2709         Ewk_View_Smart_Class *pSmart = const_cast<Ewk_View_Smart_Class*>(pSmartData->api);
2710         SysAssertf(pSmart, "Failed to request");
2711
2712         pSmart->popup_menu_show = OnSelectBoxRequested;
2713         pSmart->popup_menu_hide = OnSelectBoxClosed;
2714         pSmart->popup_menu_update = OnSelectBoxUpdateRequested;
2715
2716         pSmart->input_picker_show = OnDatePickerProviderRequested;
2717         pSmart->input_picker_color_request = OnColorPickerProviderRequested;
2718         pSmart->input_picker_color_dismiss = OnColorPickerProviderDismissed;
2719
2720         evas_object_data_set(pWebNativeNode, WEB_CTRL, this);
2721
2722         // add loading event callbacks for ILoadingListener
2723         evas_object_smart_callback_add(pWebNativeNode, "create,window", OnWebWindowCreateRequested, this);
2724         evas_object_smart_callback_add(pWebNativeNode, "close,window", OnWebWindowClosedRequested, this);
2725
2726         evas_object_smart_callback_add(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested, this);
2727         evas_object_smart_callback_add(pWebNativeNode, "load,started", OnLoadingStarted, this);
2728         evas_object_smart_callback_add(pWebNativeNode, "load,finished", OnLoadingCompleted, this);
2729         evas_object_smart_callback_add(pWebNativeNode, "load,progress", OnEstimatedProgress, this);
2730         evas_object_smart_callback_add(pWebNativeNode, "load,progress,finished", OnProgressCompleted, this);
2731         evas_object_smart_callback_add(pWebNativeNode, "load,stop", OnLoadingCanceled, this);
2732         evas_object_smart_callback_add(pWebNativeNode, "load,error", OnLoadingErrorOccurred, this);
2733         evas_object_smart_callback_add(pWebNativeNode, "title,changed", OnPageTitleReceived, this);
2734         evas_object_smart_callback_add(pWebNativeNode, "load,committed", OnLoadingCommitted, this);
2735
2736         evas_object_smart_callback_add(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest, this);
2737
2738         evas_object_smart_callback_add(pWinObject, "focus,in", OnWindowObjectFocusGained, this);
2739
2740         evas_object_smart_callback_add(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged, this);
2741         evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened, this);
2742         evas_object_smart_callback_add(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed, this);
2743
2744         evas_object_smart_callback_add(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested, this);
2745         evas_object_smart_callback_add(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled, this);
2746
2747         evas_object_smart_callback_add(pWebNativeNode, "request,geolocation,permission", OnGeolocationPermissionRequested, this);
2748
2749         ewk_view_javascript_alert_callback_set(pWebNativeNode, OnScriptAlertRequested, const_cast< _WebImpl* >(this));
2750         ewk_view_javascript_prompt_callback_set(pWebNativeNode, OnScriptPromptRequested, const_cast< _WebImpl* >(this));
2751         ewk_view_javascript_confirm_callback_set(pWebNativeNode, OnScriptConfirmRequested, const_cast< _WebImpl* >(this));
2752
2753         evas_object_smart_callback_add(pWebNativeNode, "policy,response,decide", OnWebDataReceived, this);
2754
2755         evas_object_smart_callback_add(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested, this);
2756         evas_object_smart_callback_add(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested, this);
2757
2758         evas_object_smart_callback_add(pWebNativeNode, "text,found", OnTextFound, this);
2759
2760         Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
2761         SysAssertf(pContext, "Failed to get webkit instance.");
2762         ewk_context_did_start_download_callback_set(pContext, OnDidStartDownloadCallback, const_cast< _WebImpl* >(this));
2763         ewk_view_open_panel_callback_set(pWebNativeNode, OnSelectUploadFile, const_cast< _WebImpl* >(this));
2764
2765         evas_object_event_callback_add(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained, this);
2766 }
2767
2768
2769 void
2770 _WebImpl::RemoveEventListenerCallback(void) const
2771 {
2772         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
2773         SysTryReturnVoidResult(NID_WEB_CTRL, pWebNativeNode, E_SYSTEM, "[%s] Failed to get Web evas object.", GetErrorMessage(E_SYSTEM));
2774
2775         _EcoreEvas* pEcoreEvas = GetEcoreEvasMgr()->GetEcoreEvas();
2776         SysAssertf(pEcoreEvas, "Failed to get Ui ecore evas");
2777
2778         Evas_Object* pWinObject = pEcoreEvas->GetWindowObject();
2779         SysAssertf(pWinObject, "Failed to get Ui window evas object");
2780
2781         evas_object_smart_callback_del(pWebNativeNode, "create,window", OnWebWindowCreateRequested);
2782         evas_object_smart_callback_del(pWebNativeNode, "close,window", OnWebWindowClosedRequested);
2783
2784         evas_object_smart_callback_del(pWebNativeNode, "policy,navigation,decide", OnLoadingRequested);
2785         evas_object_smart_callback_del(pWebNativeNode, "load,started", OnLoadingStarted);
2786         evas_object_smart_callback_del(pWebNativeNode, "load,finished", OnLoadingCompleted);
2787         evas_object_smart_callback_del(pWebNativeNode, "load,progress", OnEstimatedProgress);
2788         evas_object_smart_callback_del(pWebNativeNode, "load,progress,finished", OnProgressCompleted);
2789         evas_object_smart_callback_del(pWebNativeNode, "load,stop", OnLoadingCanceled);
2790         evas_object_smart_callback_del(pWebNativeNode, "load,error", OnLoadingErrorOccurred);
2791         evas_object_smart_callback_del(pWebNativeNode, "title,changed", OnPageTitleReceived);
2792
2793         evas_object_smart_callback_del(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest);
2794
2795         evas_object_smart_callback_del(pWinObject, "focus,in", OnWindowObjectFocusGained);
2796
2797         evas_object_smart_callback_del(pWebNativeNode, "inputmethod,changed", OnWebKeypadStateChanged);
2798         evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,opened", OnWebKeypadOpened);
2799         evas_object_smart_callback_del(pWebNativeNode, "editorclient,ime,closed", OnWebKeypadClosed);
2800
2801         evas_object_smart_callback_del(pWebNativeNode, "authentication,challenge", OnHttpAuthenticationRequested);
2802         evas_object_smart_callback_del(pWebNativeNode, "authentication,canceled", OnHttpAuthenticationCanceled);
2803
2804         evas_object_smart_callback_del(pWebNativeNode, "request,geolocation,permission", OnGeolocationPermissionRequested);
2805
2806         ewk_view_javascript_alert_callback_set(null, null, null);
2807         ewk_view_javascript_prompt_callback_set(null, null, null);
2808         ewk_view_javascript_confirm_callback_set(null, null, null);
2809
2810         evas_object_smart_callback_del(pWebNativeNode, "policy,response,decide", OnWebDataReceived);
2811
2812         evas_object_smart_callback_del(pWebNativeNode, "load,nonemptylayout,finished", OnWebPageShowRequested);
2813         evas_object_smart_callback_del(pWebNativeNode, "request,certificate,confirm", OnCertificateRequested);
2814
2815         evas_object_smart_callback_del(pWebNativeNode, "text,found", OnTextFound);
2816
2817         ewk_view_open_panel_callback_set(null, null, null);
2818
2819         evas_object_event_callback_del(pWebNativeNode, EVAS_CALLBACK_FOCUS_IN, OnWebNativeNodeFocusGained);
2820 }
2821
2822
2823 result
2824 _WebImpl::SetBlockSelectionPosition(const Point& startPoint)
2825 {
2826         Evas_Object* pWebNativeNode = __pWebCore->GetWebNativeNode();
2827
2828         Ewk_View_Smart_Data* pSmartData = (Ewk_View_Smart_Data*) evas_object_smart_data_get(pWebNativeNode);
2829         SysAssertf(pSmartData, "Failed to request");
2830
2831         Point absPoint(__pWebCore->GetAbsoluteCoordinate(startPoint));
2832
2833         pSmartData->api->text_selection_down(pSmartData, absPoint.x, absPoint.y);
2834         pSmartData->api->text_selection_up(pSmartData, absPoint.x, absPoint.y);
2835
2836         ewk_view_command_execute(pWebNativeNode, "SelectWord", 0);
2837
2838         SysTryReturnResult(NID_WEB_CTRL, GetTextFromBlock().GetLength() > 0, E_INVALID_ARG, "Failed to set text selection up.");
2839
2840         if (__pUserUiListener)
2841         {
2842                 FireWebPageBlockSelectedEvent();
2843         }
2844
2845         return E_SUCCESS;
2846 }
2847
2848
2849 result
2850 _WebImpl::ReleaseBlock(void)
2851 {
2852         ewk_view_command_execute(__pWebCore->GetWebNativeNode(), "Unselect", 0);
2853
2854         return E_SUCCESS;
2855 }
2856
2857
2858 result
2859 _WebImpl::GetBlockRange(Point& startPoint, Point& endPoint) const
2860 {
2861         Eina_Rectangle leftHandle;
2862         Eina_Rectangle rightHandle;
2863
2864         ewk_view_text_selection_range_get(__pWebCore->GetWebNativeNode(), &leftHandle, &rightHandle);
2865
2866         startPoint.x = leftHandle.x;
2867         startPoint.y = leftHandle.y;
2868         endPoint.x = rightHandle.x + rightHandle.w;
2869         endPoint.y = rightHandle.y + rightHandle.h;
2870
2871         if ((endPoint.x != 0) && (endPoint.y != 0))
2872         {
2873                 startPoint = __pWebCore->GetRelativeCoordinate(startPoint);
2874                 endPoint = __pWebCore->GetRelativeCoordinate(endPoint);
2875         }
2876
2877         return E_SUCCESS;
2878 }
2879
2880
2881 void
2882 _WebImpl::FireWebPageBlockSelectedEvent(void) const
2883 {
2884         result r = E_SUCCESS;
2885
2886         std::unique_ptr<Point> startPoint(new (std::nothrow) Point());
2887         std::unique_ptr<Point> endPoint(new (std::nothrow) Point());
2888         SysTryReturnVoidResult(NID_WEB_CTRL, startPoint.get() && endPoint.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2889
2890         r = GetBlockRange(*startPoint.get(), *endPoint.get());
2891         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2892
2893         std::unique_ptr<_WebUiEventArg> pEventArg(new (std::nothrow) _WebUiEventArg(WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED));
2894         SysTryReturnVoidResult(NID_WEB_CTRL, pEventArg.get(), E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
2895
2896         r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_START, *startPoint.get());
2897         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2898         startPoint.release();
2899
2900         r = pEventArg->SetEventInfo(_WebUiEventArg::BLOCK_END, *endPoint.get());
2901         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2902         endPoint.release();
2903
2904         r = __pWebEvent->FireAsync(*pEventArg.get());
2905         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2906         pEventArg.release();
2907 }
2908
2909 void
2910 _WebImpl::SetLoadingErrorOccurred(bool arg)
2911 {
2912         __isLoadingErrorOccurred = arg;
2913 }
2914
2915
2916 bool
2917 _WebImpl::IsLoadingErrorOccurred(void) const
2918 {
2919         return __isLoadingErrorOccurred;
2920 }
2921
2922
2923 void
2924 _WebImpl::SetRedirectRequested(bool arg)
2925 {
2926         __isRedirectRequested = arg;
2927 }
2928
2929
2930 bool
2931 _WebImpl::IsRedirectRequested(void) const
2932 {
2933         return __isRedirectRequested;
2934 }
2935
2936
2937 void
2938 _WebImpl::SetPolicyDecision(DecisionPolicy policy)
2939 {
2940         __policy = policy;
2941 }
2942
2943
2944 DecisionPolicy
2945 _WebImpl::GetPolicyDecision(void) const
2946 {
2947         return __policy;
2948 }
2949
2950
2951 LoadingErrorType
2952 _ConvertToOspErrorCode(int error)
2953 {
2954         LoadingErrorType errorCode = WEB_ERROR_UNKNOWN;
2955
2956         switch (error)
2957         {
2958         case EWK_ERROR_NETWORK_STATUS_CANCELLED:
2959         //fall through
2960         case EWK_ERROR_NETWORK_STATUS_CANT_RESOLVE:
2961         //fall through
2962         case EWK_ERROR_NETWORK_STATUS_CANT_RESOLVE_PROXY:
2963         //fall through
2964         case EWK_ERROR_NETWORK_STATUS_CANT_CONNECT:
2965         //fall through
2966         case EWK_ERROR_NETWORK_STATUS_CANT_CONNECT_PROXY:
2967         //fall through
2968         case EWK_ERROR_NETWORK_STATUS_SSL_FAILED:
2969         //fall through
2970         case EWK_ERROR_NETWORK_STATUS_IO_ERROR:
2971         //fall through
2972         case EWK_ERROR_NETWORK_STATUS_MALFORMED:
2973         //fall through
2974         case EWK_ERROR_NETWORK_STATUS_TRY_AGAIN:
2975         //fall through
2976         case EWK_ERROR_NETWORK_STATUS_TOO_MANY_REDIRECTS:
2977         //fall through
2978         case EWK_ERROR_NETWORK_STATUS_TLS_FAILED:
2979         //fall through
2980         case EWK_ERROR_NETWORK_STATUS_INTERNAL_SERVER_ERROR:
2981         //fall through
2982         case EWK_ERROR_NETWORK_STATUS_BAD_GATEWAY:
2983         //fall through
2984         case EWK_ERROR_NETWORK_STATUS_SERVICE_UNAVAILABLE:
2985         //fall through
2986         case EWK_ERROR_NETWORK_STATUS_GATEWAY_TIMEOUT:
2987                 errorCode = WEB_NO_CONNECTION;
2988                 break;
2989
2990         case EWK_ERROR_NETWORK_STATUS_BAD_REQUEST:
2991         //fall through
2992         case EWK_ERROR_NETWORK_STATUS_REQUEST_URI_TOO_LONG:
2993                 errorCode = WEB_BAD_URL;
2994                 break;
2995
2996         case EWK_ERROR_NETWORK_STATUS_FORBIDDEN:
2997                 errorCode = WEB_FILE_ACCESS_FAILED;
2998                 break;
2999
3000         case EWK_ERROR_NETWORK_STATUS_REQUEST_TIMEOUT:
3001                 errorCode = WEB_REQUEST_TIMEOUT;
3002                 break;
3003
3004         case EWK_ERROR_NETWORK_STATUS_UNSUPPORTED_MEDIA_TYPE:
3005                 errorCode = WEB_MIME_NOT_SUPPORTED;
3006                 break;
3007
3008         case EWK_ERROR_NETWORK_STATUS_INSUFFICIENT_STORAGE:
3009                 errorCode = WEB_OUT_OF_MEMORY;
3010                 break;
3011
3012         case EWK_ERROR_NETWORK_STATUS_REQUEST_ENTITY_TOO_LARGE:
3013                 errorCode = WEB_REQUEST_MAX_EXCEEDED;
3014                 break;
3015
3016         case EWK_ERROR_NETWORK_STATUS_CONTINUE:
3017         //fall through
3018         case EWK_ERROR_NETWORK_STATUS_SWITCHING_PROTOCOLS:
3019         //fall through
3020         case EWK_ERROR_NETWORK_STATUS_PROCESSING:
3021         //fall through
3022         case EWK_ERROR_NETWORK_STATUS_OK:
3023         //fall through
3024         case EWK_ERROR_NETWORK_STATUS_CREATED:
3025         //fall through
3026         case EWK_ERROR_NETWORK_STATUS_ACCEPTED:
3027         //fall through
3028         case EWK_ERROR_NETWORK_STATUS_NON_AUTHORITATIVE:
3029         //fall through
3030         case EWK_ERROR_NETWORK_STATUS_NO_CONTENT:
3031         //fall through
3032         case EWK_ERROR_NETWORK_STATUS_RESET_CONTENT:
3033         //fall through
3034         case EWK_ERROR_NETWORK_STATUS_PARTIAL_CONTENT:
3035         //fall through
3036         case EWK_ERROR_NETWORK_STATUS_MULTI_STATUS:
3037         //fall through
3038         case EWK_ERROR_NETWORK_STATUS_MULTIPLE_CHOICES:
3039         //fall through
3040         case EWK_ERROR_NETWORK_STATUS_MOVED_PERMANENTLY:
3041         //fall through
3042         case EWK_ERROR_NETWORK_STATUS_FOUND:
3043         //fall through
3044         case EWK_ERROR_NETWORK_STATUS_SEE_OTHER:
3045         //fall through
3046         case EWK_ERROR_NETWORK_STATUS_NOT_MODIFIED:
3047         //fall through
3048         case EWK_ERROR_NETWORK_STATUS_USE_PROXY:
3049         //fall through
3050         case EWK_ERROR_NETWORK_STATUS_NOT_APPEARING_IN_THIS_PROTOCOL:
3051         //fall through
3052         case EWK_ERROR_NETWORK_STATUS_TEMPORARY_REDIRECT:
3053                 errorCode = WEB_HTTP_RESPONSE;
3054                 break;
3055
3056         case 999:
3057                 errorCode = WEB_INVALID_CERTIFICATE;
3058                 break;
3059
3060         default:
3061                 errorCode = WEB_ERROR_UNKNOWN;
3062                 break;
3063         }
3064
3065         return errorCode;
3066 }
3067
3068
3069 result
3070 _WebImpl::LaunchAppControl(const IEventArg& arg)
3071 {
3072         result r = E_SUCCESS;
3073
3074         IEventArg* pArg = const_cast< IEventArg* >(&arg);
3075         _WebEventArg* pWebEventArg = dynamic_cast< _WebEventArg* >(pArg);
3076         SysTryReturnResult(NID_WEB_CTRL, pWebEventArg, E_INVALID_ARG, "Type casting failed. argument must be IEventArg type.");
3077
3078         String operationId(L"");
3079         String uriPattern(pWebEventArg->GetEventMessage());
3080         SysLog(NID_WEB_CTRL, "The current value of web event type is %d", pWebEventArg->GetEventType());
3081
3082         switch (pWebEventArg->GetEventType())
3083         {
3084         case WEB_EVENT_REQUEST_RTSP:
3085         {
3086                 String ext;
3087                 String mimeType;
3088                 int uriLength = uriPattern.GetLength();
3089                 int index;
3090
3091                 operationId = L"http://tizen.org/appcontrol/operation/view";
3092
3093                 r = uriPattern.LastIndexOf(L".", uriLength - 1, index);
3094                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3095
3096                 r = uriPattern.SubString(index + 1, ext);
3097                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3098
3099                 r = _AppControlManager::GetMimeFromExt(ext, mimeType);
3100                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3101
3102                 r = _AppControlImpl::FindAndStart(operationId, &uriPattern, &mimeType, null, null, null);
3103                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3104
3105                 return r;
3106         }
3107         case WEB_EVENT_REQUEST_TEL:
3108         {
3109                 operationId = L"http://tizen.org/appcontrol/operation/dial";
3110                 break;
3111         }
3112         case WEB_EVENT_REQUEST_EMAIL:
3113         //fall through
3114         case WEB_EVENT_REQUEST_SMS:
3115         //fall through
3116         case WEB_EVENT_REQUEST_MMS:
3117         {
3118                 operationId = L"http://tizen.org/appcontrol/operation/compose";
3119                 break;
3120         }
3121         case WEB_EVENT_REQUEST_UNKNOWN:
3122         {
3123                 break;
3124         }
3125         default:
3126                 SysAssert(false);
3127                 break;
3128         }
3129
3130         r = _AppControlImpl::FindAndStart(operationId, &uriPattern, null, null, null, null);
3131         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3132
3133         return r;
3134 }
3135
3136
3137 result
3138 _WebImpl::SetFullScreenKeypad(void)
3139 {
3140         result r = E_SUCCESS;
3141
3142         std::unique_ptr<Keypad> pKeypad(new (std::nothrow) Keypad());
3143         SysTryReturnResult(NID_WEB_CTRL, pKeypad.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
3144
3145         r = pKeypad->Construct(KEYPAD_STYLE_NORMAL, 100);
3146         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3147
3148         String text(ewk_view_focused_input_element_value_get(__pWebCore->GetWebNativeNode()));
3149         pKeypad->SetText(text);
3150
3151         r = pKeypad->SetShowState(true);
3152         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3153
3154         r = pKeypad->Show();
3155         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3156
3157         pKeypad->AddTextEventListener(*this);
3158
3159         __pKeypad = std::move(pKeypad);
3160
3161         return E_SUCCESS;
3162 }
3163
3164
3165 void
3166 _WebImpl::RemoveFullScreenKeypad(void)
3167 {
3168         __pKeypad->RemoveTextEventListener(*this);
3169
3170         __pKeypad.reset();
3171 }
3172
3173
3174 bool
3175 _WebImpl::IsFooterVisible(void) const
3176 {
3177         return __isFooterVisible;
3178 }
3179
3180
3181 void
3182 _WebImpl::SetFooterVisibleState(bool isFooterVisible)
3183 {
3184         __isFooterVisible = isFooterVisible;
3185 }
3186
3187
3188 bool
3189 _WebImpl::IsKeypadVisible(void) const
3190 {
3191         return __isKeypadVisible;
3192 }
3193
3194
3195 void
3196 _WebImpl::SetKeypadVisibleState(bool isKeypadVisible)
3197 {
3198         __isKeypadVisible = isKeypadVisible;
3199 }
3200
3201
3202 bool 
3203 _WebImpl::IsKeypadOpened(void) const
3204 {
3205         return __isKeypadOpened;
3206 }
3207
3208 void 
3209 _WebImpl::SetKeypadOpened(bool isKeypadOpened)
3210 {
3211         __isKeypadOpened = isKeypadOpened;
3212 }
3213
3214
3215 int 
3216 _WebImpl::GetKeypadHeight(void) const
3217 {
3218         return __keypadHeight;
3219 }
3220
3221
3222 void 
3223 _WebImpl::SetKeypadHeight(int keypadHeight)
3224 {
3225         __keypadHeight = keypadHeight;
3226 }
3227
3228
3229 _ControlOrientation
3230 _WebImpl::GetPreviousOrientation(void) const
3231 {
3232         return __orientation;
3233 }
3234
3235
3236 void
3237 _WebImpl::SetPreviousOrientation(_ControlOrientation orientation)
3238 {
3239         __orientation = orientation;
3240 }
3241
3242
3243 void
3244 _WebImpl::OnTextValueChangeCanceled(const Control& source)
3245 {
3246         RemoveFullScreenKeypad();
3247 }
3248
3249
3250 void
3251 _WebImpl::OnTextValueChanged(const Control& source)
3252 {
3253         std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(__pKeypad->GetText()));
3254
3255         ewk_view_focused_input_element_value_set(__pWebCore->GetWebNativeNode(), pText.get());
3256
3257         RemoveFullScreenKeypad();
3258 }
3259
3260
3261 result
3262 _WebImpl::OnHandleJavaScriptRequestByEventArg(const IEventArg& arg)
3263 {
3264         const _JsBridgeArg* pEventArg = dynamic_cast< const _JsBridgeArg* >(&arg);
3265         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. arg is not _JsBridgeArg object.");
3266
3267         std::unique_ptr<IJsonValue> pJsonValue(JsonParser::ParseN(*(pEventArg->GetJsonData())));
3268         SysTryReturn(NID_WEB_JSON, GetLastResult() == E_SUCCESS, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3269
3270         IJavaScriptBridge* pJsInterface = FindJsInterface(pJsonValue.get());
3271         SysTryReturnResult(NID_WEB_CTRL, pJsInterface, E_OBJ_NOT_FOUND, "JsInterface instance is not available.");
3272
3273         pJsInterface->HandleJavaScriptRequestN(pJsonValue.release());
3274
3275         return E_SUCCESS;
3276 }
3277
3278
3279 result
3280 _WebImpl::OnHandleLoadingEvent(const IEventArg& arg)
3281 {
3282         result r = E_SUCCESS;
3283
3284         const _LoadingEventArg* pEventArg = dynamic_cast< const _LoadingEventArg* >(&arg);
3285         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
3286
3287         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
3288
3289         ILoadingListener* pLoadingListner = GetLoadingListener();
3290         SysTryReturnResult(NID_WEB_CTRL, pLoadingListner, E_SYSTEM, "A system error has been occurred. Loading listener was not set or null.");
3291
3292         switch (pEventArg->GetEventType())
3293         {
3294         case WEB_EVENT_LOADINGLISTENER_STARTED:
3295         {
3296                 pLoadingListner->OnLoadingStarted();
3297                 break;
3298         }
3299
3300         case WEB_EVENT_LOADINGLISTENER_PROGRESS:
3301         {
3302                 const Integer* pProgressPercentage = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ESTIMATED_PROGRESS));
3303                 SysTryReturn(NID_WEB_CTRL, pProgressPercentage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3304
3305                 pLoadingListner->OnEstimatedProgress(pProgressPercentage->ToInt());
3306                 break;
3307         }
3308
3309         case WEB_EVENT_LOADINGLISTENER_PAGETITLE_RECEIVED:
3310         {
3311                 const String* pPageTitle = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::PAGE_TITLE));
3312                 SysTryReturn(NID_WEB_CTRL, pPageTitle, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3313
3314                 pLoadingListner->OnPageTitleReceived(*pPageTitle);
3315                 break;
3316         }
3317
3318         case WEB_EVENT_LOADINGLISTENER_CANCELED:
3319         {
3320                 pLoadingListner->OnLoadingCanceled();
3321                 break;
3322         }
3323
3324         case WEB_EVENT_LOADINGLISTENER_ERROR_OCCURRED:
3325         {
3326                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_TYPE));
3327                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3328
3329                 const String* pErrorMessage = dynamic_cast< const String* >(pEventArg->GetEventInfo(_LoadingEventArg::ERROR_MESSAGE));
3330                 SysTryReturn(NID_WEB_CTRL, pErrorMessage, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3331
3332                 LoadingErrorType errorType = _ConvertToOspErrorCode(pErrorType->ToInt());
3333
3334                 pLoadingListner->OnLoadingErrorOccurred(errorType, *pErrorMessage);
3335                 break;
3336         }
3337
3338         case WEB_EVENT_LOADINGLISTENER_COMPLETED:
3339         {
3340                 pLoadingListner->OnLoadingCompleted();
3341                 break;
3342         }
3343
3344         case WEB_EVENT_LOADINGLISTENER_AUTHENTICATION_CANCELED:
3345         {
3346                 pLoadingListner->OnHttpAuthenticationCanceled();
3347                 break;
3348         }
3349
3350         default:
3351         {
3352                 SysAssert(false);
3353         }
3354         }
3355
3356         return r;
3357 }
3358
3359
3360 result
3361 _WebImpl::OnHandleWebDownloadEvent(const IEventArg& arg)
3362 {
3363         result r = E_SUCCESS;
3364
3365         const _WebDownloadEventArg* pEventArg = dynamic_cast< const _WebDownloadEventArg* >(&arg);
3366         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
3367
3368         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
3369
3370         IWebDownloadListener* pWebDownloadListener = __pWebDownloadHandler->GetDownloadListener();
3371         SysTryReturnResult(NID_WEB_CTRL, pWebDownloadListener, E_SYSTEM, "A system error has been occurred. Web Downloading listener was not set or null.");
3372
3373         switch (pEventArg->GetEventType())
3374         {
3375         case WEB_EVENT_WEBDOWNLOADLISTENER_DATA_RECEIVED:
3376         {
3377                 const ByteBuffer* pChunk = dynamic_cast< const ByteBuffer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::CHUNKED_DATA));
3378                 SysTryReturn(NID_WEB_CTRL, pChunk, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3379
3380                 pWebDownloadListener->OnWebChunkedDataReceived(*pChunk);
3381                 break;
3382         }
3383
3384         case WEB_EVENT_WEBDOWNLOADLISTENER_COMPLETED:
3385         {
3386                 pWebDownloadListener->OnWebDataDownloadCompleted();
3387                 break;
3388         }
3389
3390         case WEB_EVENT_WEBDOWNLOADLISTENER_FAILED:
3391         {
3392                 const Integer* pErrorType = dynamic_cast< const Integer* >(pEventArg->GetEventInfo(_WebDownloadEventArg::ERROR_TYPE));
3393                 SysTryReturn(NID_WEB_CTRL, pErrorType, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3394
3395                 LoadingErrorType errorType = static_cast < LoadingErrorType >(pErrorType->ToInt());
3396
3397                 pWebDownloadListener->OnWebDownloadFailed(errorType);
3398                 break;
3399         }
3400
3401         default:
3402         {
3403                 SysAssert(false);
3404         }
3405         }
3406
3407         return r;
3408 }
3409
3410
3411 result
3412 _WebImpl::OnHandleWebUiEvent(const IEventArg& arg)
3413 {
3414         result r = E_SUCCESS;
3415
3416         const _WebUiEventArg* pEventArg = dynamic_cast< const _WebUiEventArg* >(&arg);
3417         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
3418
3419         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
3420
3421         IWebUiEventListener* pWebUiEventListner = GetUiEventListener();
3422         SysTryReturnResult(NID_WEB_CTRL, pWebUiEventListner, E_SYSTEM, "A system error has been occurred. Web UI listener was not set or null.");
3423
3424         switch (pEventArg->GetEventType())
3425         {
3426         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_BLOCK_SELECTED:
3427         {
3428                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
3429
3430                 Point* pStartPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_START)));
3431                 SysTryReturn(NID_WEB_CTRL, pStartPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3432
3433                 Point* pEndPoint = const_cast< Point* >(dynamic_cast< const Point* >(pEventArg->GetEventInfo(_WebUiEventArg::BLOCK_END)));
3434                 SysTryReturn(NID_WEB_CTRL, pEndPoint, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3435
3436                 pWebUiEventListner->OnWebPageBlockSelected(*pWeb, *pStartPoint, *pEndPoint);
3437                 break;
3438         }
3439
3440         case WEB_EVENT_WEBUIEVENTLISTENER_PAGE_SHOW_REQUESTED:
3441         {
3442                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
3443
3444                 pWebUiEventListner->OnWebPageShowRequested(*pWeb);
3445                 break;
3446         }
3447
3448         case WEB_EVENT_WEBUIEVENTLISTENER_WINDOW_CLOSE_REQUSTED:
3449         {
3450                 Web* pWeb = dynamic_cast< Web* >(&(this->GetPublic()));
3451
3452                 pWebUiEventListner->OnWebWindowCloseRequested(*pWeb);
3453                 break;
3454         }
3455
3456         default:
3457         {
3458                 SysAssert(false);
3459         }
3460         }
3461
3462         return r;
3463 }
3464
3465
3466 result
3467 _WebImpl::OnHandleTextSearchEvent(const IEventArg& arg)
3468 {
3469         result r = E_SUCCESS;
3470
3471         const _TextSearchEventArg* pEventArg = dynamic_cast< const _TextSearchEventArg* >(&arg);
3472         SysTryReturnResult(NID_WEB_CTRL, pEventArg, E_INVALID_ARG, "Invalid argument(s) is used. Type casting failed. argument must be IEventArg type.");
3473
3474         SysLog(NID_WEB_CTRL, "The current value of event type is %d", pEventArg->GetEventType());
3475
3476         ITextSearchListener* pTextSearchListner = GetTextSearchListener();
3477         SysTryReturnResult(NID_WEB_CTRL, pTextSearchListner, E_SYSTEM, "A system error has been occurred. Web text search listener was not set or null.");
3478
3479         switch (pEventArg->GetEventType())
3480         {
3481         case WEB_EVENT_TEXTSEARCHLISTENER_TEXT_FOUND:
3482         {
3483                 Integer* pTotalCount= dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::TOTAL_COUNT)));
3484                 SysTryReturn(NID_WEB_CTRL, pTotalCount, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3485
3486                 Integer* pCurrentOrdinal = dynamic_cast< Integer* >(const_cast< Object* >(pEventArg->GetEventInfo(_TextSearchEventArg::CURRENT_ORDINAL)));
3487                 SysTryReturn(NID_WEB_CTRL, pCurrentOrdinal, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3488
3489                 pTextSearchListner->OnTextFound(pTotalCount->ToInt(), pCurrentOrdinal->ToInt());
3490                 break;
3491         }
3492
3493         default:
3494         {
3495                 SysAssert(false);
3496         }
3497         }
3498
3499         return r;
3500 }
3501
3502
3503 result
3504 _WebImpl::HttpAuthenticationRequested(Ewk_Auth_Challenge* pChallenge)
3505 {
3506         result r = E_SUCCESS;
3507
3508         String host(ewk_auth_challenge_url_get(pChallenge));
3509         String realm(ewk_auth_challenge_realm_get(pChallenge));
3510
3511         __pAuthChallenge.reset();
3512
3513         std::unique_ptr<AuthenticationChallenge> pAuthChallenge(new (std::nothrow) AuthenticationChallenge());
3514         SysTryReturnResult(NID_WEB_CTRL, pAuthChallenge, E_OUT_OF_MEMORY, "Memory Allocation failed.");
3515
3516         _AuthenticationChallengeImpl* pAuthImpl = _AuthenticationChallengeImpl::GetInstance(pAuthChallenge.get());
3517         SysTryReturn(NID_WEB_CTRL, pAuthImpl,  GetLastResult(),  GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3518
3519         pAuthImpl->SetAuthenticationChallengeHandler(pChallenge);
3520         pAuthImpl->SetWebEvasObject(__pWebCore->GetWebNativeNode());
3521
3522         __pAuthChallenge = std::move(pAuthChallenge);
3523
3524         if (__pUserLoadingListener && __pUserLoadingListener->OnHttpAuthenticationRequestedN(host, realm, *__pAuthChallenge.get()))
3525         {
3526                 __pAuthChallenge.release();
3527         }
3528         else
3529         {
3530                 r = ShowAuthenticationPopup(host, realm, __pAuthChallenge.get());
3531                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3532         }
3533
3534         return E_SUCCESS;
3535 }
3536
3537
3538 result
3539 _WebImpl::ShowAuthenticationPopup(const String& host, const String& realm, AuthenticationChallenge* pAuthChallenge)
3540 {
3541         result r = E_SUCCESS;
3542
3543         std::unique_ptr<_AuthConfirmPopup> pAuthPopup(new (std::nothrow) _AuthConfirmPopup());
3544         SysTryReturnResult(NID_WEB_CTRL, pAuthPopup, E_OUT_OF_MEMORY, "Memory Allocation failed.");
3545
3546         r = pAuthPopup->Construct(host, realm, pAuthChallenge);
3547         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3548
3549         __pAuthPopup = std::move(pAuthPopup);
3550
3551         r = __pAuthPopup->ShowPopup();
3552         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3553
3554 CATCH:
3555         __pAuthPopup.reset();
3556
3557         return r;
3558 }
3559
3560
3561 result
3562 _WebImpl::ShowGeolocationPopup(Ewk_Geolocation_Permission_Data* pPermissionData)
3563 {
3564         result r = E_SUCCESS;
3565
3566         std::unique_ptr<_GeolocationConfirmPopup> pGeolocationPopup(new (std::nothrow) _GeolocationConfirmPopup());
3567         SysTryReturnResult(NID_WEB_CTRL, pGeolocationPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
3568
3569         r = pGeolocationPopup->Construct(pPermissionData);
3570         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3571
3572         __pGeolocationPopup = std::move(pGeolocationPopup);
3573
3574         r = __pGeolocationPopup->ShowPopup();
3575         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3576
3577         __pGeolocationPopup.release();
3578
3579         return E_SUCCESS;
3580
3581 CATCH:
3582         __pGeolocationPopup.reset();
3583
3584         return r;
3585 }
3586
3587
3588 _Form*
3589 _WebImpl::GetParentFormCore(_Control* pControlCore)
3590 {
3591         String parentName;
3592         _Form* pFormCore = null;
3593
3594         _Control* pParentControlCore = dynamic_cast< _Control* >(pControlCore->GetParent());
3595
3596         if (pParentControlCore == null)
3597         {
3598                 _Window* pWindowCore = dynamic_cast< _Window* >(pControlCore);
3599                 SysAssertf(pWindowCore, "Failed to get parent control and window core.");
3600                 pFormCore = dynamic_cast< _Form* >(pWindowCore->GetOwner());
3601                 if (pFormCore == null)
3602                 {
3603                         pParentControlCore = dynamic_cast< _Control* >(pWindowCore->GetOwner());
3604                         SysTryReturn(NID_WEB_CTRL, pParentControlCore, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
3605                 }
3606         }
3607         else
3608         {
3609                 pFormCore = dynamic_cast< _Form* >(pParentControlCore);
3610         }
3611
3612         if (pFormCore != null)
3613         {
3614                 return pFormCore;
3615         }
3616
3617         return GetParentFormCore(pParentControlCore);
3618 }
3619
3620
3621 bool 
3622 _WebImpl::OnFocusGained(const _ControlImpl& source)
3623 {
3624         return true;
3625 }
3626
3627
3628 bool 
3629 _WebImpl::OnFocusLost(const _ControlImpl& source)
3630 {
3631         if(IsKeypadVisible() == true)
3632         {
3633                 SetKeypadOpened(true);
3634         }
3635
3636         evas_object_focus_set(__pWebCore->GetWebNativeNode(), EINA_FALSE);
3637
3638         return true;
3639 }
3640
3641
3642 bool
3643 _WebImpl::HasValidNativeNode(void) const
3644 {
3645         if (__pWebCore && __pWebCore->GetWebNativeNode())
3646         {
3647                 return true;
3648         }
3649
3650         return false;
3651 }
3652
3653
3654 result
3655 _WebImpl::OnAttachedToMainTree(void)
3656 {
3657         result r = E_SUCCESS;
3658
3659         r = __pWebCore->InitializeWebNativeNode();
3660         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3661
3662         r = InitializeSetting();
3663         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3664
3665         r = _ContainerImpl::OnAttachedToMainTree();
3666         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3667
3668         return E_SUCCESS;
3669 }
3670
3671
3672 void
3673 _WebImpl::OnChangeLayout(_ControlOrientation orientation)
3674 {
3675         if (IsKeypadVisible() == true)
3676         {
3677                 _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
3678                 SysAssertf(pXformer, "Failed to get CoordinateTransformer");
3679
3680                 _Form* pFormCore = GetParentFormCore(dynamic_cast< _Control* >(&this->GetCore()));
3681                 SysAssertf(pFormCore != null, "Failed to get FormCore");
3682
3683                 if (orientation == _CONTROL_ORIENTATION_PORTRAIT)
3684                 {
3685                         pFormCore->DeflateClientRectHeight(pXformer->TransformVertical(PORTRAIT_KEYPAD_HEIGHT));
3686                 }
3687                 else if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
3688                 {
3689                         pFormCore->DeflateClientRectHeight(pXformer->TransformVertical(LANDSCAPE_KEYPAD_HEIGHT));
3690                 }
3691         }
3692
3693         if (__pColorPicker.get())
3694         {
3695                 __pColorPicker->ChangeLayout(orientation);
3696         }
3697
3698 }
3699
3700
3701 _WebDataHandler*
3702 _WebImpl::GetDownloadHandler(void) const
3703 {
3704         return __pWebDownloadHandler.get();
3705 }
3706
3707
3708 Bitmap*
3709 _WebImpl::GetFaviconN(void) const
3710 {
3711         result r = E_SUCCESS;
3712
3713         Evas_Object* pView = __pWebCore->GetWebNativeNode();
3714
3715         Evas* pEvas = evas_object_evas_get(pView);
3716         Ewk_Context* pContext = ewk_view_context_get(pView);
3717         SysAssertf(pEvas && pContext, "Failed to request");
3718
3719         const char* pUrl = ewk_view_url_get(pView);
3720
3721         Tizen::Graphics::BufferInfo bufferInfo;
3722         Tizen::Base::ByteBuffer byteBuffer;
3723
3724         std::unique_ptr<Bitmap> pBitmapImage(new (std::nothrow) Bitmap());
3725         SysTryReturn(NID_WEB_CTRL, pBitmapImage.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
3726
3727         Evas_Object* pfavicon = ewk_context_icon_database_icon_object_add(pContext, pUrl, pEvas);
3728         SysTryReturn(NID_WEB_CTRL, pfavicon, null, E_OBJ_NOT_FOUND, "[%s] Propagating.", GetErrorMessage(E_OBJ_NOT_FOUND));
3729
3730         r = _Utility::GetPixelBufferFromEvasObject(pfavicon,  bufferInfo);
3731         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3732
3733         const Dimension dimension(bufferInfo.width, bufferInfo.height);
3734
3735         r = byteBuffer.Construct((byte*)bufferInfo.pPixels, 0, dimension.height * dimension.width * 32, dimension.height * dimension.width * 32 );
3736         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3737
3738         r = pBitmapImage->Construct(byteBuffer, dimension, BITMAP_PIXEL_FORMAT_ARGB8888);
3739         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
3740
3741         return pBitmapImage.release();
3742
3743 }
3744
3745
3746 _WebImpl*
3747 _WebImpl::GetInstance(Web* pWeb)
3748 {
3749         return dynamic_cast< _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
3750 }
3751
3752
3753 const _WebImpl*
3754 _WebImpl::GetInstance(const Web* pWeb)
3755 {
3756         return dynamic_cast< const _WebImpl* >(_ControlImpl::GetInstance(*pWeb));
3757 }
3758
3759
3760 Eina_Bool
3761 _WebImpl::HideColorPicker()
3762 {
3763         __pColorPicker.reset();
3764
3765         return EINA_TRUE;
3766 }
3767
3768
3769 result
3770 _WebImpl::ShowColorPicker(int red, int green, int blue, int alpha, Color& color)
3771 {
3772         result r = E_SUCCESS;
3773
3774         std::unique_ptr<_InputPickerPopup> pColorHadler(new (std::nothrow) _InputPickerPopup());
3775         SysTryReturnResult(NID_WEB_CTRL, pColorHadler.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
3776
3777         Tizen::Graphics::Color colorVal(static_cast< byte >(red), static_cast< byte >(green), static_cast< byte >(blue), static_cast< byte >(alpha));
3778
3779         r = pColorHadler->Construct(colorVal);
3780         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3781
3782         __pColorPicker = std::move(pColorHadler);
3783
3784         r = __pColorPicker->ShowPopup();
3785         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3786
3787         color = __pColorPicker->GetColor();
3788
3789         return E_SUCCESS;
3790
3791 CATCH:
3792         __pColorPicker.reset();
3793
3794         return r;
3795 }
3796
3797
3798 result
3799 _WebImpl::ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue, String& dateStr)
3800 {
3801         result r = E_SUCCESS;
3802
3803         std::unique_ptr<_InputPickerPopup> pInputPicker(new (std::nothrow) _InputPickerPopup());
3804         SysTryReturnResult(NID_WEB_CTRL, pInputPicker.get(), E_OUT_OF_MEMORY, "Memory allocation failed.");
3805
3806         r = pInputPicker->Construct(String(inputValue), inputType);
3807         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
3808
3809         __pDatePicker = std::move(pInputPicker);
3810
3811         r = __pDatePicker->ShowPopup();
3812         SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
3813
3814         dateStr = __pDatePicker->GetDate();
3815
3816 CATCH:
3817         __pDatePicker.reset();
3818
3819         return r;
3820 }
3821
3822
3823 }}} // Tizen::Web::Controls