Update wrt-installer_0.0.54
[framework/web/wrt-installer.git] / src / jobs / widget_install / job_widget_install.cpp
index 459c9aa..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>
@@ -48,6 +50,7 @@
 #include <widget_install/task_update_files.h>
 #include <widget_install/task_new_db_insert.h>
 #include <widget_install/task_remove_backup.h>
+#include <widget_install/task_encrypt_resource.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
 #include <string>
@@ -76,6 +79,9 @@ const char* REG_TIZENID_PATTERN = "^[-. a-zA-Z0-9_@+=]*$";
 const int RESERVED_COUNT = 20;  //number of chars reserved in name (e.g. for '.desktop')
 const int MAX_TIZENID_LENTH = 255 - RESERVED_COUNT;
 
+static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption";
+static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable";
+
 class InstallerTaskFail :
     public DPL::TaskDecl<InstallerTaskFail>
 {
@@ -126,8 +132,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
     m_exceptionCaught(Exceptions::Success)
 {
     // Check installation type (config.xml or widget.wgt)
-    bool fromBrowser = hasExtension(widgetPath, XML_EXTENSION);
-    LogInfo("Hosted app installation: " << fromBrowser);
+    bool browserRequest = hasExtension(widgetPath, XML_EXTENSION);
+
+    LogInfo("Hosted app installation: " << browserRequest);
 
     struct timeval tv;
     gettimeofday(&tv, NULL);
@@ -141,15 +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, fromBrowser,
+    ConfigParserData configData = getWidgetDataFromXML(widgetPath, browserRequest,
             m_installerContext.widgetConfig.pType);
     WidgetUpdateInfo update = detectWidgetUpdate(configData);
 
+    bool needEncryption = detectResourceEncryption(configData);
+
 
     // Configure installation
-    ConfigureResult result = ConfigureInstallation(widgetPath, fromBrowser, update);
+    ConfigureResult result = ConfigureInstallation(widgetPath, update);
     if (!setTizenId(configData)) {
         result = ConfigureResult::Failed;
     } else {
@@ -157,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(
@@ -165,19 +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 (!fromBrowser) {
+        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));
@@ -196,10 +221,13 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath,
         LogInfo("Configure installation updated");
         LogInfo("Widget Update");
 
-        if (!fromBrowser) {
+        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));
@@ -329,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(
@@ -391,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;
@@ -754,5 +783,18 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType(
     return pType;
 }
 
+bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData)
+{
+    FOREACH(it, configData.settingsList)
+    {
+        if (it->m_name == SETTING_VALUE_ENCRYPTION &&
+                it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) {
+            LogDebug("resource need encryption");
+            return true;
+        }
+    }
+    return false;
+}
+
 } //namespace WidgetInstall
 } //namespace Jobs