Terminate app when manifest can not be loaded.
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 28 Apr 2015 11:15:11 +0000 (20:15 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 28 Apr 2015 11:15:11 +0000 (20:15 +0900)
Change-Id: Ie2327b6366b9ca8b2f2db79b9c9ca1f53be517f2

src/runtime/application_data.cc
src/runtime/application_data.h
src/runtime/resource_manager.cc
src/runtime/runtime.cc
src/runtime/web_application.cc
src/runtime/web_application.h

index 87bb2ff..be65ab9 100644 (file)
@@ -10,6 +10,9 @@
 
 #include <vector>
 
+#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<const wgt::parse::WidgetInfo>
 }
 
 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;
   }
 
index b1dd14c..f3e1be8 100755 (executable)
@@ -30,6 +30,8 @@ class ApplicationData {
   explicit ApplicationData(const std::string& appid);
   ~ApplicationData();
 
+  bool LoadManifestData();
+
   std::shared_ptr<const wgt::parse::ApplicationIconsInfo>
     application_icons_info() const;
   std::shared_ptr<const wgt::parse::AppWidgetInfo>
@@ -57,14 +59,11 @@ class ApplicationData {
   std::shared_ptr<const wgt::parse::WidgetInfo>
     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<const wgt::parse::ApplicationIconsInfo>
     application_icons_info_;
   std::shared_ptr<const wgt::parse::AppWidgetInfo>
@@ -92,8 +91,7 @@ class ApplicationData {
   std::shared_ptr<const wgt::parse::WidgetInfo>
     widget_info_;
 
-  std::string config_xml_path_;
-  std::string pkg_root_path_;
+  std::string application_path_;
   std::string pkg_id_;
   std::string app_id_;
 };
index d80fffe..e62f22d 100755 (executable)
@@ -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);
   }
index 885ce1e..7e17a8f 100755 (executable)
@@ -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<ApplicationData> 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
index 5e48870..8727788 100755 (executable)
@@ -60,13 +60,6 @@ namespace {
 namespace wrt {
 
 WebApplication::WebApplication(
-    NativeWindow* window, const std::string& appid)
-    : WebApplication(
-        window,
-        std::unique_ptr<ApplicationData>(new ApplicationData(appid))) {
-}
-
-WebApplication::WebApplication(
     NativeWindow* window, std::unique_ptr<ApplicationData> 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<wrt::AppControl> 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());
 
index 419cac2..1226e3b 100755 (executable)
@@ -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<ApplicationData> app_data);
+  WebApplication(NativeWindow* window,
+                 std::unique_ptr<ApplicationData> app_data);
   virtual ~WebApplication();
 
   void AppControl(std::unique_ptr<wrt::AppControl> appcontrol);