#include "widget_parser.h"
#include "parser_runner.h"
#include <widget_install/job_widget_install.h>
-#include <widget_install/task_parental_mode.h>
#include <widget_install/task_unzip.h>
#include <widget_install/task_certify.h>
#include <widget_install/task_widget_config.h>
#include <widget_install/task_smack.h>
#include <widget_install/task_desktop_file.h>
#include <widget_install/task_private_storage.h>
+#include <widget_install/task_prepare_files.h>
#include <widget_install/widget_install_errors.h>
#include <widget_install/widget_install_context.h>
#include <string>
#include <dpl/wrt-dao-rw/global_dao.h> // TODO remove
#include <aul.h>
#include <dpl/localization/w3c_file_localization.h>
+#include <libiriwrapper.h>
using namespace WrtDB;
{
const char * const CONFIG_XML = "config.xml";
-struct PathAndFilePair
-{
- std::string path;
- std::string file;
-
- PathAndFilePair(const std::string &p,
- const std::string &f) :
- path(p),
- file(f)
- {
- }
-};
-
-PathAndFilePair SplitFileAndPath(const std::string &filePath)
-{
- std::string::size_type position = filePath.rfind('/');
-
- // Is this only a file without a path ?
- if (position == std::string::npos) {
- return PathAndFilePair(std::string(), filePath);
- }
-
- // This is full file-path pair
- return PathAndFilePair(filePath.substr(0,
- position),
- filePath.substr(position + 1));
-}
-
class InstallerTaskFail :
public DPL::TaskDecl<InstallerTaskFail>
{
m_exceptionCaught(Exceptions::Success)
{
// Configure installation
- ConfigureResult result = ConfigureInstallation(widgetPath);
+ ConfigureResult result = ConfigureInstallation(widgetPath, false);
if (result == ConfigureResult::Ok) {
LogInfo("Configure installation succeeded");
// Create installation tasks
- AddTask(new TaskParentalMode(m_installerContext));
AddTask(new TaskUnzip(m_installerContext));
AddTask(new TaskWidgetConfig(m_installerContext));
AddTask(new TaskCertify(m_installerContext));
}
}
-DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
+JobWidgetInstall::JobWidgetInstall(
+ std::string const & widgetUrl,
+ std::string const & iconPath,
+ const WidgetInstallationStruct &installerStruct) :
+ Job(Installation),
+ JobContextBase<WidgetInstallationStruct>(installerStruct),
+ m_exceptionCaught(Exceptions::Success)
{
- return m_installerContext.widgetHandle;
-}
+ // Configure installation
+ ConfigureResult result = ConfigureInstallation(widgetUrl, true);
-bool JobWidgetInstall::getUnzipStartedFlag() const
-{
- return m_installerContext.unzipStarted;
+ if (result == ConfigureResult::Ok) {
+ LogInfo("Configure installation succeeded");
+
+ // Check web app url
+ LibIri::Wrapper iri(widgetUrl.c_str());
+ if (!iri.Validate()) {
+ ThrowMsg(Exceptions::InvalidWidgetUrl,
+ "Web app url must be a valid iri/uri/url");
+ }
+
+ m_installerContext.widgetConfig.configInfo.startFile =
+ DPL::FromUTF8String(widgetUrl);
+
+ m_installerContext.iconPath = iconPath;
+
+ // Create installation tasks
+ AddTask(new TaskPrepareFiles(m_installerContext));
+ AddTask(new TaskWidgetConfig(m_installerContext));
+ AddTask(new TaskCertify(m_installerContext));
+ AddTask(new TaskDbUpdate(m_installerContext));
+ // TODO: Update progress information for this task
+
+ AddTask(new TaskAceCheck(m_installerContext));
+ //This is sort of quick solution, because ACE verdicts are based upon
+ //data from DAO (DB). So AceCheck for now has to be AFTER DbUpdate
+ //task.
+ AddTask(new TaskSmack(m_installerContext));
+
+ AddTask(new TaskDesktopFile(m_installerContext));
+ AddTask(new TaskPrivateStorage(m_installerContext));
+ } else if (result == ConfigureResult::Deferred) {
+ // Installation is deferred
+ LogInfo("Configure installation deferred");
+
+ AddTask(new InstallerTaskFail(true));
+ } else if (result == ConfigureResult::Failed) {
+ // Installation is not allowed to proceed due to widget update policy
+ LogWarning("Configure installation failed!");
+
+ AddTask(new InstallerTaskFail(false));
+ } else {
+ Assert(false && "Invalid configure result!");
+ }
}
-bool JobWidgetInstall::getUnzipFinishedFlag() const
+DPL::Optional<WidgetHandle> JobWidgetInstall::getNewWidgetHandle() const
{
- return m_installerContext.unzipFinished;
+ return m_installerContext.widgetHandle;
}
JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation(
- const std::string &widgetPath)
+ const std::string &widgetSource, bool fromBrowser)
{
// Detect widget update
- WidgetUpdateInfo update = detectWidgetUpdate(widgetPath);
+ WidgetUpdateInfo update = detectWidgetUpdate(widgetSource, fromBrowser);
LogInfo(
"Widget install/update: incoming guid = '" <<
if (m_jobStruct.updateMode == WidgetUpdateMode::PolicyWac) {
LogInfo(
"Widget is already running. Policy is update according to WAC");
- LogInfo("Installation deferred: " << widgetPath);
+ LogInfo("Installation deferred: " << widgetSource);
GlobalDAO::AddDefferedWidgetPackageInstallation(
- DPL::FromUTF8String(widgetPath));
+ DPL::FromUTF8String(widgetSource));
return ConfigureResult::Deferred;
} else {
LogInfo(
"Widget is already running. Policy is not update according to WAC");
- LogInfo("Installation aborted: " << widgetPath);
+ LogInfo("Installation aborted: " << widgetSource);
return ConfigureResult::Failed;
}
LogInfo("Whether widget policy allow proceed: " << canProceed);
// Init installer context
- m_installerContext.widgetFilePath = widgetPath;
+ m_installerContext.widgetSource = widgetSource;
m_installerContext.tempWidgetPath = std::string();
m_installerContext.widgetConfig = WidgetRegisterInfo();
- m_installerContext.unzipStarted = false;
- m_installerContext.unzipFinished = false;
m_installerContext.installStep = InstallerContext::INSTALL_START;
m_installerContext.job = this;
m_installerContext.existingWidgetInfo = update.existingWidgetInfo;
}
WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate(
- const std::string &widgetPath)
+ const std::string &widgetSource, bool fromBrowser)
{
LogInfo("Checking up widget package for config.xml...");
Try
{
- // Open zip file
- DPL::ScopedPtr<DPL::ZipInput> zipFile(
- new DPL::ZipInput(widgetPath));
-
- // Open config.xml file
- DPL::ScopedPtr<DPL::ZipInput::File> configFile(
- zipFile->OpenFile(CONFIG_XML));
-
- // Extract config
- DPL::BinaryQueue buffer;
- DPL::AbstractWaitableInputAdapter inputAdapter(configFile.Get());
- DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
- DPL::Copy(&inputAdapter, &outputAdapter);
-
- // Parse config
- ParserRunner parser;
- ConfigParserData configInfo;
-
- parser.Parse(&buffer,
- ElementParserPtr(
- new RootParser<WidgetParser>(configInfo,
- DPL::FromUTF32String(
- L"widget"))));
-
- // Check widget id
- DPL::OptionalString widgetGUID = configInfo.widget_id;
-
- if (widgetGUID.IsNull()) {
- LogDebug("Installed widget has no GUID");
- return WidgetUpdateInfo();
+ DPL::OptionalString widgetGUID;
+ OptionalWidgetVersion widgetVersion;
+ if (fromBrowser) {
+ widgetGUID = DPL::FromUTF8String(widgetSource);
}
+ else {
+ // Open zip file
+ DPL::ScopedPtr<DPL::ZipInput> zipFile(
+ new DPL::ZipInput(widgetSource));
+
+ // Open config.xml file
+ DPL::ScopedPtr<DPL::ZipInput::File> configFile(
+ zipFile->OpenFile(CONFIG_XML));
+
+ // Extract config
+ DPL::BinaryQueue buffer;
+ DPL::AbstractWaitableInputAdapter inputAdapter(configFile.Get());
+ DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
+ DPL::Copy(&inputAdapter, &outputAdapter);
+
+ // Parse config
+ ParserRunner parser;
+ ConfigParserData configInfo;
+
+ parser.Parse(&buffer,
+ ElementParserPtr(
+ new RootParser<WidgetParser>(configInfo,
+ DPL::FromUTF32String(
+ L"widget"))));
+
+ // Check widget id
+ widgetGUID = configInfo.widget_id;
+
+ if (widgetGUID.IsNull()) {
+ LogDebug("Installed widget has no GUID");
+ return WidgetUpdateInfo();
+ }
- LogDebug("Installed widget GUID: " << *widgetGUID);
+ LogDebug("Installed widget GUID: " << *widgetGUID);
- // Locate widget ID with this GUID
- // Incoming widget version
- OptionalWidgetVersion widgetVersion;
- if (!configInfo.version.IsNull()) {
- widgetVersion =
- DPL::Optional<WidgetVersion>(
- WidgetVersion(*configInfo.version));
+ // Locate widget ID with this GUID
+ // Incoming widget version
+ if (!configInfo.version.IsNull()) {
+ widgetVersion =
+ DPL::Optional<WidgetVersion>(
+ WidgetVersion(*configInfo.version));
+ }
}
try
WidgetUpdateInfo::ExistingWidgetInfo(
dao.getHandle(), dao.getVersion()));
}
- Catch(WidgetDAO::Exception::WidgetNotExist){
+ Catch(WidgetDAOReadOnly::Exception::WidgetNotExist){
// GUID isn't installed
return WidgetUpdateInfo(
widgetGUID,
DPL::Optional<WidgetHandle> handle = getNewWidgetHandle();
Assert(!!handle);
- WidgetDAO dao(*handle);
+ WidgetDAOReadOnly dao(*handle);
std::ostringstream out;
WidgetLocalizedInfo localizedInfo =
}
}
- out << std::endl << "Back Supported: " <<
- (dao.getBackSupported() ? "YES" : "NO");
-
out << std::endl;
LogInfo(out.str());
}
+
} //namespace WidgetInstall
} //namespace Jobs