fix potential bug of OnLoadingRequest and OnWebDataReceived
authorSeongjun Yim <se201.yim@samsung.com>
Fri, 23 Aug 2013 08:21:07 +0000 (17:21 +0900)
committerSeongjun Yim <se201.yim@samsung.com>
Fri, 23 Aug 2013 08:21:07 +0000 (17:21 +0900)
Change-Id: I7226bb6797b1bcb6e2ee75b090d55494be35dd7b
Signed-off-by: Seongjun Yim <se201.yim@samsung.com>
src/controls/FWebCtrl_WebImpl.cpp
src/controls/inc/FWebCtrl_WebImpl.h

index 2978d7f..ed21705 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>
@@ -913,13 +910,7 @@ 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()));
@@ -933,49 +924,61 @@ OnLoadingRequested(void* pUserData, Evas_Object* pView, void* pEventInfo)
                {
                        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;
        }
        
@@ -983,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"))
        {
@@ -1105,49 +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);
-
-       String* pFieldValue = null;
-       String compareHeader(L"");
-       std::unique_ptr<IEnumerator> pFieldValueEnum;
-
-       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());
 
-       const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
-       HttpHeader httpHeader;
-
-       eina_hash_foreach(pHeader, AddHttpHeaderData, &httpHeader);
-       SysTryCatch(NID_WEB_CTRL, GetLastResult() == E_SUCCESS, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
-
-       pFieldValueEnum = std::unique_ptr<IEnumerator>(httpHeader.GetFieldValuesN(L"Content-Disposition"));
-
-       if( pFieldValueEnum != null)
-       {
-               pFieldValueEnum->MoveNext();
-               pFieldValue = dynamic_cast< String* >(pFieldValueEnum->GetCurrent());
-               pFieldValue->SubString(0, 10, compareHeader);
-       }
-
-       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)))
        {
-               DecisionPolicy policy;
-
                if (code >= REDIRECTION_HEADER_GROUP && code < REDIRECTION_HEADER_GROUP + 100)
                {
                        pImpl->SetRedirectRequested(true);
                        mime = L"";
                }
 
-               policy = pLoadingListener->OnWebDataReceived(mime, httpHeader);
-               pImpl->SetPolicyDecision(policy);
+               ILoadingListener* pLoadingListener = pImpl->GetLoadingListener();
+               if (pLoadingListener)
+               {
+                       const Eina_Hash* pHeader = ewk_policy_decision_response_headers_get(pPolicy);
+                       HttpHeader httpHeader;
+
+                       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())
@@ -1164,11 +1152,10 @@ OnWebDataReceived(void* pUserData, Evas_Object* pView, void* pEventInfo)
                        return;
                }
 
-               if ( String::Compare(compareHeader, L"attachment") != 0 && (pImpl->IsMimeSupported(mime) || mime == L""))
+               if (ewk_policy_decision_type_get(pPolicy) == EWK_POLICY_DECISION_USE)
                {
                        break;
                }
-               
                else
                {
                        ewk_policy_decision_ignore(pPolicy);
@@ -1177,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_TPLATFORM_BODY_DOWNLOAD_ABB"), _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);
@@ -1205,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);
@@ -2174,9 +2151,6 @@ _WebImpl::_WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore)
 
 _WebImpl::~_WebImpl()
 {
-       _DownloadManagerImpl* pManagerImpl = _DownloadManagerImpl::GetInstance();
-       pManagerImpl->SetDownloadListener(null);
-
        _WebManager* pWebManager = _WebManager::GetInstance();
        pWebManager->RemoveWeb(reinterpret_cast< int >(this));
 
@@ -2268,11 +2242,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");
 
@@ -5375,11 +5344,4 @@ _WebImpl::SetWebNotification(_WebNotification* pWebNotification)
 }
 
 
-void
-_WebImpl::OnDownloadCompleted(RequestId reqId, const String &path)
-{
-       _ContentManagerImpl::ScanFile(path);
-}
-
-
 }}} // Tizen::Web::Controls
index 267719f..011ded6 100755 (executable)
@@ -28,7 +28,6 @@
 #include <EWebKit2.h>
 #include <FBaseColArrayList.h>
 #include <FBaseString.h>
-#include <FCntIDownloadListener.h>
 #include <FUiIActionEventListener.h>
 #include <FUiIOrientationEventListener.h>
 #include <FUiITextEventListener.h>
@@ -144,7 +143,6 @@ class _OSP_EXPORT_ _WebImpl
        : public Tizen::Ui::_ContainerImpl
        , public Tizen::Ui::ITextEventListener
        , public Tizen::Web::Controls::_IWebEventListener
-       , public Tizen::Content::IDownloadListener
 {
 public:
        _WebImpl(Web* pWeb, Tizen::Ui::_Control* pCore);
@@ -445,12 +443,6 @@ private:
        result OnHandleWebUiEventF(const Tizen::Base::Runtime::IEventArg& arg);
        result OnHandleTextSearchEvent(const Tizen::Base::Runtime::IEventArg& arg);
 
-       virtual void OnDownloadCanceled(RequestId reqId) {}
-       virtual void OnDownloadCompleted(RequestId reqId, const Tizen::Base::String &path);
-       virtual void OnDownloadFailed(RequestId reqId, result r, const Tizen::Base::String &errorCode) {}
-       virtual void OnDownloadInProgress(RequestId reqId, unsigned long long receivedSize, unsigned long long totalSize) {}
-       virtual void OnDownloadPaused(RequestId reqId) {}
-
 private:
        bool __isFooterVisible;
        bool __isKeypadVisible;