[Release] wrt-installer_0.1.114
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_widget_config.cpp
index d7c3640..ed59d54 100644 (file)
@@ -20,6 +20,7 @@
  * @brief   Implementation file for installer task widget config
  */
 
+#include <map>
 #include <sstream>
 #include <string>
 #include <sys/stat.h>
@@ -33,6 +34,7 @@
 #include <dpl/utils/wrt_global_settings.h>
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
 #include <dpl/wrt-dao-rw/feature_dao.h>
 
 #include <libiriwrapper.h>
@@ -44,6 +46,9 @@
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_parser.h>
+#include <web_provider_plugin_info.h>
+#include <web_provider_livebox_info.h>
+#include <manifest.h>
 
 namespace { // anonymous
 const DPL::String BR = DPL::FromUTF8String("<br>");
@@ -56,39 +61,29 @@ const char *const DEFAULT_LANGUAGE = "default";
 const char *const WRT_WIDGET_CONFIG_FILE_NAME = "config.xml";
 
 const std::string WINDGET_INSTALL_NETWORK_ACCESS = "network access";
+
+const char WRT_WIDGETS_XML_SCHEMA[] = "/usr/etc/wrt-installer/widgets.xsd";
 }
 
 namespace Jobs {
 namespace WidgetInstall {
-void InstallerTaskWidgetPopupData::PopupData::addWidgetInfo(
-    const DPL::String &info)
-{
-    widgetInfo = info;
-}
 
 TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) :
     DPL::TaskDecl<TaskWidgetConfig>(this),
-    WidgetInstallPopup(installContext),
     m_installContext(installContext)
 {
+    AddStep(&TaskWidgetConfig::StartStep);
     AddStep(&TaskWidgetConfig::StepProcessConfigurationFile);
     AddStep(&TaskWidgetConfig::ReadLocaleFolders);
     AddStep(&TaskWidgetConfig::ProcessLocalizedStartFiles);
     AddStep(&TaskWidgetConfig::ProcessBackgroundPageFile);
     AddStep(&TaskWidgetConfig::ProcessLocalizedIcons);
     AddStep(&TaskWidgetConfig::ProcessWidgetInstalledPath);
+    AddStep(&TaskWidgetConfig::ProcessAppControlInfo);
+    AddStep(&TaskWidgetConfig::ProcessSecurityModel);
     AddStep(&TaskWidgetConfig::StepVerifyFeatures);
     AddStep(&TaskWidgetConfig::StepCheckMinVersionInfo);
-
-    if (!GlobalSettings::TestModeEnabled() && !m_installContext.m_quiet) {
-        AddStep(
-            &TaskWidgetConfig::
-                StepCancelWidgetInstallationAfterVerifyFeatures);
-        AddStep(&TaskWidgetConfig::StepShowWidgetInfo);
-        AddStep(&TaskWidgetConfig::StepCancelWidgetInstallation);
-        AddStep(&TaskWidgetConfig::StepCancelWidgetInstallationAfterMinVersion);
-        AddStep(&TaskWidgetConfig::StepDeletePopupWin);
-    }
+    AddStep(&TaskWidgetConfig::EndStep);
 }
 
 void TaskWidgetConfig::StepProcessConfigurationFile()
@@ -96,7 +91,7 @@ void TaskWidgetConfig::StepProcessConfigurationFile()
     Try
     {
         std::string path = m_installContext.locations->getConfigurationDir();
-        LogInfo("path: " << path);
+        LogDebug("path: " << path);
 
         processFile(path, m_installContext.widgetConfig);
     }
@@ -125,8 +120,6 @@ void TaskWidgetConfig::ReadLocaleFolders()
         return;
     }
 
-
-
     struct stat statStruct;
     struct dirent dirent;
     struct dirent *result;
@@ -178,15 +171,14 @@ void TaskWidgetConfig::ProcessLocalizedStartFiles()
     ProcessStartFile(S(L"index.svg"), S(L"image/svg+xml"));
     ProcessStartFile(S(L"index.xhtml"), S(L"application/xhtml+xml"));
     ProcessStartFile(S(L"index.xht"), S(L"application/xhtml+xml"));
-    // TODO: (l.wrzosek) we need better check if in current locales widget is
-    // valid.
+    // TODO: we need better check if in current locales widget is valid
     FOREACH(it, m_installContext.widgetConfig.localizationData.startFiles) {
         if (it->propertiesForLocales.size() > 0) {
             return;
         }
     }
-    ThrowMsg(Exceptions::WidgetConfigFileInvalid,
-             L"The Widget has no valid start file");
+    ThrowMsg(Exceptions::InvalidStartFile,
+             "The Widget has no valid start file");
 }
 
 void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
