fix crash issue
[framework/osp/web.git] / src / controls / FWebCtrl_WebImpl.cpp
index 3302be6..c8671de 100755 (executable)
@@ -37,7 +37,6 @@
 #include <FBaseRtMutexGuard.h>
 #include <FBaseSysLog.h>
 #include <FBaseUtilUri.h>
-#include <FCntDownloadRequest.h>
 #include <FGrpColor.h>
 #include <FGrpPoint.h>
 #include <FGrpRectangle.h>
@@ -70,8 +69,6 @@
 #include <FApp_AppInfo.h>
 #include <FApp_AppManagerImpl.h>
 #include <FBase_StringConverter.h>
-#include <FCnt_DownloadManagerImpl.h>
-#include <FCnt_ContentManagerImpl.h>
 #include <FGrp_CoordinateSystem.h>
 #include <FGrp_Screen.h>
 #include <FIo_DatabaseImpl.h>
@@ -832,9 +829,16 @@ void
 OnFullScreenEntered(void* pUserData, Evas_Object* pView, void* pEventInfo)
 {
        _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
+       bool* pIsHandleNeeded = reinterpret_cast< bool* >(pEventInfo);
        SysAssertf(pImpl, "Failed to request");
 
-       SysLog(NID_WEB_CTRL, "Enter.");
+       _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+       SysAssertf(pWebCore, "Failed to get Web core object");
+
+       if (pIsHandleNeeded && *pIsHandleNeeded)
+       {
+               pWebCore->SetFullScreenEntered(true);
+       }
 }
 
 
@@ -844,7 +848,32 @@ OnFullScreenExited(void* pUserData, Evas_Object* pView, void* pEventInfo)
        _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
        SysAssertf(pImpl, "Failed to request");
 
-       SysLog(NID_WEB_CTRL, "Exit.");
+       _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+       SysAssertf(pWebCore, "Failed to get Web core object");
+
+       pWebCore->SetFullScreenEntered(false);
+}
+
+
+void
+OnFocusDownRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
+{
+       _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
+       SysAssertf(pImpl, "Failed to request");
+
+       _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+       pWebCore->SetFocusEnd(true);
+}
+
+
+void
+OnFocusUpRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
+{
+       _WebImpl* pImpl = reinterpret_cast<_WebImpl*>(pUserData);
+       SysAssertf(pImpl, "Failed to request");
+
+       _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+       pWebCore->SetFocusEnd(true);
 }
 
 
@@ -881,64 +910,75 @@ OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
        String url(ewk_policy_decision_url_get(pPolicy));
        SysSecureLog(NID_WEB_CTRL, "The current value of url is %ls", url.GetPointer());
 
