[Release] wrt-installer_0.1.90
[framework/web/wrt-installer.git] / src / jobs / widget_install / task_widget_config.cpp
index 8f4710f..b8db386 100644 (file)
  * @version 1.0
  * @brief   Implementation file for installer task widget config
  */
-#include <string>
+
+#include <map>
 #include <sstream>
-#include <dpl/foreach.h>
+#include <string>
+#include <sys/stat.h>
+#include <dirent.h>
+
 #include <dpl/errno_string.h>
-#include <dpl/wrt-dao-rw/feature_dao.h>
+#include <dpl/foreach.h>
+#include <dpl/localization/w3c_file_localization.h>
+#include <dpl/singleton_impl.h>
+#include <dpl/utils/mime_type_utils.h>
+#include <dpl/utils/wrt_global_settings.h>
 #include <dpl/utils/wrt_utility.h>
-#include <root_parser.h>
-#include <powder_parser.h>
-#include <widget_parser.h>
-#include <parser_runner.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>
-#include <widget_install/task_widget_config.h>
+#include <parser_runner.h>
+#include <root_parser.h>
+
 #include <widget_install/job_widget_install.h>
-#include <widget_install/widget_install_errors.h>
+#include <widget_install/task_widget_config.h>
 #include <widget_install/widget_install_context.h>
-#include <dpl/utils/file_utils.h>
-#include <dpl/utils/mime_type_utils.h>
-#include <sys/stat.h>
-#include "wrt_powder_info_util.h"
-#include <dpl/utils/wrt_global_settings.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 char *WIDGET_SCHEMA = "widget";
-const WidgetHandle WIDGET_HANDLE_START_VALUE = 1000;
-const char * AGE_RATING = "Age Rating: ";
-const char * CATEGORY = "Category: ";
-const char * LEVEL = "Level: ";
-const char * CONTEXT = "Context: ";
-const DPL::String POWDER_INFO = DPL::FromUTF8String("Powder Info");
-const DPL::String POWDER_PASSWORD = DPL::FromUTF8String(
-        "Parental Mode is ON.<br>"
-        "Please enter your password");
-const DPL::String WIDGET_HEAD = DPL::FromUTF8String("Widget information");
-const std::string OK_BUTTON_LABEL = "OK";
-const std::string CANCEL_BUTTON_LABEL = "Cancel";
 const DPL::String BR = DPL::FromUTF8String("<br>");
-const DPL::String DOUBLE_BR = DPL::FromUTF8String("<br><br>");
-const DPL::String POWDER_HEAD = DPL::FromUTF8String("Powder information");
-const DPL::String FEATURE_HEAD = DPL::FromUTF8String("Feature information");
-} // namespace anonymous
+const std::string WIDGET_NOT_COMPATIBLE = "This widget is "
+                                          "not compatible with WRT.<br><br>";
+const std::string QUESTION = "Do you want to install it anyway?";
+
+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 &head,
-        const DPL::String &info)
+    const DPL::String &info)
 {
-    widgetInfo += head;
-    widgetInfo += DOUBLE_BR;
-    widgetInfo += info;
-    widgetInfo += BR;
+    widgetInfo = info;
 }
 
 TaskWidgetConfig::TaskWidgetConfig(InstallerContext& installContext) :
     DPL::TaskDecl<TaskWidgetConfig>(this),
