fix lock up issue for download
[framework/osp/web.git] / src / controls / FWebCtrl_WebImpl.cpp
index e541ffd..96c8b32 100755 (executable)
 #include "FWebCtrl_WebEvent.h"
 #include "FWebCtrl_WebEventArg.h"
 #include "FWebCtrl_WebImpl.h"
+#include "FWebCtrl_WebManager.h"
 #include "FWebCtrl_WebPresenter.h"
 #include "FWebCtrl_WebSettingImpl.h"
 
@@ -361,7 +362,6 @@ OnScriptConfirmRequested(Evas_Object* pView, const char* pMessage, void* pUserDa
        SysLog(NID_WEB_CTRL, "The current value of message is %s", pMessage);
 
        result r = E_SUCCESS;
-       _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
        String msg(pMessage);
 
        MessageBox messageBox;
@@ -370,8 +370,6 @@ OnScriptConfirmRequested(Evas_Object* pView, const char* pMessage, void* pUserDa
 
        int modalResult = 0;
 
-       messageBox.SetOwner(&pImpl->GetPublic());
-
        r = messageBox.ShowAndWait(modalResult);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, EINA_FALSE, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -462,7 +460,10 @@ OnCertificateRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
                        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
                }
 
-               pImpl->SetCertificateRequested(true);
+               if (pImpl)
+               {
+                       pImpl->SetCertificateRequested(true);
+               }
                break;
        }
        case WEB_CERTIFICATE_ERROR_HANDLING_MODE_CANCEL:
