Fix for issue about popup crash
[framework/osp/web.git] / src / controls / FWebCtrl_UserConfirmPopup.cpp
index 2ee0b45..5f6543b 100755 (executable)
@@ -19,6 +19,7 @@
  * @file               FWebCtrl_UserConfirmPopup.cpp
  * @brief              The file contains the definition of _UserConfirmPopup class.
  */
+#include <EWebKit2.h>
 #include <FAppApp.h>
 #include <FBaseColArrayList.h>
 #include <FBaseSysLog.h>
@@ -31,6 +32,7 @@
 #include <FUiCtrlButton.h>
 #include <FUiCtrlLabel.h>
 #include <FUiCtrlPanel.h>
+#include <FUiKeyEventInfo.h>
 #include <FUiLayout.h>
 #include <FUiVerticalBoxLayout.h>
 #include <FIo_DatabaseImpl.h>
@@ -63,17 +65,23 @@ _UserConfirmPopup::_UserConfirmPopup(void)
        , __userConfirmMode(USER_CONFIRM_USERMEDIA)
        , __pCheckButton(null)
        , __sync(false)
+       , __pImpl(null)
 {
 }
 
 
 _UserConfirmPopup::~_UserConfirmPopup(void)
 {
+       
+       if (IsModalPopup())
+       {
+               HandleUserAction(EINA_FALSE);
+       }
 }
 
 
 result
-_UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, bool sync, String msg)
+_UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo, Tizen::Web::Controls::_WebImpl* pImpl, bool sync, String msg)
 {
        result r = E_SUCCESS;
        SysTryReturnResult(NID_WEB_CTRL, pEventInfo, E_INVALID_ARG, "Invalid argument(s) is used. pPolicy is null.");
@@ -91,7 +99,10 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
        __sync = sync;
 
        bool hasTitle = true;
-       int popupMaxHeight = 2*pPopupData->labelDim.height + 2*pPopupData->btnDim.height + 6*pPopupData->sideMargin;
+       int popupMaxHeight = 2*pPopupData->labelDim.height + pPopupData->btnDim.height + 2*pPopupData->sideMargin;
+
+       __pImpl = pImpl;
+       SysAssertf(__pImpl != null, "Failed to get _WebImpl");
 
        if (__userConfirmMode == USER_CONFIRM_GEOLOCATION)
        {
@@ -100,7 +111,7 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
 
        if (__userConfirmMode == USER_SCRIPT_ALERT)
        {
-               popupMaxHeight -=  pPopupData->labelDim.height;
+               popupMaxHeight -=  2*pPopupData->sideMargin;
                hasTitle = false;
        }
 
@@ -168,16 +179,17 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
        r = titleList.Construct();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
-       idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
        if (userConfirmMode == USER_SCRIPT_ALERT)
        {
+               idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
                titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_OK"))));
        }
        else
        {
                idList.Add(*(new Integer(ID_BUTTON_USER_CANCEL)));
-               titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
+               idList.Add(*(new Integer(ID_BUTTON_USER_ALLOW)));
                titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_CANCEL"))));
+               titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_BR_OPT_ALLOW"))));
        }
 
        r = CreateAndAddButtons(idList, titleList, pButtonPanel);
@@ -193,8 +205,12 @@ _UserConfirmPopup::Construct(_UserConfirmMode userConfirmMode, void* pEventInfo,
        }
        pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
 
-       pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
+       if ( __userConfirmMode != USER_SCRIPT_ALERT )
+       {
+               pLayout->SetSpacing(*pButtonPanel, 2*pPopupData->sideMargin);
+       }
 
+       SetPropagatedKeyEventListener(this);
        return E_SUCCESS;
 }
 
@@ -226,7 +242,36 @@ _UserConfirmPopup::OnActionPerformed(const Control& source, int actionId)
 
        if (!__sync)
        {
-               GetOwner()->SendUserEvent(ID_USER_CONFIRM_POPUP_CLOSE, null);
+               switch(__userConfirmMode)
+               {
+               case USER_CONFIRM_USERMEDIA:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
+                       break;
+               }
+               case USER_CONFIRM_GEOLOCATION:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
+                       break;
+               }
+               case USER_CONFIRM_NOTIFICATION:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
+                       break;
+               }
+               case USER_SCRIPT_ALERT:
+               {
+                       __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
+                       break;
+               }
+               case USER_SCRIPT_CONFIRM:
+               {
+                       __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
+                       break;
+               }
+               default:
+                       SysAssert(false);
+               }
        }
 }
 
@@ -338,6 +383,12 @@ CATCH:
                ewk_view_javascript_alert_reply(pView);
                break;
        }
+       case USER_SCRIPT_CONFIRM:
+       {
+               Evas_Object* pView = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
+               ewk_view_javascript_confirm_reply(pView, allow);
+               break;
+       }
        case USER_CONFIRM_APP_CACHE:
        {
                Evas_Object *pObj = reinterpret_cast< Evas_Object* >(__pUserPolicyData);
@@ -398,6 +449,7 @@ _UserConfirmPopup::AddGeolocationDb(Ewk_Geolocation_Permission_Request* pPolicy,
        return E_SUCCESS;
 }
 
+
 void
 _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
 {
@@ -462,4 +514,84 @@ _UserConfirmPopup::RegisterHandler(bool checkHandler, Eina_Bool allow)
        }
 }
 
+bool
+_UserConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_UserConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       result r = E_SUCCESS;
+       if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
+       {
+               HandleUserAction(EINA_FALSE);
+               r = HidePopup();
+
+               if (IsFailed(r))
+               {
+                       SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
+               }
+               
+               switch (__userConfirmMode)
+               {
+               case USER_CONFIRM_USERMEDIA:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_USERMEDIA_CLOSE, null);
+                       break;
+               }
+               case USER_CONFIRM_GEOLOCATION:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_GEOLOCATION_CLOSE, null);
+                       break;
+               }
+               case USER_CONFIRM_NOTIFICATION:
+               {
+                       __pImpl->SendUserEvent(ID_USER_CONFIRM_NOTIFICATION_CLOSE, null);
+                       break;
+               }
+               case USER_SCRIPT_ALERT:
+               {
+                       __pImpl->SendUserEvent(ID_USER_SCRIPT_ALERT_CLOSE, null);
+                       break;
+               }
+               case USER_SCRIPT_CONFIRM:
+               {
+                       __pImpl->SendUserEvent(ID_USER_SCRIPT_CONFIRM_CLOSE, null);
+                       break;
+               }
+               case USER_PROTOCOL_HANDLER:
+               case USER_CONTENT_HANDLER:
+               case USER_CONFIRM_APP_CACHE:
+               case USER_CONFIRM_DB_QUOTA_EXCEDED:
+               case USER_CONFIRM_LOCAL_FS_QUOTA_EXCEDED:
+               case USER_CONFIRM_INDEXED_DB_QUOTA_EXCEDED:
+                       break;
+               default:
+                       SysAssert(false);
+               }
+       }
+       return false;
+}
+
+bool
+_UserConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_UserConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+bool
+_UserConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
+{
+       return false;
+}
+
+
 }}} // Tizen::Web::Controls