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