-       if (url == L"about:blank")
-       {
-               ewk_policy_decision_use(pPolicy);
-               return;
-       }
-
-       if (pImpl->GetLoadingListener() && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy))
+       if (ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy))
                && !pImpl->IsRedirectRequested())
        {
+               _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
+               SysAssertf(pWebCore, "Failed to get Web core object");
+
+               pWebCore->SetFullScreenEntered(false);
+
                pImpl->SetCertificateRequested(false);
 
                if (pImpl->GetTextSearchListener())
                {
                        pImpl->DisableAsyncSearch();
                }
-       
-               WebNavigationType navigationType = WEB_NAVIGATION_OTHER;
-               Ewk_Policy_Navigation_Type ewkNavigationType = ewk_policy_decision_navigation_type_get(pPolicy);
 
-               switch (ewkNavigationType)
+               ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
+               if (pLoadingListener)
                {
-               case EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED:
-                       navigationType = WEB_NAVIGATION_LINK_CLICKED;
-                       break;
-               case EWK_POLICY_NAVIGATION_TYPE_FORM_SUBMITTED:
-                       navigationType = WEB_NAVIGATION_FORM_SUBMITTED;
-                       break;
-               case EWK_POLICY_NAVIGATION_TYPE_BACK_FORWARD:
-                       navigationType = WEB_NAVIGATION_BACKFORWARD;
-                       break;
-               case EWK_POLICY_NAVIGATION_TYPE_RELOAD:
-                       navigationType = WEB_NAVIGATION_RELOAD;
-                       break;
-               case EWK_POLICY_NAVIGATION_TYPE_FORM_RESUBMITTED:
-                       navigationType = WEB_NAVIGATION_FORM_RESUBMITTED;
-                       break;
-               case EWK_POLICY_NAVIGATION_TYPE_OTHER:
-                       navigationType = WEB_NAVIGATION_OTHER;
-                       break;
-               default:
-                       SysAssert(false);
-               }
+                       WebNavigationType navigationType = WEB_NAVIGATION_OTHER;
+                       Ewk_Policy_Navigation_Type ewkNavigationType = ewk_policy_decision_navigation_type_get(pPolicy);
 
-               if (pImpl->GetLoadingListener()->OnLoadingRequested(url, navigationType))
-               {
-                       ewk_policy_decision_ignore(pPolicy);
+                       switch (ewkNavigationType)
+                       {
+                       case EWK_POLICY_NAVIGATION_TYPE_LINK_CLICKED:
+                               navigationType = WEB_NAVIGATION_LINK_CLICKED;
+                               break;
+                       case EWK_POLICY_NAVIGATION_TYPE_FORM_SUBMITTED:
+                               navigationType = WEB_NAVIGATION_FORM_SUBMITTED;
+                               break;
+                       case EWK_POLICY_NAVIGATION_TYPE_BACK_FORWARD:
+                               navigationType = WEB_NAVIGATION_BACKFORWARD;
+                               break;
+                       case EWK_POLICY_NAVIGATION_TYPE_RELOAD:
+                               navigationType = WEB_NAVIGATION_RELOAD;
+                               break;
+                       case EWK_POLICY_NAVIGATION_TYPE_FORM_RESUBMITTED:
+                               navigationType = WEB_NAVIGATION_FORM_RESUBMITTED;
+                               break;
+                       case EWK_POLICY_NAVIGATION_TYPE_OTHER:
+                               navigationType = WEB_NAVIGATION_OTHER;
+                               break;
+                       default:
+                               SysAssert(false);
+                       }
 
-                       return;
+                       if (pLoadingListener->OnLoadingRequested(url, navigationType))
+                       {
+                               ewk_policy_decision_ignore(pPolicy);
+
+                               return;
+                       }
                }
        }
 
+       if (url == L"about:blank")
+       {
+               ewk_policy_decision_use(pPolicy);
+
+               return;
+       }
+
        String currentUrl(pImpl->GetUrl());
        String redirectUrl(pImpl->GetProtocolFromUri(url,  currentUrl));
        if (redirectUrl != L"")
        {
-               pImpl->LoadUrl(redirectUrl);
                ewk_policy_decision_ignore(pPolicy);
 
+               pImpl->LoadUrl(redirectUrl);
+
                return;
        }
        
@@ -946,7 +986,7 @@ OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
        uri.SetUri(url);
 
        String uriScheme(uri.GetScheme());