@@ -301,21 +293,20 @@ void TaskWidgetConfig::ProcessBackgroundPageFile()
 void TaskWidgetConfig::ProcessLocalizedIcons()
 {
     using namespace WrtDB;
+        FOREACH(i, m_installContext.widgetConfig.configInfo.iconsList)
+    {
+        ProcessIcon(*i);
+    }
     ProcessIcon(ConfigParserData::Icon(L"icon.svg"));
     ProcessIcon(ConfigParserData::Icon(L"icon.ico"));
     ProcessIcon(ConfigParserData::Icon(L"icon.png"));
     ProcessIcon(ConfigParserData::Icon(L"icon.gif"));
     ProcessIcon(ConfigParserData::Icon(L"icon.jpg"));
-
-    FOREACH(i, m_installContext.widgetConfig.configInfo.iconsList)
-    {
-        ProcessIcon(*i);
-    }
 }
 
 void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
 {
-    LogInfo("enter");
+    LogDebug("enter");
     bool isAnyIconValid = false;
     //In case a default filename is passed as custom filename in config.xml, we
     //need to keep a set of already processed filenames to avoid icon
@@ -349,7 +340,7 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
             if (MimeTypeUtils::isMimeTypeSupportedForIcon(type)) {
                 isAnyIconValid = true;
                 localesAvailableForIcon.insert(*i);
-                LogInfo("Icon absolutePath :" << absolutePath <<
+                LogDebug("Icon absolutePath :" << absolutePath <<
                         ", assigned locale :" << *i << ", type: " << type);
             }
         }
@@ -371,63 +362,107 @@ void TaskWidgetConfig::ProcessWidgetInstalledPath()
             m_installContext.locations->getPackageInstallationDir());
 }
 