@@ -1128,8 +1129,6 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
                {
                        ewk_policy_decision_ignore(pPolicy);
 
-                       _SelectBox selectBox;
-                       int selectedIndex = 0;
                        String operationId(L"http://tizen.org/appcontrol/operation/view");
 
                        r = _AppControlImpl::FindAndStart(operationId, &url, &mime, null, null, null);
@@ -1137,24 +1136,15 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
        
                        if (r == E_OBJ_NOT_FOUND)
                        {
-                               r = selectBox.Construct(false, L"Select application", 1); //+1 for Downloader
-                               SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+                               _SelectBox* pSelectBox = new (std::nothrow) _SelectBox;
+                               SysTryReturnVoidResult(NID_WEB_CTRL, pSelectBox, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-                               selectBox.AddListItem(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_BODY_DOWNLOAD"), _SelectBox::LIST_ITEM_TYPE_NORMAL, false);
-                               r = selectBox.ShowAndWait(selectedIndex);
+                               r = pSelectBox->Construct(false, L"Select application", 1, null, url);
                                SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
 
-                               if (selectedIndex == 0) //download
-                               {
-                                       RequestId reqId = 0;
-                                       DownloadRequest request(pUrl);
-
-                                       _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
-                                       SysTryReturnVoidResult(NID_WEB_CTRL, pManagerImpl, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-                                       r = pManagerImpl->Start(request, reqId);
-                                       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;
@@ -1299,13 +1289,6 @@ OnLoadingCompleted(void* pUserData, Evas_Object* pView, void* pEventInfo)
 
 
 void
-OnLoadingCommitted(void* pUserData, Evas_Object* pView, void* pEventInfo)
-{
-       evas_object_focus_set(pView, EINA_FALSE);
-}
-
-
-void
 OnFaviconReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
 {
        _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
@@ -1591,44 +1574,6 @@ OnWebPageBlockSelected(void* pUserData, Evas_Object* pView, void* pEventInfo)
 }
 
 
-void
-OnWebPageBlockSelectedByOrientation(void* pUserData, Evas_Object* pView, void* pEventInfo)
-{
-       _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
-       SysAssertf(pImpl, "Failed to request");
-
-       if (!pImpl->IsOrientationChanged())
-       {
-               return;
-       }
-
-       pImpl->SetOrientationChanged(false);
-
-       int orientation = 0;
-       _ControlRotation rotation = _ControlManager::GetInstance()->GetOrientationStatus();
-       switch (rotation)
-       {
-               case _CONTROL_ROTATION_0:
-                       orientation =  0;
-                       break;
-               case _CONTROL_ROTATION_90:
-                       orientation =  90;
-                       break;
-               case _CONTROL_ROTATION_180:
-                       orientation =  180;
-                       break;
-               case _CONTROL_ROTATION_270:
-                       orientation =  -90;
-                       break;
-       }
-       ewk_view_orientation_send(pView, orientation);
-
-       OnWebPageBlockSelected(pUserData, pView, pEventInfo);
-
-       SysLog(NID_WEB_CTRL, "Enter.");
-}
-
-
 Eina_Bool
 OnSelectUploadFile(Evas_Object* pView, Eina_Bool multipleFile, Eina_List* pAcceptTypes, const char* pCapture, void* pUserData)
 {
@@ -1750,6 +1695,11 @@ OnWebKeypadStateChanged(void* pUserData, Evas_Object* pView, void* pEventInfo)
        Eina_Rectangle* pEinaRect = reinterpret_cast< Eina_Rectangle* >(pEventInfo);
        SysAssertf(pImpl && pEinaRect, "Failed to request");
 
+       if (pImpl->IsVisible() == false)
+       {
+               evas_object_focus_set(pView, EINA_FALSE);
+       }
+
        if (pImpl->GetSetting().GetInputStyle() == INPUT_STYLE_OVERLAY)
        {
                _ICoordinateSystemTransformer* pXformer = _CoordinateSystem::GetInstance()->GetInverseTransformer();
@@ -1845,15 +1795,15 @@ OnWindowObjectFocusGained(void* pUserData, Evas_Object* pWin, void* pEvent_info)
        _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(pUserData);
        SysAssertf(pImpl, "Failed to request");
 
-       if (pImpl->IsKeypadOpened() == true && pImpl->IsVisible() == true)
+       if (pImpl->IsKeypadOpened() == true && pImpl->IsVisible() == true && pImpl->IsFocused() == true)
        {
                _Web* pWebCore = dynamic_cast< _Web* >(&(pImpl->GetCore()));
                SysAssertf(pWebCore, "Failed to get Web core object");
 
                evas_object_focus_set(pWebCore->GetWebNativeNode(), EINA_TRUE);
-       }
 
-       pImpl->SetKeypadOpened(false);
+               pImpl->SetKeypadVisibleState(true);
+       }
 }
 
 
@@ -1865,9 +1815,7 @@ OnWebNativeNodeFocusGained(void* pUserData, Evas* pCanvas, Evas_Object* pView, v
 
        if (pImpl->IsKeypadOpened() == true)
        {
-               pImpl->SetKeypadOpened(false);
-
-               pImpl->SetFocused();
+               pImpl->SetKeypadOpened(false);  
        }
 } 
 
@@ -2108,7 +2056,8 @@ OnScriptExecuted(Evas_Object* pView, const char* pResult, void* pUserData)
        SysLog(NID_WEB_CTRL, "result : %ls", result.GetPointer());
 
        _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, WEB_CTRL));
-       if (pImpl && pImpl->IsPresenterAlived(pPresenter))
+       _WebManager* pWebManager = _WebManager::GetInstance();
+       if (pWebManager->IsValidCallback(reinterpret_cast< int >(pImpl), reinterpret_cast< int >(pPresenter)))
        {
                pPresenter->EndAsyncProcess(result);
        }
@@ -2221,7 +2170,6 @@ _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
        , __isRedirectRequested(false)
        , __isCertificateRequested(false)
        , __isCertificateConfirmed(false)
-       , __isOrientationChanged(false)
        , __isFormDataVisible(false)
        , __keypadBounds(0, 0, 0, 0)
        , __pWebCore(null)
@@ -2271,6 +2219,9 @@ _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
 
 _WebImpl::~_WebImpl()
 {
+       _WebManager* pWebManager = _WebManager::GetInstance();
+       pWebManager->RemoveWeb(reinterpret_cast< int >(this));
+
        _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
        pManagerImpl->SetDownloadListener(null);
 
@@ -2352,9 +2303,6 @@ _WebImpl::Construct(void)
        r = __textSearch.__searchQueue.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       r = __callbackList.Construct();
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
-
        r = __webNotificationList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -2372,6 +2320,9 @@ _WebImpl::Construct(void)
        __pWebCore = dynamic_cast< _Web* >(&(GetCore()));
        SysTryReturnResult(NID_WEB_CTRL, __pWebCore, E_SYSTEM, "A system error has been occurred. Failed to get web control");
 
+       _WebManager* pWebManager = _WebManager::GetInstance();
+       pWebManager->AddWeb(reinterpret_cast< int >(this));
+
        return E_SUCCESS;
 }
 
@@ -2564,8 +2515,6 @@ _WebImpl::ShowSelectBoxPopup(bool isMultiSelect, const String& title, Eina_List*
 
        __pSelectBox = std::move(pSelectBox);
 
-       __pSelectBox->SetOwner(&GetPublic());
-
        return __pSelectBox->ShowPopup();
 }
 
@@ -2679,35 +2628,20 @@ _WebImpl::EvaluateJavascriptN(const String& scriptCode)
                return null;
        }
        
-       result r = E_SUCCESS;
-
        std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
        SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-       std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter());
+       std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
        SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       r = __callbackList.Add(pPresenter.get());
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
        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));