-    m_installContext(installContext),
-    m_installCancel(false)
+    m_installContext(installContext)
 {
     AddStep(&TaskWidgetConfig::StepProcessConfigurationFile);
     AddStep(&TaskWidgetConfig::ReadLocaleFolders);
     AddStep(&TaskWidgetConfig::ProcessLocalizedStartFiles);
+    AddStep(&TaskWidgetConfig::ProcessBackgroundPageFile);
     AddStep(&TaskWidgetConfig::ProcessLocalizedIcons);
-    AddStep(&TaskWidgetConfig::StepProcessPowderFile);
+    AddStep(&TaskWidgetConfig::ProcessWidgetInstalledPath);
+    AddStep(&TaskWidgetConfig::ProcessAppControlInfo);
+    AddStep(&TaskWidgetConfig::ProcessSecurityModel);
     AddStep(&TaskWidgetConfig::StepVerifyFeatures);
-
-    //in case of tests, no popups are shown
-    if (GlobalSettings::GetPopupsEnabledFlag()) {
-        AddStep(&TaskWidgetConfig::StepShowWidgetInfo);
-        AddStep(&TaskWidgetConfig::StepCancelWidgetInstallation);
-    }
+    AddStep(&TaskWidgetConfig::StepCheckMinVersionInfo);
 }
 
 void TaskWidgetConfig::StepProcessConfigurationFile()
 {
     Try
     {
-        WidgetConfigurationManagerSingleton::Instance().processFile(
-            m_installContext.tempWidgetPath,
-            m_installContext.widgetConfig);
+        std::string path = m_installContext.locations->getConfigurationDir();
+        LogInfo("path: " << path);
+
+        processFile(path, m_installContext.widgetConfig);
     }
-    Catch(WidgetConfigurationManager::Exception::ProcessFailed)
+    Catch(Exception::ConfigParseFailed)
     {
         LogError("Parsing failed.");
         ReThrow(Exceptions::WidgetConfigFileInvalid);
     }
-    Try
-    {
-        // To get widget type for distribute WAC, TIZEN WebApp
-        setApplicationType();
-    }
-    Catch(WidgetConfigurationManager::Exception::ProcessFailed)
-    {
-        LogError("Config.xml has more than one namespace");
-        ReThrow(Exceptions::WidgetConfigFileInvalid);
-    }
 
-    m_installContext.job->SetProgressFlag(true);
     m_installContext.job->UpdateProgress(
         InstallerContext::INSTALL_WIDGET_CONFIG1,
-        "Parsing was suscessfull");
+        "Parse elements of configuration file and save them");
 }
 
 void TaskWidgetConfig::ReadLocaleFolders()
@@ -127,44 +115,48 @@ void TaskWidgetConfig::ReadLocaleFolders()
     //Adding default locale
     m_localeFolders.insert(L"");
 
-    std::string localePath = m_installContext.tempWidgetPath + "/locales";
+    std::string localePath =
+        m_installContext.locations->getConfigurationDir() + "/locales";
     DIR* localeDir = opendir(localePath.c_str());
     if (!localeDir) {
         LogDebug("No /locales directory in the widget package.");
         return;
     }
 
-    struct dirent* dirent;
     struct stat statStruct;