-       SysLog(NID_WEB_CTRL, "The current value of scheme is %ls", uriScheme.GetPointer());
+       SysSecureLog(NID_WEB_CTRL, "The current value of scheme is %ls", uriScheme.GetPointer());
 
        if ((uriScheme != L"http") && (uriScheme != L"https") && (uriScheme != L"file"))
        {
@@ -1068,36 +1108,34 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
 
        result r = E_SUCCESS;
 
-       _SystemResource* pSysResource = _SystemResource::GetInstance();
-       SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
-
-       const char* pUrl = ewk_policy_decision_url_get(pPolicy);
        int code = ewk_policy_decision_response_status_code_get(pPolicy);
-       String mime(ewk_policy_decision_response_mime_get(pPolicy));
-       SysSecureLog(NID_WEB_CTRL, "url : %s, mime : %ls, code : %d", pUrl, mime.GetPointer(), code);
-
-       ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
-
        String url(ewk_policy_decision_url_get(pPolicy));
+       String mime(ewk_policy_decision_response_mime_get(pPolicy));
+       SysSecureLog(NID_WEB_CTRL, "code : %d, url : %ls, mime : %ls", code, url.GetPointer(), mime.GetPointer());
 
-       if (pLoadingListener && ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy)))
+       if (ewk_frame_is_main_frame(ewk_policy_decision_frame_get(pPolicy)))
        {
-               const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
-
-               DecisionPolicy policy;
-               HttpHeader httpHeader;
-
                if (code >= REDIRECTION_HEADER_GROUP && code < REDIRECTION_HEADER_GROUP + 100)
                {
                        pImpl->SetRedirectRequested(true);
                        mime = L"";
                }
 
-               eina_hash_foreach(pHeader, AddHttpHeaderData, &httpHeader);
-               SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
+               if (pLoadingListener)
+               {
+                       const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
+                       HttpHeader httpHeader;
 
-               policy = pLoadingListener->OnWebDataReceived(mime, httpHeader);
-               pImpl->SetPolicyDecision(policy);
+                       eina_hash_foreach(pHeader, AddHttpHeaderData, &httpHeader);
+                       SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+                       pImpl->SetPolicyDecision(pLoadingListener->OnWebDataReceived(mime, httpHeader));
+               }
+               else
+               {
+                       pImpl->SetPolicyDecision(WEB_DECISION_CONTINUE);
+               }
        }
 
        switch (pImpl->GetPolicyDecision())
@@ -1114,11 +1152,10 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
                        return;
                }
 
-               if (pImpl->IsMimeSupported(mime) || mime == L"")
+               if (ewk_policy_decision_type_get(pPolicy) == EWK_POLICY_DECISION_USE)
                {
                        break;
                }
-               
                else
                {
                        ewk_policy_decision_ignore(pPolicy);
@@ -1127,24 +1164,12 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
 
                        r = _AppControlImpl::FindAndStart(operationId, &url, &mime, null, null, null);
                        SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS || r == E_OBJ_NOT_FOUND, r, "[%s] Propagating.", GetErrorMessage(r));
-       
-                       if (r == E_OBJ_NOT_FOUND)
-                       {
-                               _SelectBox* pSelectBox = new (std::nothrow) _SelectBox;
-                               SysTryReturnVoidResult(NID_WEB_CTRL, pSelectBox, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-                               r = pSelectBox->Construct(false, L"Select application", 1, null, url);
-                               SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
-
-                               pSelectBox->AddListItem(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_DOWNLOAD"), _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
-                               r = pSelectBox->ShowPopup();
-                               SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
-                       }
 
                        return;
                }
                break;
        }
+
        case WEB_DECISION_DOWNLOAD:
        {
                ewk_policy_decision_ignore(pPolicy);
@@ -1155,16 +1180,18 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
                Ewk_Context* pContext = ewk_view_context_get(pView);
                SysAssertf(pContext, "Failed to get webkit instance.");
 
-               pDownloadHandler->StartDownload(pUrl);
+               pDownloadHandler->StartDownload(url);
 
                return;
        }
+
        case WEB_DECISION_IGNORE:
        {
                ewk_policy_decision_ignore(pPolicy);
 
                return;
        }