-       pPresenter->WaitAsyncProcess(*pResult.get());
-       
-       r = __callbackList.Remove(*pPresenter.get());
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-       pPresenter.release();
-       
-       return pResult.release();
-}
 
+       pPresenter->WaitAsyncProcess(*pResult.get());
 
-bool
-_WebImpl::IsPresenterAlived(_WebPresenter* pPresenter) const
-{
-       return __callbackList.Contains(*pPresenter);
+       return pResult.release();
 }
 
 
@@ -2827,14 +2761,14 @@ _WebImpl::SearchText(const String& text, bool searchForward)
            condition = static_cast < Ewk_Find_Options >(condition | EWK_FIND_OPTIONS_BACKWARDS);
        }
 
-       _WebPresenter presenter;
-       presenter.InitAsyncProcess();
+       std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
+       SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       r = SynchronizeSearch(SEARCH_SYNC, pView, condition, text, searchForward, false, &presenter);
-       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+       r = SynchronizeSearch(SEARCH_SYNC, pView, condition, text, searchForward, false, pPresenter.get());
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, false, r, "[%s] Propagating.", GetErrorMessage(r));
 
        int result = 0;
-       presenter.WaitAsyncProcess(result);
+       pPresenter->WaitAsyncProcess(result);
 
        return static_cast < bool >(result);
 }
@@ -3329,13 +3263,13 @@ _WebImpl::IsCookieEnabled(void) const
        Ewk_Cookie_Manager* pCookieManager =  ewk_context_cookie_manager_get(pContext);
        SysAssertf(pCookieManager, "Failed to get webkit instance.");
 
-       _WebPresenter presenter;
-       presenter.InitAsyncProcess();
+       std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter(this));
+       SysTryReturn(NID_WEB_CTRL, pPresenter.get(), false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, &presenter);
+       ewk_cookie_manager_async_accept_policy_get(pCookieManager, OnCookiesPolicyGot, pPresenter.get());
 
        bool result = false;
-       presenter.WaitAsyncProcess(result);
+       pPresenter->WaitAsyncProcess(result);
 
        return result;
 }
@@ -3642,7 +3576,6 @@ _WebImpl::SetEventListenerCallback(void) const
                evas_object_smart_callback_add(pWebNativeNode, "load,stop", OnLoadingCanceled, this);
                evas_object_smart_callback_add(pWebNativeNode, "load,error", OnLoadingErrorOccurred, this);
                evas_object_smart_callback_add(pWebNativeNode, "title,changed", OnPageTitleReceived, this);
-               evas_object_smart_callback_add(pWebNativeNode, "load,committed", OnLoadingCommitted, this);
 
                evas_object_smart_callback_add(pWebNativeNode, "requestToNative,json", OnHandleJavaScriptRequest, this);
 