-    do {
-        errno = 0;
-        if ((dirent = readdir(localeDir))) {
-            DPL::String dirName = DPL::FromUTF8String(dirent->d_name);
-            std::string absoluteDirName = localePath + "/";
-            absoluteDirName += dirent->d_name;
-
-            if (stat(absoluteDirName.c_str(), &statStruct) != 0) {
-                LogError("stat() failed with " << DPL::GetErrnoString());
-                continue;
-            }
+    struct dirent dirent;
+    struct dirent *result;
+    int return_code;
+    errno = 0;
+    for (return_code = readdir_r(localeDir, &dirent, &result);
+            result != NULL && return_code == 0;
+            return_code = readdir_r(localeDir, &dirent, &result))
+    {
+        DPL::String dirName = DPL::FromUTF8String(dirent.d_name);
+        std::string absoluteDirName = localePath + "/";
+        absoluteDirName += dirent.d_name;
 
-            if (S_ISDIR(statStruct.st_mode)) {
-                //Yes, we ignore current, parent & hidden directories
-                if (dirName[0] != L'.') {
-                    LogDebug("Adding locale directory \"" << dirName << "\"");
-                    m_localeFolders.insert(dirName);
-                }
+        if (stat(absoluteDirName.c_str(), &statStruct) != 0) {
+            LogError("stat() failed with " << DPL::GetErrnoString());
+            continue;
+        }
+
+        if (S_ISDIR(statStruct.st_mode)) {
+            //Yes, we ignore current, parent & hidden directories
+            if (dirName[0] != L'.') {
+                LogDebug("Adding locale directory \"" << dirName << "\"");
+                m_localeFolders.insert(dirName);
             }
         }
     }
-    while (dirent);
 
-    if (errno != 0) {
-        LogError("readdir() failed with " << DPL::GetErrnoString());
+    if (return_code != 0 || errno != 0) {
+        LogError("readdir_r() failed with " << DPL::GetErrnoString());
     }
 
-    if (closedir(localeDir)) {
-        LogError("closedir() failed with " << DPL::GetErrnoString());
+    if (-1 == TEMP_FAILURE_RETRY(closedir(localeDir))) {
+        LogError("Failed to close dir: " << localePath << " with error: "
+                                         << DPL::GetErrnoString());
     }
 }
 
@@ -182,7 +174,7 @@ 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;
@@ -193,9 +185,9 @@ void TaskWidgetConfig::ProcessLocalizedStartFiles()
 }
 
 void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
-        const DPL::OptionalString& type,
-        const DPL::OptionalString& encoding,
-        bool typeForcedInConfig)
+                                        const DPL::OptionalString& type,
+                                        const DPL::OptionalString& encoding,
+                                        bool typeForcedInConfig)
 {
     using namespace WrtDB;
 
@@ -211,10 +203,11 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
 
             DPL::String relativePath = pathPrefix + *path;
             DPL::String absolutePath = DPL::FromUTF8String(
-                    m_installContext.tempWidgetPath) + L"/" + relativePath;
+                    m_installContext.locations->getConfigurationDir()) + L"/" +
+                relativePath;
 
             // get property data from packaged app
-            if (FileUtils::FileExists(absolutePath)) {
+            if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) {
                 WidgetRegisterInfo::StartFileProperties startFileProperties;
                 if (!!type) {
                     startFileProperties.type = *type;
@@ -232,7 +225,7 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
                     } else {
                         MimeTypeUtils::MimeAttributes attributes =
                             MimeTypeUtils::getMimeAttributes(
-                            startFileProperties.type);
+                                startFileProperties.type);
                         if (attributes.count(L"charset") > 0) {
                             startFileProperties.encoding =
                                 attributes[L"charset"];
@@ -256,12 +249,15 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
             } else {
                 // set property data for hosted start url
                 // Hosted start url only support TIZEN WebApp
-                if (m_installContext.widgetConfig.type ==
+                if (m_installContext.widgetConfig.webAppType ==
                     APP_TYPE_TIZENWEBAPP)
                 {
-                    const char *startPath =
-                        DPL::ToUTF8String(startFileData.path).c_str();
-                    if (strstr(startPath, "http") == startPath) {
+                    std::string startPath = DPL::ToUTF8String(
+                            startFileData.path);
+
+                    if (strstr(startPath.c_str(),
+                               "http") == startPath.c_str())
+                    {
                         WidgetRegisterInfo::StartFileProperties
                             startFileProperties;
                         if (!!type) {
@@ -282,6 +278,21 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path,
     }
 }
 
+void TaskWidgetConfig::ProcessBackgroundPageFile()
+{
+    if (!!m_installContext.widgetConfig.configInfo.backgroundPage) {
+        // check whether file exists
+        DPL::String backgroundPagePath = DPL::FromUTF8String(
+                m_installContext.locations->getConfigurationDir()) + L"/" +
+            *m_installContext.widgetConfig.configInfo.backgroundPage;
+        //if no then cancel installation
+        if (!WrtUtilFileExists(DPL::ToUTF8String(backgroundPagePath))) {
+            ThrowMsg(Exceptions::WidgetConfigFileInvalid,
+                     L"Given background page file not found in archive");
+        }
+    }
+}
+
 void TaskWidgetConfig::ProcessLocalizedIcons()
 {
     using namespace WrtDB;
@@ -299,9 +310,11 @@ void TaskWidgetConfig::ProcessLocalizedIcons()
 
 void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
 {
-    bool isAnyIconExisted = false;
+    LogInfo("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 duplication
+    //need to keep a set of already processed filenames to avoid icon
+    // duplication
     //in database.
 
     using namespace WrtDB;
@@ -309,7 +322,6 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
     if (m_processedIconSet.count(icon.src) > 0) {
         return;
     }
-
     m_processedIconSet.insert(icon.src);
 
     LocaleSet localesAvailableForIcon;
@@ -323,22 +335,22 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
 
         DPL::String relativePath = pathPrefix + icon.src;
         DPL::String absolutePath = DPL::FromUTF8String(
-                m_installContext.tempWidgetPath) + L"/" + relativePath;
+                m_installContext.locations->getConfigurationDir()) + L"/" +
+            relativePath;
 
-        if (FileUtils::FileExists(absolutePath)) {
-            isAnyIconExisted = true;
+        if (WrtUtilFileExists(DPL::ToUTF8String(absolutePath))) {
             DPL::String type = MimeTypeUtils::identifyFileMimeType(absolutePath);
 
             if (MimeTypeUtils::isMimeTypeSupportedForIcon(type)) {
+                isAnyIconValid = true;
                 localesAvailableForIcon.insert(*i);
+                LogInfo("Icon absolutePath :" << absolutePath <<
+                        ", assigned locale :" << *i << ", type: " << type);
             }
-            LogInfo("Icon absolutePath :" << absolutePath <<
-                    ", assigned locale :" << *i);
         }
     }
 
-    if(isAnyIconExisted)
-    {
+    if (isAnyIconValid) {
         WidgetRegisterInfo::LocalizedIcon localizedIcon(icon,
                                                         localesAvailableForIcon);
         m_installContext.widgetConfig.localizationData.icons.push_back(
@@ -346,172 +358,165 @@ void TaskWidgetConfig::ProcessIcon(const WrtDB::ConfigParserData::Icon& icon)
     }
 }
 
-void TaskWidgetConfig::StepProcessPowderFile(void)
+void TaskWidgetConfig::ProcessWidgetInstalledPath()
+{
+    LogDebug("ProcessWidgetInstalledPath");
+    m_installContext.widgetConfig.widgetInstalledPath =
+        DPL::FromUTF8String(
+            m_installContext.locations->getPackageInstallationDir());
+}
+
+void TaskWidgetConfig::ProcessAppControlInfo()
 {
+    LogDebug("ProcessAppControlInfo");
     using namespace WrtDB;
-    const std::string& path = m_installContext.tempWidgetPath;
-    WidgetRegisterInfo* widgetConfiguration =
-        &m_installContext.widgetConfig;
-
-    LogInfo("Process powder for guid " <<
-            widgetConfiguration->guid);
-    if (!!widgetConfiguration->guid) {
-        LibIri::Wrapper iri(DPL::ToUTF8String(
-                                *widgetConfiguration->guid).c_str());
-        DPL::String widgetHost;
-        DPL::String widgetPath;
-        if (NULL != iri.m_Iri->host) {
-            widgetHost = DPL::FromUTF8String(iri.m_Iri->host);
-        }
-        if (NULL != iri.m_Iri->path) {
-            widgetPath = DPL::FromUTF8String(iri.m_Iri->path);
-        }
-        PowderParserData parserData(&widgetConfiguration->powderDescription,
-                                    widgetHost, widgetPath);
-        ConfigParserData::StringsList& descriptions =
-            widgetConfiguration->configInfo.powderDescriptionLinks;
 
-        FOREACH(linkIter, descriptions)
+    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"))
         {
-            LogInfo("Process powder link: " << *linkIter);
-            LibIri::Wrapper link(DPL::ToUTF8String(*linkIter).c_str());
-            LogInfo("Parser link" << link);
-            if (strcmp(link.m_Iri->scheme, WIDGET_SCHEMA) == 0) {
-                if (NULL != link.m_Iri->host) {
-                    std::ostringstream stream;
-                    //FIXME: Current libiri library is not able to parse
-                    //       URL: widget:/powder.xml Field host
-                    //       is filed with path
-                    stream << path << "/" << link.m_Iri->host;
-                    ParserRunner().Parse(
-                        stream.str(),
-                        ElementParserPtr(new
-                                         RootParser<PowderParser>(&parserData,
-                                                                  DPL::
-                                                                      FromUTF32String(
-                                                                      L"powder"))));
-                } else {
-                    ThrowMsg(Exceptions::WidgetConfigFileInvalid,
-                             "Powder link " << *linkIter << " path empty.");
-                }
-            } else {
-                ThrowMsg(Exceptions::WidgetConfigFileInvalid,
-                         "Powder link " <<
-                         *linkIter <<
-                         " schema not supported.");
-            }
+            disposition =
+                WrtDB::ConfigParserData::AppControlInfo::Disposition::INLINE;
         }
     }
 
-    //TODO:FIXME make progress valid
-    m_installContext.job->UpdateProgress(
-        InstallerContext::INSTALL_WIDGET_CONFIG1,
-        "Widget Config powder step Finished");
-}
-
-void TaskWidgetConfig::AnswerCallback(const DPL::Popup::AnswerCallbackData &answer)
-{
-    LogInfo("Callback called");
-    if (WRT_POPUP_BUTTON_CANCEL == answer.buttonAnswer) {
-        m_installCancel = WRT_POPUP_BUTTON_CANCEL;
+    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++));
+            }
+        }
     }
-    m_installContext.job->Resume();
-}
 
-void TaskWidgetConfig::StepCancelWidgetInstallation()
-{
-    if (WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
-        ThrowMsg(Exceptions::NotAllowed, "Widget not allowed");
+    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;
+        }
     }
 }
 
-//TODO this step is not added in constructor
-void TaskWidgetConfig::StepShowPowderPasswordCancel()
+void TaskWidgetConfig::ProcessSecurityModel()
 {
-    if (WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
-        ThrowMsg(Exceptions::NotAllowed, "Parental Mode is ON");
+    // 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;
+    std::string securityModelV2supportedVersion = "2.2";
+    WrtDB::ConfigParserData &data = m_installContext.widgetConfig.configInfo;
+
+    // Parse required version
+    long majorWidget = 0, minorWidget = 0, microWidget = 0;
+    if (!parseVersionString(DPL::ToUTF8String(*data.tizenMinVersionRequired),
+                            majorWidget,
+                            minorWidget,
+                            microWidget))
+    {
+        ThrowMsg(Exceptions::NotAllowed, "Wrong version string");
     }
-}
 
-void TaskWidgetConfig::PopupCreate()
-{
-    m_installContext.job->Pause();
-    using namespace DPL::Popup;
-    CtrlPopupPtr popup = PopupControllerSingleton::Instance().CreatePopup();
-    popup->SetTitle(DPL::ToUTF8String(WIDGET_HEAD));
-    popup->Append(new PopupObject::Label(
-                      DPL::ToUTF8String(m_popupData.widgetInfo)));
-    m_popupData.widgetInfo.clear();
-    popup->Append(new PopupObject::Button(OK_BUTTON_LABEL,
-                                           WRT_POPUP_BUTTON_OK));
-    popup->Append(new PopupObject::Button(CANCEL_BUTTON_LABEL,
-                                           WRT_POPUP_BUTTON_CANCEL));
-    ListenForAnswer(popup);
-    ShowPopupEvent event(popup, MakeAnswerCallback(
-                             this,
-                             &TaskWidgetConfig::
-                                 AnswerCallback), DPL::Event::UNDEFINED_LOOP_HANDLE);
-    CONTROLLER_POST_EVENT(PopupController, event);
-}
+    // Parse since version (CSP & allow-navigation start to support since 2.2)
+    long majorSupported = 0, minorSupported = 0, microSupported = 0;
+    if (!parseVersionString(securityModelV2supportedVersion,
+                            majorSupported,
+                            minorSupported,
+                            microSupported))
+    {
+        ThrowMsg(Exceptions::NotAllowed, "Wrong version string");
+    }
 
-DPL::String TaskWidgetConfig::createPowderInfo() const
-{
-    WrtDB::Powder::Description &powderDescription =
-        m_installContext.widgetConfig.powderDescription;
-    std::ostringstream powderInfo;
-    if (!!powderDescription.ageRating) {
-        powderInfo << AGE_RATING;
-        powderInfo << *powderDescription.ageRating;
-        powderInfo << BR;
-    }
-    FOREACH(categoriesIterator, powderDescription.categories) {
-        powderInfo << CATEGORY;
-        powderInfo << PowderInfoUtilSingleton::Instance().
-            getCategoryLabel(categoriesIterator->first);
-        powderInfo << BR;
-
-        FOREACH(levelIterator, categoriesIterator->second.levels) {
-            powderInfo << LEVEL;
-            powderInfo << static_cast<int>(levelIterator->level);
-            powderInfo << BR;
-
-            FOREACH(contextIterator, levelIterator->context) {
-                powderInfo << CONTEXT;
-                powderInfo << PowderInfoUtilSingleton::Instance().
-                    getContextLabel(*contextIterator);
-                powderInfo << BR;
-            }
+    if (majorWidget < majorSupported ||
+        (majorWidget == majorSupported && minorWidget < minorSupported) ||
+        (majorWidget == majorSupported && minorWidget == minorSupported
+         && microWidget < microSupported))
+    {
+        // Under 2.2, clear v2 data
+        data.cspPolicy = DPL::OptionalString::Null;
+        data.cspPolicyReportOnly = DPL::OptionalString::Null;
+        data.allowNavigationInfoList.clear();
+    } else {
+        // More than 2.2, if v2 is defined, clear v1 data
+        if (!data.cspPolicy.IsNull() ||
+            !data.cspPolicyReportOnly.IsNull() ||
+            !data.allowNavigationInfoList.empty())
+        {
+            data.accessInfoSet.clear();
         }
     }
 
-    return DPL::FromUTF8String(powderInfo.str());
-}
+    // WARP is V1
+    if (!data.accessInfoSet.empty()) {
+        isSecurityModelV1 = true;
+    }
 
-void TaskWidgetConfig::StepShowWidgetInfo()
-{
-    if (!createPowderInfo().empty()) {
-        m_popupData.addWidgetInfo(POWDER_HEAD,
-                                  createPowderInfo());
+    // CSP & allow-navigation is V2
+    if (!data.cspPolicy.IsNull() ||
+        !data.cspPolicyReportOnly.IsNull() ||
+        !data.allowNavigationInfoList.empty())
+    {
+        isSecurityModelV2 = true;
     }
 
-    if (!m_popupData.widgetInfo.empty()) {
-        PopupCreate();
-        m_installContext.job->UpdateProgress(
-            InstallerContext::INSTALL_WIDGET_CONFIG2,
-            "Show Widget Info Finished");
+    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");
 }
 
-//TODO this step is not added in constructor
-void TaskWidgetConfig::StepShowPowderPassword()
+void TaskWidgetConfig::StepCheckMinVersionInfo()
 {
-    using namespace WrtDB;
-    if (GlobalDAOReadOnly::GetParentalMode()) {
-        m_popupData.addWidgetInfo(POWDER_INFO, POWDER_PASSWORD);
+    if (!isMinVersionCompatible(
+            m_installContext.widgetConfig.webAppType.appType,
+            m_installContext.widgetConfig.minVersion))
+    {
+        LogError(
+            "Platform version lower than required -> cancelling installation");
+        ThrowMsg(Exceptions::NotAllowed,
+                 "Platform version does not meet requirements");
     }
+
     m_installContext.job->UpdateProgress(
         InstallerContext::INSTALL_WIDGET_CONFIG2,
-        "Show Powder Password Finished");
+        "Check MinVersion Finished");
 }
 
 void TaskWidgetConfig::StepVerifyFeatures()
@@ -527,43 +532,31 @@ void TaskWidgetConfig::StepVerifyFeatures()
     {
         // check feature vender for permission
         // WAC, TIZEN WebApp cannot use other feature
-        if (!isFeatureAllowed(m_installContext.widgetConfig.type.appType,
+
+        if (!isFeatureAllowed(m_installContext.widgetConfig.webAppType.appType,
                               it->name))
         {
             LogInfo("This application type not allowed to use this feature");
             ThrowMsg(
                 Exceptions::WidgetConfigFileInvalid,
                 "This app type [" <<
-                m_installContext.widgetConfig.type.getApptypeToString() <<
+                m_installContext.widgetConfig.webAppType.getApptypeToString()
+                                  <<
                 "] cannot be allowed to use [" <<
                 DPL::ToUTF8String(it->name) + "] feature");
-        }
-        if (!WrtDB::FeatureDAOReadOnly::isFeatureInstalled(
-                DPL::ToUTF8String(it->name))) {
-            LogWarning("Feature not found. Checking if required :[" <<
-                       DPL::ToUTF8String(it->name) << "]");
-
-            if (it->required) {
-                LogWarning(
-                    "Required Features missing, Installation topped: [" <<
-                    DPL::ToUTF8String(it->name) << "]");
-
-                ThrowMsg(
-                    Exceptions::WidgetConfigFileInvalid,
-                    "Widget cannot be installedm equired feature is missing:["
-                    +
-                    DPL::ToUTF8String(it->name) + "]");
-            }
         } else {
             newList.insert(*it);
             featureInfo += DPL::ToUTF8String(it->name);
             featureInfo += DPL::ToUTF8String(BR);
         }
     }
+    if (!data.accessInfoSet.empty()) {
+        featureInfo += WINDGET_INSTALL_NETWORK_ACCESS;
+        featureInfo += DPL::ToUTF8String(BR);
+    }
     data.featuresList = newList;
     if (!featureInfo.empty()) {
-        m_popupData.addWidgetInfo(FEATURE_HEAD,
-                                  DPL::FromUTF8String(featureInfo));
+        m_popupData.addWidgetInfo(DPL::FromUTF8String(featureInfo));
     }
 
     m_installContext.job->UpdateProgress(
@@ -571,48 +564,50 @@ void TaskWidgetConfig::StepVerifyFeatures()
         "Widget Config step2 Finished");
 }
 
-void TaskWidgetConfig::setApplicationType()
+void TaskWidgetConfig::StepVerifyLivebox()
 {
     using namespace WrtDB;
-    WidgetRegisterInfo* widgetInfo = &(m_installContext.widgetConfig);
-    ConfigParserData* configInfo = &(widgetInfo->configInfo);
+    ConfigParserData &data = m_installContext.widgetConfig.configInfo;
+    ConfigParserData::LiveboxList liveBoxList = data.m_livebox;
 
-    FOREACH(iterator, configInfo->nameSpaces) {
-        LogInfo("namespace = [" << *iterator << "]");
-        AppType currentAppType = APP_TYPE_UNKNOWN;
+    if (liveBoxList.size() <= 0) {
+        return;
+    }
 
-        if (*iterator == ConfigurationNamespace::W3CWidgetNamespaceName) {
-            continue;
-        } else if (*iterator ==
-                ConfigurationNamespace::JilWidgetNamespaceName) {
-            currentAppType = APP_TYPE_WAC10;
-        } else if (
-            *iterator ==
-            ConfigurationNamespace::WacWidgetNamespaceNameForLinkElement ||
-            *iterator ==
-            ConfigurationNamespace::WacWidgetNamespaceName)
-        {
-            currentAppType = APP_TYPE_WAC20;
-        } else if (*iterator == ConfigurationNamespace::TizenWebAppNamespaceName) {
-            currentAppType = APP_TYPE_TIZENWEBAPP;
-        }
+    FOREACH (it, liveBoxList) {
+        std::string boxType;
 
-        if (widgetInfo->type == APP_TYPE_UNKNOWN) {
-            widgetInfo->type = currentAppType;
-        } else if (widgetInfo->type == currentAppType) {
-            continue;
+        if ((**it).m_type.empty()) {
+            boxType = web_provider_livebox_get_default_type();
         } else {
-            ThrowMsg(Exceptions::WidgetConfigFileInvalid,
-                     "Config.xml has more than one namespace");
+            boxType = DPL::ToUTF8String((**it).m_type);
         }
-    }
 
-    // If there is no define, type set to WAC 2.0
-    if (widgetInfo->type == APP_TYPE_UNKNOWN) {
-        widgetInfo->type = APP_TYPE_WAC20;
-    }
+        LogInfo("livebox type: " << boxType);
+
+        ConfigParserData::LiveboxInfo::BoxSizeList boxSizeList =
+            (**it).m_boxInfo.m_boxSize;
+        char** boxSize = static_cast<char**>(
+            malloc(sizeof(char*)* boxSizeList.size()));
 
-    LogInfo("type = [" << widgetInfo->type.getApptypeToString() << "]");
+        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,
@@ -624,7 +619,9 @@ bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType,
     LogInfo("FetureName = [" << featureName << "]");
 
     AppType featureType = APP_TYPE_UNKNOWN;
-    const char* feature = DPL::ToUTF8String(featureName).c_str();
+    std::string featureStr = DPL::ToUTF8String(featureName);
+    const char* feature = featureStr.c_str();
+
     // check prefix of  feature name
     if (strstr(feature, PluginsPrefix::TIZENPluginsPrefix) == feature) {
         // Tizen WebApp feature
@@ -648,5 +645,250 @@ bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType,
     return false;
 }
 
+bool TaskWidgetConfig::parseVersionString(const std::string &version,
+                                          long &majorVersion,
+                                          long &minorVersion,
+                                          long &microVersion) const
+{
+    std::istringstream inputString(version);
+    inputString >> majorVersion;
+    if (inputString.bad() || inputString.fail()) {
+        LogWarning("Invalid minVersion format.");
+        return false;
+    }
+    inputString.get(); // skip period
+    inputString >> minorVersion;
+    if (inputString.bad() || inputString.fail()) {
+        LogWarning("Invalid minVersion format");
+        return false;
+    } else {
+        inputString.get(); // skip period
+        if (inputString.bad() || inputString.fail()) {
+            inputString >> microVersion;
+        }
+    }
+    return true;
+}
+
+bool TaskWidgetConfig::isMinVersionCompatible(
+    WrtDB::AppType appType,
+    const DPL::OptionalString &
+    widgetVersion) const
+{
+    if (widgetVersion.IsNull() || (*widgetVersion).empty()) {
+        if (appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) {
+            return false;
+        } else {
+            LogWarning("minVersion attribute is empty. WRT assumes platform "
+                    "supports this widget.");
+            return true;
+        }
+    }
+
+    //Parse widget version
+    long majorWidget = 0, minorWidget = 0, microWidget = 0;
+    if (!parseVersionString(DPL::ToUTF8String(*widgetVersion), majorWidget,
+                            minorWidget, microWidget))
+    {
+        LogWarning("Invalid format of widget version string.");
+        return false;
+    }
+
+    //Parse supported version
+    long majorSupported = 0, minorSupported = 0, microSupported = 0;
+    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;
+    }
+
+    if (!parseVersionString(version,
+                            majorSupported, minorSupported, microSupported))
+    {
+        LogWarning("Invalid format of platform version string.");
+        return true;
+    }
+
+    if (majorWidget > majorSupported ||
+        (majorWidget == majorSupported && minorWidget > minorSupported) ||
+        (majorWidget == majorSupported && minorWidget == minorSupported
+         && microWidget > microSupported))
+    {
+        LogInfo("Platform doesn't support this widget.");
+        return false;
+    }
+    return true;
+}
+
+bool TaskWidgetConfig::isTizenWebApp() const
+{
+    bool ret = FALSE;
+    if (m_installContext.widgetConfig.webAppType.appType
+        == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
+    {
+        ret = TRUE;
+    }
+
+    return ret;
+}
+
+bool TaskWidgetConfig::parseConfigurationFileBrowser(
+    WrtDB::ConfigParserData& configInfo,
+    const std::string& _currentPath)
+{
+    ParserRunner parser;
+    Try
+    {
+        parser.Parse(_currentPath, ElementParserPtr(new
+                                                    RootParser<
+                                                        WidgetParser>(
+                                                        configInfo,
+                                                        DPL::FromUTF32String(
+                                                            L"widget"))));
+    }
+    Catch(ElementParser::Exception::Base)
+    {
+        LogError("Invalid widget configuration file!");
+        return false;
+    }
+    return true;
+}
+
+bool TaskWidgetConfig::parseConfigurationFileWidget(
+    WrtDB::ConfigParserData& configInfo,
+    const std::string& _currentPath)
+{
+    std::string configFilePath;
+    WrtUtilJoinPaths(configFilePath, _currentPath, WRT_WIDGET_CONFIG_FILE_NAME);
+    if (!WrtUtilFileExists(configFilePath))
+    {
+        LogError("Archive does not contain configuration file");
+        return false;
+    }
+
+    LogDebug("Configuration file: " << configFilePath);
+
+    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,
+                                          DPL::FromUTF32String(L"widget"))));
+        return true;
+    }
+    Catch (ElementParser::Exception::Base)
+    {
+        LogError("Invalid configuration file!");
+        return false;
+    }
+}
+
+bool TaskWidgetConfig::locateAndParseConfigurationFile(
+    const std::string& _currentPath,
+    WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+    const std::string& baseFolder)
+{
+    using namespace WrtDB;
+
+    ConfigParserData& configInfo = pWidgetConfigInfo.configInfo;
+
+    // check if this installation from browser, or not.
+    size_t pos = _currentPath.rfind("/");
+    std::ostringstream infoPath;
+    infoPath << _currentPath.substr(pos + 1);
+
+    if (infoPath.str() != WRT_WIDGET_CONFIG_FILE_NAME) {
+        if (_currentPath.empty() || baseFolder.empty()) {
+            return false;
+        }
+        // in case of general installation using wgt archive
+        if (!parseConfigurationFileWidget(configInfo, _currentPath))
+        {
+            return false;
+        }
+    } else {
+        // in case of browser installation
+        if (!parseConfigurationFileBrowser(configInfo, _currentPath))
+        {
+            return false;
+        }
+    }
+
+    if (!fillWidgetConfig(pWidgetConfigInfo, configInfo)) {
+        return false;
+    }
+    return true;
+}
+
+bool TaskWidgetConfig::fillWidgetConfig(
+    WrtDB::WidgetRegisterInfo& pWidgetConfigInfo,
+    WrtDB::ConfigParserData& configInfo)
+{
+    if (!!configInfo.widget_id) {
+        if (!pWidgetConfigInfo.guid) {
+            pWidgetConfigInfo.guid = configInfo.widget_id;
+        } else {
+            if (pWidgetConfigInfo.guid != configInfo.widget_id) {
+                LogError("Invalid archive");
+                return false;
+            }
+        }
+    }
+    if (!!configInfo.tizenAppId) {
+        if (DPL::ToUTF8String(pWidgetConfigInfo.tzAppid).compare(
+                DPL::ToUTF8String(*configInfo.tizenAppId)) < 0)
+        {
+            LogError("Invalid archive - Tizen App ID not same error");
+            return false;
+        }
+    }
+    if (!!configInfo.tizenPkgId) {
+        if (pWidgetConfigInfo.tzPkgid != *configInfo.tizenPkgId) {
+            LogError("Invalid archive - Tizen Pkg ID not same error");
+            return false;
+        }
+    }
+    if (!!configInfo.version) {
+        if (!pWidgetConfigInfo.version) {
+            pWidgetConfigInfo.version = configInfo.version;
+        } else {
+            if (pWidgetConfigInfo.version != configInfo.version) {
+                LogError("Invalid archive");
+                return false;
+            }
+        }
+    }
+    if (!!configInfo.minVersionRequired) {
+        pWidgetConfigInfo.minVersion = configInfo.minVersionRequired;
+    } else if (!!configInfo.tizenMinVersionRequired) {
+        pWidgetConfigInfo.minVersion = configInfo.tizenMinVersionRequired;
+    }
+    return true;
+}
+
+void TaskWidgetConfig::processFile(
+    const std::string& path,
+    WrtDB::WidgetRegisterInfo &
+    widgetConfiguration)
+{
+    if (!locateAndParseConfigurationFile(path, widgetConfiguration,
+                                         DEFAULT_LANGUAGE))
+    {
+        LogWarning("Widget archive: Failed while parsing config file");
+        ThrowMsg(Exception::ConfigParseFailed, path);
+    }
+}
 } //namespace WidgetInstall
 } //namespace Jobs