+
        default:
        {
                SysAssert(false);
@@ -1718,7 +1745,7 @@ OnWebNativeNodeFocusGained(void* pUserData, Evas* pCanvas, Evas_Object* pView, v
 
        if (pImpl->IsKeypadOpened() == true)
        {
-               pImpl->SetKeypadOpened(false);  
+               pImpl->SetKeypadOpened(false);
        }
 } 
 
@@ -2124,6 +2151,15 @@ _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
 
 _WebImpl::~_WebImpl()
 {
+       _WebManager* pWebManager = _WebManager::GetInstance();
+       SysTryCatch(NID_WEB_CTRL, pWebManager, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       pWebManager->RemoveWeb(reinterpret_cast< int >(this));
+       pWebManager->RemoveActiveWeb(this);
+
+CATCH:
+       RemoveEventListenerCallback();
+
        ClearCertificateDb();
 }
 
@@ -2210,11 +2246,6 @@ _WebImpl::Construct(void)
        r = InitWebEvent();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
-       SysTryReturn(NID_WEB_CTRL, pManagerImpl, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       pManagerImpl->SetDownloadListener(this);
-
        __pWebCore = dynamic_cast< _Web* >(&(GetCore()));
        SysTryReturnResult(NID_WEB_CTRL, __pWebCore, E_SYSTEM, "A system error has been occurred. Failed to get web control");
 
@@ -2430,6 +2461,8 @@ _WebImpl::ClearSelectBoxPopup(void)
 
        __pSelectBox.reset();
 
+       Resume();
+
        return E_SUCCESS;
 }
 
@@ -2531,12 +2564,12 @@ _WebImpl::EvaluateJavascriptN(const String& scriptCode)
 
        ewk_view_script_execute(pView, pScript.get(), OnScriptExecuted, pPresenter.get());
 
-       std::unique_ptr<String> pResult(new (std::nothrow) String(L""));
-       SysTryReturn(NID_WEB_CTRL, pResult.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       String* pResult = new (std::nothrow) String(L"");
+       SysTryReturn(NID_WEB_CTRL, pResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       pPresenter->WaitAsyncProcess(*pResult.get());
+       pPresenter->WaitAsyncProcess(*pResult);
 
-       return pResult.release();
+       return pResult;
 }
 
 
@@ -2736,6 +2769,10 @@ _WebImpl::SynchronizeSearch(_SearchType type, Evas_Object* pView, Ewk_Find_Optio
        std::unique_ptr<char[]> pText(_StringConverter::CopyToCharArrayN(text));
        SysTryReturn(NID_WEB_CTRL, pText.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
+       Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
+       SysAssertf(pSettings, "Failed to get webkit instance.");
+       ewk_settings_clear_text_selection_automatically_set(pSettings, true);
+
        switch (type)
        {
        case SEARCH_SYNC:
@@ -3516,6 +3553,9 @@ _WebImpl::SetEventListenerCallback(void) const
                evas_object_smart_callback_add(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered, this);
                evas_object_smart_callback_add(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited, this);
 
+               evas_object_smart_callback_add(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested, this);
+               evas_object_smart_callback_add(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested, this);
+
                Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
                SysAssertf(pContext, "Failed to get webkit instance.");
                ewk_context_did_start_download_callback_set(pContext, OnDidStartDownloadCallback, const_cast< _WebImpl* >(this));
@@ -3568,9 +3608,9 @@ _WebImpl::RemoveEventListenerCallback(void) const
 
                evas_object_smart_callback_del(pWebNativeNode, "geolocation,permission,request", OnGeolocationPermissionRequested);
 
-               ewk_view_javascript_alert_callback_set(null, null, null);
-               ewk_view_javascript_prompt_callback_set(null, null, null);
-               ewk_view_javascript_confirm_callback_set(null, null, null);
+               ewk_view_javascript_alert_callback_set(pWebNativeNode, null, null);
+               ewk_view_javascript_prompt_callback_set(pWebNativeNode, null, null);
+               ewk_view_javascript_confirm_callback_set(pWebNativeNode, null, null);
 
                evas_object_smart_callback_del(pWebNativeNode, "policy,response,decide", OnWebDataReceived);
 
@@ -3599,6 +3639,9 @@ _WebImpl::RemoveEventListenerCallback(void) const
                evas_object_smart_callback_del(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered);
                evas_object_smart_callback_del(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited);
 
+               evas_object_smart_callback_del(pWebNativeNode, "keyevent,down,not,handled", OnFocusDownRequested);
+               evas_object_smart_callback_del(pWebNativeNode, "keyevent,up,not,handled", OnFocusUpRequested);
+
                Ewk_Context* pContext = ewk_view_context_get(pWebNativeNode);
                SysAssertf(pContext, "Failed to get webkit instance.");
                ewk_context_vibration_client_callbacks_set(pContext, null, null, null);
@@ -3655,6 +3698,10 @@ _WebImpl::SetBlockSelectionPosition(const FloatPoint& startPoint)
        {
                Point absPoint( _CoordinateSystemUtils::ConvertToInteger(__pWebCore->GetAbsoluteCoordinate(startPoint)));
 
+               Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
+               SysAssertf(pSettings, "Failed to get webkit instance.");
+               ewk_settings_clear_text_selection_automatically_set(pSettings, true);
+
                Eina_Bool ret = pSmartData->api->text_selection_down(pSmartData, absPoint.x, absPoint.y);
                if (ret)
                {
@@ -4448,7 +4495,7 @@ _WebImpl::ShowCertificateConfirmPopup(_CertificatePopupMode userConfirmMode, Ewk
        std::unique_ptr<_CertificateConfirmPopup> pCertConfirmPopup(new (std::nothrow) _CertificateConfirmPopup());
        SysTryReturnResult(NID_WEB_CTRL, pCertConfirmPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
-       r = pCertConfirmPopup->Construct(userConfirmMode, pPolicy, this);
+       r = pCertConfirmPopup->Construct(userConfirmMode, pPolicy);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pCertConfirmPopup = std::move(pCertConfirmPopup);
@@ -4615,14 +4662,13 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
        {
        case USER_CONFIRM_USERMEDIA:
        {
-        __pUserMediaConfirmPopup.reset();
+               __pUserMediaConfirmPopup.reset();
 
                __pUserMediaConfirmPopup = std::move(pUserConfirmPopup);
 
                r = __pUserMediaConfirmPopup->ShowPopup();
                SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pUserMediaConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-               __pUserMediaConfirmPopup.release();
                break;
        }
        case USER_CONFIRM_GEOLOCATION:
@@ -4634,7 +4680,6 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
                r = __pGeolocationConfirmPopup->ShowPopup();
                SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pGeolocationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-               __pGeolocationConfirmPopup.release();
                break;
        }
        case USER_CONFIRM_NOTIFICATION:
@@ -4646,7 +4691,6 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
                r = __pNotificationConfirmPopup->ShowPopup();
                SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pNotificationConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-               __pNotificationConfirmPopup.release();
                break;
        }
        case USER_SCRIPT_ALERT:
@@ -4658,7 +4702,6 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
                r = __pScriptAlertConfirmPopup->ShowPopup();
                SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptAlertConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-               __pScriptAlertConfirmPopup.release();
                break;
        }
        case USER_SCRIPT_CONFIRM:
@@ -4670,8 +4713,6 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
                r = __pScriptConfirmPopup->ShowPopup();
                SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, __pScriptConfirmPopup.reset(), r, "[%s] Propagating.", GetErrorMessage(r));
 
-               __pScriptConfirmPopup.release();
-
                break;
        }
        default:
@@ -4710,11 +4751,15 @@ _WebImpl::GetParentFormImpl(_ControlImpl* pControlImpl)
 bool 
 _WebImpl::OnFocusGained(const _ControlImpl& source)
 {
-       Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
-       SysAssertf(pSettings, "Failed to get webkit instance.");
-       ewk_settings_clear_text_selection_automatically_set(pSettings, true);
+       Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
+       if (!pWebview)
+       {
+               return false;
+       }
 
-       evas_object_focus_set(__pWebCore->GetWebNativeNode(), EINA_TRUE);
+       Ewk_Settings* pSettings = ewk_view_settings_get(pWebview);
+       SysAssertf(pSettings, "Failed to get settings instance.");
+       ewk_settings_clear_text_selection_automatically_set(pSettings, true);
 
        return false;
 }
@@ -4723,18 +4768,23 @@ _WebImpl::OnFocusGained(const _ControlImpl& source)
 bool 
 _WebImpl::OnFocusLost(const _ControlImpl& source)
 {
+       Evas_Object* pWebview = __pWebCore->GetWebNativeNode();
+       if (!pWebview)
+       {
+               return false;
+       }
+
        if(IsKeypadVisible() == true)
        {
                SetKeypadOpened(true);
-
                SetKeypadVisibleState(false);
        }
 
-       Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
-       SysAssertf(pSettings, "Failed to get webkit instance.");
+       Ewk_Settings* pSettings = ewk_view_settings_get(pWebview);
+       SysAssertf(pSettings, "Failed to get settings instance.");
        ewk_settings_clear_text_selection_automatically_set(pSettings, false);
 
-       evas_object_focus_set(__pWebCore->GetWebNativeNode(), EINA_FALSE);
+       evas_object_focus_set(pWebview, EINA_FALSE);
 
        return false;
 }
@@ -4763,21 +4813,24 @@ _WebImpl::OnPreAttachedToMainTree(void)
                pWebManager->SetActiveWeb(this);
        }
 
-       r = __pWebCore->InitializeWebNativeNode();
+       r = _ContainerImpl::OnPreAttachedToMainTree();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       _ControlManager* pControlManager = _ControlManager::GetInstance();
-       SysTryReturnResult(NID_WEB_CTRL, pControlManager, E_SYSTEM, "Failed to get the ControlManager instance.");
-       OnChangeLayout(pControlManager->GetScreenRotation());
+       if (!HasValidNativeNode())
+       {
+               r = __pWebCore->InitializeWebNativeNode();
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       r = InitializeSetting();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+               _ControlManager* pControlManager = _ControlManager::GetInstance();
+               SysTryReturnResult(NID_WEB_CTRL, pControlManager, E_SYSTEM, "Failed to get the ControlManager instance.");
+               OnChangeLayout(pControlManager->GetScreenRotation());
 
-       r = _ContainerImpl::OnPreAttachedToMainTree();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+               r = InitializeSetting();
+               SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       _WebManager* pWebManager = _WebManager::GetInstance();
-       pWebManager->AddWeb(reinterpret_cast< int >(this));
+               _WebManager* pWebManager = _WebManager::GetInstance();
+               pWebManager->AddWeb(reinterpret_cast< int >(this));
+       }
 
        return E_SUCCESS;
 }
@@ -4786,14 +4839,13 @@ _WebImpl::OnPreAttachedToMainTree(void)
 result
 _WebImpl::OnDetachingFromMainTree(void)
 {
-       _WebManager* pWebManager = _WebManager::GetInstance();
-       pWebManager->RemoveWeb(reinterpret_cast< int >(this));
-       pWebManager->RemoveActiveWeb(this);     
+       result r = E_SUCCESS;
 
-       _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
-       pManagerImpl->SetDownloadListener(null);
+       _WebManager* pWebManager = _WebManager::GetInstance();
+       pWebManager->RemoveActiveWeb(this);
 
-       RemoveEventListenerCallback();
+       r = _ContainerImpl::OnDetachingFromMainTree();
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        return E_SUCCESS;
 }
@@ -4869,7 +4921,7 @@ void
 _WebImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
 {
        _ContainerImpl::OnUserEventReceivedN(requestId, pArgs);
-
+       
        switch (requestId)
        {
        case ID_CERTIFICATE_CONFIRM_POPUP_CLOSE:
@@ -4896,6 +4948,8 @@ _WebImpl::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::ILi
        default:
                break;
        }
+
+       Resume();
 }
 
 
@@ -4911,6 +4965,8 @@ _WebImpl::HideColorPicker(void)
 {
        __pColorPicker.reset();
 
+       Resume();
+
        return EINA_TRUE;
 }
 
@@ -4942,6 +4998,7 @@ CATCH:
        if (__pColorPicker)
        {
                __pColorPicker.reset();
+               Resume();
        }
 
        return r;
@@ -4973,6 +5030,7 @@ CATCH:
        if (__pDatePicker)
        {
                __pDatePicker.reset();
+               Resume();
        }
 
        return r;
@@ -5301,11 +5359,4 @@ _WebImpl::SetWebNotification(_WebNotification* pWebNotification)
 }
 
 
-void
-_WebImpl::OnDownloadCompleted(RequestId reqId, const String &path)
-{
-       _ContentManagerImpl::ScanFile(path);
-}
-
-
 }}} // Tizen::Web::Controls