@@ -3684,7 +3617,6 @@ _WebImpl::SetEventListenerCallback(void) const
                evas_object_smart_callback_add(pWebNativeNode, "icon,received", OnFaviconReceived, this);
 
                evas_object_smart_callback_add(pWebNativeNode, "text,selected", OnWebPageBlockSelected, this);
-               evas_object_smart_callback_add(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation, this);
 
                evas_object_smart_callback_add(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered, this);
                evas_object_smart_callback_add(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited, this);
@@ -3769,7 +3701,6 @@ _WebImpl::RemoveEventListenerCallback(void) const
                evas_object_smart_callback_del(pWebNativeNode, "icon,received", OnFaviconReceived);
 
                evas_object_smart_callback_del(pWebNativeNode, "text,selected", OnWebPageBlockSelected);
-               evas_object_smart_callback_del(pWebNativeNode, "frame,rendered", OnWebPageBlockSelectedByOrientation);
 
                evas_object_smart_callback_del(pWebNativeNode, "fullscreen,enterfullscreen", OnFullScreenEntered);
                evas_object_smart_callback_del(pWebNativeNode, "fullscreen,exitfullscreen", OnFullScreenExited);
@@ -3987,7 +3918,7 @@ _WebImpl::GetPageSize(void) const
 
 
 result
