From cbed979a997b651c27f4c04865e8f66aa3fa30b5 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Tue, 28 Apr 2015 20:15:11 +0900 Subject: [PATCH] Terminate app when manifest can not be loaded. Change-Id: Ie2327b6366b9ca8b2f2db79b9c9ca1f53be517f2 --- src/runtime/application_data.cc | 22 ++++++++++++---------- src/runtime/application_data.h | 10 ++++------ src/runtime/resource_manager.cc | 19 ++++++++++++------- src/runtime/runtime.cc | 8 +++++++- src/runtime/web_application.cc | 26 +++++++++++++------------- src/runtime/web_application.h | 5 ++--- 6 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/runtime/application_data.cc b/src/runtime/application_data.cc index 87bb2ff..be65ab9 100644 --- a/src/runtime/application_data.cc +++ b/src/runtime/application_data.cc @@ -10,6 +10,9 @@ #include +#include "common/logger.h" +#include "common/file_utils.h" + namespace wrt { namespace { @@ -59,15 +62,9 @@ ApplicationData::ApplicationData(const std::string& appid) : app_id_(appid) { pkg_id_ = GetPackageIdByAppId(appid); if (!pkg_id_.empty()) { - pkg_root_path_ = GetPackageRootPath(pkg_id_); - } - - if (!pkg_root_path_.empty()) { - config_xml_path_ = pkg_root_path_ + kPathSeparator + - app_id_ + kPathSeparator + kConfigXml; + application_path_ = GetPackageRootPath(pkg_id_) + kPathSeparator + + appid + kPathSeparator; } - - LoadManifestData(); } ApplicationData::~ApplicationData() {} @@ -138,7 +135,10 @@ std::shared_ptr } bool ApplicationData::LoadManifestData() { - if (config_xml_path_.empty()) { + std::string config_xml_path(application_path_ + kConfigXml); + if (!utils::Exists(config_xml_path)) { + LoggerE("Failed to load manifest data. : No such file '%s'", + config_xml_path.c_str()); return false; } @@ -178,10 +178,12 @@ bool ApplicationData::LoadManifestData() { registry.reset(new parser::ManifestHandlerRegistry(handlers)); parser::ManifestParser manifest_parser(std::move(registry)); - if (!manifest_parser.ParseManifest(config_xml_path_)) { + if (!manifest_parser.ParseManifest(config_xml_path)) { for (auto iter = handlers.begin(); iter != handlers.end(); ++iter) { delete *iter; } + LoggerE("Failed to load manifest data. : %s", + manifest_parser.GetErrorMessage().c_str()); return false; } diff --git a/src/runtime/application_data.h b/src/runtime/application_data.h index b1dd14c..f3e1be8 100755 --- a/src/runtime/application_data.h +++ b/src/runtime/application_data.h @@ -30,6 +30,8 @@ class ApplicationData { explicit ApplicationData(const std::string& appid); ~ApplicationData(); + bool LoadManifestData(); + std::shared_ptr application_icons_info() const; std::shared_ptr @@ -57,14 +59,11 @@ class ApplicationData { std::shared_ptr widget_info() const; - std::string config_xml_path() const { return config_xml_path_; } - const std::string pkg_root_path() const { return pkg_root_path_; } + const std::string application_path() const { return application_path_; } const std::string pkg_id() const { return pkg_id_; } const std::string app_id() const { return app_id_; } private: - bool LoadManifestData(); - std::shared_ptr application_icons_info_; std::shared_ptr @@ -92,8 +91,7 @@ class ApplicationData { std::shared_ptr widget_info_; - std::string config_xml_path_; - std::string pkg_root_path_; + std::string application_path_; std::string pkg_id_; std::string app_id_; }; diff --git a/src/runtime/resource_manager.cc b/src/runtime/resource_manager.cc index d80fffe..e62f22d 100755 --- a/src/runtime/resource_manager.cc +++ b/src/runtime/resource_manager.cc @@ -170,15 +170,20 @@ std::string ResourceManager::GetDefaultOrEmpty() { // TODO(yons.kim): tizen content src // content src - const AppWidgetVector app_widgets = - application_data_->app_widget_info()->app_widgets(); - for (auto iter = app_widgets.begin(); - iter != app_widgets.end(); ++iter) { - if (iter->id == appid_) { - default_src = iter->content_src; - break; + auto app_widget_info = application_data_->app_widget_info(); + if (app_widget_info) { + const AppWidgetVector app_widgets = app_widget_info->app_widgets(); + for (auto iter = app_widgets.begin(); + iter != app_widgets.end(); ++iter) { + if (iter->id == appid_) { + default_src = iter->content_src; + break; + } } + } else { + LoggerW("AppWidgetInfo is NULL."); } + if (!default_src.empty()) { return InsertPrefixPath(default_src); } diff --git a/src/runtime/runtime.cc b/src/runtime/runtime.cc index 885ce1e..7e17a8f 100755 --- a/src/runtime/runtime.cc +++ b/src/runtime/runtime.cc @@ -13,6 +13,7 @@ #include "common/command_line.h" #include "runtime/native_app_window.h" #include "runtime/app_control.h" +#include "runtime/application_data.h" namespace wrt { @@ -72,8 +73,13 @@ bool Runtime::OnCreate() { std::string appid = CommandLine::ForCurrentProcess()->appid(); // Process First Launch + std::unique_ptr appdata(new ApplicationData(appid)); + if (!appdata->LoadManifestData()) { + return false; + } + native_window_ = CreateNativeWindow(); - application_ = new WebApplication(native_window_, appid); + application_ = new WebApplication(native_window_, std::move(appdata)); application_->set_terminator([](){ ui_app_exit(); }); // Start DBus Server for Runtime diff --git a/src/runtime/web_application.cc b/src/runtime/web_application.cc index 5e48870..8727788 100755 --- a/src/runtime/web_application.cc +++ b/src/runtime/web_application.cc @@ -60,13 +60,6 @@ namespace { namespace wrt { WebApplication::WebApplication( - NativeWindow* window, const std::string& appid) - : WebApplication( - window, - std::unique_ptr(new ApplicationData(appid))) { -} - -WebApplication::WebApplication( NativeWindow* window, std::unique_ptr app_data) : launched_(false), debug_mode_(false), @@ -85,7 +78,7 @@ WebApplication::WebApplication( resource_manager_.reset( new ResourceManager(app_data_.get(), locale_manager_.get())); resource_manager_->set_base_resource_path( - app_data_->pkg_root_path() + "/" + appid_ + "/"); + app_data_->application_path()); Initialize(); } @@ -121,12 +114,7 @@ bool WebApplication::Initialize() { vibration_stop_callback, NULL); - // send widget info to injected bundle - // TODO(wy80.choi): ewk_send_widget_info should be fixed to receive uuid of - // application instead of widget_id. - // Currently, uuid is passed as theme argument temporarily. - ewk_send_widget_info(ewk_context_, 1, 0.0, uuid_.c_str(), ""); // TODO(sngn.lee): Find the path of certificate file // ewk_context_certificate_file_set(ewk_context_, .... ); @@ -145,7 +133,19 @@ void WebApplication::Launch(std::unique_ptr appcontrol) { WebView* view = new WebView(window_, ewk_context_); view->SetEventListener(this); + // send widget info to injected bundle + // TODO(wy80.choi): ewk_send_widget_info should be fixed to receive uuid of + // application instead of widget_id. + // Currently, uuid is passed as encoded_bundle argument temporarily. + // ewk_send_widget_info(ewk_context_, 1, + // elm_config_scale_get(), + // elm_theme_get(NULL), + // uuid_.c_str()); + + // view->LoadUrl("file:///home/owner/apps_rw/33CFo0eFJe/" + // "33CFo0eFJe.annex/index.html"); view->LoadUrl(resource_manager_->GetStartURL()); + view_stack_.push_front(view); window_->SetContent(view->evas_object()); diff --git a/src/runtime/web_application.h b/src/runtime/web_application.h index 419cac2..1226e3b 100755 --- a/src/runtime/web_application.h +++ b/src/runtime/web_application.h @@ -23,9 +23,8 @@ class ResourceManager; class WebApplication : public WebView::EventListener { public: - explicit WebApplication(NativeWindow* window, const std::string& appid); - explicit WebApplication(NativeWindow* window, - std::unique_ptr app_data); + WebApplication(NativeWindow* window, + std::unique_ptr app_data); virtual ~WebApplication(); void AppControl(std::unique_ptr appcontrol); -- 2.7.4