Added parsing for background-category element. 00/50500/5
authorLukasz Wysocki <l.wysocki@samsung.com>
Thu, 29 Oct 2015 10:15:20 +0000 (11:15 +0100)
committerLukasz Wysocki <l.wysocki@samsung.com>
Wed, 18 Nov 2015 14:22:09 +0000 (15:22 +0100)
Change-Id: Idab18c81bdafbd3c0cbfffdcac0387ded1d5c257

src/manifest_handlers/CMakeLists.txt
src/manifest_handlers/application_manifest_constants.cc
src/manifest_handlers/application_manifest_constants.h
src/manifest_handlers/background_category_handler.cc [new file with mode: 0644]
src/manifest_handlers/background_category_handler.h [new file with mode: 0644]
src/manifest_handlers/widget_config_parser.cc

index c97378a50abd0b461824876e42fcdf822c120503..b9e4afd6a626cf759ee17f2c212ad89db00c50f9 100644 (file)
@@ -5,6 +5,7 @@ SET(SRCS
   application_manifest_constants.cc
   application_icons_handler.cc
   appwidget_handler.cc
+  background_category_handler.cc
   category_handler.cc
   content_handler.cc
   csp_handler.cc
index c88473e778874104709b87e526bf2ba29918ae5b..80c0374178bf6a9f80a54ab45e12da14baafb493 100644 (file)
@@ -49,6 +49,7 @@ const char kTizenApplicationLaunchModeKey[] = "@launch_mode";
 const char kTizenApplicationPackageKey[] = "@package";
 
 const char kAllowNavigationKey[] = "widget.allow-navigation";
+const char kTizenBackgroundCategoryKey[] = "widget.background-category";
 const char kTizenSettingKey[] = "widget.setting";
 const char kTizenInstallLocationKey[] = "@install-location";
 const char kTizenUserAgentKey[] = "@user-agent";
index 1f688c42e14a4fb3e91c90eee685c3584c19e39b..51380811a4ce4f846789fe6209ace64684dc7c0e 100644 (file)
@@ -31,6 +31,7 @@ extern const char kIconsKey[];
 extern const char kTizenApplicationAppControlsKey[];
 extern const char kTizenApplicationKey[];
 extern const char kTizenAppWidgetFullKey[];
+extern const char kTizenBackgroundCategoryKey[];
 extern const char kTizenCategoryKey[];
 extern const char kTizenContentKey[];
 extern const char kTizenImeKey[];
diff --git a/src/manifest_handlers/background_category_handler.cc b/src/manifest_handlers/background_category_handler.cc
new file mode 100644 (file)
index 0000000..172d1da
--- /dev/null
@@ -0,0 +1,63 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE-xwalk file.
+
+#include "manifest_handlers/background_category_handler.h"
+
+#include "manifest_handlers/application_manifest_constants.h"
+
+namespace {
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kTizenBackgroundCategoryValueKey[] = "@value";
+const char kErrMsgElementParse[] = "Parsing background-category element failed";
+}  // namespace
+
+namespace wgt {
+namespace parse {
+
+namespace keys = wgt::application_widget_keys;
+
+bool BackgroundCategoryHandler::ParseBackgroundCategoryElement(
+    const parser::DictionaryValue& element_dict,
+    BackgroundCategoryInfoList* bclist) {
+  std::string value;
+
+  if (!element_dict.GetString(kTizenBackgroundCategoryValueKey, &value))
+    return false;
+
+  bclist->background_categories.emplace_back(value);
+
+  return true;
+}
+
+bool BackgroundCategoryHandler::Parse(
+    const parser::Manifest& manifest,
+    std::shared_ptr<parser::ManifestData>* output,
+    std::string* error) {
+  if (!manifest.HasPath(keys::kTizenBackgroundCategoryKey))
+    return true;
+
+  std::shared_ptr<BackgroundCategoryInfoList> bclist(
+      new BackgroundCategoryInfoList());
+
+  for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+      keys::kTizenBackgroundCategoryKey, kTizenNamespacePrefix)) {
+    if (!ParseBackgroundCategoryElement(*dict, bclist.get())) {
+      *error = kErrMsgElementParse;
+      return false;
+    }
+  }
+
+  *output = std::static_pointer_cast<parser::ManifestData>(bclist);
+  return true;
+}
+
+std::string BackgroundCategoryHandler::Key() const {
+  return keys::kTizenBackgroundCategoryKey;
+}
+
+BackgroundCategoryInfo::BackgroundCategoryInfo(const std::string& value) :
+    value_(value) {}
+
+}  // namespace parse
+}  // namespace wgt
diff --git a/src/manifest_handlers/background_category_handler.h b/src/manifest_handlers/background_category_handler.h
new file mode 100644 (file)
index 0000000..95a809b
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE-xwalk file.
+
+#ifndef MANIFEST_HANDLERS_BACKGROUND_CATEGORY_HANDLER_H_
+#define MANIFEST_HANDLERS_BACKGROUND_CATEGORY_HANDLER_H_
+
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+/**
+ * \brief Holds details about background-category element
+ *
+ * Purpose of this class is to hold information declared in background-category
+ * element in manifest xml document
+ */
+class BackgroundCategoryInfo : public parser::ManifestData {
+ public:
+  explicit BackgroundCategoryInfo(const std::string& value);
+  virtual ~BackgroundCategoryInfo() {}
+
+  const std::string& value() const { return value_; }
+
+ private:
+  std::string value_;
+};
+
+/**
+ * \brief Container for detailed information of each declaration of
+ *        background-category element
+ */
+struct BackgroundCategoryInfoList : public parser::ManifestData {
+  std::vector<BackgroundCategoryInfo> background_categories;
+};
+
+/**
+ * \brief The BackgroundCategoryHandler class
+ *
+ * Handler of config.xml for xml elements:
+ *  - <tizen:background-category>.
+ */
+class BackgroundCategoryHandler : public parser::ManifestHandler {
+ public:
+  bool Parse(
+      const parser::Manifest& manifest,
+      std::shared_ptr<parser::ManifestData>* output,
+      std::string* error) override;
+  std::string Key() const override;
+
+ private:
+  bool ParseBackgroundCategoryElement(
+      const parser::DictionaryValue& element_dict,
+      BackgroundCategoryInfoList* bclist);
+};
+
+}  // namespace parse
+}  // namespace wgt
+
+#endif  // MANIFEST_HANDLERS_BACKGROUND_CATEGORY_HANDLER_H_
index bde00009318435527b963f932b59c3061c84856d..d663e0b761e74e7793c6cd6f9722eb84531bdfb3 100644 (file)
@@ -23,6 +23,7 @@
 #include "manifest_handlers/application_icons_handler.h"
 #include "manifest_handlers/application_manifest_constants.h"
 #include "manifest_handlers/appwidget_handler.h"
+#include "manifest_handlers/background_category_handler.h"
 #include "manifest_handlers/category_handler.h"
 #include "manifest_handlers/content_handler.h"
 #include "manifest_handlers/csp_handler.h"
@@ -224,7 +225,8 @@ WidgetConfigParser::WidgetConfigParser() {
     new SplashScreenHandler,
     new TizenApplicationHandler,
     new WarpHandler,
-    new WidgetHandler
+    new WidgetHandler,
+    new BackgroundCategoryHandler
   };
 
   std::unique_ptr<parser::ManifestHandlerRegistry> registry(