add patch
[framework/osp/web.git] / src / controls / FWebCtrl_AppControlListener.cpp
index 73e0349..5b2929e 100755 (executable)
  *
  * The file contains the definition of _AppControlListener classes.
  */
-#include <EWebKit2.h>
 #include <FAppAppControl.h>
 #include <FBaseSysLog.h>
-#include <FBaseUtilStringTokenizer.h>
+#include <FBaseUtilStringUtil.h>
 #include "FWebCtrl_AppControlListener.h"
 
 
@@ -99,63 +98,62 @@ _LocationSettingListener::OnAppControlCompleteResponseReceived(const Tizen::App:
 
 
 _MediaSelectionListener::_MediaSelectionListener(void)
-       : __isSelectionCompleted(false)
-       , __pSelectedFiles(null)
+       : __pWebFrame(null)
+       , __pMediaAppControl(null)
 {
 
 }
 
-
-_MediaSelectionListener::~_MediaSelectionListener(void)
+void
+_MediaSelectionListener::Construct(Evas_Object* pWebFrame, Tizen::App::AppControl* pMediaAppControl)
 {
-
+       __pWebFrame = pWebFrame;
+       std::unique_ptr<AppControl> pAppControl(pMediaAppControl);
+       __pMediaAppControl = std::move(pAppControl);
 }
 
 
-const ArrayList*
-_MediaSelectionListener::GetSelectedFiles(void) const
+_MediaSelectionListener::~_MediaSelectionListener(void)
 {
-       return __pSelectedFiles.get();
-}
 
-
-bool
-_MediaSelectionListener::IsSelectionCompleted(void) const
-{
-       return __isSelectionCompleted;
 }
 
 
 void
 _MediaSelectionListener::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& providerId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pAppData)
 {
-       __isSelectionCompleted = true;
-       SysTryReturnVoidResult(NID_WEB_CTRL, pAppData &&  providerId == L"tizen.filemanager" && operationId == L"http://tizen.org/appcontrol/operation/pick", E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments to _MediaSelectionListener::OnAppControlCompleted");
+       Eina_List* pSelectedFileNames = null;
+       ArrayList* pSelectedFiles = null;
+       int fileCount = 0;
 
-       std::unique_ptr<ArrayList, AllElementsDeleter> pSelectedFiles(new (std::nothrow) ArrayList());
-       SysTryReturnVoidResult(NID_WEB_CTRL, pSelectedFiles.get(), E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       SysTryCatch(NID_WEB_CTRL, pAppData, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments to _MediaSelectionListener::OnAppControlCompleted");
+       pSelectedFiles = dynamic_cast< ArrayList* >(const_cast< Object* >(pAppData->GetValue(String("http://tizen.org/appcontrol/data/selected"))));
+       SysTryCatch(NID_WEB_CTRL, pSelectedFiles, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       result r = pSelectedFiles->Construct();
-       SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
+       fileCount = pSelectedFiles->GetCount();
 
-       String *pFiles = static_cast< String* >(const_cast< Object* >(pAppData->GetValue(String("path"))));
-       SysTryReturnVoidResult(NID_WEB_CTRL, pFiles, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       StringTokenizer strTok(*pFiles, L";");
-       String token;
-
-       while (strTok.HasMoreTokens())
+       for (int i = 0; i < fileCount; i++)
        {
-               strTok.GetNextToken(token);
-               std::unique_ptr<String> pFile(new (std::nothrow) String(token));
-               SysTryReturnVoidResult(NID_WEB_CTRL, pFile, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+               String* pFile = static_cast<String*>(pSelectedFiles->GetAt(i));
+               SysTryCatch(NID_WEB_CTRL, pFile, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
 
-               r = pSelectedFiles->Add(*pFile);
-               SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
-               pFile.release();
+               std::unique_ptr<ByteBuffer> pByteBuf(StringUtil::StringToUtf8N(*pFile));
+               SysTryCatch(NID_WEB_CTRL, pByteBuf.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
+
+               pSelectedFileNames = eina_list_append(pSelectedFileNames, strdup((const char*)pByteBuf->GetPointer()));
+               SysTryCatch(NID_WEB_CTRL, pSelectedFileNames, , E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
        }
 
-       __pSelectedFiles = std::move(pSelectedFiles);
+       ewk_view_open_panel_reply(__pWebFrame, pSelectedFileNames, EINA_TRUE);
+       eina_list_free(pSelectedFileNames);
+
+       delete this;
+       return;
+
+CATCH:
+       ewk_view_open_panel_reply(__pWebFrame, null, EINA_FALSE);
+       eina_list_free(pSelectedFileNames);
+       delete this;
 }