fix crash issue submit/tizen_2.1/20130514.054703
authorSeongjun Yim <se201.yim@samsung.com>
Fri, 10 May 2013 14:21:32 +0000 (23:21 +0900)
committerSeongjun Yim <se201.yim@samsung.com>
Fri, 10 May 2013 14:21:32 +0000 (23:21 +0900)
Change-Id: I0daadb031f45b9696c321c7c08efae346bbc2f4b
Signed-off-by: Seongjun Yim <se201.yim@samsung.com>
inc/FWebCtrlWeb.h
src/controls/FWebCtrl_WebImpl.cpp
src/controls/FWebCtrl_WebImpl.h

index ce14a5c..148f3d4 100755 (executable)
@@ -424,7 +424,7 @@ public:
         * @privilege   %http://tizen.org/privilege/web.service
         *
         * @return              The result of the evaluated JavaScript, @n
-        *                                      else an empty string if an error occurs
+        *                                      else null if an error occurs
         * @param[in]   scriptCode              The JavaScript code as string
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_PRIVILEGE_DENIED      The application does not have the privilege to call this method.
index 39855d0..1894dbc 100755 (executable)
@@ -1911,7 +1911,11 @@ OnScriptExecuted(Evas_Object* pView, const char* pResult, void* pUserData)
        String result(pResult);
        SysLog(NID_WEB_CTRL, "result : %ls", result.GetPointer());
 
-       pPresenter->EndAsyncProcess(result);
+       _WebImpl* pImpl = reinterpret_cast< _WebImpl* >(evas_object_data_get(pView, WEB_CTRL));
+       if (pImpl && pImpl->IsPresenterAlived(pPresenter))
+       {
+               pPresenter->EndAsyncProcess(result);
+       }
 }
 
 
@@ -2134,6 +2138,9 @@ _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 = InitJsBridgeList();
        SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
 
@@ -2443,27 +2450,42 @@ _WebImpl::Reload(void) const
 
 
 String*
-_WebImpl::EvaluateJavascriptN(const String& scriptCode) const
+_WebImpl::EvaluateJavascriptN(const String& scriptCode)
 {
-       if (scriptCode.GetLength())
+       if (scriptCode.GetLength() == 0)
        {
-               std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
-               SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+               return null;
+       }
+       
+       result r = E_SUCCESS;
 
-               std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter());
-               SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-               pPresenter->InitAsyncProcess();
+       std::unique_ptr<char[]> pScript(_StringConverter::CopyToCharArrayN(scriptCode));
+       SysTryReturn(NID_WEB_CTRL, pScript.get(), null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-               ewk_view_script_execute(__pWebCore->GetWebNativeNode(), pScript.get(), OnScriptExecuted, pPresenter.get());
+       std::unique_ptr<_WebPresenter> pPresenter(new (std::nothrow) _WebPresenter());
+       SysTryReturn(NID_WEB_CTRL, pPresenter.get(), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-               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.Add(pPresenter.get());
+       SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
 
-               return pResult.release();
-       }
+       ewk_view_script_execute(__pWebCore->GetWebNativeNode(), pScript.get(), OnScriptExecuted, pPresenter.get());
 
-       return null;
+       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();
+}
+
+
+bool
+_WebImpl::IsPresenterAlived(_WebPresenter* pPresenter) const
+{
+       return __callbackList.Contains(*pPresenter);
 }
 
 
index 983e2c6..1c61205 100755 (executable)
@@ -26,6 +26,7 @@
 
 #include <unique_ptr.h>
 #include <EWebKit2.h>
+#include <FBaseColArrayList.h>
 #include <FBaseString.h>
 #include <FUiIActionEventListener.h>
 #include <FUiIOrientationEventListener.h>
@@ -191,7 +192,7 @@ public:
 
        Tizen::Base::String GetTextFromBlock(void) const;
 
-       Tizen::Base::String* EvaluateJavascriptN(const Tizen::Base::String& scriptCode) const;
+       Tizen::Base::String* EvaluateJavascriptN(const Tizen::Base::String& scriptCode);
 
        bool IsPrivateBrowsingEnabled(void) const;
 
@@ -330,6 +331,7 @@ public:
 
        void SetKeypadOpened(bool isKeypadOpened);
 
+       bool IsPresenterAlived(_WebPresenter* pPresenter) const;
        Tizen::Graphics::Rectangle GetPreviousKeypadBounds(void) const;
 
        void SetPreviousKeypadBounds(Tizen::Graphics::Rectangle& bounds);
@@ -454,6 +456,8 @@ private:
 
        _TextSearch __textSearch;
 
+       Tizen::Base::Collection::ArrayList __callbackList;
+
        DecisionPolicy __policy;
 
        Tizen::Base::String __defaultUserAgent;