Update wrt-installer_0.0.54
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.cpp
index 24db446..059a957 100755 (executable)
@@ -30,6 +30,7 @@
 #include <dpl/assert.h>
 #include <dpl/sstream.h>
 #include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <dpl/utils/file_utils.h>
 #include "root_parser.h"
 #include "widget_parser.h"
 #include "parser_runner.h"
@@ -38,6 +39,7 @@
 #include <widget_install/task_certify.h>
 #include <widget_install/task_widget_config.h>
 #include <widget_install/task_db_update.h>
+#include <widget_install/task_file_manipulation.h>
 #include <widget_install/task_ace_check.h>
 #include <widget_install/task_smack.h>
 #include <widget_install/task_manifest_file.h>
@@ -130,9 +132,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
     m_exceptionCaught(Exceptions::Success)
 {
     // Check installation type (config.xml or widget.wgt)
-    m_installerContext.browserRequest = hasExtension(widgetPath, XML_EXTENSION);
+    bool browserRequest = hasExtension(widgetPath, XML_EXTENSION);
 
-    LogInfo("Hosted app installation: " << m_installerContext.browserRequest);
+    LogInfo("Hosted app installation: " << browserRequest);
 
     struct timeval tv;
     gettimeofday(&tv, NULL);
@@ -146,17 +148,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
     m_installerContext.widgetHandle = handle;
     m_installerContext.m_quiet = m_jobStruct.m_quiet;
 
-    m_installerContext.widgetConfig.pType = checkPackageType(widgetPath);
+    if(!browserRequest)
+    {
+        m_installerContext.widgetConfig.pType = checkPackageType(widgetPath);
+    }
+    else
+    {
+        m_installerContext.widgetConfig.pType = WrtDB::PKG_TYPE_TIZEN_WEBAPP;
+    }
+    LogDebug("widgetPath:" << widgetPath);
 
-    ConfigParserData configData = getWidgetDataFromXML(widgetPath,
-            m_installerContext.browserRequest,
+    ConfigParserData configData = getWidgetDataFromXML(widgetPath, browserRequest,
             m_installerContext.widgetConfig.pType);
     WidgetUpdateInfo update = detectWidgetUpdate(configData);
+
     bool needEncryption = detectResourceEncryption(configData);
 
+
     // Configure installation
-    ConfigureResult result = ConfigureInstallation(widgetPath,
-            m_installerContext.browserRequest, update);
+    ConfigureResult result = ConfigureInstallation(widgetPath, update);
     if (!setTizenId(configData)) {
         result = ConfigureResult::Failed;
     } else {
@@ -164,6 +174,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         LogInfo("WidgetHandle: " << m_installerContext.widgetHandle);
         LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname);
 
+        configureWidgetLocation(widgetPath, browserRequest);
+
         // send start signal of pkgmgr
         PkgmgrSignalSingleton::Instance().setPkgname(
                     DPL::ToUTF8String(
@@ -172,22 +184,25 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
                     PKGMGR_START_KEY,
                     PKGMGR_START_INSTALL);
     }
-
     if (result == ConfigureResult::Ok) {
         LogInfo("Configure installation succeeded");
 
         AddTask(new TaskRecovery(m_installerContext));
 
         // Create installation tasks
-        if (!m_installerContext.browserRequest) {
+        if (!m_installerContext.locations->browserRequest()) {
             AddTask(new TaskUnzip(m_installerContext));
         }
         AddTask(new TaskWidgetConfig(m_installerContext));
+        if (m_installerContext.locations->browserRequest()) {
+            AddTask(new TaskPrepareFiles(m_installerContext));
+        }
         AddTask(new TaskCertify(m_installerContext));
         if (needEncryption) {
             AddTask(new TaskEncryptResource(m_installerContext));
         }
         AddTask(new TaskDbUpdate(m_installerContext));
+        AddTask(new TaskFileManipulation(m_installerContext));
         // TODO: Update progress information for this task
 
         AddTask(new TaskPrivateStorage(m_installerContext));
@@ -206,10 +221,13 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         LogInfo("Configure installation updated");
         LogInfo("Widget Update");
 
-        if (!m_installerContext.browserRequest) {
+        if (!m_installerContext.locations->browserRequest()) {
             AddTask(new TaskUnzip(m_installerContext));
         }
         AddTask(new TaskWidgetConfig(m_installerContext));
+        if (m_installerContext.locations->browserRequest()) {
+            AddTask(new TaskPrepareFiles(m_installerContext));
+        }
 
         AddTask(new TaskCertify(m_installerContext));
         AddTask(new TaskUpdateFiles(m_installerContext));
@@ -339,9 +357,24 @@ DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
     return m_installerContext.widgetHandle;
 }
 
+void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, bool browserRequest)
+{
+    Try
+    {
+        m_installerContext.locations = WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname),
+                    widgetPath, browserRequest, m_installerContext.widgetConfig.pType);
+    }
+    Catch(FileUtils::CreateDirectoryException)
+    {
+        LogError("Failed to create temporary path for widget");
+        ReThrowMsg(FileUtils::CreateDirectoryException, "Failed to create temporary path for widget");
+    }
+
+    LogInfo("widgetSource " << widgetPath);
+}
+
 JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
         const std::string &widgetSource,
-        bool fromBrowser,
         const WidgetUpdateInfo &update)
 {
     LogInfo(
@@ -401,20 +434,6 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
     LogInfo("Whether widget policy allow proceed: " << canProceed);
 
     // Init installer context
-    m_installerContext.widgetSource = widgetSource;
-    m_installerContext.tempWidgetPath = std::string();
-
-    // setup config xml path
-    if (fromBrowser) {
-        LogInfo("widgetSource " << widgetSource);
-        size_t slash = widgetSource.find_last_of("\\/");
-        if (std::string::npos != slash) {
-            m_installerContext.tempWidgetPath = widgetSource.substr(0, slash+1);
-        } else {
-            m_installerContext.tempWidgetPath = ".";
-        }
-    }
-
     m_installerContext.installStep = InstallerContext::INSTALL_START;
     m_installerContext.job = this;
     m_installerContext.existingWidgetInfo = update.existingWidgetInfo;