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