-void TaskWidgetConfig::StepCancelWidgetInstallationAfterVerifyFeatures()
+void TaskWidgetConfig::ProcessAppControlInfo()
 {
-    LogDebug("StepCancelWidgetInstallationAfterVerifyFeatures");
-    if (InfoPopupButton::WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
-        m_installCancel = WRT_POPUP_BUTTON;
-        destroyPopup();
-        ThrowMsg(Exceptions::WidgetConfigFileInvalid, "Widget not allowed");
+    LogDebug("ProcessAppControlInfo");
+    using namespace WrtDB;
+
+    WrtDB::ConfigParserData::AppControlInfo::Disposition disposition =
+        WrtDB::ConfigParserData::AppControlInfo::Disposition::WINDOW;
+    FOREACH(it, m_installContext.widgetConfig.configInfo.settingsList) {
+        if (!strcmp(DPL::ToUTF8String(it->m_name).c_str(), "nodisplay") &&
+            !strcmp(DPL::ToUTF8String(it->m_value).c_str(), "true"))
+        {
+            disposition =
+                WrtDB::ConfigParserData::AppControlInfo::Disposition::INLINE;
+        }
     }
-}
 
-void TaskWidgetConfig::StepCancelWidgetInstallation()
-{
-    if (InfoPopupButton::WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
-        m_installCancel = WRT_POPUP_BUTTON;
-        destroyPopup();
-        ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
+    std::map<std::string, int> srcMap;
+    int index = 0;
+    // index = 0 is reserved for start file
+    FOREACH(startFileIt, m_installContext.widgetConfig.localizationData.startFiles)
+    {
+        if (!startFileIt->propertiesForLocales.empty()) {
+            std::string src = DPL::ToUTF8String(startFileIt->path);
+             if (srcMap.find(src) == srcMap.end()) {
+                LogDebug("Insert [" << src << "," << index << "]");
+                srcMap.insert(std::pair<std::string, int>(src, index++));
+            }
+        }
     }
-}
 
-void TaskWidgetConfig::StepCancelWidgetInstallationAfterMinVersion()
-{
-    if (InfoPopupButton::WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
-        m_installCancel = WRT_POPUP_BUTTON;
-        destroyPopup();
-        ThrowMsg(Exceptions::NotAllowed, "WRT version incompatible.");
+    FOREACH(appControlIt, m_installContext.widgetConfig.configInfo.appControlList)
+    {
+        appControlIt->m_disposition = disposition;
+        std::string src = DPL::ToUTF8String(appControlIt->m_src);
+        LogDebug("src = [" << src << "]");
+        std::map<std::string, int>::iterator findIt = srcMap.find(src);
+        if (findIt == srcMap.end()) {
+            LogDebug("Insert [" << src << "," << index << "]");
+            srcMap.insert(std::pair<std::string, int>(src, index));
+            appControlIt->m_index = index++;
+        } else {
+            LogDebug("Exist  [" << src << "," << findIt->second << "]");
+            appControlIt->m_index = findIt->second;
+        }
     }
 }
 
-void TaskWidgetConfig::createInstallPopup(PopupType type,
-                                          const std::string &label)
+void TaskWidgetConfig::ProcessSecurityModel()
 {
-    m_installContext.job->Pause();
-    if (m_popup) {
-        destroyPopup();
+    // 0104.  If the "required_version" specified in the Web Application's
+    // configuration is 2.2 or higher and if the Web Application's
+    // configuration is "CSP-compatible configuration", then the WRT MUST be
+    // set to "CSP-based security mode". Otherwise, the WRT MUST be set to
+    // "WARP-based security mode".
+    // 0105.  A Web Application configuration is "CSP-compatible configuration"
+    // if the configuration includes one or more of
+    // <tizen:content-security-policy> /
+    // <tizen:content-security-policy-report-only> /
+    // <tizen:allow-navigation> elements.
+
+    bool isSecurityModelV1 = false;
+    bool isSecurityModelV2 = false;
+    WrtDB::ConfigParserData &data = m_installContext.widgetConfig.configInfo;
+
+    if (!data.cspPolicy.IsNull() ||
+        !data.cspPolicyReportOnly.IsNull() ||
+        !data.allowNavigationInfoList.empty())
+    {
+        data.accessInfoSet.clear();
     }
 
-    bool ret = createPopup();
-    if (ret) {
-        loadPopup(type, label);
-        showPopup();
+    // WARP is V1
+    if (!data.accessInfoSet.empty()) {
+        isSecurityModelV1 = true;
     }
-}
 
-void TaskWidgetConfig::StepDeletePopupWin()
-{
-    destroyPopup();
-}
-
-void TaskWidgetConfig::StepShowWidgetInfo()
-{
-    if (!m_popupData.widgetInfo.empty()) {
-        std::string label = DPL::ToUTF8String(m_popupData.widgetInfo);
-        createInstallPopup(PopupType::WIDGET_FEATURE_INFO, label);
-        m_installContext.job->UpdateProgress(
-            InstallerContext::INSTALL_WIDGET_CONFIG2,
-            "Show Widget Info Finished");
+    // CSP & allow-navigation is V2
+    if (!data.cspPolicy.IsNull() ||
+        !data.cspPolicyReportOnly.IsNull() ||
+        !data.allowNavigationInfoList.empty())
+    {
+        isSecurityModelV2 = true;
+    }
+
+    if (isSecurityModelV1 && isSecurityModelV2) {
+        LogError("Security model is conflict");
+        ThrowMsg(Exceptions::NotAllowed, "Security model is conflict");
+    } else if (isSecurityModelV1) {
+        data.securityModelVersion =
+            WrtDB::ConfigParserData::SecurityModelVersion::SECURITY_MODEL_V1;
+    } else if (isSecurityModelV2) {
+        data.securityModelVersion =
+            WrtDB::ConfigParserData::SecurityModelVersion::SECURITY_MODEL_V2;
+    } else {
+        data.securityModelVersion =
+            WrtDB::ConfigParserData::SecurityModelVersion::SECURITY_MODEL_V1;
     }
+
+    m_installContext.job->UpdateProgress(
+        InstallerContext::INSTALL_WIDGET_CONFIG2,
+        "Finished process security model");
 }
 
 void TaskWidgetConfig::StepCheckMinVersionInfo()
@@ -436,16 +471,10 @@ void TaskWidgetConfig::StepCheckMinVersionInfo()
             m_installContext.widgetConfig.webAppType.appType,
             m_installContext.widgetConfig.minVersion))
     {
-        if (!GlobalSettings::TestModeEnabled() && !m_installContext.m_quiet) {
-            LogDebug("Platform version to low - launching");
-            std::string label = WIDGET_NOT_COMPATIBLE + QUESTION;
-            createInstallPopup(PopupType::WIDGET_MIN_VERSION, label);
-        } else {
-            LogError(
-                "Platform version lower than required -> cancelling installation");
-            ThrowMsg(Exceptions::NotAllowed,
-                     "Platform version does not meet requirements");
-        }
+        LogError(
+            "Platform version lower than required -> cancelling installation");
+        ThrowMsg(Exceptions::NotAllowed,
+                 "Platform version does not meet requirements");
     }
 
     m_installContext.job->UpdateProgress(
@@ -470,7 +499,7 @@ void TaskWidgetConfig::StepVerifyFeatures()
         if (!isFeatureAllowed(m_installContext.widgetConfig.webAppType.appType,
                               it->name))
         {
-            LogInfo("This application type not allowed to use this feature");
+            LogDebug("This application type not allowed to use this feature");
             ThrowMsg(
                 Exceptions::WidgetConfigFileInvalid,
                 "This app type [" <<
@@ -489,22 +518,65 @@ void TaskWidgetConfig::StepVerifyFeatures()
         featureInfo += DPL::ToUTF8String(BR);
     }
     data.featuresList = newList;
-    if (!featureInfo.empty()) {
-        m_popupData.addWidgetInfo(DPL::FromUTF8String(featureInfo));
-    }
 
     m_installContext.job->UpdateProgress(
         InstallerContext::INSTALL_WIDGET_CONFIG2,
         "Widget Config step2 Finished");
 }
 
+void TaskWidgetConfig::StepVerifyLivebox()
+{
+    using namespace WrtDB;
+    ConfigParserData &data = m_installContext.widgetConfig.configInfo;
+    ConfigParserData::LiveboxList liveBoxList = data.m_livebox;
+
+    if (liveBoxList.size() <= 0) {
+        return;
+    }
+
+    FOREACH (it, liveBoxList) {
+        std::string boxType;
+
+        if ((**it).m_type.empty()) {
+            boxType = web_provider_livebox_get_default_type();
+        } else {
+            boxType = DPL::ToUTF8String((**it).m_type);
+        }
+
+        LogDebug("livebox type: " << boxType);
+
+        ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
+            (**it).m_boxInfo.m_boxSize;
+        char** boxSize = static_cast<char**>(
+            malloc(sizeof(char*)* boxSizeList.size()));
+
+        int boxSizeCnt = 0;
+        FOREACH (m, boxSizeList) {
+            boxSize[boxSizeCnt++] = strdup(DPL::ToUTF8String((*m).m_size).c_str());
+        }
+
+        bool chkSize = web_provider_plugin_check_supported_size(
+            boxType.c_str(), boxSize, boxSizeCnt);
+
+        for(int i = 0; i < boxSizeCnt; i++) {
+            free(boxSize[i]);
+        }
+        free(boxSize);
+
+        if(!chkSize) {
+            LogError("Invalid boxSize");
+            ThrowMsg(Exceptions::WidgetConfigFileInvalid, "Invalid boxSize");
+        }
+    }
+}
+
 bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType,
                                         DPL::String featureName)
 {
     using namespace WrtDB;
-    LogInfo("AppType = [" <<
+    LogDebug("AppType = [" <<
             WidgetType(appType).getApptypeToString() << "]");
-    LogInfo("FetureName = [" << featureName << "]");
+    LogDebug("FetureName = [" << featureName << "]");
 
     AppType featureType = APP_TYPE_UNKNOWN;
     std::string featureStr = DPL::ToUTF8String(featureName);
@@ -514,9 +586,6 @@ bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType,
     if (strstr(feature, PluginsPrefix::TIZENPluginsPrefix) == feature) {
         // Tizen WebApp feature
         featureType = APP_TYPE_TIZENWEBAPP;
-    } else if (strstr(feature, PluginsPrefix::WACPluginsPrefix) == feature) {
-        // WAC 2.0 feature
-        featureType = APP_TYPE_WAC20;
     } else if (strstr(feature, PluginsPrefix::W3CPluginsPrefix) == feature) {
         // W3C standard feature
         // Both WAC and TIZEN WebApp are possible to use W3C plugins
@@ -587,8 +656,6 @@ bool TaskWidgetConfig::isMinVersionCompatible(
     std::string version;
     if (appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) {
         version = WrtDB::GlobalConfig::GetTizenVersion();
-    } else if (appType == WrtDB::AppType::APP_TYPE_WAC20) {
-        version = WrtDB::GlobalConfig::GetWACVersion();
     } else {
         LogWarning("Invaild AppType");
         return false;
@@ -606,7 +673,7 @@ bool TaskWidgetConfig::isMinVersionCompatible(
         (majorWidget == majorSupported && minorWidget == minorSupported
          && microWidget > microSupported))
     {
-        LogInfo("Platform doesn't support this widget.");
+        LogDebug("Platform doesn't support this widget.");
         return false;
     }
     return true;
@@ -663,6 +730,13 @@ bool TaskWidgetConfig::parseConfigurationFileWidget(
     Try
     {
         ParserRunner parser;
+#ifdef SCHEMA_VALIDATION_ENABLED
+        if(!parser.Validate(configFilePath, WRT_WIDGETS_XML_SCHEMA))
+        {
+            LogError("Invalid configuration file - schema validation failed");
+            return false;
+        }
+#endif
         parser.Parse(configFilePath,
                      ElementParserPtr(new RootParser<WidgetParser>(
                                           configInfo,
@@ -771,5 +845,15 @@ void TaskWidgetConfig::processFile(
         ThrowMsg(Exception::ConfigParseFailed, path);
     }
 }
+
+void TaskWidgetConfig::StartStep()
+{
+    LogDebug("--------- <TaskWidgetConfig> : START ----------");
+}
+
+void TaskWidgetConfig::EndStep()
+{
+    LogDebug("--------- <TaskWidgetConfig> : END ----------");
+}
 } //namespace WidgetInstall
 } //namespace Jobs