-_WebImpl::AddCustomHeader(const String& name, const String& value)
+_WebImpl::AddHttpHeaderField(const String& name, const String& value)
 {
        SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing.");
 
@@ -4003,7 +3934,7 @@ _WebImpl::AddCustomHeader(const String& name, const String& value)
 
 
 result
-_WebImpl::RemoveCustomHeader(const String& name)
+_WebImpl::RemoveHttpHeaderField(const String& name)
 {
        SysTryReturnResult(NID_WEB_CTRL, name.GetLength() > 0, E_INVALID_ARG, "Invalid argument(s) is used. name key is missing.");
 
@@ -4086,20 +4017,6 @@ _WebImpl::IsCertificateConfirmed(void) const
 }
 
 
-void
-_WebImpl::SetOrientationChanged(bool arg)
-{
-       __isOrientationChanged = arg;
-}
-
-
-bool
-_WebImpl::IsOrientationChanged(void) const
-{
-       return __isOrientationChanged;
-}
-
-
 result
 _WebImpl::SetFullScreenKeypad(void)
 {
@@ -4617,13 +4534,14 @@ _WebImpl::ShowAuthenticationPopup(const String& host, const String& realm, Authe
 
        int modalResult = 0;
 
-       __pAuthPopup->SetOwner(&GetPublic());
-       
        r = __pAuthPopup->ShowAndWait(modalResult);
        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
 CATCH:
-       __pAuthPopup.reset();
+       if (__pAuthPopup)
+       {
+               __pAuthPopup.reset();
+       }
 
        return r;
 }
@@ -4644,18 +4562,19 @@ _WebImpl::ShowCertificateConfirmPopup(_CertificatePopupMode userConfirmMode, Ewk
 
        int modalResult = 0;
 
-       __pCertConfirmPopup->SetOwner(&GetPublic());
-       
        r = __pCertConfirmPopup->ShowAndWait(modalResult);
        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-       if (userConfirmMode == CERTIFICATE_POPUP_MODE_USER_CONFIRM)
+       if (__pCertConfirmPopup.get() && userConfirmMode == CERTIFICATE_POPUP_MODE_USER_CONFIRM)
        {
                __isCertificateConfirmed = __pCertConfirmPopup->GetConfirmResult();
        }
 
 CATCH:
-       __pCertConfirmPopup.reset();
+       if (__pCertConfirmPopup.get())
+       {
+               __pCertConfirmPopup.reset();
+       }
 
        return r;
 }
@@ -4669,13 +4588,11 @@ _WebImpl::ShowPromptPopup(String msg, String defVal)
        std::unique_ptr< _PromptPopup > pPromptPopup(new (std::nothrow) _PromptPopup());
        SysTryReturnResult(NID_WEB_CTRL, pPromptPopup.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
 
-       r = pPromptPopup->Construct(msg, defVal, __pWebCore->GetWebNativeNode());
+       r = pPromptPopup->Construct(msg, defVal, __pWebCore->GetWebNativeNode(), this);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
        __pPromptPopup = std::move(pPromptPopup);
 
-       __pPromptPopup->SetOwner(&GetPublic());
-
        r = __pPromptPopup->ShowPopup();
        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -4700,8 +4617,6 @@ _WebImpl::ShowUserConfirmPopup(_UserConfirmMode userConfirmMode, void* pPolicy,
        r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, true, msg);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pUserConfirmPopup->SetOwner(&GetPublic());
-
        int modalResult = 0;
 
        switch(userConfirmMode)
@@ -4785,8 +4700,6 @@ _WebImpl::ShowUserConfirmPopupAsync(_UserConfirmMode userConfirmMode, void* pPol
        r = pUserConfirmPopup->Construct(userConfirmMode, pPolicy, false, msg);
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       pUserConfirmPopup->SetOwner(&GetPublic());
-
        switch(userConfirmMode)
        {
        case USER_CONFIRM_USERMEDIA:
@@ -4873,6 +4786,12 @@ _WebImpl::GetParentFormCore(_Control* pControlCore)
 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_focus_set(__pWebCore->GetWebNativeNode(), EINA_TRUE);
+
        return false;
 }
 
@@ -4887,6 +4806,10 @@ _WebImpl::OnFocusLost(const _ControlImpl& source)
                SetKeypadVisibleState(false);
        }
 
+       Ewk_Settings* pSettings = ewk_view_settings_get(__pWebCore->GetWebNativeNode());
+       SysAssertf(pSettings, "Failed to get webkit instance.");
+       ewk_settings_clear_text_selection_automatically_set(pSettings, false);
+
        evas_object_focus_set(__pWebCore->GetWebNativeNode(), EINA_FALSE);
 
        return false;
@@ -4924,12 +4847,36 @@ _WebImpl::OnPreAttachedToMainTree(void)
 
 
 void
+_WebImpl::OnChangeLayout(_ControlRotation rotation)
+{
+       int degree = 0;
+
+       switch (rotation)
+       {
+               case _CONTROL_ROTATION_0:
+                       degree =  0;
+                       break;
+               case _CONTROL_ROTATION_90:
+                       degree =  90;
+                       break;
+               case _CONTROL_ROTATION_180:
+                       degree =  180;
+                       break;
+               case _CONTROL_ROTATION_270:
+                       degree =  -90;
+                       break;
+               default:
+                       SysAssert(false);
+       }
+       ewk_view_orientation_send(__pWebCore->GetWebNativeNode(), degree);
+}
+
+
+void
 _WebImpl::OnChangeLayout(_ControlOrientation orientation)
 {
        _ContainerImpl::OnChangeLayout(orientation);
 
-       __isOrientationChanged = true;
-
        if (__pColorPicker.get())
        {
                __pColorPicker->ChangeLayout(orientation);
@@ -5027,12 +4974,16 @@ _WebImpl::ShowColorPicker(int red, int green, int blue, int alpha, Color& color)
        r = __pColorPicker->ShowPopup();
        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-       color = __pColorPicker->GetColor();
-
-       return E_SUCCESS;
+       if (__pColorPicker)
+       {
+               color = __pColorPicker->GetColor();
+       }
 
 CATCH:
-       __pColorPicker.reset();
+       if (__pColorPicker)
+       {
+               __pColorPicker.reset();
+       }
 
        return r;
 }
@@ -5054,10 +5005,16 @@ _WebImpl::ShowDatePicker(Ewk_Input_Type inputType, const char* inputValue, Strin
        r = __pDatePicker->ShowPopup();
        SysTryCatch(NID_WEB_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
-       dateStr = __pDatePicker->GetDate();
+       if (__pDatePicker)
+       {
+               dateStr = __pDatePicker->GetDate();
+       }
 
 CATCH:
-       __pDatePicker.reset();
+       if (__pDatePicker)
+       {
+               __pDatePicker.reset();
+       }
 
        return r;
 }