SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++11 -g --coverage")
# Targets
-SET(TARGET_LIBNAME_MANIFEST_HANDLERS "manifest-handlers")
+SET(TARGET_LIBNAME_WGT_MANIFEST_HANDLERS "wgt-manifest-handlers")
SET(TARGET_LIBNAME_TPK_MANIFEST_HANDLERS "tpk-manifest-handlers")
SET(TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS "delta-manifest-handlers")
SET(TARGET_LIBNAME_PARSER "manifest-parser")
%{_datarootdir}/manifest-parser/languages-only.txt
%{_libdir}/libmanifest-parser.so*
%{_libdir}/libmanifest-parser-utils.so*
-%{_libdir}/libmanifest-handlers.so*
%{_libdir}/libtpk-manifest-handlers.so*
+%{_libdir}/libwgt-manifest-handlers.so*
%{_libdir}/libdelta-manifest-handlers.so*
%license LICENSE LICENSE-xwalk
%{_libdir}/pkgconfig/*.pc
%{_includedir}/manifest_parser/*.h
%{_includedir}/manifest_parser/utils/*.h
-%{_includedir}/manifest_handlers/*.h
%{_includedir}/tpk_manifest_handlers/*.h
%{_includedir}/tpk_manifest_handlers/common/*.h
+%{_includedir}/wgt_manifest_handlers/*.h
%{_includedir}/delta/*.h
%files tests
ADD_SUBDIRECTORY(manifest_parser)
-ADD_SUBDIRECTORY(manifest_handlers)
ADD_SUBDIRECTORY(tpk_manifest_handlers)
ADD_SUBDIRECTORY(unit_tests)
+ADD_SUBDIRECTORY(wgt_manifest_handlers)
ADD_SUBDIRECTORY(examples)
ADD_SUBDIRECTORY(delta)
"${CMAKE_CURRENT_SOURCE_DIR}/../")
# Extra
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES VERSION ${VERSION})
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${VERSION_MAJOR})
# Install
INSTALL(TARGETS ${TARGET_LIBNAME_DELTA_MANIFEST_HANDLERS} DESTINATION ${LIB_INSTALL_DIR})
Boost
)
-TARGET_LINK_LIBRARIES(${TARGET_EXAMPLES} PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_MANIFEST_HANDLERS})
+TARGET_LINK_LIBRARIES(${TARGET_EXAMPLES} PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS})
INSTALL(FILES config.xml DESTINATION ${SHAREDIR}/manifest-parser)
// Include manifest parser
#include <manifest_parser/manifest_parser.h>
// Include manifest handler, which is packaged with manifest parser
-#include <manifest_handlers/tizen_application_handler.h>
+#include <wgt_manifest_handlers/tizen_application_handler.h>
#include <boost/filesystem/path.hpp>
#include <cassert>
+++ /dev/null
-# Target - sources
-SET(SRCS
- account_handler.cc
- app_control_handler.cc
- application_manifest_constants.cc
- application_icons_handler.cc
- appwidget_handler.cc
- background_category_handler.cc
- category_handler.cc
- content_handler.cc
- csp_handler.cc
- ime_handler.cc
- metadata_handler.cc
- navigation_handler.cc
- permissions_handler.cc
- platform_version.cc
- setting_handler.cc
- service_handler.cc
- splash_screen_handler.cc
- tizen_application_handler.cc
- warp_handler.cc
- widget_config_parser.cc
- widget_handler.cc
-)
-
-# Target - definition
-ADD_LIBRARY(${TARGET_LIBNAME_MANIFEST_HANDLERS} SHARED ${SRCS})
-# Target - includes
-TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PUBLIC
- "${CMAKE_CURRENT_SOURCE_DIR}/../")
-APPLY_PKG_CONFIG(${TARGET_LIBNAME_MANIFEST_HANDLERS} PUBLIC
- XGDMIME_DEPS
-)
-
-# Extra
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES VERSION ${VERSION})
-SET_TARGET_PROPERTIES(${TARGET_LIBNAME_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${VERSION_MAJOR})
-
-# Install
-INSTALL(TARGETS ${TARGET_LIBNAME_MANIFEST_HANDLERS} DESTINATION ${LIB_INSTALL_DIR})
-
-# Install includes
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}
- FILES_MATCHING PATTERN "*.h")
-
-# Configure and install pkgconfig file
-SET(PKG_FILE manifest-handlers.pc)
-CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
-INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+++ /dev/null
-// 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 file.
-
-#include "manifest_handlers/account_handler.h"
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/language_tag_validator.h"
-#include "manifest_parser/utils/logging.h"
-
-namespace {
-
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kAccountKey[] = "widget.account";
-
-const char kSectionIconAccount[] = "Account";
-const char kSectionIconAccountSmall[] = "AccountSmall";
-const char kTrueValueString[] = "true";
-const char kFalseValueString[] = "false";
-const char kAccountMASKey[] = "@multiple-account-support";
-const char kAccountSectionKey[] = "@section";
-const char kAccountTextKey[] = "#text";
-const char kAccountNameKey[] = "display-name";
-const char kAccountLangKey[] = "@lang";
-const char kAccountIconKey[] = "icon";
-const char kAccountCapabilityKey[] = "capability";
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-bool AccountHandler::Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kAccountKey))
- return true;
-
- auto info = std::make_shared<AccountInfo>();
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kAccountKey, kTizenNamespacePrefix)) {
- if (!ParseSingleAccountElement(dict, info, error))
- return false;
- }
-
- *output = std::static_pointer_cast<AccountInfo>(info);
- return true;
-}
-
-std::string AccountHandler::Key() const {
- return kAccountKey;
-}
-
-std::string AccountInfo::Key() {
- return kAccountKey;
-}
-
-bool AccountHandler::ParseSingleAccountElement(
- const parser::DictionaryValue* item_dict,
- std::shared_ptr<AccountInfo> info,
- std::string* error) {
- std::string multiple_apps_support;
- SingleAccountInfo single_account;
- if (!item_dict->GetString(kAccountMASKey, &multiple_apps_support)) {
- *error = "Error while parsing multiple apps support in account";
- return false;
- }
- bool mas_bool = false;
- if (multiple_apps_support == kFalseValueString) {
- mas_bool = false;
- } else if (multiple_apps_support == kTrueValueString) {
- mas_bool = true;
- } else {
- *error = "Multiple apps support in account has invalid (not boolean) value";
- return false;
- }
- single_account.multiple_account_support = mas_bool;
- if (!ParseAccountNames(item_dict, &single_account)) {
- *error = "Error while parsing account names";
- return false;
- }
- if (!ParseAccountIcons(item_dict, &single_account)) {
- *error = "Error while parsing account icons";
- return false;
- }
- if (!ParseCapabilities(item_dict, &single_account)) {
- *error = "Error while parsing account capabilities";
- return false;
- }
- info->set_account(single_account);
- return true;
-}
-
-bool AccountHandler::ParseAccountIcons(
- const parser::DictionaryValue* item_dict,
- SingleAccountInfo* info) {
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (item_dict->Get(kAccountIconKey, &val)) {
- if (val->GetAsDictionary(&dict)) {
- if (!ParseSingleAccountIcon(dict, info))
- return false;
- } else if (val->GetAsList(&list)) {
- for (auto& item : *list)
- if (item->GetAsDictionary(&dict) &&
- !ParseSingleAccountIcon(dict, info))
- return false;
- }
- return true;
- }
- return false;
-}
-
-bool AccountHandler::ParseSingleAccountIcon(
- const parser::DictionaryValue* item_dict,
- SingleAccountInfo* info) {
- std::string section;
- item_dict->GetString(kAccountSectionKey, §ion);
- if (section.compare(kSectionIconAccount) != 0 &&
- section.compare(kSectionIconAccountSmall) != 0)
- return false;
- std::string icon_path;
- item_dict->GetString(kAccountTextKey, &icon_path);
- info->icon_paths.push_back(std::make_pair(section, icon_path));
- return true;
-}
-
-bool AccountHandler::ParseAccountNames(
- const parser::DictionaryValue* item_dict,
- SingleAccountInfo* info) {
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (item_dict->Get(kAccountNameKey, &val)) {
- if (val->GetAsDictionary(&dict)) {
- if (!ParseSingleAccountName(dict, info))
- return false;
- } else if (val->GetAsList(&list)) {
- for (auto& item : *list)
- if (item->GetAsDictionary(&dict) &&
- !ParseSingleAccountName(dict, info))
- return false;
- }
- return true;
- }
- return false;
-}
-
-bool AccountHandler::ParseSingleAccountName(
- const parser::DictionaryValue* item_dict,
- SingleAccountInfo* info) {
- std::string lang;
- if (item_dict->GetString(kAccountLangKey, &lang) &&
- !utils::w3c_languages::ValidateLanguageTag(lang)) {
- return false;
- }
- std::string name;
- item_dict->GetString(kAccountTextKey, &name);
- info->names.push_back(std::make_pair(name, lang));
- return true;
-}
-
-
-bool AccountHandler::ParseCapabilities(
- const parser::DictionaryValue* item_dict,
- SingleAccountInfo* info) {
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (item_dict->Get(kAccountCapabilityKey, &val)) {
- std::string capability;
- if (val->GetAsDictionary(&dict)) {
- dict->GetString(kAccountTextKey, &capability);
- info->capabilities.push_back(capability);
- } else if (val->GetAsList(&list)) {
- for (auto& item : *list)
- if (item->GetAsDictionary(&dict)) {
- dict->GetString(kAccountTextKey, &capability);
- info->capabilities.push_back(capability);
- }
- }
- }
- return true;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// 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 file.
-
-#ifndef MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
-#define MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
-
-#include <utility>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-struct SingleAccountInfo {
- bool multiple_account_support;
- std::vector<std::pair<std::string, std::string>> names;
- std::vector<std::pair<std::string, std::string>> icon_paths;
- std::vector<std::string> capabilities;
-};
-
-class AccountInfo : public parser::ManifestData {
- public:
- AccountInfo() {}
- ~AccountInfo() override {}
- static std::string Key();
-
- /**
- * @brief This method returns all the accounts successfully parsed
- */
- const std::vector<SingleAccountInfo>& accounts() const {
- return accounts_;
- }
-
- /**
- * @brief Method add to the vector successfully created account
- */
- void set_account(const SingleAccountInfo& single_account) {
- accounts_.push_back(single_account);
- }
-
- private:
- std::vector<SingleAccountInfo> accounts_;
-};
-
-/**
- * @brief The AccountHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:account>.
- */
-class AccountHandler : 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:
- /**
- * @brief ParseSingleAccountElement everything between <account> </account>
- * @param item_dict dictionary to be parsed
- * @param info ptr for entity that stores successfully parsed results
- * @param error information about error that happened
- * @return true if operation of parsing was successful
- */
- bool ParseSingleAccountElement(const parser::DictionaryValue* item_dict,
- std::shared_ptr<AccountInfo> info,
- std::string* error);
- /**
- * @brief ParseAccountIcons icons of account
- * @param item_dict dictionary to be parsed
- * @param singel_account the single account entity
- * @return true parsed successfully
- */
- bool ParseAccountIcons(const parser::DictionaryValue* item_dict,
- SingleAccountInfo* singel_account);
- bool ParseSingleAccountIcon(const parser::DictionaryValue* item_dict,
- SingleAccountInfo* singel_account);
- /**
- * @brief ParseAccountNames parse and validates account name
- * @param item_dict dictionary to be parsed
- * @param singel_account the single account entity
- * @return true if parsed successfully
- */
- bool ParseAccountNames(const parser::DictionaryValue* item_dict,
- SingleAccountInfo* singel_account);
- bool ParseSingleAccountName(const parser::DictionaryValue* item_dict,
- SingleAccountInfo* singel_account);
- /**
- * @brief ParseCapabilities parses capabilities and validates them
- * @param item_dict dictionary to be parsed
- * @param singel_account the single account entity
- * @return true if parsed successfully
- */
- bool ParseCapabilities(const parser::DictionaryValue* item_dict,
- SingleAccountInfo* singel_account);
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/app_control_handler.h"
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_handlers/tizen_application_handler.h"
-#include "manifest_parser/utils/iri_util.h"
-#include "manifest_parser/utils/version_number.h"
-#include "manifest_parser/values.h"
-
-namespace {
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-
-const char kEnabledValue[] = "enable";
-const char kDisabledValue[] = "disable";
-
-const utils::VersionNumber kReloadRequiredVersion("2.4");
-const char kTizenApplicationKey[] = "widget.application";
-const char kTizenApplicationAppControlSrcKey[] = "src";
-const char kTizenApplicationAppControlOperationKey[] = "operation";
-const char kTizenApplicationAppControlUriKey[] = "uri";
-const char kTizenApplicationAppControlMimeKey[] = "mime";
-const char kTizenApplicationAppControlReloadKey[] = "@reload";
-const char kTizenApplicationAppControlChildNameAttrKey[] = "@name";
-const char kTizenApplicationAppControlsKey[] = "widget.app-control";
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-namespace {
-
-void ParseAppControlEntryAndStore(
- const parser::DictionaryValue& control_dict,
- AppControlInfoList* aplist) {
- std::string src;
- std::string reload;
- const parser::DictionaryValue* src_dict;
- if (control_dict.GetDictionary(kTizenApplicationAppControlSrcKey,
- &src_dict)) {
- src_dict->GetString(
- kTizenApplicationAppControlChildNameAttrKey, &src);
- src_dict->GetString(kTizenApplicationAppControlReloadKey, &reload);
- }
-
- std::string operation;
- const parser::DictionaryValue* operation_dict;
- if (control_dict.GetDictionary(
- kTizenApplicationAppControlOperationKey,
- &operation_dict)) {
- operation_dict->GetString(
- kTizenApplicationAppControlChildNameAttrKey, &operation);
- }
-
- std::string uri;
- const parser::DictionaryValue* uri_dict;
- if (control_dict.GetDictionary(kTizenApplicationAppControlUriKey,
- &uri_dict)) {
- uri_dict->GetString(
- kTizenApplicationAppControlChildNameAttrKey, &uri);
- }
-
- std::string mime;
- const parser::DictionaryValue* mime_dict;
- if (control_dict.GetDictionary(kTizenApplicationAppControlMimeKey,
- &mime_dict)) {
- mime_dict->GetString(
- kTizenApplicationAppControlChildNameAttrKey, &mime);
- }
-
- aplist->controls.emplace_back(src, operation, uri, mime, reload);
-}
-
-} // namespace
-
-AppControlHandler::AppControlHandler() {
-}
-
-AppControlHandler::~AppControlHandler() {
-}
-
-bool AppControlHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
-
- if (!manifest.HasPath(kTizenApplicationAppControlsKey))
- return true;
-
- auto aplist = std::make_shared<AppControlInfoList>();
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenApplicationAppControlsKey, kTizenNamespacePrefix)) {
- ParseAppControlEntryAndStore(*dict, aplist.get());
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(aplist);
- return true;
-}
-
-bool AppControlHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const {
- const AppControlInfoList& app_controls =
- static_cast<const AppControlInfoList&>(data);
-
- for (const auto& item : app_controls.controls) {
- if (item.src().empty()) {
- *error = "The src child element of app-control element is obligatory";
- return false;
- }
-
- const std::string& operation = item.operation();
- if (operation.empty()) {
- *error =
- "The operation child element of app-control element is obligatory";
- return false;
- }
-
- if (!parser::utils::IsValidIRI(operation)) {
- *error =
- "The operation child element of app-control element is not valid url";
- return false;
- }
-
- const TizenApplicationInfo& app_info =
- static_cast<const TizenApplicationInfo&>(
- *handlers_output.find(kTizenApplicationKey)->second);
- utils::VersionNumber required_version(app_info.required_version());
- if (!required_version.IsValid()) {
- *error = "Cannot retrieve required API version from widget";
- return false;
- }
-
- if (required_version >= kReloadRequiredVersion) {
- if (item.reload().empty()) {
- // FIXME for now, this const_cast is used, but it is not the best way.
- AppControlInfo &tmp = const_cast<AppControlInfo &>(item);
- tmp.set_reload(kEnabledValue); // default parameter
- } else if (item.reload() != kEnabledValue &&
- item.reload() != kDisabledValue) {
- *error = "The improper value was given for appcontrol reload";
- return false;
- }
- } else if (!item.reload().empty()) {
- *error = "reload attribute cannot be used for api version lower "
- "than 2.4";
- return false;
- }
- }
- return true;
-}
-
-std::vector<std::string> AppControlHandler::PrerequisiteKeys() const {
- return { kTizenApplicationKey };
-}
-
-std::string AppControlInfo::Key() {
- return kTizenApplicationAppControlsKey;
-}
-
-std::string AppControlHandler::Key() const {
- return kTizenApplicationAppControlsKey;
-}
-
-AppControlInfo::AppControlInfo(
- const std::string& src,
- const std::string& operation,
- const std::string& uri,
- const std::string& mime,
- const std::string& reload)
- : src_(src),
- operation_(operation),
- uri_(uri),
- mime_(mime),
- reload_(reload) {}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_APP_CONTROL_HANDLER_H_
-#define MANIFEST_HANDLERS_APP_CONTROL_HANDLER_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest.h"
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-/**
- * @brief The AppControlHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:app-control>.
- */
-class AppControlHandler : public parser::ManifestHandler {
- public:
- AppControlHandler();
- ~AppControlHandler() override;
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
- std::vector<std::string> PrerequisiteKeys() const override;
-};
-
-class AppControlInfo {
- public:
- AppControlInfo(const std::string& src, const std::string& operation,
- const std::string& uri, const std::string& mime,
- const std::string& reload);
-
- static std::string Key();
- /**
- * @brief src return the source attribute
- * @return the value of source attribute
- */
- const std::string& src() const {
- return src_;
- }
- /**
- * @brief
- * @return the value of operation attribute
- */
- const std::string& operation() const {
- return operation_;
- }
- /**
- * @brief uri
- * @return the value of the uri attribute
- */
- const std::string& uri() const {
- return uri_;
- }
- /**
- * @brief mime
- * @return the value of the mime attribute
- */
- const std::string& mime() const {
- return mime_;
- }
- /**
- * @brief reload
- * @return the value of reload attribute
- */
- const std::string& reload() const {
- return reload_;
- }
- void set_reload(const std::string &rel) {
- reload_ = rel;
- }
-
- private:
- std::string src_;
- std::string operation_;
- std::string uri_;
- std::string mime_;
- std::string reload_;
-};
-
-struct AppControlInfoList : public parser::ManifestData {
- std::vector<AppControlInfo> controls;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_APP_CONTROL_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "manifest_handlers/application_icons_handler.h"
-
-#include <algorithm>
-#include <string>
-
-#include "manifest_parser/utils/logging.h"
-
-namespace {
-
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kWidgetIconKey[] = "widget.icon";
-const char kWidgetIconSrcKey[] = "@src";
-const char kWidgetIconWidthKey[] = "@width";
-const char kWidgetIconHeightKey[] = "@height";
-const char kIconsKey[] = "icons";
-
-bool ExtractIconSrc(const parser::Value& dict, std::string* value,
- std::string* /*error*/) {
- const parser::DictionaryValue* inner_dict;
- if (!dict.GetAsDictionary(&inner_dict)) {
- LOG(INFO) << "Cannot get key value as a dictionary. Key name: widget.icon";
- return true;
- }
- std::string src;
- if (!inner_dict->GetString(kWidgetIconSrcKey, &src)) {
- LOG(INFO) << "Cannot find mandatory key. Key name: .@src";
- return true;
- }
- *value = src;
- return true;
-}
-
-/**
- * @brief ExtractIconDimensions
- *
- * Parses and sets icon dimensions. If value cannot be received it is set to -1.
- *
- * @param dict dictionary value of icon
- * @param height output parameter of height of icon
- * @param width output parameter of width of icon
- */
-void ExtractIconDimensions(const parser::Value& dict, int* height, int* width) {
- *width = -1;
- *height = -1;
- const parser::DictionaryValue* inner_dict;
- if (!dict.GetAsDictionary(&inner_dict)) {
- return;
- }
-
- std::string width_str;
- if (inner_dict->GetString(kWidgetIconWidthKey, &width_str)) {
- try {
- *width = std::stoi(width_str);
- } catch (const std::logic_error&) {
- // ignore, width is set to -1
- }
- }
-
- std::string height_str;
- if (inner_dict->GetString(kWidgetIconHeightKey, &height_str)) {
- try {
- *height = std::stoi(height_str);
- } catch (const std::logic_error&) {
- // ignore, height is set to -1
- }
- }
-}
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-ApplicationIcon::ApplicationIcon(const std::string& path, int height, int width)
- : path_(path),
- height_((height >= 0) ? height : -1),
- width_((width >= 0) ? width : -1) {
-}
-
-bool ApplicationIcon::GetWidth(int* width) const {
- if (!width || width_ < 0)
- return false;
- *width = width_;
- return true;
-}
-
-bool ApplicationIcon::GetHeight(int* height) const {
- if (!height || height_ < 0)
- return false;
- *height = height_;
- return true;
-}
-
-const std::string& ApplicationIcon::path() const {
- return path_;
-}
-
-void ApplicationIcon::set_width(int width) {
- if (width >= 0)
- width_ = width;
-}
-
-void ApplicationIcon::set_height(int height) {
- if (height >= 0)
- height_ = height;
-}
-
-std::string ApplicationIconsInfo::Key() {
- return kIconsKey;
-}
-
-
-const std::vector<ApplicationIcon>& ApplicationIconsInfo::icons() const {
- return icons_;
-}
-
-void ApplicationIconsInfo::AddIcon(const ApplicationIcon& new_icon) {
- // Eliminate duplicates, keep order
- if (std::find_if(icons_.begin(), icons_.end(),
- [&new_icon](const ApplicationIcon& icon) {
- return icon.path() == new_icon.path();
- })
- != icons_.end()) {
- return;
- }
- icons_.push_back(new_icon);
-}
-
-ApplicationIconsHandler::ApplicationIconsHandler() {
-}
-
-ApplicationIconsHandler::~ApplicationIconsHandler() {
-}
-
-bool ApplicationIconsHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- std::shared_ptr<ApplicationIconsInfo> app_icons_info =
- std::make_shared<ApplicationIconsInfo>();
-
- if (!manifest.HasPath(kWidgetIconKey)) {
- *output = std::static_pointer_cast<parser::ManifestData>(app_icons_info);
- return true;
- }
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kWidgetIconKey, kWidgetNamespacePrefix)) {
- std::string icon_path;
-
- if (!ExtractIconSrc(*dict, &icon_path, error)) {
- *error = "Cannot get key value as a dictionary. Key name: widget.icon";
- return false;
- }
-
- int width;
- int height;
-
- ExtractIconDimensions(*dict, &height, &width);
- app_icons_info->AddIcon(ApplicationIcon(icon_path, height, width));
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(app_icons_info);
- return true;
-}
-
-bool ApplicationIconsHandler::AlwaysParseForKey() const {
- return true;
-}
-
-std::string ApplicationIconsHandler::Key() const {
- return wgt::application_manifest_keys::kIconsKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
-#define MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
-
-#include <string>
-#include <vector>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class ApplicationIcon {
- public:
- explicit ApplicationIcon(const std::string& path, int height = -1,
- int width = -1);
- /**
- * @brief GetWidth
- * @param width
- * @return true if successful
- */
- bool GetWidth(int* width) const;
- /**
- * @brief GetHeight
- * @param height
- * @return true if successful
- */
- bool GetHeight(int* height) const;
- /**
- * @brief path
- * @return string to the path
- */
- const std::string& path() const;
- /**
- * @brief set_width sets width
- * @param width
- */
- void set_width(int width);
- /**
- * @brief set_height sets height
- * @param height
- */
- void set_height(int height);
-
- private:
- std::string path_;
- int height_;
- int width_;
-};
-
-class ApplicationIconsInfo : public parser::ManifestData {
- public:
- static std::string Key();
-
- const std::vector<ApplicationIcon>& icons() const;
- /**
- * @brief AddIcon adds icon
- * @param icon_path
- */
- void AddIcon(const ApplicationIcon& icon_path);
- private:
- std::vector<ApplicationIcon> icons_;
-};
-
-/**
- * @brief The ApplicationIconsHandler class
- *
- * Handler of config.xml for xml elements:
- * - <w3c:icon>.
- */
-class ApplicationIconsHandler : public parser::ManifestHandler {
- public:
- ApplicationIconsHandler();
- ~ApplicationIconsHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool AlwaysParseForKey() const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// 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.
-
-#include "manifest_handlers/application_manifest_constants.h"
-
-namespace wgt {
-
-namespace application_manifest_keys {
-
-// TODO(p.sikorski): below key should be removed, when nwrt and app-installer
-// will stop use it. Now, it is just copied.
-const char kIconsKey[] = "icons";
-
-} // namespace application_manifest_keys
-
-// manifest keys for widget applications.
-namespace application_widget_keys {
-
-const char kCSPKey[] = "widget.content-security-policy";
-const char kCSPReportOnlyKey[] = "widget.content-security-policy-report-only";
-const char kIconsKey[] = "icons";
-const char kAccountKey[] = "widget.account";
-const char kDefaultLocaleKey[] = "widget.@defaultlocale";
-const char kViewModesKey[] = "widget.@viewmodes";
-const char kWidgetKey[] = "widget";
-const char kAuthorKey[] = "widget.author";
-const char kDescriptionKey[] = "widget.description";
-const char kShortKey[] = "@short";
-const char kIDKey[] = "widget.@id";
-const char kHeightKey[] = "widget.@height";
-const char kWidthKey[] = "widget.@width";
-const char kPreferencesKey[] = "widget.preference";
-const char kAccessKey[] = "widget.access";
-const char kLicenseKey[] = "widget.license";
-
-const char kTizenWidgetKey[] = "widget";
-// Child keys inside 'kPreferencesKey'.
-const char kPreferencesNameKey[] = "@name";
-
-const char kWidgetLangKey[] = "widget.@lang";
-
-const char kTizenApplicationKey[] = "widget.application";
-const char kTizenAppWidgetFullKey[] = "widget.app-widget";
-// Child keys inside 'kTizenApplicationKey'
-
-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 kTizenNoDisplayKey[] = "@nodisplay";
-const char kTizenIndicatorPresenceKey[] = "@indicator-presence";
-const char kTizenBackbuttonPresenceKey[] = "@backbutton-presence";
-const char kTizenUserAgentKey[] = "@user-agent";
-const char kTizenSoundModeKey[] = "@sound-mode";
-const char kTizenBackgroundVibrationKey[] = "@background-vibration";
-const char kTizenMetaDataKey[] = "widget.metadata";
-const char kTizenSplashScreenKey[] = "widget.splash-screen";
-// Child keys inside 'kTizenMetaDataKey'
-const char kTizenPermissionsKey[] = "widget.privilege";
-
-// App control
-const char kTizenApplicationAppControlsKey[] = "widget.app-control";
-// IME
-const char kTizenImeKey[] = "widget.ime";
-// Content
-const char kTizenContentKey[] = "widget.content";
-// Category
-const char kTizenCategoryKey[] = "widget.category";
-// Service
-const char kTizenServiceKey[] = "widget.service";
-
-// launch_screen
-const char kSplashScreenKey[] = "widget.launch_screen";
-
-} // namespace application_widget_keys
-
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// 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_APPLICATION_MANIFEST_CONSTANTS_H_
-#define MANIFEST_HANDLERS_APPLICATION_MANIFEST_CONSTANTS_H_
-
-#include "manifest_parser/manifest.h"
-
-// Keys used in JSON representation of applications.
-namespace wgt {
-namespace application_manifest_keys {
-
-// TODO(p.sikorski): below key should be removed, when nwrt and app-installer
-// will stop use it. Now, it is just copied.
-extern const char kIconsKey[];
-
-} // namespace application_manifest_keys
-
-namespace application_widget_keys {
-
-extern const char kAccessKey[];
-extern const char kAccountKey[];
-extern const char kAllowNavigationKey[];
-extern const char kAuthorKey[];
-extern const char kCSPKey[];
-extern const char kCSPReportOnlyKey[];
-extern const char kDescriptionKey[];
-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[];
-extern const char kTizenMetaDataKey[];
-extern const char kTizenPermissionsKey[];
-extern const char kTizenServiceKey[];
-extern const char kTizenSettingKey[];
-extern const char kTizenSplashScreenKey[];
-extern const char kTizenWidgetKey[];
-extern const char kVersionKey[];
-extern const char kWidgetKey[];
-extern const char kSplashScreenKey[];
-
-} // namespace application_widget_keys
-
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_APPLICATION_MANIFEST_CONSTANTS_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/appwidget_handler.h"
-
-#include <cassert>
-#include <cstdlib>
-#include <limits>
-#include <regex>
-#include <set>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_handlers/tizen_application_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-
-const char kTizenAppWidgetFullKey[] = "widget.app-widget";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kNamespaceKey[] = "@namespace";
-const char kTizenWidgetKey[] = "widget";
-const char kTizenAppWidgetKey[] = "app-widget";
-const char kTizenAppWidgetBoxLabelLangKey[] = "@lang";
-const char kTizenAppWidgetBoxIconSrcKey[] = "@src";
-const char kTizenAppWidgetBoxContentSizePreviewKey[] = "@preview";
-const char kTizenAppWidgetBoxContentSizeUseDecorationKey[] = "@use-decoration";
-const char kTizenAppWidgetBoxContentDropViewSrcKey[] = "@src";
-const char kTizenAppWidgetBoxContentDropViewWidthKey[] = "@width";
-const char kTizenAppWidgetBoxContentDropViewHeightKey[] = "@height";
-const char kTizenAppWidgetBoxContentSrcKey[] = "@src";
-const char kTizenAppWidgetBoxContentMouseEventKey[] = "@mouse-event";
-const char kTizenAppWidgetBoxContentTouchEffectKey[] = "@touch-effect";
-const char kTizenAppWidgetBoxContentSizeKey[] = "box-size";
-const char kTizenAppWidgetBoxContentDropViewKey[] = "pd";
-const char kTizenAppWidgetAutoLaunchKey[] = "@auto-launch";
-const char kTizenAppWidgetBoxLabelKey[] = "box-label";
-const char kTizenAppWidgetBoxIconKey[] = "box-icon";
-const char kTizenAppWidgetBoxContentKey[] = "box-content";
-const char kTizenAppWidgetIdKey[] = "@id";
-const char kTizenAppWidgetPrimaryKey[] = "@primary";
-const char kTizenAppWidgetUpdatePeriodKey[] = "@update-period";
-const char kTizenAppWidgetBoxLabelTextKey[] = "#text";
-const char kTizenAppWidgetBoxContentSizeTextKey[] = "#text";
-
-const char kErrMsgInvalidDictionary[] =
- "Cannot get key value as a dictionary. Key name: ";
-const char kErrMsgInvalidList[] = "Cannot get key value as a list. Key name: ";
-const char kErrMsgNoMandatoryKey[] = "Cannot find mandatory key. Key name: ";
-const char kErrMsgInvalidKeyValue[] = "Invalid key value. Key name: ";
-const char kErrMsgMultipleKeys[] = "Too many keys found. Key name: ";
-const char kErrMsgNoNamespace[] =
- "Element pointed by key has no namespace specified. Key name: ";
-const char kErrMsgInvalidNamespace[] =
- "Invalid namespace of element pointed by key. Key name: ";
-const char kErrMsgUpdatePeriodOutOfDomain[] =
- "Value of an update-period attribute in app-widget element out of domain."
- " The value: ";
-const char kErrMsgNoLabel[] =
- "No box-label element in app-widget element.";
-const char kErrMsgInvalidContentSrc[] =
- "Invalid path or url in a src attribute of box-content element."
- " The value: ";
-const char kErrMsgNoMandatoryContentSize1x1[] =
- "No mandatory box-size element (1x1) in box-content element.";
-const char kErrMsgInvalidContentDropViewSrc[] =
- "Invalid path or url in a src attribute of pd element. The value: ";
-const char kErrMsgContentDropViewHeightOutOfDomain[] =
- "Value of a height attribute in box-content element out of domain."
- " The value: ";
-
-const std::regex kStringRegex("[.][0-9a-zA-Z]+");
-
-// If the error parameter is specified, it is filled with the given message
-// otherwise it does nothing.
-void SetError(const std::string& message, std::string* error) {
- if (error) *error = message;
-}
-
-// If the error parameter is specified, it is filled with concatenation
-// of message and arg parameters otherwise it does nothing.
-void SetError(const std::string& message, const std::string& arg,
- std::string* error) {
- if (error) *error = message + arg;
-}
-
-// Converts given text value to a value of specific type. Returns true
-// if convertion is successful or false otherwise.
-template <typename ValueType>
-bool ConvertValue(const std::string& /*str_value*/, ValueType* /*value*/) {
- assert(false &&
- "Use one of already defined template specializations"
- " or define a new one.");
- return false;
-}
-
-// Converts given text value to a string value. Returns true
-// if convertion is successful or false otherwise.
-template <>
-bool ConvertValue(const std::string& str_value, std::string* value) {
- assert(value);
- *value = str_value;
- return true;
-}
-
-// Converts given text value to a boolean value. Returns true
-// if convertion is successful or false otherwise.
-template <>
-bool ConvertValue(const std::string& str_value, bool* value) {
- assert(value);
- if (str_value == "true") {
- *value = true;
- return true;
- }
- if (str_value == "false") {
- *value = false;
- return true;
- }
- return false;
-}
-
-// Converts given text value to an integer value. Returns true
-// if convertion is successful or false otherwise.
-template <>
-bool ConvertValue(const std::string& str_value, int* value) {
- assert(value);
- char* end = nullptr;
- *value = strtol(str_value.c_str(), &end, 10);
- return end == &*str_value.end();
-}
-
-// Converts given text value to a floating point value. Returns true
-// if convertion is successful or false otherwise.
-template <>
-bool ConvertValue(const std::string& str_value, double* value) {
- assert(value);
- char* end = nullptr;
- *value = strtod(str_value.c_str(), &end);
- return end == &*str_value.end();
-}
-
-// Retrieves a mandatory value from specified dictionary and specified key.
-// Returns true, if the value is found or false otherwise. If the error
-// parameter is specified, it is also filled with proper message.
-template <typename ValueType>
-bool GetMandatoryValue(const parser::DictionaryValue& dict,
- const std::string& key, ValueType* value,
- std::string* error) {
- assert(value);
- std::string tmp;
- if (!dict.GetString(key, &tmp)) {
- SetError(kErrMsgNoMandatoryKey, key, error);
- return false;
- }
- bool result = ConvertValue(tmp, value);
- if (!result) SetError(kErrMsgInvalidKeyValue, key, error);
- return result;
-}
-
-// Retrieves an optional value from specified dictionary and specified key.
-// If the value is found, the function returns true and fills value
-// parameter. If the value is not found, the function returns true and fills
-// value parameter with default value. If an error occurs, it returns false
-// and fills error parameter if it is set.
-template <typename ValueType>
-bool GetOptionalValue(const parser::DictionaryValue& dict,
- const std::string& key, ValueType default_value,
- ValueType* value, std::string* error) {
- assert(value);
- std::string tmp;
- if (!dict.GetString(key, &tmp)) {
- *value = default_value;
- return true;
- }
- bool result = ConvertValue(tmp, value);
- if (!result) SetError(kErrMsgInvalidKeyValue, key, error);
- return result;
-}
-
-// Verifies whether specified dictionary represents an element in specified
-// namespace. Returns true, if the namespace is set and equal to the specified
-// one or false otherwise. If the error parameter is specified, it is also
-// filled with proper message.
-bool VerifyElementNamespace(const parser::DictionaryValue& dict,
- const std::string& key,
- const std::string& desired_namespace_value,
- std::string* error) {
- std::string namespace_value;
- if (!GetMandatoryValue(dict, kNamespaceKey, &namespace_value, nullptr)) {
- SetError(kErrMsgNoNamespace, key, error);
- return false;
- }
- if (namespace_value != desired_namespace_value) {
- SetError(kErrMsgInvalidNamespace, key, error);
- return false;
- }
- return true;
-}
-
-// Parses box-label part
-bool ParseLabel(const parser::DictionaryValue& dict, const std::string& key,
- AppWidget* app_widget, std::string* error) {
- assert(app_widget);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- std::string lang;
- if (!GetOptionalValue(dict, kTizenAppWidgetBoxLabelLangKey, std::string(),
- &lang, error))
- return false;
-
- std::string text;
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxLabelTextKey, &text, error))
- return false;
-
- if (lang.empty()) {
- // Note: Tizen 2.2 WRT Core Spec does not determine how many times the value
- // without lang attribute can appear in one app-widget, so overwrite.
- app_widget->label.default_value = text;
- } else {
- // Note: Tizen 2.2 WRT Core Spec does not determine how many times the value
- // with specific lang attribute can appear in one app-widget, so overwrite.
- app_widget->label.lang_value_map[lang] = text;
- }
-
- return true;
-}
-
-// Parses box-icon part
-bool ParseIcon(const parser::DictionaryValue& dict, const std::string& key,
- AppWidget* app_widget, std::string* error) {
- assert(app_widget);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- if (!app_widget->icon_src.empty()) {
- SetError(kErrMsgMultipleKeys, key, error);
- return false;
- }
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxIconSrcKey,
- &app_widget->icon_src, error))
- return false;
-
- return true;
-}
-
-// Converts size type from text to enum representation
-bool StringToSizeType(const std::string& str_type,
- AppWidgetSizeType* enum_type) {
- assert(enum_type);
- if (str_type == "1x1") {
- *enum_type = AppWidgetSizeType::k1x1;
- return true;
- }
- if (str_type == "2x1") {
- *enum_type = AppWidgetSizeType::k2x1;
- return true;
- }
- if (str_type == "2x2") {
- *enum_type = AppWidgetSizeType::k2x2;
- return true;
- }
- return false;
-}
-
-// Parses box-size part
-bool ParseContentSizes(const parser::DictionaryValue& dict,
- const std::string& key, AppWidget* app_widget,
- std::string* error) {
- assert(app_widget);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- AppWidgetSize size;
-
- std::string str_type;
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentSizeTextKey, &str_type,
- error))
- return false;
-
- AppWidgetSizeType type;
- if (!StringToSizeType(str_type, &type)) {
- SetError(kErrMsgInvalidKeyValue, kTizenAppWidgetBoxContentSizeTextKey,
- error);
- return false;
- }
- size.type = type;
-
- if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentSizePreviewKey,
- std::string(), &size.preview, error))
- return false;
-
- if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentSizeUseDecorationKey,
- true, &size.use_decoration, error))
- return false;
-
- app_widget->content_size.push_back(size);
-
- return true;
-}
-
-// Parses pd part
-bool ParseContentDropView(const parser::DictionaryValue& dict,
- const std::string& key, AppWidget* app_widget,
- std::string* error) {
- assert(app_widget);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- if (!app_widget->content_drop_view.empty()) {
- SetError(kErrMsgMultipleKeys, key, error);
- return false;
- }
-
- AppWidgetDropView drop_view;
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewSrcKey,
- &drop_view.src, error))
- return false;
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewWidthKey,
- &drop_view.width, error))
- return false;
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewHeightKey,
- &drop_view.height, error))
- return false;
-
- app_widget->content_drop_view.push_back(drop_view);
-
- return true;
-}
-
-// Parses box-content part
-bool ParseContent(const parser::DictionaryValue& dict, const std::string& key,
- AppWidget* app_widget, std::string* error) {
- assert(app_widget);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- if (!app_widget->content_src.empty()) {
- SetError(kErrMsgMultipleKeys, key, error);
- return false;
- }
- if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentSrcKey,
- &app_widget->content_src, error))
- return false;
-
- if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentMouseEventKey, false,
- &app_widget->content_mouse_event, error))
- return false;
-
- if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentTouchEffectKey, true,
- &app_widget->content_touch_effect, error))
- return false;
-
- if (!dict.HasKey(kTizenAppWidgetBoxContentSizeKey))
- return false;
-
- for (const auto& dict_cs : parser::GetOneOrMany(&dict,
- kTizenAppWidgetBoxContentSizeKey, "")) {
- if (!ParseContentSizes(*dict_cs, kTizenAppWidgetBoxContentSizeKey,
- app_widget, error))
- return false;
- }
-
- for (const auto& dict_dv : parser::GetOneOrMany(&dict,
- kTizenAppWidgetBoxContentDropViewKey, "")) {
- if (!ParseContentDropView(*dict_dv,
- kTizenAppWidgetBoxContentDropViewKey, app_widget, error))
- return false;
- }
-
- return true;
-}
-
-// Parses app-widget part
-bool ParseAppWidget(const parser::DictionaryValue& dict, const std::string& key,
- AppWidgetVector* app_widgets, std::string* error) {
- assert(app_widgets);
-
- if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
- return false;
-
- AppWidget app_widget;
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetIdKey, &app_widget.id, error))
- return false;
-
- if (!GetMandatoryValue(dict, kTizenAppWidgetPrimaryKey, &app_widget.primary,
- error))
- return false;
-
- double update_period;
- double no_update_period = std::numeric_limits<double>::min();
- if (!GetOptionalValue(dict, kTizenAppWidgetUpdatePeriodKey, no_update_period,
- &update_period, error))
- return false;
- if (update_period != no_update_period)
- app_widget.update_period.push_back(update_period);
-
- if (!GetOptionalValue(dict, kTizenAppWidgetAutoLaunchKey, false,
- &app_widget.auto_launch, error))
- return false;
-
- if (!dict.HasKey(kTizenAppWidgetBoxLabelKey))
- return false;
-
- for (const auto& dict_l : parser::GetOneOrMany(&dict,
- kTizenAppWidgetBoxLabelKey, kTizenNamespacePrefix)) {
- if (!ParseLabel(*dict_l, kTizenAppWidgetBoxLabelKey,
- &app_widget, error))
- return false;
- }
-
- for (const auto& dict_i : parser::GetOneOrMany(&dict,
- kTizenAppWidgetBoxIconKey, kTizenNamespacePrefix)) {
- if (!ParseIcon(*dict_i, kTizenAppWidgetBoxIconKey,
- &app_widget, error))
- return false;
- }
-
- if (!dict.HasKey(kTizenAppWidgetBoxContentKey))
- return false;
-
- for (const auto& dict_c : parser::GetOneOrMany(&dict,
- kTizenAppWidgetBoxContentKey, kTizenNamespacePrefix)) {
- if (!ParseContent(*dict_c, kTizenAppWidgetBoxContentKey,
- &app_widget, error))
- return false;
- }
-
- app_widgets->push_back(app_widget);
-
- return true;
-}
-
-// Validates all content sizes in an app-widget
-bool ValidateContentSize(const AppWidgetSizeVector& content_size,
- std::string* error) {
- bool mandatory_1x1_found = false;
-
- for (const AppWidgetSize& size : content_size) {
- mandatory_1x1_found |= size.type == AppWidgetSizeType::k1x1;
- }
-
- if (!mandatory_1x1_found) {
- SetError(kErrMsgNoMandatoryContentSize1x1, error);
- return false;
- }
-
- return true;
-}
-
-} // namespace
-
-AppWidgetInfo::AppWidgetInfo(const AppWidgetVector& app_widgets)
- : app_widgets_(app_widgets) {}
-
-AppWidgetInfo::~AppWidgetInfo() {}
-
-AppWidgetHandler::AppWidgetHandler() {}
-
-AppWidgetHandler::~AppWidgetHandler() {}
-
-
-bool AppWidgetHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenAppWidgetKey))
- return false;
-
- AppWidgetVector app_widgets;
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenAppWidgetKey, kTizenNamespacePrefix)) {
- if (!ParseAppWidget(*dict, kTizenAppWidgetKey, &app_widgets, error))
- return false;
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(
- std::make_shared<AppWidgetInfo>(app_widgets));
- return true;
-}
-
-bool AppWidgetHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const AppWidgetInfo& app_widget_info =
- static_cast<const AppWidgetInfo&>(data);
- const AppWidgetVector& app_widgets = app_widget_info.app_widgets();
-
- for (const AppWidget& app_widget : app_widgets) {
- if (!app_widget.update_period.empty() &&
- app_widget.update_period.front() < 1800) {
- SetError(kErrMsgUpdatePeriodOutOfDomain,
- std::to_string(app_widget.update_period.front()), error);
- return false;
- }
-
- if (app_widget.label.default_value.empty() &&
- app_widget.label.lang_value_map.empty()) {
- SetError(kErrMsgNoLabel, error);
- return false;
- }
-
- if (!ValidateContentSize(app_widget.content_size, error))
- return false;
-
- if (!app_widget.content_drop_view.empty()) {
- const AppWidgetDropView& drop_view = app_widget.content_drop_view.front();
-
- if (drop_view.height < 1 || drop_view.height > 380) {
- SetError(kErrMsgContentDropViewHeightOutOfDomain,
- std::to_string(drop_view.height), error);
- return false;
- }
- }
- }
-
- return true;
-}
-
-std::string AppWidgetHandler::Key() const {
- return kTizenAppWidgetFullKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_APPWIDGET_HANDLER_H_
-#define MANIFEST_HANDLERS_APPWIDGET_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-typedef std::map<std::string, std::string> AppWidgetLabelLangValueMap;
-
-struct AppWidgetLabel {
- // may be empty
- std::string default_value;
-
- // may be empty if default is set
- AppWidgetLabelLangValueMap lang_value_map;
-};
-
-enum AppWidgetSizeType {
- k1x1, k2x1, k2x2
-};
-
-struct AppWidgetSize {
- // mandatory
- AppWidgetSizeType type;
-
- // optional, relative to web app directory
- std::string preview;
-
- // optional, default: true
- bool use_decoration;
-};
-
-typedef std::vector<AppWidgetSize> AppWidgetSizeVector;
-
-struct AppWidgetDropView {
- // mandatory, relative to web app directory or remote URL
- std::string src;
-
- // mandatory
- int width;
-
- // mandatory, <1, 380>
- int height;
-};
-
-typedef std::vector<AppWidgetDropView> AppWidgetDropViewVector;
-
-struct AppWidget {
- // mandatory, unique, must start with application id and end with label
- // separated with dot, the label can contain only 0-9, a-z, A-Z
- std::string id;
-
- // mandatory, if 2 or more app widgets have the primary attribute set to true,
- // the default icon and title of the parent web app can be used
- bool primary;
-
- // optional(0-1), min: 1800.0, default: no update
- std::vector<double> update_period;
-
- // optional, default: false
- bool auto_launch;
-
- // box label, multiple(1+)
- AppWidgetLabel label;
-
- // box icon, optional(0-1), src, mandatory, relative to web app directory
- std::string icon_src;
-
- // box content, mandatory(1) -[
-
- // mandatory, relative to web app directory or remote URL
- std::string content_src;
-
- // optional, default: false
- bool content_mouse_event;
-
- // optional, default: true
- bool content_touch_effect;
-
- // box size, mandatory(1-3), 1x1 must exist
- AppWidgetSizeVector content_size;
-
- // drop view, optional(0-1)
- AppWidgetDropViewVector content_drop_view;
-
- // ]- box content
-};
-
-typedef std::vector<AppWidget> AppWidgetVector;
-
-class AppWidgetInfo : public parser::ManifestData {
- public:
- explicit AppWidgetInfo(const AppWidgetVector& app_widgets);
- virtual ~AppWidgetInfo();
-
- const AppWidgetVector& app_widgets() const {
- return app_widgets_;
- }
-
- private:
- // multiple(0+)
- AppWidgetVector app_widgets_;
-};
-
-/**
- * @brief The AppWidgetHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:app-widget>.
- */
-class AppWidgetHandler : public parser::ManifestHandler {
- public:
- AppWidgetHandler();
- virtual ~AppWidgetHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_APPWIDGET_HANDLER_H_
+++ /dev/null
-// 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
+++ /dev/null
-// 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_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/category_handler.h"
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kTizenCategoryNameKey[] = "@name";
-const char kErrMsgCategory[] = "Parsing category element failed";
-const char kTizenCategoryKey[] = "widget.category";
-const char kErrMsgCategoryName[] =
- "The name element inside category element is obligatory";
-
-bool ParseCategoryEntryAndStore(const parser::DictionaryValue& control_dict,
- CategoryInfoList* aplist) {
- std::string name;
- if (!control_dict.GetString(kTizenCategoryNameKey, &name)) return false;
- aplist->categories.push_back(name);
- return true;
-}
-
-} // namespace
-
-CategoryHandler::CategoryHandler() {}
-
-CategoryHandler::~CategoryHandler() {}
-
-
-bool CategoryHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- if (!manifest.HasPath(kTizenCategoryKey))
- return true;
-
- auto aplist = std::make_shared<CategoryInfoList>();
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenCategoryKey, kTizenNamespacePrefix)) {
- if (!ParseCategoryEntryAndStore(*dict, aplist.get()))
- return false;
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(aplist);
- return true;
-}
-
-bool CategoryHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const CategoryInfoList& categories_list =
- static_cast<const CategoryInfoList&>(data);
-
- for (const auto& item : categories_list.categories) {
- if (item.empty()) {
- *error = kErrMsgCategoryName;
- return false;
- }
- }
- return true;
-}
-
-std::string CategoryHandler::Key() const {
- return kTizenCategoryKey;
-}
-
-
-std::string CategoryInfoList::Key() {
- return kTizenCategoryKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_CATEGORY_HANDLER_H_
-#define MANIFEST_HANDLERS_CATEGORY_HANDLER_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-struct CategoryInfoList : public parser::ManifestData {
- static std::string Key();
- std::vector<std::string> categories;
-};
-
-/**
- * @brief The CategoryHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:category>.
- */
-class CategoryHandler : public parser::ManifestHandler {
- public:
- CategoryHandler();
- virtual ~CategoryHandler();
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_CATEGORY_HANDLER_H_
+++ /dev/null
-// 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/content_handler.h"
-
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/algorithm/string/trim.hpp>
-
-#include <map>
-#include <set>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/iri_util.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/utils/string_util.h"
-
-namespace ba = boost::algorithm;
-
-namespace {
-
-const char kNamespaceKey[] = "@namespace";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kTizenContentEncodingKey[] = "@encoding";
-const char kTizenContentTypeKey[] = "@type";
-const char kTizenContentKey[] = "widget.content";
-const char kMimeMainComponent[] = "";
-const char kMimeCharsetComponent[] = "charset";
-const char kDefaultMimeType[] = "text/html";
-const char kDefaultEncoding[] = "UTF-8";
-const char kTizenContentSrcKey[] = "@src";
-
-const std::set<std::string> ValidMimeTypeStartFile = {
- "text/html", "application/xhtml+xml", "image/svg+xml"};
-
-std::map<std::string, std::string> ParseMimeComponents(
- const std::string& type) {
- std::map<std::string, std::string> mime_components;
- std::vector<std::string> components;
-
- ba::split(components, type, ba::is_any_of(";"));
- for (auto& component : components) {
- auto split = component.find("=");
- std::string key;
- std::string value;
- if (split != std::string::npos) {
- key = component.substr(0, split);
- value = component.substr(split + 1);
- } else {
- key = kMimeMainComponent;
- value = component;
- }
- ba::trim(key);
- ba::trim(value);
- mime_components.insert(std::make_pair(key, value));
- }
- return mime_components;
-}
-
-bool ValidateMimeTypeStartFile(const std::string& type) {
- return ValidMimeTypeStartFile.find(parser::utils::CollapseWhitespaceUTF8(
- type)) != ValidMimeTypeStartFile.end();
-}
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-ContentHandler::ContentHandler()
- : w3c_content_found_(false), tizen_content_found_(false) {}
-
-ContentHandler::~ContentHandler() {}
-
-/**
- * @brief ParseAndSetContentValue
- *
- * This function should return parse result and set output parameter content
- * to valid content if returning OK
- *
- * @param dict input dictionary for content element
- * @param content content element to be set if valid one found
- * @param error parser error to be set if parsing failed with error
- * @return enum value describing result of parsing
- */
-ContentHandler::ParseResult ContentHandler::ParseAndSetContentValue(
- const parser::DictionaryValue& dict,
- std::shared_ptr<wgt::parse::ContentInfo>* content, std::string* error) {
- std::string element_namespace;
- dict.GetString(kNamespaceKey, &element_namespace);
-
- if (element_namespace == kTizenNamespacePrefix) {
- if (tizen_content_found_) {
- // tizen:content already found
- return ParseResult::IGNORE;
- }
- tizen_content_found_ = true;
- } else {
- if (w3c_content_found_) {
- // ignore all content element that are not first
- return ParseResult::IGNORE;
- }
- w3c_content_found_ = true;
- }
-
- std::string src;
- if (!dict.GetString(kTizenContentSrcKey, &src)) {
- return ParseResult::IGNORE;
- }
-
- // error if empty
- if (src.empty()) {
- // ignore this element
- return ParseResult::IGNORE;
- }
-
- std::string type = kDefaultMimeType;
- dict.GetString(kTizenContentTypeKey, &type);
- // TODO(t.iwanek): this will fail for "quoted-string"
- // use/implement proper mime parsing...
- std::map<std::string, std::string> mime_components =
- ParseMimeComponents(type);
-
- auto mime_iter = mime_components.find(kMimeMainComponent);
- if (mime_iter != mime_components.end()) {
- if (!ValidateMimeTypeStartFile(mime_iter->second)) {
- *error = "Not proper type of starting file";
- return ParseResult::IGNORE;
- }
- }
-
- std::string encoding = kDefaultEncoding;
- if (!dict.GetString(kTizenContentEncodingKey, &encoding)) {
- auto charset_iter = mime_components.find(kMimeCharsetComponent);
- if (charset_iter != mime_components.end()) {
- encoding = charset_iter->second;
- }
- }
- ba::trim(encoding);
-
- if (*content && (*content)->is_tizen_content()) {
- // Prefer tizen:content if both are correct
- return ParseResult::IGNORE;
- }
-
- content->reset(new wgt::parse::ContentInfo());
- (*content)->set_src(src);
- (*content)->set_type(type);
- (*content)->set_encoding(encoding);
- (*content)->set_is_tizen_content(element_namespace == kTizenNamespacePrefix);
- return ParseResult::OK;
-}
-
-bool ContentHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenContentKey))
- return true;
-
- std::shared_ptr<ContentInfo> content_info;
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenContentKey, "")) {
- if (ParseAndSetContentValue(*dict, &content_info, error)
- == ParseResult::ERROR) {
- return false;
- }
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(content_info);
-
- return true;
-}
-
-std::string ContentHandler::Key() const {
- return kTizenContentKey;
-}
-
-std::string ContentInfo::Key() {
- return kTizenContentKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// 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.
-
-#ifndef MANIFEST_HANDLERS_CONTENT_HANDLER_H_
-#define MANIFEST_HANDLERS_CONTENT_HANDLER_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class ContentInfo : public parser::ManifestData {
- public:
- ContentInfo()
- : is_tizen_content_(false) { }
-
- virtual ~ContentInfo() { }
-
- static std::string Key();
-
- const std::string& src() const {
- return src_;
- }
- const std::string& type() const {
- return type_;
- }
- const std::string& encoding() const {
- return encoding_;
- }
- /**
- * @brief set_src sets source
- * @param src
- */
- void set_src(const std::string& src) { src_ = src; }
- /**
- * @brief set_type sets type
- * @param type
- */
- void set_type(const std::string& type) { type_ = type; }
- /**
- * @brief set_encoding sets encoding
- * @param encoding
- */
- void set_encoding(const std::string& encoding) { encoding_ = encoding; }
- /**
- * @brief is_tizen_content
- * @return if is tizen content
- */
- bool is_tizen_content() const {
- return is_tizen_content_;
- }
- /**
- * @brief set_is_tizen_content
- * @param is_tizen_content
- */
- void set_is_tizen_content(bool is_tizen_content) {
- is_tizen_content_ = is_tizen_content;
- }
-
- private:
- std::string src_;
- std::string type_;
- std::string encoding_;
- bool is_tizen_content_;
-};
-
-/**
- * @brief The ContentHandler class
- *
- * Handler of config.xml for xml elements:
- * - <w3c:content>,
- * - <tizen:content>.
- */
-class ContentHandler : public parser::ManifestHandler {
- public:
- enum class ParseResult {
- OK,
- IGNORE,
- ERROR,
- };
-
- ContentHandler();
- virtual ~ContentHandler();
-
- ParseResult ParseAndSetContentValue(
- const parser::DictionaryValue& dict,
- std::shared_ptr<wgt::parse::ContentInfo>* content,
- std::string* error);
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- std::string Key() const override;
-
- private:
- bool w3c_content_found_;
- bool tizen_content_found_;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_CONTENT_HANDLER_H_
+++ /dev/null
-// 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/csp_handler.h"
-
-#include <string.h>
-#include <cassert>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-
-namespace {
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kXmlTextKey[] = "#text";
-const char kCSPKey[] = "widget.content-security-policy";
-const char kCSPReportOnlyKey[] = "widget.content-security-policy-report-only";
-}
-
-namespace wgt {
-namespace parse {
-
-std::string CSPInfo::Key() {
- return kCSPKey;
-}
-
-std::string CSPInfo::Report_only_key() {
- return kCSPReportOnlyKey;
-}
-
-bool CSPHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- std::string security_key = (security_type_ == SecurityType::CSP) ?
- kCSPKey : kCSPReportOnlyKey;
-
- if (!manifest.HasPath(security_key))
- return true;
-
- std::shared_ptr<CSPInfo> info(new CSPInfo);
-
- const auto& dict = parser::GetOneOrMany(manifest.value()
- , security_key, kTizenNamespacePrefix);
- std::string security_rules;
-
- if (dict.front()->GetString(kXmlTextKey, &security_rules)) {
- info->set_security_rules(security_rules);
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(info);
-
- return true;
-}
-
-std::string CSPHandler::Key() const {
- return security_type_ == SecurityType::CSP ? kCSPKey
- : kCSPReportOnlyKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// 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.
-
-#ifndef MANIFEST_HANDLERS_CSP_HANDLER_H_
-#define MANIFEST_HANDLERS_CSP_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "manifest_parser/values.h"
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class CSPInfo : public parser::ManifestData {
- public:
- CSPInfo() {}
- ~CSPInfo() override {}
-
- static std::string Key();
- static std::string Report_only_key();
- /**
- * @brief set_security_rules sets up string with security rules
- * @param security_rules
- */
- void set_security_rules(const std::string& security_rules) {
- security_rules_ = security_rules;
- }
- /**
- * @brief security_rules
- * @return string with security_rules
- */
- const std::string security_rules() const {
- return security_rules_;
- }
-
- private:
- std::string security_rules_;
-};
-
-/**
- * @brief The CSPHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:content-security-policy>,
- * - <tizen:content-security-policy-report-only>.
- */
-class CSPHandler : public parser::ManifestHandler {
- public:
- enum class SecurityType {
- CSP,
- CSP_REPORT_ONLY
- };
- explicit CSPHandler(SecurityType securityType)
- : security_type_(securityType) {}
- ~CSPHandler() override {}
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- std::string Key() const override;
- private:
- SecurityType security_type_;
-};
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_CSP_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/ime_handler.h"
-
-#include <cassert>
-#include <memory>
-#include <regex>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kTizenImeUuidKey[] = "uuid";
-const char kTizenImeUuidTextKey[] = "#text";
-const char kTizenImeLanguagesKey[] = "languages";
-const char kTizenImeLanguageKey[] = "language";
-const char kTizenImeLanguageTextKey[] = "#text";
-const char kTizenImeKey[] = "widget.ime";
-
-const char kErrMsgLanguages[] =
- "At least and only ONE tizen:languages tag should be specified";
-const char kErrMsgEmptyLanguage[] = "Language cannot be empty";
-const char kErrMsgParsingIme[] = "Only one ime tag should be specified";
-const char kErrMsgParsingUuid[] = "Only one uuid tag should be specified";
-const char kErrMsgValidatingUuidEmpty[] =
- "The UUID of ime element is obligatory";
-const char kErrMsgUuidFormat[] = "Uuid should be in proper format (8-4-4-4-12)";
-const char kErrMsgNoLanguages[] =
- "At least one language of ime element should be specified";
-
-const std::regex kUuidRegex(
- "^[0-9a-zA-Z]{8}([-][0-9a-zA-Z]{4}){3}[-][0-9a-zA-Z]{12}$");
-
-bool GetLanguage(const parser::Value* item, ImeInfo* ime_info,
- std::string* error) {
- const parser::DictionaryValue* language_dict;
- if (item->GetAsDictionary(&language_dict)) {
- std::string language;
- if (!language_dict->GetString(kTizenImeLanguageTextKey, &language) ||
- language.empty()) {
- *error = kErrMsgEmptyLanguage;
- return false;
- }
- ime_info->AddLanguage(language);
- }
- return true;
-}
-
-bool ParseImeEntryAndStore(const parser::DictionaryValue& control_dict,
- ImeInfo* ime_info, std::string* error) {
- // parsing uuid element
- const parser::DictionaryValue* uuid_dict;
- std::string uuid;
- if (control_dict.GetDictionary(kTizenImeUuidKey, &uuid_dict) &&
- uuid_dict->GetString(kTizenImeUuidTextKey, &uuid)) {
- ime_info->set_uuid(uuid);
- } else {
- *error = kErrMsgParsingUuid;
- return false;
- }
-
- const parser::DictionaryValue* languages_dict;
- if (!control_dict.GetDictionary(kTizenImeLanguagesKey, &languages_dict)) {
- *error = kErrMsgLanguages;
- return false;
- }
-
- const parser::Value* languages;
- if (!languages_dict->Get(kTizenImeLanguageKey, &languages)) {
- *error = kErrMsgNoLanguages;
- return false;
- }
-
- if (languages->GetType() == parser::Value::TYPE_LIST) {
- // many languages
- const parser::ListValue* list;
- languages->GetAsList(&list);
- for (const auto& item : *list) {
- if (!GetLanguage(item, ime_info, error)) return false;
- }
- } else if (languages->GetType() == parser::Value::TYPE_DICTIONARY) {
- if (!GetLanguage(languages, ime_info, error)) return false;
- }
-
- return true;
-}
-
-// UUID is string of 36 characters in form 8-4-4-4-12
-bool IsValidUuid(const std::string& uuid) {
- return std::regex_match(uuid, kUuidRegex);
-}
-
-} // namespace
-
-ImeInfo::ImeInfo() {}
-
-ImeInfo::~ImeInfo() {}
-
-ImeHandler::ImeHandler() {}
-
-ImeHandler::~ImeHandler() {}
-
-void ImeInfo::AddLanguage(const std::string& language) {
- languages_.push_back(language);
-}
-
-
-bool ImeHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenImeKey))
- return true;
-
- auto ime_info = std::make_shared<ImeInfo>();
-
- const auto& dict = parser::GetOneOrMany(manifest.value(),
- kTizenImeKey, kTizenNamespacePrefix).front();
-
- if (!ParseImeEntryAndStore(*dict, ime_info.get(), error)) {
- return false;
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(ime_info);
-
- return true;
-}
-
-bool ImeHandler::Validate(const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const ImeInfo& ime_info = static_cast<const ImeInfo&>(data);
-
- if (!ime_info.exists()) return true;
-
- if (ime_info.uuid().empty()) {
- *error = kErrMsgValidatingUuidEmpty;
- return false;
- }
-
- if (!IsValidUuid(ime_info.uuid())) {
- *error = kErrMsgUuidFormat;
- return false;
- }
-
- if (ime_info.languages().empty()) {
- *error = kErrMsgNoLanguages;
- return false;
- }
-
- return true;
-}
-
-std::string ImeHandler::Key() const { return kTizenImeKey; }
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_IME_HANDLER_H_
-#define MANIFEST_HANDLERS_IME_HANDLER_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class ImeInfo : public parser::ManifestData {
- public:
- ImeInfo();
- virtual ~ImeInfo();
- /**
- * @brief uuid
- * @return uuid string
- */
- const std::string& uuid() const {
- return uuid_;
- }
- /**
- * @brief set_uuid sets uuid string
- * @param uuid
- */
- void set_uuid(const std::string& uuid) { uuid_ = uuid; }
- const std::vector<std::string>& languages() const {
- return languages_;
- }
- /**
- * @brief AddLanguage adds language
- * @param language
- */
- void AddLanguage(const std::string& language);
-
- private:
- std::string uuid_;
- std::vector<std::string> languages_;
-};
-
-/**
- * @brief The ImeHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:ime>.
- */
-class ImeHandler : public parser::ManifestHandler {
- public:
- ImeHandler();
- virtual ~ImeHandler();
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& application,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_IME_HANDLER_H_
+++ /dev/null
-prefix=@PREFIX@
-exec_prefix=@PREFIX@
-libdir=@LIBDIR@
-includedir=@INCLUDEDIR@
-
-Name: manifest-handlers
-Description: Manifest handlers for manifest parser
-Version: @VERSION@
-Requires: manifest-parser
-Libs: -L${libdir} -lmanifest-handlers
-Cflags: -I${includedir}
\ No newline at end of file
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/metadata_handler.h"
-
-#include <cassert>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-typedef std::pair<std::string, std::string> MetaDataPair;
-typedef std::map<std::string, std::string> MetaDataMap;
-typedef std::map<std::string, std::string>::const_iterator MetaDataIter;
-
-namespace {
-
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kTizenMetaDataNameKey[] = "@key";
-const char kTizenMetaDataValueKey[] = "@value";
-const char kTizenMetaDataKey[] = "widget.metadata";
-
-MetaDataPair ParseMetaDataItem(const parser::DictionaryValue* dict,
- std::string* error) {
- assert(dict && dict->IsType(parser::Value::TYPE_DICTIONARY));
- MetaDataPair result;
- if (!dict->GetString(kTizenMetaDataNameKey, &result.first)) {
- *error = "Invalid key of tizen metaData.";
- } else {
- if (!dict->GetString(kTizenMetaDataValueKey, &result.second)) {
- result.second = "";
- }
- }
-
- return result;
-}
-
-} // namespace
-
-MetaDataInfo::MetaDataInfo() {}
-
-MetaDataInfo::~MetaDataInfo() {}
-
-bool MetaDataInfo::HasKey(const std::string& key) const {
- return metadata_.find(key) != metadata_.end();
-}
-
-std::string MetaDataInfo::GetValue(const std::string& key) const {
- MetaDataIter it = metadata_.find(key);
- if (it != metadata_.end()) return it->second;
- return std::string("");
-}
-
-void MetaDataInfo::SetValue(const std::string& key, const std::string& value) {
- metadata_.insert(MetaDataPair(key, value));
-}
-
-MetaDataHandler::MetaDataHandler() {}
-
-MetaDataHandler::~MetaDataHandler() {}
-
-
-bool MetaDataHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenMetaDataKey))
- return true;
-
- auto metadata_info = std::make_shared<MetaDataInfo>();
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenMetaDataKey, kTizenNamespacePrefix)) {
- MetaDataPair metadata_item;
-
- metadata_item = ParseMetaDataItem(dict, error);
- metadata_info->SetValue(metadata_item.first, metadata_item.second);
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(metadata_info);
-
- return true;
-}
-
-bool MetaDataHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* /*error*/) const {
- const MetaDataInfo& mdata_info = static_cast<const MetaDataInfo&>(data);
- // TODO(j.izydorczyk):
- // Here should be performed *info class members validity check
- (void)mdata_info;
- return true;
-}
-
-std::string MetaDataHandler::Key() const {
- return kTizenMetaDataKey;
-}
-
-std::string MetaDataInfo::Key() {
- return kTizenMetaDataKey;
-}
-
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_METADATA_HANDLER_H_
-#define MANIFEST_HANDLERS_METADATA_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-class MetaDataInfo : public parser::ManifestData {
- public:
- MetaDataInfo();
- virtual ~MetaDataInfo();
-
- static std::string Key();
- /**
- * @brief HasKey
- * @param key
- * @return true if has key
- */
- bool HasKey(const std::string& key) const;
- /**
- * @brief GetValue gets value
- * @param key
- * @return
- */
- std::string GetValue(const std::string& key) const;
- /**
- * @brief SetValue sets value
- * @param key
- * @param value
- */
- void SetValue(const std::string& key, const std::string& value);
- /**
- * @brief metadata
- * @return map of metadata
- */
- const std::map<std::string, std::string>& metadata() const {
- return metadata_;
- }
-
- private:
- std::map<std::string, std::string> metadata_;
-};
-
-/**
- * @brief The MetaDataHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:metadata>.
- */
-class MetaDataHandler : public parser::ManifestHandler {
- public:
- MetaDataHandler();
- virtual ~MetaDataHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_METADATA_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/navigation_handler.h"
-
-#include <boost/tokenizer.hpp>
-
-#include "manifest_handlers/application_manifest_constants.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kAllowNavigationKey[] = "widget.allow-navigation";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kXmlTextKey[] = "#text";
-const boost::char_separator<char> navigation_separator(" ");
-
-} // namespace
-
-AllowedNavigationInfo::AllowedNavigationInfo(
- const std::string& allowed_domains) {
- boost::tokenizer<boost::char_separator<char>> tokens(allowed_domains,
- navigation_separator);
- for (auto& item : tokens) {
- allowed_domains_.push_back(item);
- }
-}
-
-AllowedNavigationInfo::~AllowedNavigationInfo() {}
-
-std::string AllowedNavigationInfo::Key() {
- return kAllowNavigationKey;
-}
-
-NavigationHandler::NavigationHandler() {}
-
-NavigationHandler::~NavigationHandler() {}
-
-
-bool NavigationHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- if (!manifest.HasPath(kAllowNavigationKey))
- return true;
-
- std::string allowed_domains;
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kAllowNavigationKey, kTizenNamespacePrefix)) {
- if (!dict->GetString(kXmlTextKey, &allowed_domains))
- return true;
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(
- std::make_shared<AllowedNavigationInfo>(allowed_domains));
- return true;
-}
-
-bool NavigationHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* /*error*/) const {
- const AllowedNavigationInfo& navi_info =
- static_cast<const AllowedNavigationInfo&>(data);
- // TODO(j.izydorczyk): There should be done 'navi_info' validity check.
- (void)navi_info;
- return true;
-}
-
-std::string NavigationHandler::Key() const {
- return kAllowNavigationKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_NAVIGATION_HANDLER_H_
-#define MANIFEST_HANDLERS_NAVIGATION_HANDLER_H_
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class AllowedNavigationInfo : public parser::ManifestData {
- public:
- explicit AllowedNavigationInfo(const std::string& allowed_domains);
- virtual ~AllowedNavigationInfo();
-
- static std::string Key();
- /**
- * @brief GetAllowedDomains
- * @return vector with allowed domains
- */
- const std::vector<std::string>& GetAllowedDomains() const {
- return allowed_domains_;
- }
-
- private:
- std::vector<std::string> allowed_domains_;
-};
-
-/**
- * @brief The NavigationHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:allow-navigation>.
- */
-class NavigationHandler : public parser::ManifestHandler {
- public:
- NavigationHandler();
- virtual ~NavigationHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
-
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_NAVIGATION_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/permissions_handler.h"
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/values.h"
-
-namespace {
-const char kTizenPermissionsKey[] = "widget.privilege";
-}
-
-namespace wgt {
-namespace parse {
-
-namespace {
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kTizenPermissionsNameKey[] = "@name";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-}
-
-PermissionsInfo::PermissionsInfo() {}
-
-PermissionsInfo::~PermissionsInfo() {}
-
-PermissionsHandler::PermissionsHandler() {}
-
-PermissionsHandler::~PermissionsHandler() {}
-
-bool PermissionsHandler::Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenPermissionsKey)) {
- return true;
- }
-
- parser::Value* value;
- if (!manifest.Get(kTizenPermissionsKey, &value)) {
- *error = "Invalid value of tizen permissions.";
- return false;
- }
-
- auto permissions_info = std::make_shared<PermissionsInfo>();
- parser::PermissionSet api_permissions;
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kTizenPermissionsKey, kTizenNamespacePrefix)) {
- std::string permission;
-
- if (!dict->GetString(kTizenPermissionsNameKey, &permission) ||
- permission.empty())
- continue;
-
- if (api_permissions.find(permission) != api_permissions.end())
- LOG(WARNING) << "Duplicated permission names found: " << permission;
-
- api_permissions.insert(permission);
- }
-
- permissions_info->SetAPIPermissions(api_permissions);
-
- *output = std::static_pointer_cast<parser::ManifestData>(permissions_info);
- return true;
-}
-
-bool PermissionsHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* /*error*/) const {
- const PermissionsInfo& perm_info = static_cast<const PermissionsInfo&>(data);
- // TODO(j.izydorczyk): there should be done 'perm_info' members validation
- (void)perm_info;
- return true;
-}
-
-std::string PermissionsInfo::Key() {
- return kTizenPermissionsKey;
-}
-
-std::string PermissionsHandler::Key() const {
- return kTizenPermissionsKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_PERMISSIONS_HANDLER_H_
-#define MANIFEST_HANDLERS_PERMISSIONS_HANDLER_H_
-
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/permission_types.h"
-
-namespace wgt {
-namespace parse {
-
-class PermissionsInfo: public parser::ManifestData {
- public:
- PermissionsInfo();
- virtual ~PermissionsInfo();
-
- static std::string Key();
- /**
- * @brief GetAPIPermissions
- * @return permission set
- */
- const parser::PermissionSet& GetAPIPermissions() const {
- return api_permissions_;
- }
- /**
- * @brief SetAPIPermissions sets api permissions
- * @param api_permissions
- */
- void SetAPIPermissions(const parser::PermissionSet& api_permissions) {
- api_permissions_ = api_permissions;
- }
-
- private:
- parser::PermissionSet api_permissions_;
-};
-
-/**
- * @brief The PermissionsHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:privilege>.
- */
-class PermissionsHandler: public parser::ManifestHandler {
- public:
- PermissionsHandler();
- virtual ~PermissionsHandler();
-
- bool Parse(
- const parser::Manifest& data,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_PERMISSIONS_HANDLER_H_
+++ /dev/null
-// 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.
-
-#include "manifest_handlers/platform_version.h"
-
-namespace parser {
-
-utils::VersionNumber GetCurrentPlatformVersion() {
- return utils::VersionNumber(TIZEN_VERSION);
-}
-
-utils::VersionNumber GetMinimumPlatformVersion() {
-#ifdef TIZEN_TV
- return utils::VersionNumber("2.3");
-#elif TIZEN_WEARABLE
- return utils::VersionNumber("2.3.1");
-#else
- return utils::VersionNumber("2.2.1");
-#endif
-}
-
-} // namespace parser
+++ /dev/null
-// 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 file.
-
-#ifndef MANIFEST_HANDLERS_PLATFORM_VERSION_H_
-#define MANIFEST_HANDLERS_PLATFORM_VERSION_H_
-
-#include <string>
-
-#include "manifest_parser/utils/version_number.h"
-
-namespace parser {
-/**
- * @brief GetCurrentPlatformVersion
- * @return number version of the platform currently used
- */
-utils::VersionNumber GetCurrentPlatformVersion();
-
-/**
- * @brief GetMinimumPlatformVersion
- * @return number version of the minimum platform for current profile
- */
-utils::VersionNumber GetMinimumPlatformVersion();
-
-} // namespace parser
-
-#endif // MANIFEST_HANDLERS_PLATFORM_VERSION_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/service_handler.h"
-
-#include <cassert>
-#include <map>
-#include <utility>
-#include <set>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/manifest_util.h"
-#include "manifest_parser/values.h"
-
-namespace {
-const char kTizenServiceKey[] = "widget.service";
-const char kTizenServiceIdKey[] = "@id";
-const char kTizenServiceAutoRestartKey[] = "@auto-restart";
-const char kTizenServiceOnBootKey[] = "@on-boot";
-const char kTizenServiceCategoryKey[] = "category";
-const char kTizenServiceCategoryNameKey[] = "@name";
-const char kTizenServiceContentKey[] = "content";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kTizenServiceNameKey[] = "name";
-const char kTizenServiceContentSrcKey[] = "@src";
-const char kTizenServiceIconKey[] = "icon";
-const char kTizenServiceIconSrcKey[] = "@src";
-const char kTizenServiceDescriptionKey[] = "description";
-const char kTizenServiceMetadataKey[] = "metadata";
-const char kTizenServiceMetadataKeyKey[] = "@key";
-const char kTizenServiceMetadataValueKey[] = "@value";
-const char kXmlLangKey[] = "@lang";
-const char kXmlTextKey[] = "#text";
-
-bool ParseServiceContent(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- std::string content;
- bool found = false;
- for (auto& item : parser::GetOneOrMany(dict, kTizenServiceContentKey,
- kTizenNamespacePrefix)) {
- if (found) {
- *error = "tizen:content element of tizen:service "
- "should be declared only once";
- return false;
- }
- found = true;
- if (!item->GetString(kTizenServiceContentSrcKey, &content)) {
- *error =
- "Missing 'src' attribute in tizen:content tag in tizen:service";
- return false;
- }
- }
- if (!found) {
- *error = "Missing tizen:content tag in tizen:service";
- return false;
- }
- service_info->set_content(content);
- return true;
-}
-
-bool ParseServiceIcon(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- std::string icon;
- const auto& items = parser::GetOneOrMany(dict, kTizenServiceIconKey,
- kTizenNamespacePrefix);
- if (!items.empty()) {
- if (items.size() > 1) {
- *error = "tizen:icon element of tizen:service "
- "should be declared only once";
- return false;
- }
- if (!items[0]->GetString(kTizenServiceIconSrcKey, &icon)) {
- *error = "Missing 'src' attribute in tizen:icon tag in tizen:service";
- return false;
- }
- service_info->set_icon(icon);
- }
- return true;
-}
-
-bool ParseServiceDescription(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- const parser::Value* value = nullptr;
- if (!dict->Get(kTizenServiceDescriptionKey, &value)) return true;
- std::string description;
-
- const auto& items = parser::GetOneOrMany(dict,
- kTizenServiceDescriptionKey,
- kTizenNamespacePrefix);
- if (!items.empty()) {
- if (items.size() > 1) {
- *error = "tizen:description element of tizen:service "
- "should be declared only once";
- return false;
- }
- items[0]->GetString(kXmlTextKey, &description);
- service_info->set_description(description);
- }
- return true;
-}
-
-bool ParseServiceCategory(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- std::vector<std::string> categories;
- for (auto& item : parser::GetOneOrMany(dict, kTizenServiceCategoryKey,
- kTizenNamespacePrefix)) {
- std::string category;
- if (!item->GetString(kTizenServiceCategoryNameKey, &category)) {
- *error =
- "Missing 'name' attribute of tizen:category tag in tizen:service";
- return false;
- }
- categories.push_back(category);
- }
- service_info->set_categories(categories);
- return true;
-}
-
-bool ParseServiceName(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- wgt::parse::LangNameVector names;
- for (auto& item : parser::GetOneOrMany(dict, kTizenServiceNameKey,
- kTizenNamespacePrefix)) {
- std::string lang;
- std::string name;
- item->GetString(kXmlLangKey, &lang);
- item->GetString(kXmlTextKey, &name);
- names.emplace_back(lang, name);
- }
- if (names.empty()) {
- *error = "Cannot find tizen:name element for tizen:service. "
- "At least one must be provided.";
- return false;
- }
- service_info->set_names(names);
- return true;
-}
-
-bool ParseServiceMetadata(const parser::DictionaryValue* dict,
- wgt::parse::ServiceInfo* service_info,
- std::string* error) {
- wgt::parse::KeyValueVector metadata_set;
- for (auto& item : parser::GetOneOrMany(dict, kTizenServiceMetadataKey,
- kTizenNamespacePrefix)) {
- std::string key;
- std::string value;
- if (!item->GetString(kTizenServiceMetadataKeyKey, &key)) {
- *error = "'key' attribute of metadata is obligatory";
- return false;
- }
- item->GetString(kTizenServiceMetadataValueKey, &value);
- metadata_set.emplace_back(key, value);
- }
- service_info->set_metadata_set(metadata_set);
- return true;
-}
-
-std::unique_ptr<wgt::parse::ServiceInfo> ParseService(
- const parser::DictionaryValue* dict, std::string* error) {
- std::string id;
- if (!dict->GetString(kTizenServiceIdKey, &id)) {
- *error = "Cannot get appid for tizen:service";
- return nullptr;
- }
-
- std::unique_ptr<wgt::parse::ServiceInfo> service(
- new wgt::parse::ServiceInfo(id));
-
- std::string auto_restart = "false";
- if (dict->GetString(kTizenServiceAutoRestartKey, &auto_restart))
- service->set_auto_restart(auto_restart == "true");
-
- std::string on_boot = "false";
- if (dict->GetString(kTizenServiceOnBootKey, &on_boot))
- service->set_on_boot(on_boot == "true");
-
- if (!ParseServiceContent(dict, service.get(), error)) return nullptr;
-
- if (!ParseServiceIcon(dict, service.get(), error)) return nullptr;
-
- if (!ParseServiceDescription(dict, service.get(), error)) return nullptr;
-
- if (!ParseServiceCategory(dict, service.get(), error)) return nullptr;
-
- if (!ParseServiceName(dict, service.get(), error)) return nullptr;
-
- if (!ParseServiceMetadata(dict, service.get(), error)) return nullptr;
-
- return service;
-}
-
-} // namespace
-
-namespace wgt {
-
-namespace parse {
-
-ServiceInfo::ServiceInfo(const std::string& id, bool auto_restart, bool on_boot)
- : id_(id), auto_restart_(auto_restart), on_boot_(on_boot) {}
-
-ServiceInfo::~ServiceInfo() {}
-
-ServiceHandler::ServiceHandler() {}
-
-ServiceHandler::~ServiceHandler() {}
-
-
-bool ServiceHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- if (!manifest.HasPath(kTizenServiceKey)) {
- return true;
- }
- std::shared_ptr<ServiceList> services_data(new ServiceList());
-
- for (auto& item : parser::GetOneOrMany(manifest.value(),
- kTizenServiceKey, kTizenNamespacePrefix)) {
- auto service = ParseService(item, error);
- if (!service)
- return false;
- services_data->services.push_back(*service);
- }
- *output = std::static_pointer_cast<parser::ManifestData>(services_data);
- return true;
-}
-
-bool ServiceHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const auto services = static_cast<const wgt::parse::ServiceList&>(data);
-
- for (auto& service : services.services) {
- if (!parser::ValidateTizenApplicationId(service.id())) {
- *error =
- "The id property of application element "
- "does not match the format\n";
- return false;
- }
- }
-
- return true;
-}
-
-std::string ServiceInfo::Key() {
- return kTizenServiceKey;
-}
-
-std::string ServiceHandler::Key() const {
- return kTizenServiceKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_SERVICE_HANDLER_H_
-#define MANIFEST_HANDLERS_SERVICE_HANDLER_H_
-
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-using LangNameVector = std::vector<std::pair<std::string, std::string>>;
-using KeyValueVector = std::vector<std::pair<std::string, std::string>>;
-
-class ServiceInfo {
- public:
- explicit ServiceInfo(const std::string& id, bool auto_restart = false,
- bool on_boot = false);
- virtual ~ServiceInfo();
-
- static std::string Key();
- /**
- * @brief id
- * @return string id
- */
- const std::string& id() const { return id_; }
- void set_id(const std::string& id) {
- id_ = id;
- }
- /**
- * @brief auto_restart
- * @return true is auto-restart is set
- */
- bool auto_restart() const { return auto_restart_; }
- /**
- * @brief set_auto_restart sets auto restart
- * @param auto_restart
- */
- void set_auto_restart(bool auto_restart) {
- auto_restart_ = auto_restart;
- }
- /**
- * @brief on_boot
- * @return if is on boot
- */
- bool on_boot() const { return on_boot_; }
- void set_on_boot(bool on_boot) {
- on_boot_ = on_boot;
- }
- /**
- * @brief names
- * @return lang names vector
- */
- const LangNameVector& names() const {
- return names_;
- }
- /**
- * @brief set_names sets name lang vector
- * @param names
- */
- void set_names(const LangNameVector& names) {
- names_ = names;
- }
- /**
- * @brief icon
- * @return string to the icon
- */
- const std::string& icon() const {
- return icon_;
- }
- /**
- * @brief set_icon set string to the icon
- * @param icon
- */
- void set_icon(const std::string& icon) {
- icon_ = icon;
- }
- /**
- * @brief content
- * @return content string
- */
-
- const std::string& content() const {
- return content_;
- }
- /**
- * @brief set_content sets content string
- * @param content
- */
- void set_content(const std::string& content) {
- content_ = content;
- }
- /**
- * @brief description
- * @return description string
- */
- const std::string& description() const {
- return description_;
- }
- /**
- * @brief set_description sets description
- * @param description
- */
- void set_description(const std::string& description) {
- description_ = description;
- }
- /**
- * @brief categories
- * @return categories vector
- */
-
- const std::vector<std::string>& categories() const {
- return categories_;
- }
- /**
- * @brief set_categories sets categories
- * @param categories
- */
- void set_categories(const std::vector<std::string>& categories) {
- categories_ = categories;
- }
- /**
- * @brief metadata_set
- * @return key value vector
- */
- const KeyValueVector& metadata_set() const {
- return metadata_set_;
- }
- /**
- * @brief set_metadata_set sets metadata
- * @param metadata_set
- */
- void set_metadata_set(const KeyValueVector& metadata_set) {
- metadata_set_ = metadata_set;
- }
-
- private:
- std::string id_;
- bool auto_restart_;
- bool on_boot_;
- LangNameVector names_;
- std::string icon_;
- std::string content_;
- std::string description_;
- std::vector<std::string> categories_;
- KeyValueVector metadata_set_;
-};
-
-struct ServiceList : public parser::ManifestData {
- std::vector<ServiceInfo> services;
-};
-
-/**
- * @brief The ServiceHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:service>.
- */
-class ServiceHandler : public parser::ManifestHandler {
- public:
- ServiceHandler();
- virtual ~ServiceHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_SERVICE_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/setting_handler.h"
-
-#include <boost/algorithm/string.hpp>
-#include <string.h>
-
-#include <cassert>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-
-namespace {
-
-const char kTrueValue[] = "true";
-const char kFalseValue[] = "false";
-
-const char kTizenHardwareKey[] = "@hwkey-event";
-const char kTizenScreenOrientationKey[] = "@screen-orientation";
-const char kTizenEncryptionKey[] = "@encryption";
-const char kTizenContextMenuKey[] = "@context-menu";
-const char kTizenBackgroundSupportKey[] = "@background-support";
-const char kTizenNoDisplayKey[] = "@nodisplay";
-const char kTizenIndicatorPresenceKey[] = "@indicator-presence";
-const char kTizenBackbuttonPresenceKey[] = "@backbutton-presence";
-const char kTizenInstallLocationKey[] = "@install-location";
-const char kTizenUserAgentKey[] = "@user-agent";
-const char kTizenSoundModeKey[] = "@sound-mode";
-const char kTizenBackgroundVibrationKey[] = "@background-vibration";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kTizenSettingKey[] = "widget.setting";
-
-bool ForAllFindKey(const parser::Value* value, const std::string& key,
- std::string* result) {
- if (value->GetType() == parser::Value::TYPE_DICTIONARY) {
- const parser::DictionaryValue* dict = nullptr;
- value->GetAsDictionary(&dict);
- if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
- return false;
- if (dict->GetString(key, result)) return true;
- } else if (value->GetType() == parser::Value::TYPE_LIST) {
- const parser::ListValue* list = nullptr;
- value->GetAsList(&list);
- for (auto& item : *list) {
- const parser::DictionaryValue* dict = nullptr;
- if (item->GetAsDictionary(&dict)) {
- if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
- continue;
- if (dict->GetString(key, result)) return true;
- }
- }
- }
- return false;
-}
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-SettingInfo::SettingInfo()
- : hwkey_enabled_(true),
- screen_orientation_(ScreenOrientation::AUTO),
- encryption_enabled_(false),
- context_menu_enabled_(true),
- background_support_enabled_(false),
- install_location_(InstallLocation::AUTO),
- no_display_(false),
- indicator_presence_(true),
- backbutton_presence_(false),
- sound_mode_(SoundMode::SHARED),
- background_vibration_(false) {}
-
-SettingInfo::~SettingInfo() {}
-
-SettingHandler::SettingHandler() {}
-
-SettingHandler::~SettingHandler() {}
-
-bool SettingHandler::Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- const parser::Value* value = nullptr;
- manifest.Get(kTizenSettingKey, &value);
-
- std::shared_ptr<SettingInfo> app_info(new SettingInfo);
- std::string hwkey;
- ForAllFindKey(value, kTizenHardwareKey, &hwkey);
- app_info->set_hwkey_enabled(hwkey != "disable");
-
- std::string screen_orientation;
- ForAllFindKey(value, kTizenScreenOrientationKey, &screen_orientation);
- if (strcasecmp("portrait", screen_orientation.c_str()) == 0)
- app_info->set_screen_orientation(SettingInfo::ScreenOrientation::PORTRAIT);
- else if (strcasecmp("landscape", screen_orientation.c_str()) == 0)
- app_info->set_screen_orientation(SettingInfo::ScreenOrientation::LANDSCAPE);
- else
- app_info->set_screen_orientation(SettingInfo::ScreenOrientation::AUTO);
-
- std::string encryption;
- ForAllFindKey(value, kTizenEncryptionKey, &encryption);
- app_info->set_encryption_enabled(encryption == "enable");
-
- std::string context_menu;
- ForAllFindKey(value, kTizenContextMenuKey, &context_menu);
- app_info->set_context_menu_enabled(context_menu != "disable");
-
- std::string background_support;
- ForAllFindKey(value, kTizenBackgroundSupportKey, &background_support);
- app_info->set_background_support_enabled(background_support == "enable");
-
- std::string install_location;
- ForAllFindKey(value, kTizenInstallLocationKey, &install_location);
- if (strcasecmp("internal-only", install_location.c_str()) == 0)
- app_info->set_install_location(SettingInfo::InstallLocation::INTERNAL);
- else if (strcasecmp("prefer-external", install_location.c_str()) == 0)
- app_info->set_install_location(SettingInfo::InstallLocation::EXTERNAL);
-
- std::string no_display;
- ForAllFindKey(value, kTizenNoDisplayKey, &no_display);
- app_info->set_no_display(boost::iequals(no_display, kTrueValue));
-
- std::string indicator_presence;
- if (ForAllFindKey(value, kTizenIndicatorPresenceKey, &indicator_presence)) {
- if (boost::iequals(indicator_presence, kTrueValue)) {
- app_info->set_indicator_presence(true);
- } else if (boost::iequals(indicator_presence, kFalseValue)) {
- app_info->set_indicator_presence(false);
- }
- }
-
- std::string backbutton_presence;
- if (ForAllFindKey(value, kTizenBackbuttonPresenceKey, &backbutton_presence)) {
- if (boost::iequals(backbutton_presence, kTrueValue)) {
- app_info->set_backbutton_presence(true);
- } else if (boost::iequals(backbutton_presence, kFalseValue)) {
- app_info->set_backbutton_presence(false);
- }
- }
-
- std::string user_agent;
- ForAllFindKey(value, kTizenUserAgentKey, &user_agent);
- app_info->set_user_agent(user_agent);
-
- std::string background_vibration;
- ForAllFindKey(value, kTizenBackgroundVibrationKey, &background_vibration);
- app_info->set_background_vibration(background_vibration == "enable");
-
- std::string sound_mode;
- ForAllFindKey(value, kTizenSoundModeKey, &sound_mode);
- if (strcasecmp("exclusive", sound_mode.c_str()) == 0)
- app_info->set_sound_mode(SettingInfo::SoundMode::EXCLUSIVE);
-
- *output = std::static_pointer_cast<parser::ManifestData>(app_info);
- return true;
-}
-
-bool SettingHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const SettingInfo& setting_info = static_cast<const SettingInfo&>(data);
- if (setting_info.screen_orientation() !=
- SettingInfo::ScreenOrientation::AUTO &&
- setting_info.screen_orientation() !=
- SettingInfo::ScreenOrientation::PORTRAIT &&
- setting_info.screen_orientation() !=
- SettingInfo::ScreenOrientation::LANDSCAPE) {
- *error = "Wrong value of screen orientation";
- return false;
- }
-
- if (setting_info.install_location() != SettingInfo::InstallLocation::AUTO &&
- setting_info.install_location() !=
- SettingInfo::InstallLocation::INTERNAL &&
- setting_info.install_location() !=
- SettingInfo::InstallLocation::EXTERNAL) {
- *error = "Wrong value of install location";
- return false;
- }
-
- if (setting_info.sound_mode() != SettingInfo::SoundMode::SHARED &&
- setting_info.sound_mode() != SettingInfo::SoundMode::EXCLUSIVE) {
- *error = "Wrong value of screen sound mode";
- return false;
- }
-
- return true;
-}
-
-
-std::string SettingHandler::Key() const {
- return kTizenSettingKey;
-}
-
-std::string SettingInfo::Key() {
- return kTizenSettingKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_SETTING_HANDLER_H_
-#define MANIFEST_HANDLERS_SETTING_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/values.h"
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class SettingInfo : public parser::ManifestData {
- public:
- enum class ScreenOrientation {
- PORTRAIT,
- LANDSCAPE,
- AUTO
- };
-
- enum class InstallLocation {
- INTERNAL,
- EXTERNAL,
- AUTO
- };
-
- enum class SoundMode {
- SHARED,
- EXCLUSIVE
- };
-
- SettingInfo();
- virtual ~SettingInfo();
-
- static std::string Key();
- /**
- * @brief set_hwkey_enabled sets value of hw_key to true or false
- * @param enabled
- */
- void set_hwkey_enabled(bool enabled) { hwkey_enabled_ = enabled; }
- /**
- * @brief hwkey_enabled
- * @return current value of hw_key
- */
- bool hwkey_enabled() const { return hwkey_enabled_; }
- /**
- * @brief set_screen_orientation sets screen_orientation
- * @param orientation
- */
- void set_screen_orientation(ScreenOrientation orientation) {
- screen_orientation_ = orientation;
- }
- /**
- * @brief screen_orientation
- * @return currently selected screen orientation
- */
-
- ScreenOrientation screen_orientation() const { return screen_orientation_; }
- /**
- * @brief set_encryption_enabled sets if encryption is enabled or disabled
- * @param enabled
- */
- void set_encryption_enabled(bool enabled) { encryption_enabled_ = enabled; }
- /**
- * @brief encryption_enabled
- * @return true if encryption is enable
- */
- bool encryption_enabled() const { return encryption_enabled_; }
- /**
- * @brief set_context_menu_enabled sets context menu enabled
- * @param enabled
- */
- void set_context_menu_enabled(bool enabled) {
- context_menu_enabled_ = enabled;
- }
- /**
- * @brief context_menu_enabled
- * @return true if context menu is enabled
- */
- bool context_menu_enabled() const { return context_menu_enabled_; }
- /**
- * @brief set_background_support_enabled whether it is enabled
- * @param enabled
- */
- void set_background_support_enabled(bool enabled) {
- background_support_enabled_ = enabled;
- }
- /**
- * @brief background_support_enabled
- * @return true if background support is enabled
- */
- bool background_support_enabled() const {
- return background_support_enabled_;
- }
- /**
- * @brief set_install_location sets install location
- * @param installLocation
- */
- void set_install_location(InstallLocation installLocation) {
- install_location_ = installLocation;
- }
- /**
- * @brief install_location
- * @return what InstallLocation is chosen
- */
- InstallLocation install_location() const { return install_location_; }
- /**
- * @brief set_no_display sets is there is no display
- * @param enabled
- */
- void set_no_display(bool enabled) { no_display_ = enabled; }
- /**
- * @brief no_display
- * @return if there is no supoort for display
- */
- bool no_display() const { return no_display_; }
- /**
- * @brief set_indicator_presence sets indicator presence
- * @param enabled
- */
- void set_indicator_presence(bool enabled) { indicator_presence_ = enabled; }
- /**
- * @brief indicator_presence
- * @return if the indicator is present
- */
- bool indicator_presence() const { return indicator_presence_; }
- /**
- * @brief set_backbutton_presence sets if backbutton is present
- * @param enabled
- */
- void set_backbutton_presence(bool enabled) { backbutton_presence_ = enabled; }
- /**
- * @brief backbutton_presence
- * @return true if backbutton is present
- */
- bool backbutton_presence() const { return backbutton_presence_; }
- /**
- * @brief set_user_agent sets user_agent()
- * @param user_agent
- */
- void set_user_agent(std::string user_agent) { user_agent_ = user_agent; }
- /**
- * @brief user_agent
- * @return actual user agent
- */
- std::string user_agent() const { return user_agent_; }
- /**
- * @brief set_sound_mode sets sound mode
- * @param soundMode
- */
- void set_sound_mode(SoundMode soundMode) { sound_mode_ = soundMode; }
- /**
- * @brief sound_mode
- * @return current sound mode
- */
- SoundMode sound_mode() const { return sound_mode_; }
- /**
- * @brief set_background_vibration set background vibration
- * @param enabled
- */
- void set_background_vibration(bool enabled) {
- background_vibration_ = enabled;
- }
- /**
- * @brief background_vibration
- * @return background vibration
- */
- bool background_vibration() const { return background_vibration_; }
-
- private:
- bool hwkey_enabled_;
- ScreenOrientation screen_orientation_;
- bool encryption_enabled_;
- bool context_menu_enabled_;
- bool background_support_enabled_;
- InstallLocation install_location_;
- bool no_display_;
- bool indicator_presence_;
- bool backbutton_presence_;
- std::string user_agent_;
- SoundMode sound_mode_;
- bool background_vibration_;
-};
-
-/**
- * @brief The SettingHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:setting>.
- */
-class SettingHandler : public parser::ManifestHandler {
- public:
- SettingHandler();
- virtual ~SettingHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& application,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-};
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_SETTING_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/splash_screen_handler.h"
-
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <algorithm>
-#include <cassert>
-#include <cstdlib>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/logging.h"
-
-namespace bf = boost::filesystem;
-namespace keys = wgt::application_widget_keys;
-namespace wgt_parse = wgt::parse;
-
-namespace {
-const char kTizenSplashScreenSrcKey[] = "@src";
-const char kTizenSplashScreenKey[] = "widget.splash-screen";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kTagDelimiter[] = " ";
-const char kFirstPaint[] = "first-paint";
-const char kComplete[] = "complete";
-const char kCustom[] = "custom";
-const char kSplashScreenDefault[] = "widget.launch_screen.ls_default";
-const char kSplashScreenPortrait[] = "widget.launch_screen.ls_portrait";
-const char kSplashScreenLandscape[] = "widget.launch_screen.ls_landscape";
-const char kSplashScreenKey[] = "widget.launch_screen";
-const char kSplashScreenReadyWhen[] = "@ready_when";
-const char kSplashScreenBgColor[] = "@background_color";
-const char kSplashScreenBgImage[] = "@background_image";
-const char kSplashScreenImage[] = "@image";
-const char kSplashScreenImageBorder[] = "@image_border";
-const std::map<wgt_parse::ScreenOrientation, const char*> kOrientationMap = {
- {wgt_parse::ScreenOrientation::AUTO, kSplashScreenDefault},
- {wgt_parse::ScreenOrientation::LANDSCAPE, kSplashScreenLandscape},
- {wgt_parse::ScreenOrientation::PORTRAIT, kSplashScreenPortrait}};
-
-std::shared_ptr< wgt_parse::Color>
-ConvertStringToColor(const std::string& color_str) {
- auto to_long = [&color_str](unsigned int start, unsigned int end) -> int {
- return std::strtoul(color_str.substr(start, end).c_str(), 0, 16);
- };
- std::shared_ptr<wgt_parse::Color> color(new wgt_parse::Color);
- switch (color_str.size()) {
- case 3:
- color->red = to_long(0, 0);
- color->green = to_long(1, 1);
- color->blue = to_long(2, 1);
- break;
- case 6:
- color->red = to_long(0, 2);
- color->green = to_long(2, 2);
- color->blue = to_long(4, 2);
- }
- return color;
-}
-
-bool IsStringToColorConvertable(const std::string& string_color) {
- return string_color[0] == '#' &&
- (string_color.size() == 4 || string_color.size() == 7);
-}
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-std::string SplashScreenInfo::Key() {
- return kTizenSplashScreenKey;
-}
-
-bool SplashScreenHandler::ParseSingleOrientation(
- const parser::Manifest& manifest, ScreenOrientation orientation,
- SplashScreenInfo* ss_info) {
- auto dict_element_parser =
- [this](SplashScreenData& splash_screen,
- const parser::DictionaryValue* dict) -> bool {
- if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
- return false;
-
- bool parsed_color = ParseColor(dict, &splash_screen);
- ParseElement(dict, &splash_screen.background_image, kSplashScreenBgImage);
- ParseElement(dict, &splash_screen.image, kSplashScreenImage);
- ParseElement(dict, &splash_screen.image_border, kSplashScreenImageBorder);
-
- return parsed_color || !splash_screen.background_image.empty() ||
- !splash_screen.image.empty();
- };
-
- auto orientation_chosen = kOrientationMap.at(orientation);
- SplashScreenData splash_screen;
-
- bool valid_element = false;
- for (auto& dict_element :
- parser::GetOneOrMany(manifest.value(),
- orientation_chosen,
- kTizenNamespacePrefix)) {
- if (dict_element_parser(splash_screen, dict_element))
- valid_element = true;
- }
- if (!valid_element) return false;
-
- ss_info->set_splash_screen_data(std::make_pair(orientation, splash_screen));
- return true;
-}
-
-bool SplashScreenHandler::ParseElement(const parser::DictionaryValue* dict,
- std::vector<std::string>* to_be_saved,
- const char* keyToParse) {
- // TODO(w.kosowicz) check which elements not declared should cause fail
- std::string element;
- dict->GetString(keyToParse, &element);
- boost::split(*to_be_saved, element, boost::is_any_of(kTagDelimiter));
- return true;
-}
-
-bool SplashScreenHandler::ParseColor(const parser::DictionaryValue* dict,
- SplashScreenData* splash_screen) {
- std::string background_color;
- if (!dict->GetString(kSplashScreenBgColor, &background_color) ||
- !IsStringToColorConvertable(background_color))
- return false;
-
- std::string only_hex = background_color.substr(1);
- if (!std::all_of(only_hex.begin(), only_hex.end(), isxdigit)) return false;
-
- splash_screen->background_color = ConvertStringToColor(only_hex);
- return true;
-}
-
-bool SplashScreenHandler::ParseReadyWhen(const parser::Manifest& manifest,
- SplashScreenInfo* ss_info) {
- auto dict_values = parser::GetOneOrMany(manifest.value(),
- kSplashScreenKey,
- kTizenNamespacePrefix);
- if (dict_values.empty())
- return false;
-
- std::string ready_when;
- dict_values[0]->GetAsString(&ready_when);
-
- if (ready_when.empty()) return false;
- if (ready_when != kFirstPaint && ready_when != kComplete &&
- ready_when != kCustom)
- return false;
-
- std::map<std::string, std::function<void()>> ready_when_functors;
- ready_when_functors[kFirstPaint] = std::bind(
- &SplashScreenInfo::set_ready_when, ss_info, ReadyWhen::FIRSTPAINT);
- ready_when_functors[kComplete] = std::bind(&SplashScreenInfo::set_ready_when,
- ss_info, ReadyWhen::COMPLETE);
- ready_when_functors[kCustom] =
- std::bind(&SplashScreenInfo::set_ready_when, ss_info, ReadyWhen::CUSTOM);
- ready_when_functors[ready_when]();
-
- return true;
-}
-
-bool SplashScreenHandler::Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- auto ss_info = std::make_shared<SplashScreenInfo>();
- if (!ParseReadyWhen(manifest, ss_info.get())) return false;
-
- ParseSingleOrientation(manifest, ScreenOrientation::AUTO, ss_info.get());
- ParseSingleOrientation(manifest, ScreenOrientation::LANDSCAPE, ss_info.get());
- ParseSingleOrientation(manifest, ScreenOrientation::PORTRAIT, ss_info.get());
-
- *output = std::static_pointer_cast<parser::ManifestData>(ss_info);
-
- return true;
-}
-
-bool SplashScreenHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const SplashScreenInfo& splash_data =
- static_cast<const SplashScreenInfo&>(data);
- std::string src = splash_data.src();
- // According to w3c specification splash screen image should be of one of
- // below types.
- if (src.compare(src.size() - 3, 3, "png") &&
- src.compare(src.size() - 3, 3, "svg") &&
- src.compare(src.size() - 3, 3, "gif") &&
- src.compare(src.size() - 3, 3, "jpg")) {
- *error = "Not supported file extension of splash image";
- return false;
- }
- return true;
-}
-
-std::string SplashScreenHandler::Key() const {
- return kTizenSplashScreenKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_SPLASH_SCREEN_HANDLER_H_
-#define MANIFEST_HANDLERS_SPLASH_SCREEN_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "manifest_handlers/setting_handler.h"
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-enum class ReadyWhen { FIRSTPAINT, COMPLETE, CUSTOM };
-
-enum class ScreenOrientation { AUTO, PORTRAIT, LANDSCAPE, NONE };
-
-struct Color {
- unsigned char red;
- unsigned char green;
- unsigned char blue;
-};
-
-struct SplashScreenData {
- ScreenOrientation orientation;
- std::shared_ptr<Color> background_color;
- std::vector<std::string> background_image;
- std::vector<std::string> image;
- std::vector<std::string> image_border;
-};
-
-class SplashScreenInfo : public parser::ManifestData {
- public:
- SplashScreenInfo() { }
- virtual ~SplashScreenInfo() { }
-
- static std::string Key();
-
- void set_src(const std::string& src) { src_ = src; }
- const std::string& src() const { return src_; }
- void set_splash_screen_data(
- std::pair<ScreenOrientation, SplashScreenData> splash_screen_data) {
- splash_screen_data_.insert(splash_screen_data);
- }
- const std::map<ScreenOrientation, SplashScreenData>& splash_screen_data()
- const {
- return splash_screen_data_;
- }
- void set_ready_when(ReadyWhen ready_when) { ready_when_ = ready_when; }
- ReadyWhen ready_when() const { return ready_when_; }
-
- private:
- std::string src_;
- std::map<ScreenOrientation, SplashScreenData> splash_screen_data_;
- ReadyWhen ready_when_;
-};
-
-/**
- * @brief The SplashScreenHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:splash-screen>.
- */
-class SplashScreenHandler : public parser::ManifestHandler {
- public:
- SplashScreenHandler() {}
- virtual ~SplashScreenHandler() {}
- bool Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- std::string Key() const override;
-
- private:
- bool ParseSingleOrientation(const parser::Manifest& manifest,
- ScreenOrientation orientation,
- SplashScreenInfo* ss_info);
- bool ParseElement(const parser::DictionaryValue* dict,
- std::vector<std::string>* to_be_saved,
- const char* keyToParse);
- bool ParseReadyWhen(const parser::Manifest& manifest,
- SplashScreenInfo* ss_info);
- bool ParseColor(const parser::DictionaryValue* dict,
- SplashScreenData* splash_screen);
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_SPLASH_SCREEN_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/tizen_application_handler.h"
-
-#include <cassert>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_handlers/platform_version.h"
-#include "manifest_parser/manifest_util.h"
-#include "manifest_parser/utils/version_number.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-
-const char kTizenApplicationKey[] = "widget.application";
-const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
-const char kNamespaceKey[] = "@namespace";
-const char kTizenApplicationIdKey[] = "@id";
-const char kTizenApplicationPackageKey[] = "@package";
-const char kTizenApplicationLaunchModeKey[] = "@launch_mode";
-const char kTizenApplicationRequiredVersionKey[] = "@required_version";
-const utils::VersionNumber kLaunchModeRequiredVersion("2.4");
-} // namespace
-
-TizenApplicationInfo::TizenApplicationInfo() {}
-
-TizenApplicationInfo::~TizenApplicationInfo() {}
-
-TizenApplicationHandler::TizenApplicationHandler() {}
-
-TizenApplicationHandler::~TizenApplicationHandler() {}
-
-bool TizenApplicationHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output, std::string* error) {
- std::shared_ptr<TizenApplicationInfo> app_info(new TizenApplicationInfo);
- parser::Value* app_value = nullptr;
- manifest.Get(kTizenApplicationKey, &app_value);
- // Find an application element with tizen namespace
- parser::DictionaryValue* app_dict;
- std::string value;
- bool found = false;
- if (app_value && app_value->IsType(parser::Value::TYPE_DICTIONARY)) {
- app_value->GetAsDictionary(&app_dict);
- found = app_dict->GetString(kNamespaceKey, &value);
- found = found && (value == kTizenNamespacePrefix);
- } else if (app_value && app_value->IsType(parser::Value::TYPE_LIST)) {
- parser::ListValue* list;
- app_value->GetAsList(&list);
- for (parser::ListValue::iterator it = list->begin(); it != list->end();
- ++it) {
- (*it)->GetAsDictionary(&app_dict);
- app_dict->GetString(kNamespaceKey, &value);
- bool is_tizen = (value == kTizenNamespacePrefix);
- if (is_tizen) {
- if (found) {
- *error = "There should be no more than one tizen:application element";
- return false;
- }
- found = true;
- }
- }
- }
-
- if (!found) {
- *error =
- "Cannot find application element with tizen namespace "
- "or the tizen namespace prefix is incorrect.\n";
- return false;
- }
- if (app_dict->GetString(kTizenApplicationIdKey, &value))
- app_info->set_id(value);
- if (app_dict->GetString(kTizenApplicationPackageKey, &value)) {
- app_info->set_package(value);
- }
- if (app_dict->GetString(kTizenApplicationRequiredVersionKey, &value)) {
- if (!value.empty()) {
- utils::VersionNumber req_version(value);
- utils::VersionNumber min_version = parser::GetMinimumPlatformVersion();
- if (req_version < min_version) {
- app_info->set_required_version(min_version.ToString());
- } else {
- app_info->set_required_version(value);
- }
- }
- }
-
- std::string launch_mode;
- app_dict->GetString(kTizenApplicationLaunchModeKey, &launch_mode);
- app_info->set_launch_mode(launch_mode);
-
- *output = std::static_pointer_cast<parser::ManifestData>(app_info);
- return true;
-}
-
-bool TizenApplicationHandler::Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const TizenApplicationInfo& app_info =
- static_cast<const TizenApplicationInfo&>(data);
-
- if (!parser::ValidateTizenApplicationId(app_info.id())) {
- *error =
- "The id property of application element "
- "does not match the format\n";
- return false;
- }
-
- if (!parser::ValidateTizenPackageId(app_info.package())) {
- *error =
- "The package property of application element "
- "does not match the format\n";
- return false;
- }
-
- if (app_info.id().find(app_info.package()) != 0) {
- *error =
- "The application element property id "
- "does not start with package.\n";
- return false;
- }
- if (app_info.required_version().empty()) {
- *error =
- "The required_version property of application "
- "element does not exist.\n";
- return false;
- }
- utils::VersionNumber supported_version = parser::GetCurrentPlatformVersion();
- if (!supported_version.IsValid()) {
- *error = "Cannot retrieve supported API version from platform";
- return false;
- }
- utils::VersionNumber required_version(app_info.required_version());
- if (!required_version.IsValid()) {
- *error = "Cannot retrieve supported API version from widget";
- return false;
- }
- if (supported_version < required_version) {
- *error =
- "The required_version of Tizen Web API "
- "is not supported.\n";
- return false;
- }
- if (required_version >= kLaunchModeRequiredVersion) {
- if (app_info.launch_mode().empty()) {
- // FIXME for now, this const_cast is used, but it is not the best way.
- TizenApplicationInfo &tmp = const_cast<TizenApplicationInfo &>(app_info);
- tmp.set_launch_mode("single"); // default parameter
- } else if (app_info.launch_mode() != "caller" &&
- app_info.launch_mode() != "group" &&
- app_info.launch_mode() != "single") {
- *error = "Wrong value of launch mode";
- return false;
- }
- } else if (!app_info.launch_mode().empty()) {
- *error = "launch_mode attribute cannot be used for api version lower"
- " than 2.4";
- return false;
- }
- return true;
-}
-
-std::string TizenApplicationInfo::Key() {
- return kTizenApplicationKey;
-}
-
-std::string TizenApplicationHandler::Key() const {
- return kTizenApplicationKey;
-}
-
-bool TizenApplicationHandler::AlwaysParseForKey() const { return true; }
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_TIZEN_APPLICATION_HANDLER_H_
-#define MANIFEST_HANDLERS_TIZEN_APPLICATION_HANDLER_H_
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-class TizenApplicationInfo : public parser::ManifestData {
- public:
- TizenApplicationInfo();
- virtual ~TizenApplicationInfo();
-
- static std::string Key();
-
- void set_id(const std::string& id) {
- id_ = id;
- }
- void set_launch_mode(const std::string& launch_mode) {
- launch_mode_ = launch_mode;
- }
- void set_package(const std::string& package) {
- package_ = package;
- }
- void set_required_version(
- const std::string& required_version) {
- required_version_ = required_version;
- }
- const std::string& id() const {
- return id_;
- }
- const std::string& launch_mode() const {
- return launch_mode_;
- }
- const std::string& package() const {
- return package_;
- }
- const std::string& required_version() const {
- return required_version_;
- }
-
- private:
- std::string id_;
- std::string launch_mode_;
- std::string package_;
- std::string required_version_;
-};
-
-/**
- * @brief The TizenApplicationHandler class
- *
- * Handler of config.xml for xml elements:
- * - <tizen:application>.
- */
-class TizenApplicationHandler : public parser::ManifestHandler {
- public:
- TizenApplicationHandler();
- virtual ~TizenApplicationHandler();
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
- bool AlwaysParseForKey() const override;
- std::string Key() const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_TIZEN_APPLICATION_HANDLER_H_
+++ /dev/null
-// 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/warp_handler.h"
-
-#include <string.h>
-#include <cassert>
-#include <map>
-#include <utility>
-
-#include "manifest_handlers/application_manifest_constants.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-const char kAccessKey[] = "widget.access";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kAccessSubdomainsKey[] = "@subdomains";
-const char kAccessOriginKey[] = "@origin";
-}
-
-void WarpHandler::ParseSingleAccessElement(
- const parser::DictionaryValue& item_dict,
- std::shared_ptr<WarpInfo> info) {
- std::string domain_name;
- std::string subdomains_str;
- bool subdomains = false;
-
- if (item_dict.HasKey(kAccessSubdomainsKey)) {
- item_dict.GetString(kAccessSubdomainsKey, &subdomains_str);
- if (subdomains_str == "true")
- subdomains = true;
- }
- // TODO(w.kosowicz): address validation
- item_dict.GetString(kAccessOriginKey, &domain_name);
- if (domain_name == "*")
- subdomains = true;
- info->set_access_element(std::make_pair(domain_name, subdomains));
-}
-
-bool WarpHandler::Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* /*error*/) {
- if (!manifest.HasPath(kAccessKey))
- return true;
-
- auto info = std::make_shared<WarpInfo>();
-
- for (const auto& dict : parser::GetOneOrMany(manifest.value(),
- kAccessKey, kWidgetNamespacePrefix)) {
- ParseSingleAccessElement(*dict, info);
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(info);
-
- return true;
-}
-
-std::string WarpInfo::Key() {
- return kAccessKey;
-}
-
-std::string WarpHandler::Key() const {
- return kAccessKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// 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.
-
-#ifndef MANIFEST_HANDLERS_WARP_HANDLER_H_
-#define MANIFEST_HANDLERS_WARP_HANDLER_H_
-
-#include <map>
-#include <memory>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "manifest_parser/values.h"
-#include "manifest_parser/manifest_handler.h"
-
-namespace wgt {
-namespace parse {
-
-class WarpInfo : public parser::ManifestData {
- public:
- static std::string Key();
-
- WarpInfo() {}
- ~WarpInfo() override {}
- /**
- * @brief set_access_element push single access_element inside vector
- * @param access_element
- */
- void set_access_element(const std::pair<std::string, bool>& access_element) {
- access_map_.push_back(access_element);
- }
- /**
- * @brief access_map
- * @return vector containing access_elements
- */
- const std::vector<std::pair<std::string, bool> >& access_map() const {
- return access_map_;
- }
-
- private:
- std::vector<std::pair<std::string, bool> > access_map_;
-};
-
-/**
- * @brief The WarpHandler class
- *
- * Handler of config.xml for xml elements:
- * - <w3c:access>.
- */
-class WarpHandler : public parser::ManifestHandler {
- public:
- WarpHandler() {}
- ~WarpHandler() override {}
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- void ParseSingleAccessElement(
- const parser::DictionaryValue& item_dict,
- std::shared_ptr<WarpInfo> info);
- std::string Key() const override;
-};
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_WARP_HANDLER_H_
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#include "manifest_handlers/widget_config_parser.h"
-
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <boost/filesystem/path.hpp>
-#include <boost/filesystem/operations.hpp>
-#include <boost/system/error_code.hpp>
-
-#include <xdgmime.h>
-
-#include <algorithm>
-#include <string>
-#include <map>
-#include <vector>
-
-#include "manifest_handlers/account_handler.h"
-#include "manifest_handlers/app_control_handler.h"
-#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"
-#include "manifest_handlers/ime_handler.h"
-#include "manifest_handlers/metadata_handler.h"
-#include "manifest_handlers/navigation_handler.h"
-#include "manifest_handlers/permissions_handler.h"
-#include "manifest_handlers/service_handler.h"
-#include "manifest_handlers/setting_handler.h"
-#include "manifest_handlers/splash_screen_handler.h"
-#include "manifest_handlers/tizen_application_handler.h"
-#include "manifest_handlers/warp_handler.h"
-#include "manifest_handlers/widget_handler.h"
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/utils/iri_util.h"
-#include "manifest_parser/utils/logging.h"
-
-namespace ba = boost::algorithm;
-namespace bf = boost::filesystem;
-namespace bs = boost::system;
-
-namespace {
-
-const char kLocaleDirectory[] = "locales";
-
-const char* kDefaultStartFiles[] = {
- "index.htm",
- "index.html",
- "index.svg",
- "index.xhtml",
- "index.xht"
-};
-
-const char* kDefaultIconFiles[] = {
- "icon.svg",
- "icon.ico",
- "icon.png",
- "icon.gif",
- "icon.jpg"
-};
-
-const std::map<std::string, std::string> kFileIdenticationTable = {
- {".html", "text/html"},
- {".htm", "text/html"},
- {".css", "text/css"},
- {".js", "application/javascript"},
- {".xml", "application/xml"},
- {".txt", "text/plain"},
- {".wav", "audio/x-wav"},
- {".xhtml", "application/xhtml+xml"},
- {".xht", "application/xhtml+xml"},
- {".gif", "image/gif"},
- {".png", "image/png"},
- {".ico", "image/vnd.microsoft.icon"},
- {".svg", "image/svg+xml"},
- {".jpg", "image/jpeg"},
- {".mp3", "audio/mpeg"}
-};
-
-const char* kIconsSupportedMimeTypes[] = {
- "image/gif",
- "image/png",
- "image/vnd.microsoft.icon",
- "image/svg+xml",
- "image/jpeg"
-};
-
-// http://www.w3.org/TR/widgets/#rule-for-identifying-the-media-type-of-a-file-0
-bool IsIconMimeTypeSupported(const bf::path& icon_path) {
- std::string ext = icon_path.extension().string();
- std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
- std::string mime_type;
- if (!ext.empty() && std::all_of(++ext.begin(), ext.end(), ::isalpha)) {
- auto iter = kFileIdenticationTable.find(ext);
- if (iter != kFileIdenticationTable.end()) {
- mime_type = iter->second;
- }
- }
- if (mime_type.empty()) {
- // sniff the mime type
- mime_type =
- xdg_mime_get_mime_type_for_file(icon_path.string().c_str(), nullptr);
- }
- for (auto mime : kIconsSupportedMimeTypes) {
- if (mime_type == mime)
- return true;
- }
- return false;
-}
-
-enum class FindResult {
- OK,
- NUL,
- ERROR
-};
-
-// http://www.w3.org/TR/widgets/#rule-for-finding-a-file-within-a-widget-package-0 // NOLINT
-FindResult FindFileWithinWidget(const bf::path& widget_path,
- const std::string& content, bf::path* file = nullptr) {
- std::string content_value = content;
- if (content_value.empty())
- return FindResult::ERROR;
- if (content_value[0] == '/') {
- content_value = content_value.substr(1);
- }
- // Steps 4. && 5.
- std::vector<std::string> path_components;
- ba::split(path_components, content_value, ba::is_any_of("/"));
- if (path_components.size() >= 1 && path_components[0] == kLocaleDirectory) {
- if (path_components.size() == 1) {
- return FindResult::NUL;
- }
-
- // TODO(t.iwanek): validate language tag
-
- path_components.erase(path_components.begin(), ++++path_components.begin());
- content_value = ba::join(path_components, "/");
- }
- // for each locale in widget
- // TODO(t.iwanek): this algorithm should accept input of preferred locale list
- bs::error_code error;
- bf::path locale_directory = widget_path / kLocaleDirectory;
- if (bf::exists(locale_directory, error)) {
- for (auto iter = bf::directory_iterator(locale_directory);
- iter != bf::directory_iterator(); ++iter) {
- const bf::path& path = *iter;
-
- // TODO(t.iwanek): validate language tag
-
- bf::path candidate = path / content_value;
- if (bf::exists(candidate, error)) {
- if (bf::is_directory(candidate, error)) {
- return FindResult::ERROR;
- }
- if (file)
- *file = candidate;
- return FindResult::OK;
- }
- }
- }
-
- // default locale
- bf::path root_candidate = widget_path / content_value;
- if (bf::exists(root_candidate, error)) {
- if (bf::is_directory(root_candidate, error)) {
- return FindResult::ERROR;
- }
- if (file)
- *file = root_candidate;
- return FindResult::OK;
- }
-
- return FindResult::NUL;
-}
-
-bool CheckW3CContentSrcExits(const bf::path& widget_path,
- const std::string& content) {
- if (!content.empty()) {
- if (FindFileWithinWidget(widget_path, content) == FindResult::OK) {
- return true;
- }
- }
- return false;
-}
-
-// http://www.w3.org/TR/widgets/#step-8-locate-the-start-file
-bool CheckStartFileInWidget(const bf::path& widget_path) {
- for (auto& file : kDefaultStartFiles) {
- if (FindFileWithinWidget(widget_path, file) == FindResult::OK) {
- LOG(INFO) << "Start file is: " << file;
- return true;
- }
- }
- LOG(ERROR) << "No valid start file found";
- return false;
-}
-
-} // namespace
-
-namespace wgt {
-namespace parse {
-
-WidgetConfigParser::WidgetConfigParser() {
- std::vector<parser::ManifestHandler*> handlers = {
- new AccountHandler,
- new AppControlHandler,
- new ApplicationIconsHandler,
- new AppWidgetHandler,
- new CategoryHandler,
- new ContentHandler,
- new CSPHandler(CSPHandler::SecurityType::CSP),
- new CSPHandler(CSPHandler::SecurityType::CSP_REPORT_ONLY),
- new ImeHandler,
- new MetaDataHandler,
- new NavigationHandler,
- new PermissionsHandler,
- new ServiceHandler,
- new SettingHandler,
- new SplashScreenHandler,
- new TizenApplicationHandler,
- new WarpHandler,
- new WidgetHandler,
- new BackgroundCategoryHandler
- };
-
- std::unique_ptr<parser::ManifestHandlerRegistry> registry(
- new parser::ManifestHandlerRegistry(handlers));
-
- parser_.reset(new parser::ManifestParser(std::move(registry)));
-}
-
-std::shared_ptr<const parser::ManifestData> WidgetConfigParser::GetManifestData(
- const std::string& key) {
- // TODO(t.iwanek): replace this method with required getters
- // do not force client to use keyys from application_manifest_constants
- return parser_->GetManifestData(key);
-}
-
-const std::string& WidgetConfigParser::GetErrorMessage() const {
- if (!error_.empty())
- return error_;
- return parser_->GetErrorMessage();
-}
-
-bool WidgetConfigParser::CheckStartFile() {
- std::shared_ptr<const ContentInfo> content_info =
- std::static_pointer_cast<const ContentInfo>(parser_->GetManifestData(
- ContentInfo::Key()));
- if (content_info) {
- std::string content = content_info->src();
- if (content_info->is_tizen_content()) {
- // tizen:content may be external url
- if (parser::utils::IsValidIRI(content))
- return true;
- }
-
- if (CheckW3CContentSrcExits(widget_path_, content)) {
- // Content is valid
- LOG(INFO) << "Start file is: " << content
- << " type: " << content_info->type()
- << " encoding: " << content_info->encoding();
-
- return true;
- } else {
- // Remove content as it is invalid
- parser_->EraseManifestData(ContentInfo::Key());
- }
- }
-
- if (!CheckStartFileInWidget(widget_path_)) {
- parser_->EraseManifestData(ContentInfo::Key());
- error_ = "Could not find valid start file";
- return false;
- }
- return true;
-}
-
-bool WidgetConfigParser::CheckServicesStartFiles() {
- std::shared_ptr<const ServiceList> service_list =
- std::static_pointer_cast<const ServiceList>(
- parser_->GetManifestData(ServiceInfo::Key()));
- if (!service_list)
- return true;
- for (auto& service_info : service_list->services) {
- bf::path start_file = widget_path_ / service_info.content();
- if (!bf::exists(start_file)) {
- error_ = std::string("Could not find valid service start file: ")
- + start_file.string();
- return false;
- }
- }
- return true;
-}
-
-bool WidgetConfigParser::CheckWidgetIcons() {
- std::shared_ptr<ApplicationIconsInfo> icons_info =
- std::static_pointer_cast<ApplicationIconsInfo>(
- parser_->AccessManifestData(application_manifest_keys::kIconsKey));
- if (!icons_info) {
- error_ = "Failed to get icon info";
- return false;
- }
- ApplicationIconsInfo icons;
- // custom icons
- for (auto& icon : icons_info->icons()) {
- bf::path result;
- if (FindFileWithinWidget(widget_path_, icon.path(), &result)
- == FindResult::OK) {
- if (!IsIconMimeTypeSupported(result)) {
- LOG(WARNING) << "Unsupported icon: " << result;
- continue;
- }
- std::string relative =
- result.string().substr(widget_path_.string().size() + 1);
- int width = -1;
- int height = -1;
- icon.GetWidth(&width);
- icon.GetHeight(&height);
- icons.AddIcon(ApplicationIcon(relative, height, width));
- }
- }
- // default icons
- for (auto& icon : kDefaultIconFiles) {
- bf::path result;
- if (FindFileWithinWidget(widget_path_, icon, &result)
- == FindResult::OK) {
- if (!IsIconMimeTypeSupported(result)) {
- LOG(WARNING) << "Unsupported icon: " << result;
- continue;
- }
- std::string relative =
- result.string().substr(widget_path_.string().size() + 1);
- icons.AddIcon(ApplicationIcon(relative));
- }
- }
- for (auto& icon : icons.icons()) {
- LOG(DEBUG) << "Valid icon: " << icon.path();
- int value = 0;
- if (icon.GetWidth(&value))
- LOG(DEBUG) << " with width: " << value;
- if (icon.GetHeight(&value))
- LOG(DEBUG) << " with height: " << value;
- }
- *icons_info = icons;
- return true;
-}
-
-bool WidgetConfigParser::ParseManifest(const boost::filesystem::path& path) {
- widget_path_ = path.parent_path();
- if (!parser_->ParseManifest(path))
- return false;
-
- if (!CheckWidgetIcons())
- return false;
-
- has_valid_start_file_ = CheckStartFile();
- has_valid_services_start_files_ = CheckServicesStartFiles();
-
- return true;
-}
-
-bool WidgetConfigParser::HasValidStartFile() const {
- return has_valid_start_file_;
-}
-
-bool WidgetConfigParser::HasValidServicesStartFiles() const {
- return has_valid_services_start_files_;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
-// Use of this source code is governed by an apache 2.0 license that can be
-// found in the LICENSE file.
-
-#ifndef MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
-#define MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
-
-#include <boost/filesystem/path.hpp>
-
-#include <memory>
-#include <string>
-
-#include "manifest_parser/manifest_parser.h"
-
-namespace wgt {
-namespace parse {
-
-/**
- * @brief The WidgetConfigParser class
- * Parser class of widget's config.xml configuration file.
- *
- * Instance of this class may be used to parse single configuration file.
- * Depending on boolean result of @ref ParseManifest method, client code may
- * call:
- * - on success -> @ref GetManifestData(), passing the key of ManifestData
- * instance that it is interested in.
- * - on failure -> @ref GetErrorMessage(), to get value of error which was set
- * during the processing of config.xml
- *
- * Additional check of presence of start files may be done via calling
- * @ref HasValidStartFile(). This method is extracted separetly as missing start
- * file will not cause the failure of parsing the config.xml file.
- *
- * To investigate which key do you need to get certain parsed piece of data,
- * check the key reported by handler's @ref ManifestHandler::Key() method.
- * Key returned by this method is the key to access data set by handler.
- */
-class WidgetConfigParser {
- public:
- WidgetConfigParser();
-
- std::shared_ptr<const parser::ManifestData> GetManifestData(
- const std::string& key);
- const std::string& GetErrorMessage() const;
- bool ParseManifest(const boost::filesystem::path& path);
- /**
- * @brief HasValidStartFile
- * @return true valid start file exists
- */
- bool HasValidStartFile() const;
- /**
- * @brief HasValidServicesStartFiles
- * @return true if has valid service start files
- */
- bool HasValidServicesStartFiles() const;
-
- private:
- /**
- * @brief CheckStartFile
- * @return true if start file is correct
- */
- bool CheckStartFile();
- /**
- * @brief CheckServicesStartFiles
- * @return true if services start files are correct
- */
- bool CheckServicesStartFiles();
- // This function creates list of icons that are valid disregarding
- // (in actual version) current system's locale as installer do not need to
- // know about it.
- // Edited/Created list is present as kIconsKey key in parser.
- /**
- * @brief CheckWidgetIcons
- * @return true if widget icons are correct
- */
- bool CheckWidgetIcons();
-
- std::unique_ptr<parser::ManifestParser> parser_;
- boost::filesystem::path widget_path_;
- std::string error_;
- bool has_valid_start_file_;
- bool has_valid_services_start_files_;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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.
-
-#include "manifest_handlers/widget_handler.h"
-
-#include <string.h>
-
-#include <algorithm>
-#include <cassert>
-#include <map>
-#include <utility>
-#include <set>
-
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_parser/utils/iri_util.h"
-#include "manifest_parser/utils/language_tag_validator.h"
-#include "manifest_parser/utils/logging.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-namespace {
-const char kWidgetKey[] = "widget";
-
-const char kAuthorKey[] = "widget.author";
-const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
-const char kWidgetNamespaceKey[] = "widget.@namespace";
-const char kAuthorHrefKey[] = "@href";
-const char kAuthorEmailKey[] = "@email";
-const char kVersionKey[] = "widget.@version";
-const char kNameKey[] = "widget.name";
-const char kPreferencesNameKey[] = "@name";
-const char kPreferencesValueKey[] = "@value";
-const char kPreferencesReadonlyKey[] = "@readonly";
-const char kXmlLangKey[] = "@lang";
-const char kXmlHrefKey[] = "@href";
-const char kLicenseKey[] = "widget.license";
-const char kShortKey[] = "@short";
-const char kWidgetLangKey[] = "widget.@lang";
-const char kIDKey[] = "widget.@id";
-const char kHeightKey[] = "widget.@height";
-const char kWidthKey[] = "widget.@width";
-const char kDefaultLocaleKey[] = "widget.@defaultlocale";
-const char kViewModesKey[] = "widget.@viewmodes";
-const char kPreferencesKey[] = "widget.preference";
-const char kXmlTextKey[] = "#text";
-const char kDescriptionKey[] = "widget.description";
-
-bool ParserPreferenceItem(const parser::Value* val, Preference** output,
- std::string* error) {
- const parser::DictionaryValue* pref_dict;
- if (!val->GetAsDictionary(&pref_dict)) {
- *error = "Parsing preference element failed";
- return false;
- }
- std::string name;
- std::string value;
- std::string readonly = "false";
- pref_dict->GetString(kPreferencesNameKey, &name);
- pref_dict->GetString(kPreferencesValueKey, &value);
- pref_dict->GetString(kPreferencesReadonlyKey, &readonly);
- *output = new Preference(name, value, readonly == "true");
- return true;
-}
-
-} // namespace
-
-void WidgetHandler::ParseSingleLocalizedLicenseElement(
- const parser::DictionaryValue* item_dict, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- bool lang_overwriten = false;
- std::string lang;
- std::string text;
- std::string href;
-
- if (item_dict->HasKey(kXmlLangKey)) {
- lang_overwriten = true;
- item_dict->GetString(kXmlLangKey, &lang);
- if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
- LOG(ERROR) << "Tag " << lang << " is invalid";
- return;
- }
- }
- if (item_dict->HasKey(kXmlHrefKey)) {
- item_dict->GetString(kXmlHrefKey, &href);
- }
- item_dict->GetString(kXmlTextKey, &text);
- // TODO(w.kosowicz) check where href should be put...
- if (lang_overwriten) {
- info->license_set_.insert(std::make_pair(lang, text + href));
- } else {
- info->license_set_.insert(std::make_pair(parent_lang, text + href));
- }
-}
-
-void WidgetHandler::ParseLocalizedLicenseElements(
- const parser::Manifest& manifest, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- if (!manifest.HasPath(kLicenseKey)) return;
-
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (manifest.Get(kLicenseKey, &val)) {
- if (val->GetAsDictionary(&dict)) {
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedLicenseElement(dict, parent_lang, info);
- } else if (val->GetAsList(&list)) {
- for_each(list->begin(), list->end(),
- [list, &dict, parent_lang, info, this](parser::Value* item) {
- if (item->GetAsDictionary(&dict))
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedLicenseElement(dict, parent_lang, info);
- });
- }
- }
-}
-
-void WidgetHandler::ParseSingleLocalizedDescriptionElement(
- const parser::DictionaryValue* item_dict, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- bool lang_overwriten = false;
- std::string lang;
- std::string text;
-
- if (item_dict->HasKey(kXmlLangKey)) {
- lang_overwriten = true;
- item_dict->GetString(kXmlLangKey, &lang);
- if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
- LOG(ERROR) << "Tag " << lang << " is invalid";
- return;
- }
- }
- item_dict->GetString(kXmlTextKey, &text);
- if (lang_overwriten) {
- info->description_set_.insert(std::make_pair(lang, text));
- } else {
- info->description_set_.insert(std::make_pair(parent_lang, text));
- }
-}
-
-void WidgetHandler::ParseLocalizedDescriptionElements(
- const parser::Manifest& manifest, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- if (!manifest.HasPath(kDescriptionKey)) return;
-
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (manifest.Get(kDescriptionKey, &val)) {
- if (val->GetAsDictionary(&dict)) {
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedDescriptionElement(dict, parent_lang, info);
- } else if (val->GetAsList(&list)) {
- for (auto& item : *list)
- if (item->GetAsDictionary(&dict))
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedDescriptionElement(dict, parent_lang, info);
- }
- }
-}
-
-void WidgetHandler::ParseSingleLocalizedNameElement(
- const parser::DictionaryValue* item_dict, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- bool lang_overwriten = false;
- std::string lang;
- std::string name;
- std::string short_name;
-
- if (item_dict->HasKey(kXmlLangKey)) {
- lang_overwriten = true;
- item_dict->GetString(kXmlLangKey, &lang);
- if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
- LOG(ERROR) << "Tag " << lang << " is invalid";
- return;
- }
- }
- if (item_dict->HasKey(kShortKey)) {
- item_dict->GetString(kShortKey, &short_name);
- }
- item_dict->GetString(kXmlTextKey, &name);
-
- // ignore if given language already spotted
- if (info->name_set_.find(lang) != info->name_set_.end()) return;
-
- if (lang_overwriten) {
- info->name_set_.insert(std::make_pair(lang, name));
- if (!short_name.empty())
- info->short_name_set_.insert(std::make_pair(lang, short_name));
- } else {
- info->name_set_.insert(std::make_pair(parent_lang, name));
- if (!short_name.empty())
- info->short_name_set_.insert(std::make_pair(parent_lang, short_name));
- }
-}
-
-void WidgetHandler::ParseLocalizedNameElements(
- const parser::Manifest& manifest, const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info) {
- if (!manifest.HasPath(kNameKey)) return;
-
- const parser::Value* val = nullptr;
- const parser::DictionaryValue* dict = nullptr;
- const parser::ListValue* list = nullptr;
- if (manifest.Get(kNameKey, &val)) {
- if (val->GetAsDictionary(&dict)) {
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedNameElement(dict, parent_lang, info);
- } else if (val->GetAsList(&list)) {
- for (auto& item : *list)
- if (item->GetAsDictionary(&dict))
- if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
- ParseSingleLocalizedNameElement(dict, parent_lang, info);
- }
- }
-}
-
-void WidgetHandler::ParseSingleAuthorElement(
- const parser::DictionaryValue* author_dict,
- std::shared_ptr<WidgetInfo> info) {
- author_dict->GetString(kXmlTextKey, &info->author_);
- author_dict->GetString(kAuthorEmailKey, &info->author_email_);
- std::string author_href;
- author_dict->GetString(kAuthorHrefKey, &author_href);
- if (!author_href.empty() && parser::utils::IsValidIRI(author_href))
- info->author_href_ = author_href;
-}
-
-void WidgetHandler::ParseAuthorElements(const parser::Manifest& manifest,
- std::shared_ptr<WidgetInfo> info) {
- if (manifest.HasPath(kAuthorKey)) {
- const parser::Value* author_value = nullptr;
- manifest.Get(kAuthorKey, &author_value);
-
- auto& authors = parser::GetOneOrMany(manifest.value(), kAuthorKey,
- kWidgetNamespacePrefix);
- if (!authors.empty())
- ParseSingleAuthorElement(authors[0], info);
- }
-}
-
-bool WidgetHandler::Parse(const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) {
- std::shared_ptr<WidgetInfo> widget_info(new WidgetInfo());
- widget_info->preferences_ = std::vector<Preference*>();
-
- std::string parent_lang;
-
- if (manifest.HasPath(kWidgetNamespaceKey)) {
- manifest.GetString(kWidgetNamespaceKey, &widget_info->widget_namespace_);
- manifest.GetString(kWidgetLangKey, &parent_lang);
- }
-
- if (widget_info->widget_namespace_ != kWidgetNamespacePrefix) {
- *error = "Wrong namespace of <widget> element. Config.xml is invalid";
- return false;
- }
-
- ParseAuthorElements(manifest, widget_info);
-
- ParseLocalizedDescriptionElements(manifest, parent_lang, widget_info);
- ParseLocalizedNameElements(manifest, parent_lang, widget_info);
- ParseLocalizedLicenseElements(manifest, parent_lang, widget_info);
-
- if (manifest.HasPath(kVersionKey))
- manifest.GetString(kVersionKey, &widget_info->version_);
- if (manifest.HasPath(kIDKey)) {
- std::string id;
- manifest.GetString(kIDKey, &id);
- if (!id.empty() && parser::utils::IsValidIRI(id)) widget_info->id_ = id;
- }
- if (manifest.HasPath(kHeightKey)) {
- int h;
- manifest.GetInteger(kHeightKey, &h);
- widget_info->height_ = static_cast<unsigned int>(h);
- }
- if (manifest.HasPath(kWidthKey)) {
- int w;
- manifest.GetInteger(kWidthKey, &w);
- widget_info->width_ = static_cast<unsigned int>(w);
- }
- if (manifest.HasPath(kDefaultLocaleKey))
- manifest.GetString(kDefaultLocaleKey, &widget_info->default_locale_);
- if (manifest.HasPath(kViewModesKey))
- manifest.GetString(kViewModesKey, &widget_info->viewmodes_);
-
- for (auto& pref_dict : parser::GetOneOrMany(manifest.value(),
- kPreferencesKey,
- kWidgetNamespacePrefix)) {
- Preference* preference = nullptr;
- if (!ParserPreferenceItem(pref_dict, &preference, error))
- return false;
- widget_info->preferences_.push_back(preference);
- }
-
- *output = std::static_pointer_cast<parser::ManifestData>(widget_info);
- return true;
-}
-
-bool WidgetHandler::Validate(const parser::ManifestData& data,
- const parser::ManifestDataMap& /*handlers_output*/,
- std::string* error) const {
- const WidgetInfo& widget_info = static_cast<const WidgetInfo&>(data);
- if (widget_info.widget_namespace() != kWidgetNamespacePrefix) {
- *error = "The widget namespace is invalid.";
- return false;
- }
- return true;
-}
-
-
-std::string WidgetHandler::Key() const {
- return kWidgetKey;
-}
-
-std::string WidgetInfo::Key() {
- return kWidgetKey;
-}
-
-} // namespace parse
-} // namespace wgt
+++ /dev/null
-// Copyright (c) 2014 Intel Corporation. All rights reserved.
-// 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_WIDGET_HANDLER_H_
-#define MANIFEST_HANDLERS_WIDGET_HANDLER_H_
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "manifest_parser/manifest_handler.h"
-#include "manifest_parser/values.h"
-
-namespace wgt {
-namespace parse {
-
-class Preference {
- public:
- Preference(const std::string& name, const std::string& value,
- bool readonly)
- : name_(name),
- value_(value),
- readonly_(readonly) {}
-
- std::string Name() const { return name_; }
- std::string Value() const { return value_; }
- bool ReadOnly() const { return readonly_; }
- private:
- std::string name_;
- std::string value_;
- bool readonly_;
-};
-
-typedef std::map<std::string, std::string> LangValMap;
-
-class WidgetInfo : public parser::ManifestData {
- public:
- WidgetInfo() {}
- WidgetInfo(const WidgetInfo&) = delete;
- WidgetInfo& operator=(const WidgetInfo&) = delete;
- virtual ~WidgetInfo() {
- for (auto p : preferences_)
- delete p;
- }
- static std::string Key();
-
- const LangValMap& name_set() const { return name_set_; }
- const LangValMap& short_name_set() const { return short_name_set_; }
- const LangValMap& description_set() const { return description_set_; }
- const LangValMap& license_set() const { return license_set_; }
-
- const std::string& id() const { return id_; }
- const std::string& version() const { return version_; }
- const std::string& view_modes() const { return viewmodes_; }
- const std::string& default_locale() const { return default_locale_; }
- const std::string& author() const { return author_; }
- const std::string& author_email() const { return author_email_; }
- const std::string& author_href() const { return author_href_; }
- const std::string& widget_namespace() const { return widget_namespace_; }
- const std::vector<Preference*>& preferences() const { return preferences_; }
- unsigned int height() const { return height_; }
- unsigned int width() const { return width_; }
-
- private:
- std::vector<Preference*> preferences_;
- std::string id_;
- std::string version_;
- std::string viewmodes_;
- std::string default_locale_;
- std::string author_;
- LangValMap description_set_;
- LangValMap name_set_;
- LangValMap short_name_set_;
- LangValMap license_set_;
- std::string author_email_;
- std::string author_href_;
- std::string widget_namespace_;
- unsigned int height_;
- unsigned int width_;
-
- friend class WidgetHandler;
-};
-
-/**
- * @brief The WidgetHandler class
- *
- * Handler of config.xml for root xml element <w3c:widget>.
- * Children parsed within this handlers:
- * - <w3c:author>,
- * - <w3c:description>,
- * - <w3c:license>,
- * - <w3c:name>,
- * - <w3c:preference>.
- *
- * Code parsing rest of children is located in other handlers.
- */
-class WidgetHandler : public parser::ManifestHandler {
- public:
- WidgetHandler() {}
- virtual ~WidgetHandler() {}
-
- bool Parse(
- const parser::Manifest& manifest,
- std::shared_ptr<parser::ManifestData>* output,
- std::string* error) override;
- bool AlwaysParseForKey() const override { return true; }
- std::string Key() const override;
- /**
- * @brief ParseSingleLocalizedLicenseElement parses single license element
- * @param item_dict
- * @param parent_lang
- * @param info
- */
- void ParseSingleLocalizedLicenseElement(
- const parser::DictionaryValue* item_dict,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseLocalizedLicenseElements parser localized element
- * @param manifest
- * @param parent_lang
- * @param info
- */
- void ParseLocalizedLicenseElements(
- const parser::Manifest& manifest,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseSingleLocalizedDescriptionElement parses
- * single localized description
- * @param item_dict
- * @param parent_lang
- * @param info
- */
- void ParseSingleLocalizedDescriptionElement(
- const parser::DictionaryValue* item_dict,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseLocalizedDescriptionElements parses localized description
- * element
- * @param manifest
- * @param parent_lang
- * @param info
- */
- void ParseLocalizedDescriptionElements(
- const parser::Manifest& manifest,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseSingleLocalizedNameElement parses single localized name
- * @param item_dict
- * @param parent_lang
- * @param info
- */
- void ParseSingleLocalizedNameElement(
- const parser::DictionaryValue* item_dict,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseLocalizedNameElements parses localized name
- * @param manifest
- * @param parent_lang
- * @param info
- */
- void ParseLocalizedNameElements(
- const parser::Manifest& manifest,
- const std::string& parent_lang,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseAuthorElements parses author element
- * @param manifest
- * @param info
- */
- void ParseAuthorElements(
- const parser::Manifest& manifest,
- std::shared_ptr<WidgetInfo> info);
- /**
- * @brief ParseSingleAuthorElement parses single author element
- * @param author_dict
- * @param info
- */
- void ParseSingleAuthorElement(
- const parser::DictionaryValue* author_dict,
- std::shared_ptr<WidgetInfo> info);
-
- bool Validate(
- const parser::ManifestData& data,
- const parser::ManifestDataMap& handlers_output,
- std::string* error) const override;
-};
-
-} // namespace parse
-} // namespace wgt
-
-#endif // MANIFEST_HANDLERS_WIDGET_HANDLER_H_
target_link_libraries(values_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(manifest_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(manifest_handler_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(manifest_util_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(manifest_util_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(parser_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(service_handler_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(content_handler_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(service_handler_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(content_handler_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(string_util_unittest PUBLIC ${TARGET_LIBNAME_UTILS} ${GTEST_MAIN_LIBRARIES})
target_link_libraries(version_number_unittest PUBLIC ${TARGET_LIBNAME_UTILS} ${GTEST_MAIN_LIBRARIES})
#include <memory>
#include <vector>
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_handlers/content_handler.h"
#include "manifest_parser/manifest.h"
#include "manifest_parser/manifest_handler.h"
#include "manifest_parser/manifest_parser_impl.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/content_handler.h"
namespace bf = boost::filesystem;
#include <boost/filesystem/operations.hpp>
#include <gtest/gtest.h>
-#include "manifest_handlers/application_manifest_constants.h"
#include "manifest_parser/manifest.h"
#include "manifest_parser/manifest_util.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
namespace bf = boost::filesystem;
#include <initializer_list>
#include <vector>
-#include "manifest_handlers/application_manifest_constants.h"
-#include "manifest_handlers/service_handler.h"
#include "manifest_parser/manifest.h"
#include "manifest_parser/manifest_handler.h"
#include "manifest_parser/manifest_parser_impl.h"
#include "manifest_parser/manifest_parser.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/service_handler.h"
namespace bf = boost::filesystem;
--- /dev/null
+# Target - sources
+SET(SRCS
+ account_handler.cc
+ app_control_handler.cc
+ application_manifest_constants.cc
+ application_icons_handler.cc
+ appwidget_handler.cc
+ background_category_handler.cc
+ category_handler.cc
+ content_handler.cc
+ csp_handler.cc
+ ime_handler.cc
+ metadata_handler.cc
+ navigation_handler.cc
+ permissions_handler.cc
+ platform_version.cc
+ setting_handler.cc
+ service_handler.cc
+ splash_screen_handler.cc
+ tizen_application_handler.cc
+ warp_handler.cc
+ widget_config_parser.cc
+ widget_handler.cc
+)
+
+# Target - definition
+ADD_LIBRARY(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} SHARED ${SRCS})
+# Target - includes
+TARGET_INCLUDE_DIRECTORIES(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../")
+APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PUBLIC
+ XGDMIME_DEPS
+)
+
+# Extra
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PROPERTIES VERSION ${VERSION})
+SET_TARGET_PROPERTIES(${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} PROPERTIES SOVERSION ${VERSION_MAJOR})
+
+# Install
+INSTALL(TARGETS ${TARGET_LIBNAME_WGT_MANIFEST_HANDLERS} DESTINATION ${LIB_INSTALL_DIR})
+
+# Install includes
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${INCLUDEDIR}
+ FILES_MATCHING PATTERN "*.h")
+
+# Configure and install pkgconfig file
+SET(PKG_FILE manifest-handlers.pc)
+CONFIGURE_FILE(${PKG_FILE}.in ${PKG_FILE} @ONLY)
+INSTALL(FILES ${PKG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
--- /dev/null
+// 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 file.
+
+#include "wgt_manifest_handlers/account_handler.h"
+
+#include "manifest_parser/utils/language_tag_validator.h"
+#include "manifest_parser/utils/logging.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace {
+
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kAccountKey[] = "widget.account";
+
+const char kSectionIconAccount[] = "Account";
+const char kSectionIconAccountSmall[] = "AccountSmall";
+const char kTrueValueString[] = "true";
+const char kFalseValueString[] = "false";
+const char kAccountMASKey[] = "@multiple-account-support";
+const char kAccountSectionKey[] = "@section";
+const char kAccountTextKey[] = "#text";
+const char kAccountNameKey[] = "display-name";
+const char kAccountLangKey[] = "@lang";
+const char kAccountIconKey[] = "icon";
+const char kAccountCapabilityKey[] = "capability";
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+bool AccountHandler::Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kAccountKey))
+ return true;
+
+ auto info = std::make_shared<AccountInfo>();
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kAccountKey, kTizenNamespacePrefix)) {
+ if (!ParseSingleAccountElement(dict, info, error))
+ return false;
+ }
+
+ *output = std::static_pointer_cast<AccountInfo>(info);
+ return true;
+}
+
+std::string AccountHandler::Key() const {
+ return kAccountKey;
+}
+
+std::string AccountInfo::Key() {
+ return kAccountKey;
+}
+
+bool AccountHandler::ParseSingleAccountElement(
+ const parser::DictionaryValue* item_dict,
+ std::shared_ptr<AccountInfo> info,
+ std::string* error) {
+ std::string multiple_apps_support;
+ SingleAccountInfo single_account;
+ if (!item_dict->GetString(kAccountMASKey, &multiple_apps_support)) {
+ *error = "Error while parsing multiple apps support in account";
+ return false;
+ }
+ bool mas_bool = false;
+ if (multiple_apps_support == kFalseValueString) {
+ mas_bool = false;
+ } else if (multiple_apps_support == kTrueValueString) {
+ mas_bool = true;
+ } else {
+ *error = "Multiple apps support in account has invalid (not boolean) value";
+ return false;
+ }
+ single_account.multiple_account_support = mas_bool;
+ if (!ParseAccountNames(item_dict, &single_account)) {
+ *error = "Error while parsing account names";
+ return false;
+ }
+ if (!ParseAccountIcons(item_dict, &single_account)) {
+ *error = "Error while parsing account icons";
+ return false;
+ }
+ if (!ParseCapabilities(item_dict, &single_account)) {
+ *error = "Error while parsing account capabilities";
+ return false;
+ }
+ info->set_account(single_account);
+ return true;
+}
+
+bool AccountHandler::ParseAccountIcons(
+ const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* info) {
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (item_dict->Get(kAccountIconKey, &val)) {
+ if (val->GetAsDictionary(&dict)) {
+ if (!ParseSingleAccountIcon(dict, info))
+ return false;
+ } else if (val->GetAsList(&list)) {
+ for (auto& item : *list)
+ if (item->GetAsDictionary(&dict) &&
+ !ParseSingleAccountIcon(dict, info))
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+bool AccountHandler::ParseSingleAccountIcon(
+ const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* info) {
+ std::string section;
+ item_dict->GetString(kAccountSectionKey, §ion);
+ if (section.compare(kSectionIconAccount) != 0 &&
+ section.compare(kSectionIconAccountSmall) != 0)
+ return false;
+ std::string icon_path;
+ item_dict->GetString(kAccountTextKey, &icon_path);
+ info->icon_paths.push_back(std::make_pair(section, icon_path));
+ return true;
+}
+
+bool AccountHandler::ParseAccountNames(
+ const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* info) {
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (item_dict->Get(kAccountNameKey, &val)) {
+ if (val->GetAsDictionary(&dict)) {
+ if (!ParseSingleAccountName(dict, info))
+ return false;
+ } else if (val->GetAsList(&list)) {
+ for (auto& item : *list)
+ if (item->GetAsDictionary(&dict) &&
+ !ParseSingleAccountName(dict, info))
+ return false;
+ }
+ return true;
+ }
+ return false;
+}
+
+bool AccountHandler::ParseSingleAccountName(
+ const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* info) {
+ std::string lang;
+ if (item_dict->GetString(kAccountLangKey, &lang) &&
+ !utils::w3c_languages::ValidateLanguageTag(lang)) {
+ return false;
+ }
+ std::string name;
+ item_dict->GetString(kAccountTextKey, &name);
+ info->names.push_back(std::make_pair(name, lang));
+ return true;
+}
+
+
+bool AccountHandler::ParseCapabilities(
+ const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* info) {
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (item_dict->Get(kAccountCapabilityKey, &val)) {
+ std::string capability;
+ if (val->GetAsDictionary(&dict)) {
+ dict->GetString(kAccountTextKey, &capability);
+ info->capabilities.push_back(capability);
+ } else if (val->GetAsList(&list)) {
+ for (auto& item : *list)
+ if (item->GetAsDictionary(&dict)) {
+ dict->GetString(kAccountTextKey, &capability);
+ info->capabilities.push_back(capability);
+ }
+ }
+ }
+ return true;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// 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 file.
+
+#ifndef WGT_MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
+
+#include <utility>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+struct SingleAccountInfo {
+ bool multiple_account_support;
+ std::vector<std::pair<std::string, std::string>> names;
+ std::vector<std::pair<std::string, std::string>> icon_paths;
+ std::vector<std::string> capabilities;
+};
+
+class AccountInfo : public parser::ManifestData {
+ public:
+ AccountInfo() {}
+ ~AccountInfo() override {}
+ static std::string Key();
+
+ /**
+ * @brief This method returns all the accounts successfully parsed
+ */
+ const std::vector<SingleAccountInfo>& accounts() const {
+ return accounts_;
+ }
+
+ /**
+ * @brief Method add to the vector successfully created account
+ */
+ void set_account(const SingleAccountInfo& single_account) {
+ accounts_.push_back(single_account);
+ }
+
+ private:
+ std::vector<SingleAccountInfo> accounts_;
+};
+
+/**
+ * @brief The AccountHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:account>.
+ */
+class AccountHandler : 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:
+ /**
+ * @brief ParseSingleAccountElement everything between <account> </account>
+ * @param item_dict dictionary to be parsed
+ * @param info ptr for entity that stores successfully parsed results
+ * @param error information about error that happened
+ * @return true if operation of parsing was successful
+ */
+ bool ParseSingleAccountElement(const parser::DictionaryValue* item_dict,
+ std::shared_ptr<AccountInfo> info,
+ std::string* error);
+ /**
+ * @brief ParseAccountIcons icons of account
+ * @param item_dict dictionary to be parsed
+ * @param singel_account the single account entity
+ * @return true parsed successfully
+ */
+ bool ParseAccountIcons(const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* singel_account);
+ bool ParseSingleAccountIcon(const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* singel_account);
+ /**
+ * @brief ParseAccountNames parse and validates account name
+ * @param item_dict dictionary to be parsed
+ * @param singel_account the single account entity
+ * @return true if parsed successfully
+ */
+ bool ParseAccountNames(const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* singel_account);
+ bool ParseSingleAccountName(const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* singel_account);
+ /**
+ * @brief ParseCapabilities parses capabilities and validates them
+ * @param item_dict dictionary to be parsed
+ * @param singel_account the single account entity
+ * @return true if parsed successfully
+ */
+ bool ParseCapabilities(const parser::DictionaryValue* item_dict,
+ SingleAccountInfo* singel_account);
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_ACCOUNT_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/app_control_handler.h"
+
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/version_number.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/tizen_application_handler.h"
+
+namespace {
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+
+const char kEnabledValue[] = "enable";
+const char kDisabledValue[] = "disable";
+
+const utils::VersionNumber kReloadRequiredVersion("2.4");
+const char kTizenApplicationKey[] = "widget.application";
+const char kTizenApplicationAppControlSrcKey[] = "src";
+const char kTizenApplicationAppControlOperationKey[] = "operation";
+const char kTizenApplicationAppControlUriKey[] = "uri";
+const char kTizenApplicationAppControlMimeKey[] = "mime";
+const char kTizenApplicationAppControlReloadKey[] = "@reload";
+const char kTizenApplicationAppControlChildNameAttrKey[] = "@name";
+const char kTizenApplicationAppControlsKey[] = "widget.app-control";
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+namespace {
+
+void ParseAppControlEntryAndStore(
+ const parser::DictionaryValue& control_dict,
+ AppControlInfoList* aplist) {
+ std::string src;
+ std::string reload;
+ const parser::DictionaryValue* src_dict;
+ if (control_dict.GetDictionary(kTizenApplicationAppControlSrcKey,
+ &src_dict)) {
+ src_dict->GetString(
+ kTizenApplicationAppControlChildNameAttrKey, &src);
+ src_dict->GetString(kTizenApplicationAppControlReloadKey, &reload);
+ }
+
+ std::string operation;
+ const parser::DictionaryValue* operation_dict;
+ if (control_dict.GetDictionary(
+ kTizenApplicationAppControlOperationKey,
+ &operation_dict)) {
+ operation_dict->GetString(
+ kTizenApplicationAppControlChildNameAttrKey, &operation);
+ }
+
+ std::string uri;
+ const parser::DictionaryValue* uri_dict;
+ if (control_dict.GetDictionary(kTizenApplicationAppControlUriKey,
+ &uri_dict)) {
+ uri_dict->GetString(
+ kTizenApplicationAppControlChildNameAttrKey, &uri);
+ }
+
+ std::string mime;
+ const parser::DictionaryValue* mime_dict;
+ if (control_dict.GetDictionary(kTizenApplicationAppControlMimeKey,
+ &mime_dict)) {
+ mime_dict->GetString(
+ kTizenApplicationAppControlChildNameAttrKey, &mime);
+ }
+
+ aplist->controls.emplace_back(src, operation, uri, mime, reload);
+}
+
+} // namespace
+
+AppControlHandler::AppControlHandler() {
+}
+
+AppControlHandler::~AppControlHandler() {
+}
+
+bool AppControlHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+
+ if (!manifest.HasPath(kTizenApplicationAppControlsKey))
+ return true;
+
+ auto aplist = std::make_shared<AppControlInfoList>();
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenApplicationAppControlsKey, kTizenNamespacePrefix)) {
+ ParseAppControlEntryAndStore(*dict, aplist.get());
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(aplist);
+ return true;
+}
+
+bool AppControlHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const {
+ const AppControlInfoList& app_controls =
+ static_cast<const AppControlInfoList&>(data);
+
+ for (const auto& item : app_controls.controls) {
+ if (item.src().empty()) {
+ *error = "The src child element of app-control element is obligatory";
+ return false;
+ }
+
+ const std::string& operation = item.operation();
+ if (operation.empty()) {
+ *error =
+ "The operation child element of app-control element is obligatory";
+ return false;
+ }
+
+ if (!parser::utils::IsValidIRI(operation)) {
+ *error =
+ "The operation child element of app-control element is not valid url";
+ return false;
+ }
+
+ const TizenApplicationInfo& app_info =
+ static_cast<const TizenApplicationInfo&>(
+ *handlers_output.find(kTizenApplicationKey)->second);
+ utils::VersionNumber required_version(app_info.required_version());
+ if (!required_version.IsValid()) {
+ *error = "Cannot retrieve required API version from widget";
+ return false;
+ }
+
+ if (required_version >= kReloadRequiredVersion) {
+ if (item.reload().empty()) {
+ // FIXME for now, this const_cast is used, but it is not the best way.
+ AppControlInfo &tmp = const_cast<AppControlInfo &>(item);
+ tmp.set_reload(kEnabledValue); // default parameter
+ } else if (item.reload() != kEnabledValue &&
+ item.reload() != kDisabledValue) {
+ *error = "The improper value was given for appcontrol reload";
+ return false;
+ }
+ } else if (!item.reload().empty()) {
+ *error = "reload attribute cannot be used for api version lower "
+ "than 2.4";
+ return false;
+ }
+ }
+ return true;
+}
+
+std::vector<std::string> AppControlHandler::PrerequisiteKeys() const {
+ return { kTizenApplicationKey };
+}
+
+std::string AppControlInfo::Key() {
+ return kTizenApplicationAppControlsKey;
+}
+
+std::string AppControlHandler::Key() const {
+ return kTizenApplicationAppControlsKey;
+}
+
+AppControlInfo::AppControlInfo(
+ const std::string& src,
+ const std::string& operation,
+ const std::string& uri,
+ const std::string& mime,
+ const std::string& reload)
+ : src_(src),
+ operation_(operation),
+ uri_(uri),
+ mime_(mime),
+ reload_(reload) {}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_APP_CONTROL_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_APP_CONTROL_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest.h"
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+/**
+ * @brief The AppControlHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:app-control>.
+ */
+class AppControlHandler : public parser::ManifestHandler {
+ public:
+ AppControlHandler();
+ ~AppControlHandler() override;
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+ std::vector<std::string> PrerequisiteKeys() const override;
+};
+
+class AppControlInfo {
+ public:
+ AppControlInfo(const std::string& src, const std::string& operation,
+ const std::string& uri, const std::string& mime,
+ const std::string& reload);
+
+ static std::string Key();
+ /**
+ * @brief src return the source attribute
+ * @return the value of source attribute
+ */
+ const std::string& src() const {
+ return src_;
+ }
+ /**
+ * @brief
+ * @return the value of operation attribute
+ */
+ const std::string& operation() const {
+ return operation_;
+ }
+ /**
+ * @brief uri
+ * @return the value of the uri attribute
+ */
+ const std::string& uri() const {
+ return uri_;
+ }
+ /**
+ * @brief mime
+ * @return the value of the mime attribute
+ */
+ const std::string& mime() const {
+ return mime_;
+ }
+ /**
+ * @brief reload
+ * @return the value of reload attribute
+ */
+ const std::string& reload() const {
+ return reload_;
+ }
+ void set_reload(const std::string &rel) {
+ reload_ = rel;
+ }
+
+ private:
+ std::string src_;
+ std::string operation_;
+ std::string uri_;
+ std::string mime_;
+ std::string reload_;
+};
+
+struct AppControlInfoList : public parser::ManifestData {
+ std::vector<AppControlInfo> controls;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_APP_CONTROL_HANDLER_H_
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "wgt_manifest_handlers/application_icons_handler.h"
+
+#include <algorithm>
+#include <string>
+
+#include "manifest_parser/utils/logging.h"
+
+namespace {
+
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kWidgetIconKey[] = "widget.icon";
+const char kWidgetIconSrcKey[] = "@src";
+const char kWidgetIconWidthKey[] = "@width";
+const char kWidgetIconHeightKey[] = "@height";
+const char kIconsKey[] = "icons";
+
+bool ExtractIconSrc(const parser::Value& dict, std::string* value,
+ std::string* /*error*/) {
+ const parser::DictionaryValue* inner_dict;
+ if (!dict.GetAsDictionary(&inner_dict)) {
+ LOG(INFO) << "Cannot get key value as a dictionary. Key name: widget.icon";
+ return true;
+ }
+ std::string src;
+ if (!inner_dict->GetString(kWidgetIconSrcKey, &src)) {
+ LOG(INFO) << "Cannot find mandatory key. Key name: .@src";
+ return true;
+ }
+ *value = src;
+ return true;
+}
+
+/**
+ * @brief ExtractIconDimensions
+ *
+ * Parses and sets icon dimensions. If value cannot be received it is set to -1.
+ *
+ * @param dict dictionary value of icon
+ * @param height output parameter of height of icon
+ * @param width output parameter of width of icon
+ */
+void ExtractIconDimensions(const parser::Value& dict, int* height, int* width) {
+ *width = -1;
+ *height = -1;
+ const parser::DictionaryValue* inner_dict;
+ if (!dict.GetAsDictionary(&inner_dict)) {
+ return;
+ }
+
+ std::string width_str;
+ if (inner_dict->GetString(kWidgetIconWidthKey, &width_str)) {
+ try {
+ *width = std::stoi(width_str);
+ } catch (const std::logic_error&) {
+ // ignore, width is set to -1
+ }
+ }
+
+ std::string height_str;
+ if (inner_dict->GetString(kWidgetIconHeightKey, &height_str)) {
+ try {
+ *height = std::stoi(height_str);
+ } catch (const std::logic_error&) {
+ // ignore, height is set to -1
+ }
+ }
+}
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+ApplicationIcon::ApplicationIcon(const std::string& path, int height, int width)
+ : path_(path),
+ height_((height >= 0) ? height : -1),
+ width_((width >= 0) ? width : -1) {
+}
+
+bool ApplicationIcon::GetWidth(int* width) const {
+ if (!width || width_ < 0)
+ return false;
+ *width = width_;
+ return true;
+}
+
+bool ApplicationIcon::GetHeight(int* height) const {
+ if (!height || height_ < 0)
+ return false;
+ *height = height_;
+ return true;
+}
+
+const std::string& ApplicationIcon::path() const {
+ return path_;
+}
+
+void ApplicationIcon::set_width(int width) {
+ if (width >= 0)
+ width_ = width;
+}
+
+void ApplicationIcon::set_height(int height) {
+ if (height >= 0)
+ height_ = height;
+}
+
+std::string ApplicationIconsInfo::Key() {
+ return kIconsKey;
+}
+
+
+const std::vector<ApplicationIcon>& ApplicationIconsInfo::icons() const {
+ return icons_;
+}
+
+void ApplicationIconsInfo::AddIcon(const ApplicationIcon& new_icon) {
+ // Eliminate duplicates, keep order
+ if (std::find_if(icons_.begin(), icons_.end(),
+ [&new_icon](const ApplicationIcon& icon) {
+ return icon.path() == new_icon.path();
+ })
+ != icons_.end()) {
+ return;
+ }
+ icons_.push_back(new_icon);
+}
+
+ApplicationIconsHandler::ApplicationIconsHandler() {
+}
+
+ApplicationIconsHandler::~ApplicationIconsHandler() {
+}
+
+bool ApplicationIconsHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ std::shared_ptr<ApplicationIconsInfo> app_icons_info =
+ std::make_shared<ApplicationIconsInfo>();
+
+ if (!manifest.HasPath(kWidgetIconKey)) {
+ *output = std::static_pointer_cast<parser::ManifestData>(app_icons_info);
+ return true;
+ }
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kWidgetIconKey, kWidgetNamespacePrefix)) {
+ std::string icon_path;
+
+ if (!ExtractIconSrc(*dict, &icon_path, error)) {
+ *error = "Cannot get key value as a dictionary. Key name: widget.icon";
+ return false;
+ }
+
+ int width;
+ int height;
+
+ ExtractIconDimensions(*dict, &height, &width);
+ app_icons_info->AddIcon(ApplicationIcon(icon_path, height, width));
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(app_icons_info);
+ return true;
+}
+
+bool ApplicationIconsHandler::AlwaysParseForKey() const {
+ return true;
+}
+
+std::string ApplicationIconsHandler::Key() const {
+ return wgt::application_manifest_keys::kIconsKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
+
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+class ApplicationIcon {
+ public:
+ explicit ApplicationIcon(const std::string& path, int height = -1,
+ int width = -1);
+ /**
+ * @brief GetWidth
+ * @param width
+ * @return true if successful
+ */
+ bool GetWidth(int* width) const;
+ /**
+ * @brief GetHeight
+ * @param height
+ * @return true if successful
+ */
+ bool GetHeight(int* height) const;
+ /**
+ * @brief path
+ * @return string to the path
+ */
+ const std::string& path() const;
+ /**
+ * @brief set_width sets width
+ * @param width
+ */
+ void set_width(int width);
+ /**
+ * @brief set_height sets height
+ * @param height
+ */
+ void set_height(int height);
+
+ private:
+ std::string path_;
+ int height_;
+ int width_;
+};
+
+class ApplicationIconsInfo : public parser::ManifestData {
+ public:
+ static std::string Key();
+
+ const std::vector<ApplicationIcon>& icons() const;
+ /**
+ * @brief AddIcon adds icon
+ * @param icon_path
+ */
+ void AddIcon(const ApplicationIcon& icon_path);
+ private:
+ std::vector<ApplicationIcon> icons_;
+};
+
+/**
+ * @brief The ApplicationIconsHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <w3c:icon>.
+ */
+class ApplicationIconsHandler : public parser::ManifestHandler {
+ public:
+ ApplicationIconsHandler();
+ ~ApplicationIconsHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool AlwaysParseForKey() const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_APPLICATION_ICONS_HANDLER_H_
--- /dev/null
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+
+namespace application_manifest_keys {
+
+// TODO(p.sikorski): below key should be removed, when nwrt and app-installer
+// will stop use it. Now, it is just copied.
+const char kIconsKey[] = "icons";
+
+} // namespace application_manifest_keys
+
+// manifest keys for widget applications.
+namespace application_widget_keys {
+
+const char kCSPKey[] = "widget.content-security-policy";
+const char kCSPReportOnlyKey[] = "widget.content-security-policy-report-only";
+const char kIconsKey[] = "icons";
+const char kAccountKey[] = "widget.account";
+const char kDefaultLocaleKey[] = "widget.@defaultlocale";
+const char kViewModesKey[] = "widget.@viewmodes";
+const char kWidgetKey[] = "widget";
+const char kAuthorKey[] = "widget.author";
+const char kDescriptionKey[] = "widget.description";
+const char kShortKey[] = "@short";
+const char kIDKey[] = "widget.@id";
+const char kHeightKey[] = "widget.@height";
+const char kWidthKey[] = "widget.@width";
+const char kPreferencesKey[] = "widget.preference";
+const char kAccessKey[] = "widget.access";
+const char kLicenseKey[] = "widget.license";
+
+const char kTizenWidgetKey[] = "widget";
+// Child keys inside 'kPreferencesKey'.
+const char kPreferencesNameKey[] = "@name";
+
+const char kWidgetLangKey[] = "widget.@lang";
+
+const char kTizenApplicationKey[] = "widget.application";
+const char kTizenAppWidgetFullKey[] = "widget.app-widget";
+// Child keys inside 'kTizenApplicationKey'
+
+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 kTizenNoDisplayKey[] = "@nodisplay";
+const char kTizenIndicatorPresenceKey[] = "@indicator-presence";
+const char kTizenBackbuttonPresenceKey[] = "@backbutton-presence";
+const char kTizenUserAgentKey[] = "@user-agent";
+const char kTizenSoundModeKey[] = "@sound-mode";
+const char kTizenBackgroundVibrationKey[] = "@background-vibration";
+const char kTizenMetaDataKey[] = "widget.metadata";
+const char kTizenSplashScreenKey[] = "widget.splash-screen";
+// Child keys inside 'kTizenMetaDataKey'
+const char kTizenPermissionsKey[] = "widget.privilege";
+
+// App control
+const char kTizenApplicationAppControlsKey[] = "widget.app-control";
+// IME
+const char kTizenImeKey[] = "widget.ime";
+// Content
+const char kTizenContentKey[] = "widget.content";
+// Category
+const char kTizenCategoryKey[] = "widget.category";
+// Service
+const char kTizenServiceKey[] = "widget.service";
+
+// launch_screen
+const char kSplashScreenKey[] = "widget.launch_screen";
+
+} // namespace application_widget_keys
+
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_APPLICATION_MANIFEST_CONSTANTS_H_
+#define WGT_MANIFEST_HANDLERS_APPLICATION_MANIFEST_CONSTANTS_H_
+
+#include "manifest_parser/manifest.h"
+
+// Keys used in JSON representation of applications.
+namespace wgt {
+namespace application_manifest_keys {
+
+// TODO(p.sikorski): below key should be removed, when nwrt and app-installer
+// will stop use it. Now, it is just copied.
+extern const char kIconsKey[];
+
+} // namespace application_manifest_keys
+
+namespace application_widget_keys {
+
+extern const char kAccessKey[];
+extern const char kAccountKey[];
+extern const char kAllowNavigationKey[];
+extern const char kAuthorKey[];
+extern const char kCSPKey[];
+extern const char kCSPReportOnlyKey[];
+extern const char kDescriptionKey[];
+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[];
+extern const char kTizenMetaDataKey[];
+extern const char kTizenPermissionsKey[];
+extern const char kTizenServiceKey[];
+extern const char kTizenSettingKey[];
+extern const char kTizenSplashScreenKey[];
+extern const char kTizenWidgetKey[];
+extern const char kVersionKey[];
+extern const char kWidgetKey[];
+extern const char kSplashScreenKey[];
+
+} // namespace application_widget_keys
+
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_APPLICATION_MANIFEST_CONSTANTS_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/appwidget_handler.h"
+
+#include <cassert>
+#include <cstdlib>
+#include <limits>
+#include <regex>
+#include <set>
+
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/tizen_application_handler.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+
+const char kTizenAppWidgetFullKey[] = "widget.app-widget";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kNamespaceKey[] = "@namespace";
+const char kTizenWidgetKey[] = "widget";
+const char kTizenAppWidgetKey[] = "app-widget";
+const char kTizenAppWidgetBoxLabelLangKey[] = "@lang";
+const char kTizenAppWidgetBoxIconSrcKey[] = "@src";
+const char kTizenAppWidgetBoxContentSizePreviewKey[] = "@preview";
+const char kTizenAppWidgetBoxContentSizeUseDecorationKey[] = "@use-decoration";
+const char kTizenAppWidgetBoxContentDropViewSrcKey[] = "@src";
+const char kTizenAppWidgetBoxContentDropViewWidthKey[] = "@width";
+const char kTizenAppWidgetBoxContentDropViewHeightKey[] = "@height";
+const char kTizenAppWidgetBoxContentSrcKey[] = "@src";
+const char kTizenAppWidgetBoxContentMouseEventKey[] = "@mouse-event";
+const char kTizenAppWidgetBoxContentTouchEffectKey[] = "@touch-effect";
+const char kTizenAppWidgetBoxContentSizeKey[] = "box-size";
+const char kTizenAppWidgetBoxContentDropViewKey[] = "pd";
+const char kTizenAppWidgetAutoLaunchKey[] = "@auto-launch";
+const char kTizenAppWidgetBoxLabelKey[] = "box-label";
+const char kTizenAppWidgetBoxIconKey[] = "box-icon";
+const char kTizenAppWidgetBoxContentKey[] = "box-content";
+const char kTizenAppWidgetIdKey[] = "@id";
+const char kTizenAppWidgetPrimaryKey[] = "@primary";
+const char kTizenAppWidgetUpdatePeriodKey[] = "@update-period";
+const char kTizenAppWidgetBoxLabelTextKey[] = "#text";
+const char kTizenAppWidgetBoxContentSizeTextKey[] = "#text";
+
+const char kErrMsgInvalidDictionary[] =
+ "Cannot get key value as a dictionary. Key name: ";
+const char kErrMsgInvalidList[] = "Cannot get key value as a list. Key name: ";
+const char kErrMsgNoMandatoryKey[] = "Cannot find mandatory key. Key name: ";
+const char kErrMsgInvalidKeyValue[] = "Invalid key value. Key name: ";
+const char kErrMsgMultipleKeys[] = "Too many keys found. Key name: ";
+const char kErrMsgNoNamespace[] =
+ "Element pointed by key has no namespace specified. Key name: ";
+const char kErrMsgInvalidNamespace[] =
+ "Invalid namespace of element pointed by key. Key name: ";
+const char kErrMsgUpdatePeriodOutOfDomain[] =
+ "Value of an update-period attribute in app-widget element out of domain."
+ " The value: ";
+const char kErrMsgNoLabel[] =
+ "No box-label element in app-widget element.";
+const char kErrMsgInvalidContentSrc[] =
+ "Invalid path or url in a src attribute of box-content element."
+ " The value: ";
+const char kErrMsgNoMandatoryContentSize1x1[] =
+ "No mandatory box-size element (1x1) in box-content element.";
+const char kErrMsgInvalidContentDropViewSrc[] =
+ "Invalid path or url in a src attribute of pd element. The value: ";
+const char kErrMsgContentDropViewHeightOutOfDomain[] =
+ "Value of a height attribute in box-content element out of domain."
+ " The value: ";
+
+const std::regex kStringRegex("[.][0-9a-zA-Z]+");
+
+// If the error parameter is specified, it is filled with the given message
+// otherwise it does nothing.
+void SetError(const std::string& message, std::string* error) {
+ if (error) *error = message;
+}
+
+// If the error parameter is specified, it is filled with concatenation
+// of message and arg parameters otherwise it does nothing.
+void SetError(const std::string& message, const std::string& arg,
+ std::string* error) {
+ if (error) *error = message + arg;
+}
+
+// Converts given text value to a value of specific type. Returns true
+// if convertion is successful or false otherwise.
+template <typename ValueType>
+bool ConvertValue(const std::string& /*str_value*/, ValueType* /*value*/) {
+ assert(false &&
+ "Use one of already defined template specializations"
+ " or define a new one.");
+ return false;
+}
+
+// Converts given text value to a string value. Returns true
+// if convertion is successful or false otherwise.
+template <>
+bool ConvertValue(const std::string& str_value, std::string* value) {
+ assert(value);
+ *value = str_value;
+ return true;
+}
+
+// Converts given text value to a boolean value. Returns true
+// if convertion is successful or false otherwise.
+template <>
+bool ConvertValue(const std::string& str_value, bool* value) {
+ assert(value);
+ if (str_value == "true") {
+ *value = true;
+ return true;
+ }
+ if (str_value == "false") {
+ *value = false;
+ return true;
+ }
+ return false;
+}
+
+// Converts given text value to an integer value. Returns true
+// if convertion is successful or false otherwise.
+template <>
+bool ConvertValue(const std::string& str_value, int* value) {
+ assert(value);
+ char* end = nullptr;
+ *value = strtol(str_value.c_str(), &end, 10);
+ return end == &*str_value.end();
+}
+
+// Converts given text value to a floating point value. Returns true
+// if convertion is successful or false otherwise.
+template <>
+bool ConvertValue(const std::string& str_value, double* value) {
+ assert(value);
+ char* end = nullptr;
+ *value = strtod(str_value.c_str(), &end);
+ return end == &*str_value.end();
+}
+
+// Retrieves a mandatory value from specified dictionary and specified key.
+// Returns true, if the value is found or false otherwise. If the error
+// parameter is specified, it is also filled with proper message.
+template <typename ValueType>
+bool GetMandatoryValue(const parser::DictionaryValue& dict,
+ const std::string& key, ValueType* value,
+ std::string* error) {
+ assert(value);
+ std::string tmp;
+ if (!dict.GetString(key, &tmp)) {
+ SetError(kErrMsgNoMandatoryKey, key, error);
+ return false;
+ }
+ bool result = ConvertValue(tmp, value);
+ if (!result) SetError(kErrMsgInvalidKeyValue, key, error);
+ return result;
+}
+
+// Retrieves an optional value from specified dictionary and specified key.
+// If the value is found, the function returns true and fills value
+// parameter. If the value is not found, the function returns true and fills
+// value parameter with default value. If an error occurs, it returns false
+// and fills error parameter if it is set.
+template <typename ValueType>
+bool GetOptionalValue(const parser::DictionaryValue& dict,
+ const std::string& key, ValueType default_value,
+ ValueType* value, std::string* error) {
+ assert(value);
+ std::string tmp;
+ if (!dict.GetString(key, &tmp)) {
+ *value = default_value;
+ return true;
+ }
+ bool result = ConvertValue(tmp, value);
+ if (!result) SetError(kErrMsgInvalidKeyValue, key, error);
+ return result;
+}
+
+// Verifies whether specified dictionary represents an element in specified
+// namespace. Returns true, if the namespace is set and equal to the specified
+// one or false otherwise. If the error parameter is specified, it is also
+// filled with proper message.
+bool VerifyElementNamespace(const parser::DictionaryValue& dict,
+ const std::string& key,
+ const std::string& desired_namespace_value,
+ std::string* error) {
+ std::string namespace_value;
+ if (!GetMandatoryValue(dict, kNamespaceKey, &namespace_value, nullptr)) {
+ SetError(kErrMsgNoNamespace, key, error);
+ return false;
+ }
+ if (namespace_value != desired_namespace_value) {
+ SetError(kErrMsgInvalidNamespace, key, error);
+ return false;
+ }
+ return true;
+}
+
+// Parses box-label part
+bool ParseLabel(const parser::DictionaryValue& dict, const std::string& key,
+ AppWidget* app_widget, std::string* error) {
+ assert(app_widget);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ std::string lang;
+ if (!GetOptionalValue(dict, kTizenAppWidgetBoxLabelLangKey, std::string(),
+ &lang, error))
+ return false;
+
+ std::string text;
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxLabelTextKey, &text, error))
+ return false;
+
+ if (lang.empty()) {
+ // Note: Tizen 2.2 WRT Core Spec does not determine how many times the value
+ // without lang attribute can appear in one app-widget, so overwrite.
+ app_widget->label.default_value = text;
+ } else {
+ // Note: Tizen 2.2 WRT Core Spec does not determine how many times the value
+ // with specific lang attribute can appear in one app-widget, so overwrite.
+ app_widget->label.lang_value_map[lang] = text;
+ }
+
+ return true;
+}
+
+// Parses box-icon part
+bool ParseIcon(const parser::DictionaryValue& dict, const std::string& key,
+ AppWidget* app_widget, std::string* error) {
+ assert(app_widget);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ if (!app_widget->icon_src.empty()) {
+ SetError(kErrMsgMultipleKeys, key, error);
+ return false;
+ }
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxIconSrcKey,
+ &app_widget->icon_src, error))
+ return false;
+
+ return true;
+}
+
+// Converts size type from text to enum representation
+bool StringToSizeType(const std::string& str_type,
+ AppWidgetSizeType* enum_type) {
+ assert(enum_type);
+ if (str_type == "1x1") {
+ *enum_type = AppWidgetSizeType::k1x1;
+ return true;
+ }
+ if (str_type == "2x1") {
+ *enum_type = AppWidgetSizeType::k2x1;
+ return true;
+ }
+ if (str_type == "2x2") {
+ *enum_type = AppWidgetSizeType::k2x2;
+ return true;
+ }
+ return false;
+}
+
+// Parses box-size part
+bool ParseContentSizes(const parser::DictionaryValue& dict,
+ const std::string& key, AppWidget* app_widget,
+ std::string* error) {
+ assert(app_widget);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ AppWidgetSize size;
+
+ std::string str_type;
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentSizeTextKey, &str_type,
+ error))
+ return false;
+
+ AppWidgetSizeType type;
+ if (!StringToSizeType(str_type, &type)) {
+ SetError(kErrMsgInvalidKeyValue, kTizenAppWidgetBoxContentSizeTextKey,
+ error);
+ return false;
+ }
+ size.type = type;
+
+ if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentSizePreviewKey,
+ std::string(), &size.preview, error))
+ return false;
+
+ if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentSizeUseDecorationKey,
+ true, &size.use_decoration, error))
+ return false;
+
+ app_widget->content_size.push_back(size);
+
+ return true;
+}
+
+// Parses pd part
+bool ParseContentDropView(const parser::DictionaryValue& dict,
+ const std::string& key, AppWidget* app_widget,
+ std::string* error) {
+ assert(app_widget);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ if (!app_widget->content_drop_view.empty()) {
+ SetError(kErrMsgMultipleKeys, key, error);
+ return false;
+ }
+
+ AppWidgetDropView drop_view;
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewSrcKey,
+ &drop_view.src, error))
+ return false;
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewWidthKey,
+ &drop_view.width, error))
+ return false;
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentDropViewHeightKey,
+ &drop_view.height, error))
+ return false;
+
+ app_widget->content_drop_view.push_back(drop_view);
+
+ return true;
+}
+
+// Parses box-content part
+bool ParseContent(const parser::DictionaryValue& dict, const std::string& key,
+ AppWidget* app_widget, std::string* error) {
+ assert(app_widget);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ if (!app_widget->content_src.empty()) {
+ SetError(kErrMsgMultipleKeys, key, error);
+ return false;
+ }
+ if (!GetMandatoryValue(dict, kTizenAppWidgetBoxContentSrcKey,
+ &app_widget->content_src, error))
+ return false;
+
+ if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentMouseEventKey, false,
+ &app_widget->content_mouse_event, error))
+ return false;
+
+ if (!GetOptionalValue(dict, kTizenAppWidgetBoxContentTouchEffectKey, true,
+ &app_widget->content_touch_effect, error))
+ return false;
+
+ if (!dict.HasKey(kTizenAppWidgetBoxContentSizeKey))
+ return false;
+
+ for (const auto& dict_cs : parser::GetOneOrMany(&dict,
+ kTizenAppWidgetBoxContentSizeKey, "")) {
+ if (!ParseContentSizes(*dict_cs, kTizenAppWidgetBoxContentSizeKey,
+ app_widget, error))
+ return false;
+ }
+
+ for (const auto& dict_dv : parser::GetOneOrMany(&dict,
+ kTizenAppWidgetBoxContentDropViewKey, "")) {
+ if (!ParseContentDropView(*dict_dv,
+ kTizenAppWidgetBoxContentDropViewKey, app_widget, error))
+ return false;
+ }
+
+ return true;
+}
+
+// Parses app-widget part
+bool ParseAppWidget(const parser::DictionaryValue& dict, const std::string& key,
+ AppWidgetVector* app_widgets, std::string* error) {
+ assert(app_widgets);
+
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
+ AppWidget app_widget;
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetIdKey, &app_widget.id, error))
+ return false;
+
+ if (!GetMandatoryValue(dict, kTizenAppWidgetPrimaryKey, &app_widget.primary,
+ error))
+ return false;
+
+ double update_period;
+ double no_update_period = std::numeric_limits<double>::min();
+ if (!GetOptionalValue(dict, kTizenAppWidgetUpdatePeriodKey, no_update_period,
+ &update_period, error))
+ return false;
+ if (update_period != no_update_period)
+ app_widget.update_period.push_back(update_period);
+
+ if (!GetOptionalValue(dict, kTizenAppWidgetAutoLaunchKey, false,
+ &app_widget.auto_launch, error))
+ return false;
+
+ if (!dict.HasKey(kTizenAppWidgetBoxLabelKey))
+ return false;
+
+ for (const auto& dict_l : parser::GetOneOrMany(&dict,
+ kTizenAppWidgetBoxLabelKey, kTizenNamespacePrefix)) {
+ if (!ParseLabel(*dict_l, kTizenAppWidgetBoxLabelKey,
+ &app_widget, error))
+ return false;
+ }
+
+ for (const auto& dict_i : parser::GetOneOrMany(&dict,
+ kTizenAppWidgetBoxIconKey, kTizenNamespacePrefix)) {
+ if (!ParseIcon(*dict_i, kTizenAppWidgetBoxIconKey,
+ &app_widget, error))
+ return false;
+ }
+
+ if (!dict.HasKey(kTizenAppWidgetBoxContentKey))
+ return false;
+
+ for (const auto& dict_c : parser::GetOneOrMany(&dict,
+ kTizenAppWidgetBoxContentKey, kTizenNamespacePrefix)) {
+ if (!ParseContent(*dict_c, kTizenAppWidgetBoxContentKey,
+ &app_widget, error))
+ return false;
+ }
+
+ app_widgets->push_back(app_widget);
+
+ return true;
+}
+
+// Validates all content sizes in an app-widget
+bool ValidateContentSize(const AppWidgetSizeVector& content_size,
+ std::string* error) {
+ bool mandatory_1x1_found = false;
+
+ for (const AppWidgetSize& size : content_size) {
+ mandatory_1x1_found |= size.type == AppWidgetSizeType::k1x1;
+ }
+
+ if (!mandatory_1x1_found) {
+ SetError(kErrMsgNoMandatoryContentSize1x1, error);
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace
+
+AppWidgetInfo::AppWidgetInfo(const AppWidgetVector& app_widgets)
+ : app_widgets_(app_widgets) {}
+
+AppWidgetInfo::~AppWidgetInfo() {}
+
+AppWidgetHandler::AppWidgetHandler() {}
+
+AppWidgetHandler::~AppWidgetHandler() {}
+
+
+bool AppWidgetHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenAppWidgetKey))
+ return false;
+
+ AppWidgetVector app_widgets;
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenAppWidgetKey, kTizenNamespacePrefix)) {
+ if (!ParseAppWidget(*dict, kTizenAppWidgetKey, &app_widgets, error))
+ return false;
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(
+ std::make_shared<AppWidgetInfo>(app_widgets));
+ return true;
+}
+
+bool AppWidgetHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const AppWidgetInfo& app_widget_info =
+ static_cast<const AppWidgetInfo&>(data);
+ const AppWidgetVector& app_widgets = app_widget_info.app_widgets();
+
+ for (const AppWidget& app_widget : app_widgets) {
+ if (!app_widget.update_period.empty() &&
+ app_widget.update_period.front() < 1800) {
+ SetError(kErrMsgUpdatePeriodOutOfDomain,
+ std::to_string(app_widget.update_period.front()), error);
+ return false;
+ }
+
+ if (app_widget.label.default_value.empty() &&
+ app_widget.label.lang_value_map.empty()) {
+ SetError(kErrMsgNoLabel, error);
+ return false;
+ }
+
+ if (!ValidateContentSize(app_widget.content_size, error))
+ return false;
+
+ if (!app_widget.content_drop_view.empty()) {
+ const AppWidgetDropView& drop_view = app_widget.content_drop_view.front();
+
+ if (drop_view.height < 1 || drop_view.height > 380) {
+ SetError(kErrMsgContentDropViewHeightOutOfDomain,
+ std::to_string(drop_view.height), error);
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+std::string AppWidgetHandler::Key() const {
+ return kTizenAppWidgetFullKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_APPWIDGET_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_APPWIDGET_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+typedef std::map<std::string, std::string> AppWidgetLabelLangValueMap;
+
+struct AppWidgetLabel {
+ // may be empty
+ std::string default_value;
+
+ // may be empty if default is set
+ AppWidgetLabelLangValueMap lang_value_map;
+};
+
+enum AppWidgetSizeType {
+ k1x1, k2x1, k2x2
+};
+
+struct AppWidgetSize {
+ // mandatory
+ AppWidgetSizeType type;
+
+ // optional, relative to web app directory
+ std::string preview;
+
+ // optional, default: true
+ bool use_decoration;
+};
+
+typedef std::vector<AppWidgetSize> AppWidgetSizeVector;
+
+struct AppWidgetDropView {
+ // mandatory, relative to web app directory or remote URL
+ std::string src;
+
+ // mandatory
+ int width;
+
+ // mandatory, <1, 380>
+ int height;
+};
+
+typedef std::vector<AppWidgetDropView> AppWidgetDropViewVector;
+
+struct AppWidget {
+ // mandatory, unique, must start with application id and end with label
+ // separated with dot, the label can contain only 0-9, a-z, A-Z
+ std::string id;
+
+ // mandatory, if 2 or more app widgets have the primary attribute set to true,
+ // the default icon and title of the parent web app can be used
+ bool primary;
+
+ // optional(0-1), min: 1800.0, default: no update
+ std::vector<double> update_period;
+
+ // optional, default: false
+ bool auto_launch;
+
+ // box label, multiple(1+)
+ AppWidgetLabel label;
+
+ // box icon, optional(0-1), src, mandatory, relative to web app directory
+ std::string icon_src;
+
+ // box content, mandatory(1) -[
+
+ // mandatory, relative to web app directory or remote URL
+ std::string content_src;
+
+ // optional, default: false
+ bool content_mouse_event;
+
+ // optional, default: true
+ bool content_touch_effect;
+
+ // box size, mandatory(1-3), 1x1 must exist
+ AppWidgetSizeVector content_size;
+
+ // drop view, optional(0-1)
+ AppWidgetDropViewVector content_drop_view;
+
+ // ]- box content
+};
+
+typedef std::vector<AppWidget> AppWidgetVector;
+
+class AppWidgetInfo : public parser::ManifestData {
+ public:
+ explicit AppWidgetInfo(const AppWidgetVector& app_widgets);
+ virtual ~AppWidgetInfo();
+
+ const AppWidgetVector& app_widgets() const {
+ return app_widgets_;
+ }
+
+ private:
+ // multiple(0+)
+ AppWidgetVector app_widgets_;
+};
+
+/**
+ * @brief The AppWidgetHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:app-widget>.
+ */
+class AppWidgetHandler : public parser::ManifestHandler {
+ public:
+ AppWidgetHandler();
+ virtual ~AppWidgetHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_APPWIDGET_HANDLER_H_
--- /dev/null
+// 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 "wgt_manifest_handlers/background_category_handler.h"
+
+#include "wgt_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
--- /dev/null
+// 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 WGT_MANIFEST_HANDLERS_BACKGROUND_CATEGORY_HANDLER_H_
+#define WGT_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 // WGT_MANIFEST_HANDLERS_BACKGROUND_CATEGORY_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/category_handler.h"
+
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kTizenCategoryNameKey[] = "@name";
+const char kErrMsgCategory[] = "Parsing category element failed";
+const char kTizenCategoryKey[] = "widget.category";
+const char kErrMsgCategoryName[] =
+ "The name element inside category element is obligatory";
+
+bool ParseCategoryEntryAndStore(const parser::DictionaryValue& control_dict,
+ CategoryInfoList* aplist) {
+ std::string name;
+ if (!control_dict.GetString(kTizenCategoryNameKey, &name)) return false;
+ aplist->categories.push_back(name);
+ return true;
+}
+
+} // namespace
+
+CategoryHandler::CategoryHandler() {}
+
+CategoryHandler::~CategoryHandler() {}
+
+
+bool CategoryHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ if (!manifest.HasPath(kTizenCategoryKey))
+ return true;
+
+ auto aplist = std::make_shared<CategoryInfoList>();
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenCategoryKey, kTizenNamespacePrefix)) {
+ if (!ParseCategoryEntryAndStore(*dict, aplist.get()))
+ return false;
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(aplist);
+ return true;
+}
+
+bool CategoryHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const CategoryInfoList& categories_list =
+ static_cast<const CategoryInfoList&>(data);
+
+ for (const auto& item : categories_list.categories) {
+ if (item.empty()) {
+ *error = kErrMsgCategoryName;
+ return false;
+ }
+ }
+ return true;
+}
+
+std::string CategoryHandler::Key() const {
+ return kTizenCategoryKey;
+}
+
+
+std::string CategoryInfoList::Key() {
+ return kTizenCategoryKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_CATEGORY_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_CATEGORY_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+struct CategoryInfoList : public parser::ManifestData {
+ static std::string Key();
+ std::vector<std::string> categories;
+};
+
+/**
+ * @brief The CategoryHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:category>.
+ */
+class CategoryHandler : public parser::ManifestHandler {
+ public:
+ CategoryHandler();
+ virtual ~CategoryHandler();
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_CATEGORY_HANDLER_H_
--- /dev/null
+// 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 "wgt_manifest_handlers/content_handler.h"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/trim.hpp>
+
+#include <map>
+#include <set>
+
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/utils/string_util.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace ba = boost::algorithm;
+
+namespace {
+
+const char kNamespaceKey[] = "@namespace";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kTizenContentEncodingKey[] = "@encoding";
+const char kTizenContentTypeKey[] = "@type";
+const char kTizenContentKey[] = "widget.content";
+const char kMimeMainComponent[] = "";
+const char kMimeCharsetComponent[] = "charset";
+const char kDefaultMimeType[] = "text/html";
+const char kDefaultEncoding[] = "UTF-8";
+const char kTizenContentSrcKey[] = "@src";
+
+const std::set<std::string> ValidMimeTypeStartFile = {
+ "text/html", "application/xhtml+xml", "image/svg+xml"};
+
+std::map<std::string, std::string> ParseMimeComponents(
+ const std::string& type) {
+ std::map<std::string, std::string> mime_components;
+ std::vector<std::string> components;
+
+ ba::split(components, type, ba::is_any_of(";"));
+ for (auto& component : components) {
+ auto split = component.find("=");
+ std::string key;
+ std::string value;
+ if (split != std::string::npos) {
+ key = component.substr(0, split);
+ value = component.substr(split + 1);
+ } else {
+ key = kMimeMainComponent;
+ value = component;
+ }
+ ba::trim(key);
+ ba::trim(value);
+ mime_components.insert(std::make_pair(key, value));
+ }
+ return mime_components;
+}
+
+bool ValidateMimeTypeStartFile(const std::string& type) {
+ return ValidMimeTypeStartFile.find(parser::utils::CollapseWhitespaceUTF8(
+ type)) != ValidMimeTypeStartFile.end();
+}
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+ContentHandler::ContentHandler()
+ : w3c_content_found_(false), tizen_content_found_(false) {}
+
+ContentHandler::~ContentHandler() {}
+
+/**
+ * @brief ParseAndSetContentValue
+ *
+ * This function should return parse result and set output parameter content
+ * to valid content if returning OK
+ *
+ * @param dict input dictionary for content element
+ * @param content content element to be set if valid one found
+ * @param error parser error to be set if parsing failed with error
+ * @return enum value describing result of parsing
+ */
+ContentHandler::ParseResult ContentHandler::ParseAndSetContentValue(
+ const parser::DictionaryValue& dict,
+ std::shared_ptr<wgt::parse::ContentInfo>* content, std::string* error) {
+ std::string element_namespace;
+ dict.GetString(kNamespaceKey, &element_namespace);
+
+ if (element_namespace == kTizenNamespacePrefix) {
+ if (tizen_content_found_) {
+ // tizen:content already found
+ return ParseResult::IGNORE;
+ }
+ tizen_content_found_ = true;
+ } else {
+ if (w3c_content_found_) {
+ // ignore all content element that are not first
+ return ParseResult::IGNORE;
+ }
+ w3c_content_found_ = true;
+ }
+
+ std::string src;
+ if (!dict.GetString(kTizenContentSrcKey, &src)) {
+ return ParseResult::IGNORE;
+ }
+
+ // error if empty
+ if (src.empty()) {
+ // ignore this element
+ return ParseResult::IGNORE;
+ }
+
+ std::string type = kDefaultMimeType;
+ dict.GetString(kTizenContentTypeKey, &type);
+ // TODO(t.iwanek): this will fail for "quoted-string"
+ // use/implement proper mime parsing...
+ std::map<std::string, std::string> mime_components =
+ ParseMimeComponents(type);
+
+ auto mime_iter = mime_components.find(kMimeMainComponent);
+ if (mime_iter != mime_components.end()) {
+ if (!ValidateMimeTypeStartFile(mime_iter->second)) {
+ *error = "Not proper type of starting file";
+ return ParseResult::IGNORE;
+ }
+ }
+
+ std::string encoding = kDefaultEncoding;
+ if (!dict.GetString(kTizenContentEncodingKey, &encoding)) {
+ auto charset_iter = mime_components.find(kMimeCharsetComponent);
+ if (charset_iter != mime_components.end()) {
+ encoding = charset_iter->second;
+ }
+ }
+ ba::trim(encoding);
+
+ if (*content && (*content)->is_tizen_content()) {
+ // Prefer tizen:content if both are correct
+ return ParseResult::IGNORE;
+ }
+
+ content->reset(new wgt::parse::ContentInfo());
+ (*content)->set_src(src);
+ (*content)->set_type(type);
+ (*content)->set_encoding(encoding);
+ (*content)->set_is_tizen_content(element_namespace == kTizenNamespacePrefix);
+ return ParseResult::OK;
+}
+
+bool ContentHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenContentKey))
+ return true;
+
+ std::shared_ptr<ContentInfo> content_info;
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenContentKey, "")) {
+ if (ParseAndSetContentValue(*dict, &content_info, error)
+ == ParseResult::ERROR) {
+ return false;
+ }
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(content_info);
+
+ return true;
+}
+
+std::string ContentHandler::Key() const {
+ return kTizenContentKey;
+}
+
+std::string ContentInfo::Key() {
+ return kTizenContentKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// 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.
+
+#ifndef WGT_MANIFEST_HANDLERS_CONTENT_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_CONTENT_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class ContentInfo : public parser::ManifestData {
+ public:
+ ContentInfo()
+ : is_tizen_content_(false) { }
+
+ virtual ~ContentInfo() { }
+
+ static std::string Key();
+
+ const std::string& src() const {
+ return src_;
+ }
+ const std::string& type() const {
+ return type_;
+ }
+ const std::string& encoding() const {
+ return encoding_;
+ }
+ /**
+ * @brief set_src sets source
+ * @param src
+ */
+ void set_src(const std::string& src) { src_ = src; }
+ /**
+ * @brief set_type sets type
+ * @param type
+ */
+ void set_type(const std::string& type) { type_ = type; }
+ /**
+ * @brief set_encoding sets encoding
+ * @param encoding
+ */
+ void set_encoding(const std::string& encoding) { encoding_ = encoding; }
+ /**
+ * @brief is_tizen_content
+ * @return if is tizen content
+ */
+ bool is_tizen_content() const {
+ return is_tizen_content_;
+ }
+ /**
+ * @brief set_is_tizen_content
+ * @param is_tizen_content
+ */
+ void set_is_tizen_content(bool is_tizen_content) {
+ is_tizen_content_ = is_tizen_content;
+ }
+
+ private:
+ std::string src_;
+ std::string type_;
+ std::string encoding_;
+ bool is_tizen_content_;
+};
+
+/**
+ * @brief The ContentHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <w3c:content>,
+ * - <tizen:content>.
+ */
+class ContentHandler : public parser::ManifestHandler {
+ public:
+ enum class ParseResult {
+ OK,
+ IGNORE,
+ ERROR,
+ };
+
+ ContentHandler();
+ virtual ~ContentHandler();
+
+ ParseResult ParseAndSetContentValue(
+ const parser::DictionaryValue& dict,
+ std::shared_ptr<wgt::parse::ContentInfo>* content,
+ std::string* error);
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ std::string Key() const override;
+
+ private:
+ bool w3c_content_found_;
+ bool tizen_content_found_;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_CONTENT_HANDLER_H_
--- /dev/null
+// 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 "wgt_manifest_handlers/csp_handler.h"
+
+#include <string.h>
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace {
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kXmlTextKey[] = "#text";
+const char kCSPKey[] = "widget.content-security-policy";
+const char kCSPReportOnlyKey[] = "widget.content-security-policy-report-only";
+}
+
+namespace wgt {
+namespace parse {
+
+std::string CSPInfo::Key() {
+ return kCSPKey;
+}
+
+std::string CSPInfo::Report_only_key() {
+ return kCSPReportOnlyKey;
+}
+
+bool CSPHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ std::string security_key = (security_type_ == SecurityType::CSP) ?
+ kCSPKey : kCSPReportOnlyKey;
+
+ if (!manifest.HasPath(security_key))
+ return true;
+
+ std::shared_ptr<CSPInfo> info(new CSPInfo);
+
+ const auto& dict = parser::GetOneOrMany(manifest.value()
+ , security_key, kTizenNamespacePrefix);
+ std::string security_rules;
+
+ if (dict.front()->GetString(kXmlTextKey, &security_rules)) {
+ info->set_security_rules(security_rules);
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(info);
+
+ return true;
+}
+
+std::string CSPHandler::Key() const {
+ return security_type_ == SecurityType::CSP ? kCSPKey
+ : kCSPReportOnlyKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// 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.
+
+#ifndef WGT_MANIFEST_HANDLERS_CSP_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_CSP_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/values.h"
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class CSPInfo : public parser::ManifestData {
+ public:
+ CSPInfo() {}
+ ~CSPInfo() override {}
+
+ static std::string Key();
+ static std::string Report_only_key();
+ /**
+ * @brief set_security_rules sets up string with security rules
+ * @param security_rules
+ */
+ void set_security_rules(const std::string& security_rules) {
+ security_rules_ = security_rules;
+ }
+ /**
+ * @brief security_rules
+ * @return string with security_rules
+ */
+ const std::string security_rules() const {
+ return security_rules_;
+ }
+
+ private:
+ std::string security_rules_;
+};
+
+/**
+ * @brief The CSPHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:content-security-policy>,
+ * - <tizen:content-security-policy-report-only>.
+ */
+class CSPHandler : public parser::ManifestHandler {
+ public:
+ enum class SecurityType {
+ CSP,
+ CSP_REPORT_ONLY
+ };
+ explicit CSPHandler(SecurityType securityType)
+ : security_type_(securityType) {}
+ ~CSPHandler() override {}
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ std::string Key() const override;
+ private:
+ SecurityType security_type_;
+};
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_CSP_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/ime_handler.h"
+
+#include <cassert>
+#include <memory>
+#include <regex>
+
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kTizenImeUuidKey[] = "uuid";
+const char kTizenImeUuidTextKey[] = "#text";
+const char kTizenImeLanguagesKey[] = "languages";
+const char kTizenImeLanguageKey[] = "language";
+const char kTizenImeLanguageTextKey[] = "#text";
+const char kTizenImeKey[] = "widget.ime";
+
+const char kErrMsgLanguages[] =
+ "At least and only ONE tizen:languages tag should be specified";
+const char kErrMsgEmptyLanguage[] = "Language cannot be empty";
+const char kErrMsgParsingIme[] = "Only one ime tag should be specified";
+const char kErrMsgParsingUuid[] = "Only one uuid tag should be specified";
+const char kErrMsgValidatingUuidEmpty[] =
+ "The UUID of ime element is obligatory";
+const char kErrMsgUuidFormat[] = "Uuid should be in proper format (8-4-4-4-12)";
+const char kErrMsgNoLanguages[] =
+ "At least one language of ime element should be specified";
+
+const std::regex kUuidRegex(
+ "^[0-9a-zA-Z]{8}([-][0-9a-zA-Z]{4}){3}[-][0-9a-zA-Z]{12}$");
+
+bool GetLanguage(const parser::Value* item, ImeInfo* ime_info,
+ std::string* error) {
+ const parser::DictionaryValue* language_dict;
+ if (item->GetAsDictionary(&language_dict)) {
+ std::string language;
+ if (!language_dict->GetString(kTizenImeLanguageTextKey, &language) ||
+ language.empty()) {
+ *error = kErrMsgEmptyLanguage;
+ return false;
+ }
+ ime_info->AddLanguage(language);
+ }
+ return true;
+}
+
+bool ParseImeEntryAndStore(const parser::DictionaryValue& control_dict,
+ ImeInfo* ime_info, std::string* error) {
+ // parsing uuid element
+ const parser::DictionaryValue* uuid_dict;
+ std::string uuid;
+ if (control_dict.GetDictionary(kTizenImeUuidKey, &uuid_dict) &&
+ uuid_dict->GetString(kTizenImeUuidTextKey, &uuid)) {
+ ime_info->set_uuid(uuid);
+ } else {
+ *error = kErrMsgParsingUuid;
+ return false;
+ }
+
+ const parser::DictionaryValue* languages_dict;
+ if (!control_dict.GetDictionary(kTizenImeLanguagesKey, &languages_dict)) {
+ *error = kErrMsgLanguages;
+ return false;
+ }
+
+ const parser::Value* languages;
+ if (!languages_dict->Get(kTizenImeLanguageKey, &languages)) {
+ *error = kErrMsgNoLanguages;
+ return false;
+ }
+
+ if (languages->GetType() == parser::Value::TYPE_LIST) {
+ // many languages
+ const parser::ListValue* list;
+ languages->GetAsList(&list);
+ for (const auto& item : *list) {
+ if (!GetLanguage(item, ime_info, error)) return false;
+ }
+ } else if (languages->GetType() == parser::Value::TYPE_DICTIONARY) {
+ if (!GetLanguage(languages, ime_info, error)) return false;
+ }
+
+ return true;
+}
+
+// UUID is string of 36 characters in form 8-4-4-4-12
+bool IsValidUuid(const std::string& uuid) {
+ return std::regex_match(uuid, kUuidRegex);
+}
+
+} // namespace
+
+ImeInfo::ImeInfo() {}
+
+ImeInfo::~ImeInfo() {}
+
+ImeHandler::ImeHandler() {}
+
+ImeHandler::~ImeHandler() {}
+
+void ImeInfo::AddLanguage(const std::string& language) {
+ languages_.push_back(language);
+}
+
+
+bool ImeHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenImeKey))
+ return true;
+
+ auto ime_info = std::make_shared<ImeInfo>();
+
+ const auto& dict = parser::GetOneOrMany(manifest.value(),
+ kTizenImeKey, kTizenNamespacePrefix).front();
+
+ if (!ParseImeEntryAndStore(*dict, ime_info.get(), error)) {
+ return false;
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(ime_info);
+
+ return true;
+}
+
+bool ImeHandler::Validate(const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const ImeInfo& ime_info = static_cast<const ImeInfo&>(data);
+
+ if (!ime_info.exists()) return true;
+
+ if (ime_info.uuid().empty()) {
+ *error = kErrMsgValidatingUuidEmpty;
+ return false;
+ }
+
+ if (!IsValidUuid(ime_info.uuid())) {
+ *error = kErrMsgUuidFormat;
+ return false;
+ }
+
+ if (ime_info.languages().empty()) {
+ *error = kErrMsgNoLanguages;
+ return false;
+ }
+
+ return true;
+}
+
+std::string ImeHandler::Key() const { return kTizenImeKey; }
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_IME_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_IME_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class ImeInfo : public parser::ManifestData {
+ public:
+ ImeInfo();
+ virtual ~ImeInfo();
+ /**
+ * @brief uuid
+ * @return uuid string
+ */
+ const std::string& uuid() const {
+ return uuid_;
+ }
+ /**
+ * @brief set_uuid sets uuid string
+ * @param uuid
+ */
+ void set_uuid(const std::string& uuid) { uuid_ = uuid; }
+ const std::vector<std::string>& languages() const {
+ return languages_;
+ }
+ /**
+ * @brief AddLanguage adds language
+ * @param language
+ */
+ void AddLanguage(const std::string& language);
+
+ private:
+ std::string uuid_;
+ std::vector<std::string> languages_;
+};
+
+/**
+ * @brief The ImeHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:ime>.
+ */
+class ImeHandler : public parser::ManifestHandler {
+ public:
+ ImeHandler();
+ virtual ~ImeHandler();
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& application,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_IME_HANDLER_H_
--- /dev/null
+prefix=@PREFIX@
+exec_prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: wgt-manifest-handlers
+Description: Manifest handlers for wgt manifest parser
+Version: @VERSION@
+Requires: manifest-parser
+Libs: -L${libdir} -lwgt-manifest-handlers
+Cflags: -I${includedir}
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/metadata_handler.h"
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+typedef std::pair<std::string, std::string> MetaDataPair;
+typedef std::map<std::string, std::string> MetaDataMap;
+typedef std::map<std::string, std::string>::const_iterator MetaDataIter;
+
+namespace {
+
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kTizenMetaDataNameKey[] = "@key";
+const char kTizenMetaDataValueKey[] = "@value";
+const char kTizenMetaDataKey[] = "widget.metadata";
+
+MetaDataPair ParseMetaDataItem(const parser::DictionaryValue* dict,
+ std::string* error) {
+ assert(dict && dict->IsType(parser::Value::TYPE_DICTIONARY));
+ MetaDataPair result;
+ if (!dict->GetString(kTizenMetaDataNameKey, &result.first)) {
+ *error = "Invalid key of tizen metaData.";
+ } else {
+ if (!dict->GetString(kTizenMetaDataValueKey, &result.second)) {
+ result.second = "";
+ }
+ }
+
+ return result;
+}
+
+} // namespace
+
+MetaDataInfo::MetaDataInfo() {}
+
+MetaDataInfo::~MetaDataInfo() {}
+
+bool MetaDataInfo::HasKey(const std::string& key) const {
+ return metadata_.find(key) != metadata_.end();
+}
+
+std::string MetaDataInfo::GetValue(const std::string& key) const {
+ MetaDataIter it = metadata_.find(key);
+ if (it != metadata_.end()) return it->second;
+ return std::string("");
+}
+
+void MetaDataInfo::SetValue(const std::string& key, const std::string& value) {
+ metadata_.insert(MetaDataPair(key, value));
+}
+
+MetaDataHandler::MetaDataHandler() {}
+
+MetaDataHandler::~MetaDataHandler() {}
+
+
+bool MetaDataHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenMetaDataKey))
+ return true;
+
+ auto metadata_info = std::make_shared<MetaDataInfo>();
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenMetaDataKey, kTizenNamespacePrefix)) {
+ MetaDataPair metadata_item;
+
+ metadata_item = ParseMetaDataItem(dict, error);
+ metadata_info->SetValue(metadata_item.first, metadata_item.second);
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(metadata_info);
+
+ return true;
+}
+
+bool MetaDataHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* /*error*/) const {
+ const MetaDataInfo& mdata_info = static_cast<const MetaDataInfo&>(data);
+ // TODO(j.izydorczyk):
+ // Here should be performed *info class members validity check
+ (void)mdata_info;
+ return true;
+}
+
+std::string MetaDataHandler::Key() const {
+ return kTizenMetaDataKey;
+}
+
+std::string MetaDataInfo::Key() {
+ return kTizenMetaDataKey;
+}
+
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_METADATA_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_METADATA_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+
+namespace wgt {
+namespace parse {
+
+class MetaDataInfo : public parser::ManifestData {
+ public:
+ MetaDataInfo();
+ virtual ~MetaDataInfo();
+
+ static std::string Key();
+ /**
+ * @brief HasKey
+ * @param key
+ * @return true if has key
+ */
+ bool HasKey(const std::string& key) const;
+ /**
+ * @brief GetValue gets value
+ * @param key
+ * @return
+ */
+ std::string GetValue(const std::string& key) const;
+ /**
+ * @brief SetValue sets value
+ * @param key
+ * @param value
+ */
+ void SetValue(const std::string& key, const std::string& value);
+ /**
+ * @brief metadata
+ * @return map of metadata
+ */
+ const std::map<std::string, std::string>& metadata() const {
+ return metadata_;
+ }
+
+ private:
+ std::map<std::string, std::string> metadata_;
+};
+
+/**
+ * @brief The MetaDataHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:metadata>.
+ */
+class MetaDataHandler : public parser::ManifestHandler {
+ public:
+ MetaDataHandler();
+ virtual ~MetaDataHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_METADATA_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/navigation_handler.h"
+
+#include <boost/tokenizer.hpp>
+
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kAllowNavigationKey[] = "widget.allow-navigation";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kXmlTextKey[] = "#text";
+const boost::char_separator<char> navigation_separator(" ");
+
+} // namespace
+
+AllowedNavigationInfo::AllowedNavigationInfo(
+ const std::string& allowed_domains) {
+ boost::tokenizer<boost::char_separator<char>> tokens(allowed_domains,
+ navigation_separator);
+ for (auto& item : tokens) {
+ allowed_domains_.push_back(item);
+ }
+}
+
+AllowedNavigationInfo::~AllowedNavigationInfo() {}
+
+std::string AllowedNavigationInfo::Key() {
+ return kAllowNavigationKey;
+}
+
+NavigationHandler::NavigationHandler() {}
+
+NavigationHandler::~NavigationHandler() {}
+
+
+bool NavigationHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ if (!manifest.HasPath(kAllowNavigationKey))
+ return true;
+
+ std::string allowed_domains;
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kAllowNavigationKey, kTizenNamespacePrefix)) {
+ if (!dict->GetString(kXmlTextKey, &allowed_domains))
+ return true;
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(
+ std::make_shared<AllowedNavigationInfo>(allowed_domains));
+ return true;
+}
+
+bool NavigationHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* /*error*/) const {
+ const AllowedNavigationInfo& navi_info =
+ static_cast<const AllowedNavigationInfo&>(data);
+ // TODO(j.izydorczyk): There should be done 'navi_info' validity check.
+ (void)navi_info;
+ return true;
+}
+
+std::string NavigationHandler::Key() const {
+ return kAllowNavigationKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_NAVIGATION_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_NAVIGATION_HANDLER_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class AllowedNavigationInfo : public parser::ManifestData {
+ public:
+ explicit AllowedNavigationInfo(const std::string& allowed_domains);
+ virtual ~AllowedNavigationInfo();
+
+ static std::string Key();
+ /**
+ * @brief GetAllowedDomains
+ * @return vector with allowed domains
+ */
+ const std::vector<std::string>& GetAllowedDomains() const {
+ return allowed_domains_;
+ }
+
+ private:
+ std::vector<std::string> allowed_domains_;
+};
+
+/**
+ * @brief The NavigationHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:allow-navigation>.
+ */
+class NavigationHandler : public parser::ManifestHandler {
+ public:
+ NavigationHandler();
+ virtual ~NavigationHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_NAVIGATION_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/permissions_handler.h"
+
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace {
+const char kTizenPermissionsKey[] = "widget.privilege";
+}
+
+namespace wgt {
+namespace parse {
+
+namespace {
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kTizenPermissionsNameKey[] = "@name";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+}
+
+PermissionsInfo::PermissionsInfo() {}
+
+PermissionsInfo::~PermissionsInfo() {}
+
+PermissionsHandler::PermissionsHandler() {}
+
+PermissionsHandler::~PermissionsHandler() {}
+
+bool PermissionsHandler::Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenPermissionsKey)) {
+ return true;
+ }
+
+ parser::Value* value;
+ if (!manifest.Get(kTizenPermissionsKey, &value)) {
+ *error = "Invalid value of tizen permissions.";
+ return false;
+ }
+
+ auto permissions_info = std::make_shared<PermissionsInfo>();
+ parser::PermissionSet api_permissions;
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kTizenPermissionsKey, kTizenNamespacePrefix)) {
+ std::string permission;
+
+ if (!dict->GetString(kTizenPermissionsNameKey, &permission) ||
+ permission.empty())
+ continue;
+
+ if (api_permissions.find(permission) != api_permissions.end())
+ LOG(WARNING) << "Duplicated permission names found: " << permission;
+
+ api_permissions.insert(permission);
+ }
+
+ permissions_info->SetAPIPermissions(api_permissions);
+
+ *output = std::static_pointer_cast<parser::ManifestData>(permissions_info);
+ return true;
+}
+
+bool PermissionsHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* /*error*/) const {
+ const PermissionsInfo& perm_info = static_cast<const PermissionsInfo&>(data);
+ // TODO(j.izydorczyk): there should be done 'perm_info' members validation
+ (void)perm_info;
+ return true;
+}
+
+std::string PermissionsInfo::Key() {
+ return kTizenPermissionsKey;
+}
+
+std::string PermissionsHandler::Key() const {
+ return kTizenPermissionsKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_PERMISSIONS_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_PERMISSIONS_HANDLER_H_
+
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/permission_types.h"
+
+namespace wgt {
+namespace parse {
+
+class PermissionsInfo: public parser::ManifestData {
+ public:
+ PermissionsInfo();
+ virtual ~PermissionsInfo();
+
+ static std::string Key();
+ /**
+ * @brief GetAPIPermissions
+ * @return permission set
+ */
+ const parser::PermissionSet& GetAPIPermissions() const {
+ return api_permissions_;
+ }
+ /**
+ * @brief SetAPIPermissions sets api permissions
+ * @param api_permissions
+ */
+ void SetAPIPermissions(const parser::PermissionSet& api_permissions) {
+ api_permissions_ = api_permissions;
+ }
+
+ private:
+ parser::PermissionSet api_permissions_;
+};
+
+/**
+ * @brief The PermissionsHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:privilege>.
+ */
+class PermissionsHandler: public parser::ManifestHandler {
+ public:
+ PermissionsHandler();
+ virtual ~PermissionsHandler();
+
+ bool Parse(
+ const parser::Manifest& data,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_PERMISSIONS_HANDLER_H_
--- /dev/null
+// 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.
+
+#include "wgt_manifest_handlers/platform_version.h"
+
+namespace parser {
+
+utils::VersionNumber GetCurrentPlatformVersion() {
+ return utils::VersionNumber(TIZEN_VERSION);
+}
+
+utils::VersionNumber GetMinimumPlatformVersion() {
+#ifdef TIZEN_TV
+ return utils::VersionNumber("2.3");
+#elif TIZEN_WEARABLE
+ return utils::VersionNumber("2.3.1");
+#else
+ return utils::VersionNumber("2.2.1");
+#endif
+}
+
+} // namespace parser
--- /dev/null
+// 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 file.
+
+#ifndef WGT_MANIFEST_HANDLERS_PLATFORM_VERSION_H_
+#define WGT_MANIFEST_HANDLERS_PLATFORM_VERSION_H_
+
+#include <string>
+
+#include "manifest_parser/utils/version_number.h"
+
+namespace parser {
+/**
+ * @brief GetCurrentPlatformVersion
+ * @return number version of the platform currently used
+ */
+utils::VersionNumber GetCurrentPlatformVersion();
+
+/**
+ * @brief GetMinimumPlatformVersion
+ * @return number version of the minimum platform for current profile
+ */
+utils::VersionNumber GetMinimumPlatformVersion();
+
+} // namespace parser
+
+#endif // WGT_MANIFEST_HANDLERS_PLATFORM_VERSION_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/service_handler.h"
+
+#include <cassert>
+#include <map>
+#include <utility>
+#include <set>
+
+#include "manifest_parser/manifest_util.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace {
+const char kTizenServiceKey[] = "widget.service";
+const char kTizenServiceIdKey[] = "@id";
+const char kTizenServiceAutoRestartKey[] = "@auto-restart";
+const char kTizenServiceOnBootKey[] = "@on-boot";
+const char kTizenServiceCategoryKey[] = "category";
+const char kTizenServiceCategoryNameKey[] = "@name";
+const char kTizenServiceContentKey[] = "content";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kTizenServiceNameKey[] = "name";
+const char kTizenServiceContentSrcKey[] = "@src";
+const char kTizenServiceIconKey[] = "icon";
+const char kTizenServiceIconSrcKey[] = "@src";
+const char kTizenServiceDescriptionKey[] = "description";
+const char kTizenServiceMetadataKey[] = "metadata";
+const char kTizenServiceMetadataKeyKey[] = "@key";
+const char kTizenServiceMetadataValueKey[] = "@value";
+const char kXmlLangKey[] = "@lang";
+const char kXmlTextKey[] = "#text";
+
+bool ParseServiceContent(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ std::string content;
+ bool found = false;
+ for (auto& item : parser::GetOneOrMany(dict, kTizenServiceContentKey,
+ kTizenNamespacePrefix)) {
+ if (found) {
+ *error = "tizen:content element of tizen:service "
+ "should be declared only once";
+ return false;
+ }
+ found = true;
+ if (!item->GetString(kTizenServiceContentSrcKey, &content)) {
+ *error =
+ "Missing 'src' attribute in tizen:content tag in tizen:service";
+ return false;
+ }
+ }
+ if (!found) {
+ *error = "Missing tizen:content tag in tizen:service";
+ return false;
+ }
+ service_info->set_content(content);
+ return true;
+}
+
+bool ParseServiceIcon(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ std::string icon;
+ const auto& items = parser::GetOneOrMany(dict, kTizenServiceIconKey,
+ kTizenNamespacePrefix);
+ if (!items.empty()) {
+ if (items.size() > 1) {
+ *error = "tizen:icon element of tizen:service "
+ "should be declared only once";
+ return false;
+ }
+ if (!items[0]->GetString(kTizenServiceIconSrcKey, &icon)) {
+ *error = "Missing 'src' attribute in tizen:icon tag in tizen:service";
+ return false;
+ }
+ service_info->set_icon(icon);
+ }
+ return true;
+}
+
+bool ParseServiceDescription(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ const parser::Value* value = nullptr;
+ if (!dict->Get(kTizenServiceDescriptionKey, &value)) return true;
+ std::string description;
+
+ const auto& items = parser::GetOneOrMany(dict,
+ kTizenServiceDescriptionKey,
+ kTizenNamespacePrefix);
+ if (!items.empty()) {
+ if (items.size() > 1) {
+ *error = "tizen:description element of tizen:service "
+ "should be declared only once";
+ return false;
+ }
+ items[0]->GetString(kXmlTextKey, &description);
+ service_info->set_description(description);
+ }
+ return true;
+}
+
+bool ParseServiceCategory(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ std::vector<std::string> categories;
+ for (auto& item : parser::GetOneOrMany(dict, kTizenServiceCategoryKey,
+ kTizenNamespacePrefix)) {
+ std::string category;
+ if (!item->GetString(kTizenServiceCategoryNameKey, &category)) {
+ *error =
+ "Missing 'name' attribute of tizen:category tag in tizen:service";
+ return false;
+ }
+ categories.push_back(category);
+ }
+ service_info->set_categories(categories);
+ return true;
+}
+
+bool ParseServiceName(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ wgt::parse::LangNameVector names;
+ for (auto& item : parser::GetOneOrMany(dict, kTizenServiceNameKey,
+ kTizenNamespacePrefix)) {
+ std::string lang;
+ std::string name;
+ item->GetString(kXmlLangKey, &lang);
+ item->GetString(kXmlTextKey, &name);
+ names.emplace_back(lang, name);
+ }
+ if (names.empty()) {
+ *error = "Cannot find tizen:name element for tizen:service. "
+ "At least one must be provided.";
+ return false;
+ }
+ service_info->set_names(names);
+ return true;
+}
+
+bool ParseServiceMetadata(const parser::DictionaryValue* dict,
+ wgt::parse::ServiceInfo* service_info,
+ std::string* error) {
+ wgt::parse::KeyValueVector metadata_set;
+ for (auto& item : parser::GetOneOrMany(dict, kTizenServiceMetadataKey,
+ kTizenNamespacePrefix)) {
+ std::string key;
+ std::string value;
+ if (!item->GetString(kTizenServiceMetadataKeyKey, &key)) {
+ *error = "'key' attribute of metadata is obligatory";
+ return false;
+ }
+ item->GetString(kTizenServiceMetadataValueKey, &value);
+ metadata_set.emplace_back(key, value);
+ }
+ service_info->set_metadata_set(metadata_set);
+ return true;
+}
+
+std::unique_ptr<wgt::parse::ServiceInfo> ParseService(
+ const parser::DictionaryValue* dict, std::string* error) {
+ std::string id;
+ if (!dict->GetString(kTizenServiceIdKey, &id)) {
+ *error = "Cannot get appid for tizen:service";
+ return nullptr;
+ }
+
+ std::unique_ptr<wgt::parse::ServiceInfo> service(
+ new wgt::parse::ServiceInfo(id));
+
+ std::string auto_restart = "false";
+ if (dict->GetString(kTizenServiceAutoRestartKey, &auto_restart))
+ service->set_auto_restart(auto_restart == "true");
+
+ std::string on_boot = "false";
+ if (dict->GetString(kTizenServiceOnBootKey, &on_boot))
+ service->set_on_boot(on_boot == "true");
+
+ if (!ParseServiceContent(dict, service.get(), error)) return nullptr;
+
+ if (!ParseServiceIcon(dict, service.get(), error)) return nullptr;
+
+ if (!ParseServiceDescription(dict, service.get(), error)) return nullptr;
+
+ if (!ParseServiceCategory(dict, service.get(), error)) return nullptr;
+
+ if (!ParseServiceName(dict, service.get(), error)) return nullptr;
+
+ if (!ParseServiceMetadata(dict, service.get(), error)) return nullptr;
+
+ return service;
+}
+
+} // namespace
+
+namespace wgt {
+
+namespace parse {
+
+ServiceInfo::ServiceInfo(const std::string& id, bool auto_restart, bool on_boot)
+ : id_(id), auto_restart_(auto_restart), on_boot_(on_boot) {}
+
+ServiceInfo::~ServiceInfo() {}
+
+ServiceHandler::ServiceHandler() {}
+
+ServiceHandler::~ServiceHandler() {}
+
+
+bool ServiceHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ if (!manifest.HasPath(kTizenServiceKey)) {
+ return true;
+ }
+ std::shared_ptr<ServiceList> services_data(new ServiceList());
+
+ for (auto& item : parser::GetOneOrMany(manifest.value(),
+ kTizenServiceKey, kTizenNamespacePrefix)) {
+ auto service = ParseService(item, error);
+ if (!service)
+ return false;
+ services_data->services.push_back(*service);
+ }
+ *output = std::static_pointer_cast<parser::ManifestData>(services_data);
+ return true;
+}
+
+bool ServiceHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const auto services = static_cast<const wgt::parse::ServiceList&>(data);
+
+ for (auto& service : services.services) {
+ if (!parser::ValidateTizenApplicationId(service.id())) {
+ *error =
+ "The id property of application element "
+ "does not match the format\n";
+ return false;
+ }
+ }
+
+ return true;
+}
+
+std::string ServiceInfo::Key() {
+ return kTizenServiceKey;
+}
+
+std::string ServiceHandler::Key() const {
+ return kTizenServiceKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_SERVICE_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_SERVICE_HANDLER_H_
+
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+
+namespace wgt {
+namespace parse {
+
+using LangNameVector = std::vector<std::pair<std::string, std::string>>;
+using KeyValueVector = std::vector<std::pair<std::string, std::string>>;
+
+class ServiceInfo {
+ public:
+ explicit ServiceInfo(const std::string& id, bool auto_restart = false,
+ bool on_boot = false);
+ virtual ~ServiceInfo();
+
+ static std::string Key();
+ /**
+ * @brief id
+ * @return string id
+ */
+ const std::string& id() const { return id_; }
+ void set_id(const std::string& id) {
+ id_ = id;
+ }
+ /**
+ * @brief auto_restart
+ * @return true is auto-restart is set
+ */
+ bool auto_restart() const { return auto_restart_; }
+ /**
+ * @brief set_auto_restart sets auto restart
+ * @param auto_restart
+ */
+ void set_auto_restart(bool auto_restart) {
+ auto_restart_ = auto_restart;
+ }
+ /**
+ * @brief on_boot
+ * @return if is on boot
+ */
+ bool on_boot() const { return on_boot_; }
+ void set_on_boot(bool on_boot) {
+ on_boot_ = on_boot;
+ }
+ /**
+ * @brief names
+ * @return lang names vector
+ */
+ const LangNameVector& names() const {
+ return names_;
+ }
+ /**
+ * @brief set_names sets name lang vector
+ * @param names
+ */
+ void set_names(const LangNameVector& names) {
+ names_ = names;
+ }
+ /**
+ * @brief icon
+ * @return string to the icon
+ */
+ const std::string& icon() const {
+ return icon_;
+ }
+ /**
+ * @brief set_icon set string to the icon
+ * @param icon
+ */
+ void set_icon(const std::string& icon) {
+ icon_ = icon;
+ }
+ /**
+ * @brief content
+ * @return content string
+ */
+
+ const std::string& content() const {
+ return content_;
+ }
+ /**
+ * @brief set_content sets content string
+ * @param content
+ */
+ void set_content(const std::string& content) {
+ content_ = content;
+ }
+ /**
+ * @brief description
+ * @return description string
+ */
+ const std::string& description() const {
+ return description_;
+ }
+ /**
+ * @brief set_description sets description
+ * @param description
+ */
+ void set_description(const std::string& description) {
+ description_ = description;
+ }
+ /**
+ * @brief categories
+ * @return categories vector
+ */
+
+ const std::vector<std::string>& categories() const {
+ return categories_;
+ }
+ /**
+ * @brief set_categories sets categories
+ * @param categories
+ */
+ void set_categories(const std::vector<std::string>& categories) {
+ categories_ = categories;
+ }
+ /**
+ * @brief metadata_set
+ * @return key value vector
+ */
+ const KeyValueVector& metadata_set() const {
+ return metadata_set_;
+ }
+ /**
+ * @brief set_metadata_set sets metadata
+ * @param metadata_set
+ */
+ void set_metadata_set(const KeyValueVector& metadata_set) {
+ metadata_set_ = metadata_set;
+ }
+
+ private:
+ std::string id_;
+ bool auto_restart_;
+ bool on_boot_;
+ LangNameVector names_;
+ std::string icon_;
+ std::string content_;
+ std::string description_;
+ std::vector<std::string> categories_;
+ KeyValueVector metadata_set_;
+};
+
+struct ServiceList : public parser::ManifestData {
+ std::vector<ServiceInfo> services;
+};
+
+/**
+ * @brief The ServiceHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:service>.
+ */
+class ServiceHandler : public parser::ManifestHandler {
+ public:
+ ServiceHandler();
+ virtual ~ServiceHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_SERVICE_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/setting_handler.h"
+
+#include <boost/algorithm/string.hpp>
+#include <string.h>
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace {
+
+const char kTrueValue[] = "true";
+const char kFalseValue[] = "false";
+
+const char kTizenHardwareKey[] = "@hwkey-event";
+const char kTizenScreenOrientationKey[] = "@screen-orientation";
+const char kTizenEncryptionKey[] = "@encryption";
+const char kTizenContextMenuKey[] = "@context-menu";
+const char kTizenBackgroundSupportKey[] = "@background-support";
+const char kTizenNoDisplayKey[] = "@nodisplay";
+const char kTizenIndicatorPresenceKey[] = "@indicator-presence";
+const char kTizenBackbuttonPresenceKey[] = "@backbutton-presence";
+const char kTizenInstallLocationKey[] = "@install-location";
+const char kTizenUserAgentKey[] = "@user-agent";
+const char kTizenSoundModeKey[] = "@sound-mode";
+const char kTizenBackgroundVibrationKey[] = "@background-vibration";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kTizenSettingKey[] = "widget.setting";
+
+bool ForAllFindKey(const parser::Value* value, const std::string& key,
+ std::string* result) {
+ if (value->GetType() == parser::Value::TYPE_DICTIONARY) {
+ const parser::DictionaryValue* dict = nullptr;
+ value->GetAsDictionary(&dict);
+ if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
+ return false;
+ if (dict->GetString(key, result)) return true;
+ } else if (value->GetType() == parser::Value::TYPE_LIST) {
+ const parser::ListValue* list = nullptr;
+ value->GetAsList(&list);
+ for (auto& item : *list) {
+ const parser::DictionaryValue* dict = nullptr;
+ if (item->GetAsDictionary(&dict)) {
+ if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
+ continue;
+ if (dict->GetString(key, result)) return true;
+ }
+ }
+ }
+ return false;
+}
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+SettingInfo::SettingInfo()
+ : hwkey_enabled_(true),
+ screen_orientation_(ScreenOrientation::AUTO),
+ encryption_enabled_(false),
+ context_menu_enabled_(true),
+ background_support_enabled_(false),
+ install_location_(InstallLocation::AUTO),
+ no_display_(false),
+ indicator_presence_(true),
+ backbutton_presence_(false),
+ sound_mode_(SoundMode::SHARED),
+ background_vibration_(false) {}
+
+SettingInfo::~SettingInfo() {}
+
+SettingHandler::SettingHandler() {}
+
+SettingHandler::~SettingHandler() {}
+
+bool SettingHandler::Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ const parser::Value* value = nullptr;
+ manifest.Get(kTizenSettingKey, &value);
+
+ std::shared_ptr<SettingInfo> app_info(new SettingInfo);
+ std::string hwkey;
+ ForAllFindKey(value, kTizenHardwareKey, &hwkey);
+ app_info->set_hwkey_enabled(hwkey != "disable");
+
+ std::string screen_orientation;
+ ForAllFindKey(value, kTizenScreenOrientationKey, &screen_orientation);
+ if (strcasecmp("portrait", screen_orientation.c_str()) == 0)
+ app_info->set_screen_orientation(SettingInfo::ScreenOrientation::PORTRAIT);
+ else if (strcasecmp("landscape", screen_orientation.c_str()) == 0)
+ app_info->set_screen_orientation(SettingInfo::ScreenOrientation::LANDSCAPE);
+ else
+ app_info->set_screen_orientation(SettingInfo::ScreenOrientation::AUTO);
+
+ std::string encryption;
+ ForAllFindKey(value, kTizenEncryptionKey, &encryption);
+ app_info->set_encryption_enabled(encryption == "enable");
+
+ std::string context_menu;
+ ForAllFindKey(value, kTizenContextMenuKey, &context_menu);
+ app_info->set_context_menu_enabled(context_menu != "disable");
+
+ std::string background_support;
+ ForAllFindKey(value, kTizenBackgroundSupportKey, &background_support);
+ app_info->set_background_support_enabled(background_support == "enable");
+
+ std::string install_location;
+ ForAllFindKey(value, kTizenInstallLocationKey, &install_location);
+ if (strcasecmp("internal-only", install_location.c_str()) == 0)
+ app_info->set_install_location(SettingInfo::InstallLocation::INTERNAL);
+ else if (strcasecmp("prefer-external", install_location.c_str()) == 0)
+ app_info->set_install_location(SettingInfo::InstallLocation::EXTERNAL);
+
+ std::string no_display;
+ ForAllFindKey(value, kTizenNoDisplayKey, &no_display);
+ app_info->set_no_display(boost::iequals(no_display, kTrueValue));
+
+ std::string indicator_presence;
+ if (ForAllFindKey(value, kTizenIndicatorPresenceKey, &indicator_presence)) {
+ if (boost::iequals(indicator_presence, kTrueValue)) {
+ app_info->set_indicator_presence(true);
+ } else if (boost::iequals(indicator_presence, kFalseValue)) {
+ app_info->set_indicator_presence(false);
+ }
+ }
+
+ std::string backbutton_presence;
+ if (ForAllFindKey(value, kTizenBackbuttonPresenceKey, &backbutton_presence)) {
+ if (boost::iequals(backbutton_presence, kTrueValue)) {
+ app_info->set_backbutton_presence(true);
+ } else if (boost::iequals(backbutton_presence, kFalseValue)) {
+ app_info->set_backbutton_presence(false);
+ }
+ }
+
+ std::string user_agent;
+ ForAllFindKey(value, kTizenUserAgentKey, &user_agent);
+ app_info->set_user_agent(user_agent);
+
+ std::string background_vibration;
+ ForAllFindKey(value, kTizenBackgroundVibrationKey, &background_vibration);
+ app_info->set_background_vibration(background_vibration == "enable");
+
+ std::string sound_mode;
+ ForAllFindKey(value, kTizenSoundModeKey, &sound_mode);
+ if (strcasecmp("exclusive", sound_mode.c_str()) == 0)
+ app_info->set_sound_mode(SettingInfo::SoundMode::EXCLUSIVE);
+
+ *output = std::static_pointer_cast<parser::ManifestData>(app_info);
+ return true;
+}
+
+bool SettingHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const SettingInfo& setting_info = static_cast<const SettingInfo&>(data);
+ if (setting_info.screen_orientation() !=
+ SettingInfo::ScreenOrientation::AUTO &&
+ setting_info.screen_orientation() !=
+ SettingInfo::ScreenOrientation::PORTRAIT &&
+ setting_info.screen_orientation() !=
+ SettingInfo::ScreenOrientation::LANDSCAPE) {
+ *error = "Wrong value of screen orientation";
+ return false;
+ }
+
+ if (setting_info.install_location() != SettingInfo::InstallLocation::AUTO &&
+ setting_info.install_location() !=
+ SettingInfo::InstallLocation::INTERNAL &&
+ setting_info.install_location() !=
+ SettingInfo::InstallLocation::EXTERNAL) {
+ *error = "Wrong value of install location";
+ return false;
+ }
+
+ if (setting_info.sound_mode() != SettingInfo::SoundMode::SHARED &&
+ setting_info.sound_mode() != SettingInfo::SoundMode::EXCLUSIVE) {
+ *error = "Wrong value of screen sound mode";
+ return false;
+ }
+
+ return true;
+}
+
+
+std::string SettingHandler::Key() const {
+ return kTizenSettingKey;
+}
+
+std::string SettingInfo::Key() {
+ return kTizenSettingKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_SETTING_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_SETTING_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/values.h"
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class SettingInfo : public parser::ManifestData {
+ public:
+ enum class ScreenOrientation {
+ PORTRAIT,
+ LANDSCAPE,
+ AUTO
+ };
+
+ enum class InstallLocation {
+ INTERNAL,
+ EXTERNAL,
+ AUTO
+ };
+
+ enum class SoundMode {
+ SHARED,
+ EXCLUSIVE
+ };
+
+ SettingInfo();
+ virtual ~SettingInfo();
+
+ static std::string Key();
+ /**
+ * @brief set_hwkey_enabled sets value of hw_key to true or false
+ * @param enabled
+ */
+ void set_hwkey_enabled(bool enabled) { hwkey_enabled_ = enabled; }
+ /**
+ * @brief hwkey_enabled
+ * @return current value of hw_key
+ */
+ bool hwkey_enabled() const { return hwkey_enabled_; }
+ /**
+ * @brief set_screen_orientation sets screen_orientation
+ * @param orientation
+ */
+ void set_screen_orientation(ScreenOrientation orientation) {
+ screen_orientation_ = orientation;
+ }
+ /**
+ * @brief screen_orientation
+ * @return currently selected screen orientation
+ */
+
+ ScreenOrientation screen_orientation() const { return screen_orientation_; }
+ /**
+ * @brief set_encryption_enabled sets if encryption is enabled or disabled
+ * @param enabled
+ */
+ void set_encryption_enabled(bool enabled) { encryption_enabled_ = enabled; }
+ /**
+ * @brief encryption_enabled
+ * @return true if encryption is enable
+ */
+ bool encryption_enabled() const { return encryption_enabled_; }
+ /**
+ * @brief set_context_menu_enabled sets context menu enabled
+ * @param enabled
+ */
+ void set_context_menu_enabled(bool enabled) {
+ context_menu_enabled_ = enabled;
+ }
+ /**
+ * @brief context_menu_enabled
+ * @return true if context menu is enabled
+ */
+ bool context_menu_enabled() const { return context_menu_enabled_; }
+ /**
+ * @brief set_background_support_enabled whether it is enabled
+ * @param enabled
+ */
+ void set_background_support_enabled(bool enabled) {
+ background_support_enabled_ = enabled;
+ }
+ /**
+ * @brief background_support_enabled
+ * @return true if background support is enabled
+ */
+ bool background_support_enabled() const {
+ return background_support_enabled_;
+ }
+ /**
+ * @brief set_install_location sets install location
+ * @param installLocation
+ */
+ void set_install_location(InstallLocation installLocation) {
+ install_location_ = installLocation;
+ }
+ /**
+ * @brief install_location
+ * @return what InstallLocation is chosen
+ */
+ InstallLocation install_location() const { return install_location_; }
+ /**
+ * @brief set_no_display sets is there is no display
+ * @param enabled
+ */
+ void set_no_display(bool enabled) { no_display_ = enabled; }
+ /**
+ * @brief no_display
+ * @return if there is no supoort for display
+ */
+ bool no_display() const { return no_display_; }
+ /**
+ * @brief set_indicator_presence sets indicator presence
+ * @param enabled
+ */
+ void set_indicator_presence(bool enabled) { indicator_presence_ = enabled; }
+ /**
+ * @brief indicator_presence
+ * @return if the indicator is present
+ */
+ bool indicator_presence() const { return indicator_presence_; }
+ /**
+ * @brief set_backbutton_presence sets if backbutton is present
+ * @param enabled
+ */
+ void set_backbutton_presence(bool enabled) { backbutton_presence_ = enabled; }
+ /**
+ * @brief backbutton_presence
+ * @return true if backbutton is present
+ */
+ bool backbutton_presence() const { return backbutton_presence_; }
+ /**
+ * @brief set_user_agent sets user_agent()
+ * @param user_agent
+ */
+ void set_user_agent(std::string user_agent) { user_agent_ = user_agent; }
+ /**
+ * @brief user_agent
+ * @return actual user agent
+ */
+ std::string user_agent() const { return user_agent_; }
+ /**
+ * @brief set_sound_mode sets sound mode
+ * @param soundMode
+ */
+ void set_sound_mode(SoundMode soundMode) { sound_mode_ = soundMode; }
+ /**
+ * @brief sound_mode
+ * @return current sound mode
+ */
+ SoundMode sound_mode() const { return sound_mode_; }
+ /**
+ * @brief set_background_vibration set background vibration
+ * @param enabled
+ */
+ void set_background_vibration(bool enabled) {
+ background_vibration_ = enabled;
+ }
+ /**
+ * @brief background_vibration
+ * @return background vibration
+ */
+ bool background_vibration() const { return background_vibration_; }
+
+ private:
+ bool hwkey_enabled_;
+ ScreenOrientation screen_orientation_;
+ bool encryption_enabled_;
+ bool context_menu_enabled_;
+ bool background_support_enabled_;
+ InstallLocation install_location_;
+ bool no_display_;
+ bool indicator_presence_;
+ bool backbutton_presence_;
+ std::string user_agent_;
+ SoundMode sound_mode_;
+ bool background_vibration_;
+};
+
+/**
+ * @brief The SettingHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:setting>.
+ */
+class SettingHandler : public parser::ManifestHandler {
+ public:
+ SettingHandler();
+ virtual ~SettingHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& application,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+};
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_SETTING_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/splash_screen_handler.h"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <algorithm>
+#include <cassert>
+#include <cstdlib>
+#include <map>
+#include <utility>
+
+#include "manifest_parser/utils/logging.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace bf = boost::filesystem;
+namespace keys = wgt::application_widget_keys;
+namespace wgt_parse = wgt::parse;
+
+namespace {
+const char kTizenSplashScreenSrcKey[] = "@src";
+const char kTizenSplashScreenKey[] = "widget.splash-screen";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kTagDelimiter[] = " ";
+const char kFirstPaint[] = "first-paint";
+const char kComplete[] = "complete";
+const char kCustom[] = "custom";
+const char kSplashScreenDefault[] = "widget.launch_screen.ls_default";
+const char kSplashScreenPortrait[] = "widget.launch_screen.ls_portrait";
+const char kSplashScreenLandscape[] = "widget.launch_screen.ls_landscape";
+const char kSplashScreenKey[] = "widget.launch_screen";
+const char kSplashScreenReadyWhen[] = "@ready_when";
+const char kSplashScreenBgColor[] = "@background_color";
+const char kSplashScreenBgImage[] = "@background_image";
+const char kSplashScreenImage[] = "@image";
+const char kSplashScreenImageBorder[] = "@image_border";
+const std::map<wgt_parse::ScreenOrientation, const char*> kOrientationMap = {
+ {wgt_parse::ScreenOrientation::AUTO, kSplashScreenDefault},
+ {wgt_parse::ScreenOrientation::LANDSCAPE, kSplashScreenLandscape},
+ {wgt_parse::ScreenOrientation::PORTRAIT, kSplashScreenPortrait}};
+
+std::shared_ptr< wgt_parse::Color>
+ConvertStringToColor(const std::string& color_str) {
+ auto to_long = [&color_str](unsigned int start, unsigned int end) -> int {
+ return std::strtoul(color_str.substr(start, end).c_str(), 0, 16);
+ };
+ std::shared_ptr<wgt_parse::Color> color(new wgt_parse::Color);
+ switch (color_str.size()) {
+ case 3:
+ color->red = to_long(0, 0);
+ color->green = to_long(1, 1);
+ color->blue = to_long(2, 1);
+ break;
+ case 6:
+ color->red = to_long(0, 2);
+ color->green = to_long(2, 2);
+ color->blue = to_long(4, 2);
+ }
+ return color;
+}
+
+bool IsStringToColorConvertable(const std::string& string_color) {
+ return string_color[0] == '#' &&
+ (string_color.size() == 4 || string_color.size() == 7);
+}
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+std::string SplashScreenInfo::Key() {
+ return kTizenSplashScreenKey;
+}
+
+bool SplashScreenHandler::ParseSingleOrientation(
+ const parser::Manifest& manifest, ScreenOrientation orientation,
+ SplashScreenInfo* ss_info) {
+ auto dict_element_parser =
+ [this](SplashScreenData& splash_screen,
+ const parser::DictionaryValue* dict) -> bool {
+ if (!parser::VerifyElementNamespace(*dict, kTizenNamespacePrefix))
+ return false;
+
+ bool parsed_color = ParseColor(dict, &splash_screen);
+ ParseElement(dict, &splash_screen.background_image, kSplashScreenBgImage);
+ ParseElement(dict, &splash_screen.image, kSplashScreenImage);
+ ParseElement(dict, &splash_screen.image_border, kSplashScreenImageBorder);
+
+ return parsed_color || !splash_screen.background_image.empty() ||
+ !splash_screen.image.empty();
+ };
+
+ auto orientation_chosen = kOrientationMap.at(orientation);
+ SplashScreenData splash_screen;
+
+ bool valid_element = false;
+ for (auto& dict_element :
+ parser::GetOneOrMany(manifest.value(),
+ orientation_chosen,
+ kTizenNamespacePrefix)) {
+ if (dict_element_parser(splash_screen, dict_element))
+ valid_element = true;
+ }
+ if (!valid_element) return false;
+
+ ss_info->set_splash_screen_data(std::make_pair(orientation, splash_screen));
+ return true;
+}
+
+bool SplashScreenHandler::ParseElement(const parser::DictionaryValue* dict,
+ std::vector<std::string>* to_be_saved,
+ const char* keyToParse) {
+ // TODO(w.kosowicz) check which elements not declared should cause fail
+ std::string element;
+ dict->GetString(keyToParse, &element);
+ boost::split(*to_be_saved, element, boost::is_any_of(kTagDelimiter));
+ return true;
+}
+
+bool SplashScreenHandler::ParseColor(const parser::DictionaryValue* dict,
+ SplashScreenData* splash_screen) {
+ std::string background_color;
+ if (!dict->GetString(kSplashScreenBgColor, &background_color) ||
+ !IsStringToColorConvertable(background_color))
+ return false;
+
+ std::string only_hex = background_color.substr(1);
+ if (!std::all_of(only_hex.begin(), only_hex.end(), isxdigit)) return false;
+
+ splash_screen->background_color = ConvertStringToColor(only_hex);
+ return true;
+}
+
+bool SplashScreenHandler::ParseReadyWhen(const parser::Manifest& manifest,
+ SplashScreenInfo* ss_info) {
+ auto dict_values = parser::GetOneOrMany(manifest.value(),
+ kSplashScreenKey,
+ kTizenNamespacePrefix);
+ if (dict_values.empty())
+ return false;
+
+ std::string ready_when;
+ dict_values[0]->GetAsString(&ready_when);
+
+ if (ready_when.empty()) return false;
+ if (ready_when != kFirstPaint && ready_when != kComplete &&
+ ready_when != kCustom)
+ return false;
+
+ std::map<std::string, std::function<void()>> ready_when_functors;
+ ready_when_functors[kFirstPaint] = std::bind(
+ &SplashScreenInfo::set_ready_when, ss_info, ReadyWhen::FIRSTPAINT);
+ ready_when_functors[kComplete] = std::bind(&SplashScreenInfo::set_ready_when,
+ ss_info, ReadyWhen::COMPLETE);
+ ready_when_functors[kCustom] =
+ std::bind(&SplashScreenInfo::set_ready_when, ss_info, ReadyWhen::CUSTOM);
+ ready_when_functors[ready_when]();
+
+ return true;
+}
+
+bool SplashScreenHandler::Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ auto ss_info = std::make_shared<SplashScreenInfo>();
+ if (!ParseReadyWhen(manifest, ss_info.get())) return false;
+
+ ParseSingleOrientation(manifest, ScreenOrientation::AUTO, ss_info.get());
+ ParseSingleOrientation(manifest, ScreenOrientation::LANDSCAPE, ss_info.get());
+ ParseSingleOrientation(manifest, ScreenOrientation::PORTRAIT, ss_info.get());
+
+ *output = std::static_pointer_cast<parser::ManifestData>(ss_info);
+
+ return true;
+}
+
+bool SplashScreenHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const SplashScreenInfo& splash_data =
+ static_cast<const SplashScreenInfo&>(data);
+ std::string src = splash_data.src();
+ // According to w3c specification splash screen image should be of one of
+ // below types.
+ if (src.compare(src.size() - 3, 3, "png") &&
+ src.compare(src.size() - 3, 3, "svg") &&
+ src.compare(src.size() - 3, 3, "gif") &&
+ src.compare(src.size() - 3, 3, "jpg")) {
+ *error = "Not supported file extension of splash image";
+ return false;
+ }
+ return true;
+}
+
+std::string SplashScreenHandler::Key() const {
+ return kTizenSplashScreenKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_SPLASH_SCREEN_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_SPLASH_SCREEN_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/setting_handler.h"
+
+namespace wgt {
+namespace parse {
+
+enum class ReadyWhen { FIRSTPAINT, COMPLETE, CUSTOM };
+
+enum class ScreenOrientation { AUTO, PORTRAIT, LANDSCAPE, NONE };
+
+struct Color {
+ unsigned char red;
+ unsigned char green;
+ unsigned char blue;
+};
+
+struct SplashScreenData {
+ ScreenOrientation orientation;
+ std::shared_ptr<Color> background_color;
+ std::vector<std::string> background_image;
+ std::vector<std::string> image;
+ std::vector<std::string> image_border;
+};
+
+class SplashScreenInfo : public parser::ManifestData {
+ public:
+ SplashScreenInfo() { }
+ virtual ~SplashScreenInfo() { }
+
+ static std::string Key();
+
+ void set_src(const std::string& src) { src_ = src; }
+ const std::string& src() const { return src_; }
+ void set_splash_screen_data(
+ std::pair<ScreenOrientation, SplashScreenData> splash_screen_data) {
+ splash_screen_data_.insert(splash_screen_data);
+ }
+ const std::map<ScreenOrientation, SplashScreenData>& splash_screen_data()
+ const {
+ return splash_screen_data_;
+ }
+ void set_ready_when(ReadyWhen ready_when) { ready_when_ = ready_when; }
+ ReadyWhen ready_when() const { return ready_when_; }
+
+ private:
+ std::string src_;
+ std::map<ScreenOrientation, SplashScreenData> splash_screen_data_;
+ ReadyWhen ready_when_;
+};
+
+/**
+ * @brief The SplashScreenHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:splash-screen>.
+ */
+class SplashScreenHandler : public parser::ManifestHandler {
+ public:
+ SplashScreenHandler() {}
+ virtual ~SplashScreenHandler() {}
+ bool Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ std::string Key() const override;
+
+ private:
+ bool ParseSingleOrientation(const parser::Manifest& manifest,
+ ScreenOrientation orientation,
+ SplashScreenInfo* ss_info);
+ bool ParseElement(const parser::DictionaryValue* dict,
+ std::vector<std::string>* to_be_saved,
+ const char* keyToParse);
+ bool ParseReadyWhen(const parser::Manifest& manifest,
+ SplashScreenInfo* ss_info);
+ bool ParseColor(const parser::DictionaryValue* dict,
+ SplashScreenData* splash_screen);
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_SPLASH_SCREEN_HANDLER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/tizen_application_handler.h"
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "manifest_parser/manifest_util.h"
+#include "manifest_parser/utils/version_number.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/platform_version.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+
+const char kTizenApplicationKey[] = "widget.application";
+const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets";
+const char kNamespaceKey[] = "@namespace";
+const char kTizenApplicationIdKey[] = "@id";
+const char kTizenApplicationPackageKey[] = "@package";
+const char kTizenApplicationLaunchModeKey[] = "@launch_mode";
+const char kTizenApplicationRequiredVersionKey[] = "@required_version";
+const utils::VersionNumber kLaunchModeRequiredVersion("2.4");
+} // namespace
+
+TizenApplicationInfo::TizenApplicationInfo() {}
+
+TizenApplicationInfo::~TizenApplicationInfo() {}
+
+TizenApplicationHandler::TizenApplicationHandler() {}
+
+TizenApplicationHandler::~TizenApplicationHandler() {}
+
+bool TizenApplicationHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output, std::string* error) {
+ std::shared_ptr<TizenApplicationInfo> app_info(new TizenApplicationInfo);
+ parser::Value* app_value = nullptr;
+ manifest.Get(kTizenApplicationKey, &app_value);
+ // Find an application element with tizen namespace
+ parser::DictionaryValue* app_dict;
+ std::string value;
+ bool found = false;
+ if (app_value && app_value->IsType(parser::Value::TYPE_DICTIONARY)) {
+ app_value->GetAsDictionary(&app_dict);
+ found = app_dict->GetString(kNamespaceKey, &value);
+ found = found && (value == kTizenNamespacePrefix);
+ } else if (app_value && app_value->IsType(parser::Value::TYPE_LIST)) {
+ parser::ListValue* list;
+ app_value->GetAsList(&list);
+ for (parser::ListValue::iterator it = list->begin(); it != list->end();
+ ++it) {
+ (*it)->GetAsDictionary(&app_dict);
+ app_dict->GetString(kNamespaceKey, &value);
+ bool is_tizen = (value == kTizenNamespacePrefix);
+ if (is_tizen) {
+ if (found) {
+ *error = "There should be no more than one tizen:application element";
+ return false;
+ }
+ found = true;
+ }
+ }
+ }
+
+ if (!found) {
+ *error =
+ "Cannot find application element with tizen namespace "
+ "or the tizen namespace prefix is incorrect.\n";
+ return false;
+ }
+ if (app_dict->GetString(kTizenApplicationIdKey, &value))
+ app_info->set_id(value);
+ if (app_dict->GetString(kTizenApplicationPackageKey, &value)) {
+ app_info->set_package(value);
+ }
+ if (app_dict->GetString(kTizenApplicationRequiredVersionKey, &value)) {
+ if (!value.empty()) {
+ utils::VersionNumber req_version(value);
+ utils::VersionNumber min_version = parser::GetMinimumPlatformVersion();
+ if (req_version < min_version) {
+ app_info->set_required_version(min_version.ToString());
+ } else {
+ app_info->set_required_version(value);
+ }
+ }
+ }
+
+ std::string launch_mode;
+ app_dict->GetString(kTizenApplicationLaunchModeKey, &launch_mode);
+ app_info->set_launch_mode(launch_mode);
+
+ *output = std::static_pointer_cast<parser::ManifestData>(app_info);
+ return true;
+}
+
+bool TizenApplicationHandler::Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const TizenApplicationInfo& app_info =
+ static_cast<const TizenApplicationInfo&>(data);
+
+ if (!parser::ValidateTizenApplicationId(app_info.id())) {
+ *error =
+ "The id property of application element "
+ "does not match the format\n";
+ return false;
+ }
+
+ if (!parser::ValidateTizenPackageId(app_info.package())) {
+ *error =
+ "The package property of application element "
+ "does not match the format\n";
+ return false;
+ }
+
+ if (app_info.id().find(app_info.package()) != 0) {
+ *error =
+ "The application element property id "
+ "does not start with package.\n";
+ return false;
+ }
+ if (app_info.required_version().empty()) {
+ *error =
+ "The required_version property of application "
+ "element does not exist.\n";
+ return false;
+ }
+ utils::VersionNumber supported_version = parser::GetCurrentPlatformVersion();
+ if (!supported_version.IsValid()) {
+ *error = "Cannot retrieve supported API version from platform";
+ return false;
+ }
+ utils::VersionNumber required_version(app_info.required_version());
+ if (!required_version.IsValid()) {
+ *error = "Cannot retrieve supported API version from widget";
+ return false;
+ }
+ if (supported_version < required_version) {
+ *error =
+ "The required_version of Tizen Web API "
+ "is not supported.\n";
+ return false;
+ }
+ if (required_version >= kLaunchModeRequiredVersion) {
+ if (app_info.launch_mode().empty()) {
+ // FIXME for now, this const_cast is used, but it is not the best way.
+ TizenApplicationInfo &tmp = const_cast<TizenApplicationInfo &>(app_info);
+ tmp.set_launch_mode("single"); // default parameter
+ } else if (app_info.launch_mode() != "caller" &&
+ app_info.launch_mode() != "group" &&
+ app_info.launch_mode() != "single") {
+ *error = "Wrong value of launch mode";
+ return false;
+ }
+ } else if (!app_info.launch_mode().empty()) {
+ *error = "launch_mode attribute cannot be used for api version lower"
+ " than 2.4";
+ return false;
+ }
+ return true;
+}
+
+std::string TizenApplicationInfo::Key() {
+ return kTizenApplicationKey;
+}
+
+std::string TizenApplicationHandler::Key() const {
+ return kTizenApplicationKey;
+}
+
+bool TizenApplicationHandler::AlwaysParseForKey() const { return true; }
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_TIZEN_APPLICATION_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_TIZEN_APPLICATION_HANDLER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+class TizenApplicationInfo : public parser::ManifestData {
+ public:
+ TizenApplicationInfo();
+ virtual ~TizenApplicationInfo();
+
+ static std::string Key();
+
+ void set_id(const std::string& id) {
+ id_ = id;
+ }
+ void set_launch_mode(const std::string& launch_mode) {
+ launch_mode_ = launch_mode;
+ }
+ void set_package(const std::string& package) {
+ package_ = package;
+ }
+ void set_required_version(
+ const std::string& required_version) {
+ required_version_ = required_version;
+ }
+ const std::string& id() const {
+ return id_;
+ }
+ const std::string& launch_mode() const {
+ return launch_mode_;
+ }
+ const std::string& package() const {
+ return package_;
+ }
+ const std::string& required_version() const {
+ return required_version_;
+ }
+
+ private:
+ std::string id_;
+ std::string launch_mode_;
+ std::string package_;
+ std::string required_version_;
+};
+
+/**
+ * @brief The TizenApplicationHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <tizen:application>.
+ */
+class TizenApplicationHandler : public parser::ManifestHandler {
+ public:
+ TizenApplicationHandler();
+ virtual ~TizenApplicationHandler();
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+ bool AlwaysParseForKey() const override;
+ std::string Key() const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_TIZEN_APPLICATION_HANDLER_H_
--- /dev/null
+// 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 "wgt_manifest_handlers/warp_handler.h"
+
+#include <string.h>
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+const char kAccessKey[] = "widget.access";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kAccessSubdomainsKey[] = "@subdomains";
+const char kAccessOriginKey[] = "@origin";
+}
+
+void WarpHandler::ParseSingleAccessElement(
+ const parser::DictionaryValue& item_dict,
+ std::shared_ptr<WarpInfo> info) {
+ std::string domain_name;
+ std::string subdomains_str;
+ bool subdomains = false;
+
+ if (item_dict.HasKey(kAccessSubdomainsKey)) {
+ item_dict.GetString(kAccessSubdomainsKey, &subdomains_str);
+ if (subdomains_str == "true")
+ subdomains = true;
+ }
+ // TODO(w.kosowicz): address validation
+ item_dict.GetString(kAccessOriginKey, &domain_name);
+ if (domain_name == "*")
+ subdomains = true;
+ info->set_access_element(std::make_pair(domain_name, subdomains));
+}
+
+bool WarpHandler::Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* /*error*/) {
+ if (!manifest.HasPath(kAccessKey))
+ return true;
+
+ auto info = std::make_shared<WarpInfo>();
+
+ for (const auto& dict : parser::GetOneOrMany(manifest.value(),
+ kAccessKey, kWidgetNamespacePrefix)) {
+ ParseSingleAccessElement(*dict, info);
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(info);
+
+ return true;
+}
+
+std::string WarpInfo::Key() {
+ return kAccessKey;
+}
+
+std::string WarpHandler::Key() const {
+ return kAccessKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// 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.
+
+#ifndef WGT_MANIFEST_HANDLERS_WARP_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_WARP_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "manifest_parser/values.h"
+#include "manifest_parser/manifest_handler.h"
+
+namespace wgt {
+namespace parse {
+
+class WarpInfo : public parser::ManifestData {
+ public:
+ static std::string Key();
+
+ WarpInfo() {}
+ ~WarpInfo() override {}
+ /**
+ * @brief set_access_element push single access_element inside vector
+ * @param access_element
+ */
+ void set_access_element(const std::pair<std::string, bool>& access_element) {
+ access_map_.push_back(access_element);
+ }
+ /**
+ * @brief access_map
+ * @return vector containing access_elements
+ */
+ const std::vector<std::pair<std::string, bool> >& access_map() const {
+ return access_map_;
+ }
+
+ private:
+ std::vector<std::pair<std::string, bool> > access_map_;
+};
+
+/**
+ * @brief The WarpHandler class
+ *
+ * Handler of config.xml for xml elements:
+ * - <w3c:access>.
+ */
+class WarpHandler : public parser::ManifestHandler {
+ public:
+ WarpHandler() {}
+ ~WarpHandler() override {}
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ void ParseSingleAccessElement(
+ const parser::DictionaryValue& item_dict,
+ std::shared_ptr<WarpInfo> info);
+ std::string Key() const override;
+};
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_WARP_HANDLER_H_
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "wgt_manifest_handlers/widget_config_parser.h"
+
+#include <boost/algorithm/string/classification.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/system/error_code.hpp>
+
+#include <xdgmime.h>
+
+#include <algorithm>
+#include <string>
+#include <map>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/logging.h"
+#include "wgt_manifest_handlers/account_handler.h"
+#include "wgt_manifest_handlers/app_control_handler.h"
+#include "wgt_manifest_handlers/application_icons_handler.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+#include "wgt_manifest_handlers/appwidget_handler.h"
+#include "wgt_manifest_handlers/background_category_handler.h"
+#include "wgt_manifest_handlers/category_handler.h"
+#include "wgt_manifest_handlers/content_handler.h"
+#include "wgt_manifest_handlers/csp_handler.h"
+#include "wgt_manifest_handlers/ime_handler.h"
+#include "wgt_manifest_handlers/metadata_handler.h"
+#include "wgt_manifest_handlers/navigation_handler.h"
+#include "wgt_manifest_handlers/permissions_handler.h"
+#include "wgt_manifest_handlers/service_handler.h"
+#include "wgt_manifest_handlers/setting_handler.h"
+#include "wgt_manifest_handlers/splash_screen_handler.h"
+#include "wgt_manifest_handlers/tizen_application_handler.h"
+#include "wgt_manifest_handlers/warp_handler.h"
+#include "wgt_manifest_handlers/widget_handler.h"
+
+namespace ba = boost::algorithm;
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+
+namespace {
+
+const char kLocaleDirectory[] = "locales";
+
+const char* kDefaultStartFiles[] = {
+ "index.htm",
+ "index.html",
+ "index.svg",
+ "index.xhtml",
+ "index.xht"
+};
+
+const char* kDefaultIconFiles[] = {
+ "icon.svg",
+ "icon.ico",
+ "icon.png",
+ "icon.gif",
+ "icon.jpg"
+};
+
+const std::map<std::string, std::string> kFileIdenticationTable = {
+ {".html", "text/html"},
+ {".htm", "text/html"},
+ {".css", "text/css"},
+ {".js", "application/javascript"},
+ {".xml", "application/xml"},
+ {".txt", "text/plain"},
+ {".wav", "audio/x-wav"},
+ {".xhtml", "application/xhtml+xml"},
+ {".xht", "application/xhtml+xml"},
+ {".gif", "image/gif"},
+ {".png", "image/png"},
+ {".ico", "image/vnd.microsoft.icon"},
+ {".svg", "image/svg+xml"},
+ {".jpg", "image/jpeg"},
+ {".mp3", "audio/mpeg"}
+};
+
+const char* kIconsSupportedMimeTypes[] = {
+ "image/gif",
+ "image/png",
+ "image/vnd.microsoft.icon",
+ "image/svg+xml",
+ "image/jpeg"
+};
+
+// http://www.w3.org/TR/widgets/#rule-for-identifying-the-media-type-of-a-file-0
+bool IsIconMimeTypeSupported(const bf::path& icon_path) {
+ std::string ext = icon_path.extension().string();
+ std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
+ std::string mime_type;
+ if (!ext.empty() && std::all_of(++ext.begin(), ext.end(), ::isalpha)) {
+ auto iter = kFileIdenticationTable.find(ext);
+ if (iter != kFileIdenticationTable.end()) {
+ mime_type = iter->second;
+ }
+ }
+ if (mime_type.empty()) {
+ // sniff the mime type
+ mime_type =
+ xdg_mime_get_mime_type_for_file(icon_path.string().c_str(), nullptr);
+ }
+ for (auto mime : kIconsSupportedMimeTypes) {
+ if (mime_type == mime)
+ return true;
+ }
+ return false;
+}
+
+enum class FindResult {
+ OK,
+ NUL,
+ ERROR
+};
+
+// http://www.w3.org/TR/widgets/#rule-for-finding-a-file-within-a-widget-package-0 // NOLINT
+FindResult FindFileWithinWidget(const bf::path& widget_path,
+ const std::string& content, bf::path* file = nullptr) {
+ std::string content_value = content;
+ if (content_value.empty())
+ return FindResult::ERROR;
+ if (content_value[0] == '/') {
+ content_value = content_value.substr(1);
+ }
+ // Steps 4. && 5.
+ std::vector<std::string> path_components;
+ ba::split(path_components, content_value, ba::is_any_of("/"));
+ if (path_components.size() >= 1 && path_components[0] == kLocaleDirectory) {
+ if (path_components.size() == 1) {
+ return FindResult::NUL;
+ }
+
+ // TODO(t.iwanek): validate language tag
+
+ path_components.erase(path_components.begin(), ++++path_components.begin());
+ content_value = ba::join(path_components, "/");
+ }
+ // for each locale in widget
+ // TODO(t.iwanek): this algorithm should accept input of preferred locale list
+ bs::error_code error;
+ bf::path locale_directory = widget_path / kLocaleDirectory;
+ if (bf::exists(locale_directory, error)) {
+ for (auto iter = bf::directory_iterator(locale_directory);
+ iter != bf::directory_iterator(); ++iter) {
+ const bf::path& path = *iter;
+
+ // TODO(t.iwanek): validate language tag
+
+ bf::path candidate = path / content_value;
+ if (bf::exists(candidate, error)) {
+ if (bf::is_directory(candidate, error)) {
+ return FindResult::ERROR;
+ }
+ if (file)
+ *file = candidate;
+ return FindResult::OK;
+ }
+ }
+ }
+
+ // default locale
+ bf::path root_candidate = widget_path / content_value;
+ if (bf::exists(root_candidate, error)) {
+ if (bf::is_directory(root_candidate, error)) {
+ return FindResult::ERROR;
+ }
+ if (file)
+ *file = root_candidate;
+ return FindResult::OK;
+ }
+
+ return FindResult::NUL;
+}
+
+bool CheckW3CContentSrcExits(const bf::path& widget_path,
+ const std::string& content) {
+ if (!content.empty()) {
+ if (FindFileWithinWidget(widget_path, content) == FindResult::OK) {
+ return true;
+ }
+ }
+ return false;
+}
+
+// http://www.w3.org/TR/widgets/#step-8-locate-the-start-file
+bool CheckStartFileInWidget(const bf::path& widget_path) {
+ for (auto& file : kDefaultStartFiles) {
+ if (FindFileWithinWidget(widget_path, file) == FindResult::OK) {
+ LOG(INFO) << "Start file is: " << file;
+ return true;
+ }
+ }
+ LOG(ERROR) << "No valid start file found";
+ return false;
+}
+
+} // namespace
+
+namespace wgt {
+namespace parse {
+
+WidgetConfigParser::WidgetConfigParser() {
+ std::vector<parser::ManifestHandler*> handlers = {
+ new AccountHandler,
+ new AppControlHandler,
+ new ApplicationIconsHandler,
+ new AppWidgetHandler,
+ new CategoryHandler,
+ new ContentHandler,
+ new CSPHandler(CSPHandler::SecurityType::CSP),
+ new CSPHandler(CSPHandler::SecurityType::CSP_REPORT_ONLY),
+ new ImeHandler,
+ new MetaDataHandler,
+ new NavigationHandler,
+ new PermissionsHandler,
+ new ServiceHandler,
+ new SettingHandler,
+ new SplashScreenHandler,
+ new TizenApplicationHandler,
+ new WarpHandler,
+ new WidgetHandler,
+ new BackgroundCategoryHandler
+ };
+
+ std::unique_ptr<parser::ManifestHandlerRegistry> registry(
+ new parser::ManifestHandlerRegistry(handlers));
+
+ parser_.reset(new parser::ManifestParser(std::move(registry)));
+}
+
+std::shared_ptr<const parser::ManifestData> WidgetConfigParser::GetManifestData(
+ const std::string& key) {
+ // TODO(t.iwanek): replace this method with required getters
+ // do not force client to use keyys from application_manifest_constants
+ return parser_->GetManifestData(key);
+}
+
+const std::string& WidgetConfigParser::GetErrorMessage() const {
+ if (!error_.empty())
+ return error_;
+ return parser_->GetErrorMessage();
+}
+
+bool WidgetConfigParser::CheckStartFile() {
+ std::shared_ptr<const ContentInfo> content_info =
+ std::static_pointer_cast<const ContentInfo>(parser_->GetManifestData(
+ ContentInfo::Key()));
+ if (content_info) {
+ std::string content = content_info->src();
+ if (content_info->is_tizen_content()) {
+ // tizen:content may be external url
+ if (parser::utils::IsValidIRI(content))
+ return true;
+ }
+
+ if (CheckW3CContentSrcExits(widget_path_, content)) {
+ // Content is valid
+ LOG(INFO) << "Start file is: " << content
+ << " type: " << content_info->type()
+ << " encoding: " << content_info->encoding();
+
+ return true;
+ } else {
+ // Remove content as it is invalid
+ parser_->EraseManifestData(ContentInfo::Key());
+ }
+ }
+
+ if (!CheckStartFileInWidget(widget_path_)) {
+ parser_->EraseManifestData(ContentInfo::Key());
+ error_ = "Could not find valid start file";
+ return false;
+ }
+ return true;
+}
+
+bool WidgetConfigParser::CheckServicesStartFiles() {
+ std::shared_ptr<const ServiceList> service_list =
+ std::static_pointer_cast<const ServiceList>(
+ parser_->GetManifestData(ServiceInfo::Key()));
+ if (!service_list)
+ return true;
+ for (auto& service_info : service_list->services) {
+ bf::path start_file = widget_path_ / service_info.content();
+ if (!bf::exists(start_file)) {
+ error_ = std::string("Could not find valid service start file: ")
+ + start_file.string();
+ return false;
+ }
+ }
+ return true;
+}
+
+bool WidgetConfigParser::CheckWidgetIcons() {
+ std::shared_ptr<ApplicationIconsInfo> icons_info =
+ std::static_pointer_cast<ApplicationIconsInfo>(
+ parser_->AccessManifestData(application_manifest_keys::kIconsKey));
+ if (!icons_info) {
+ error_ = "Failed to get icon info";
+ return false;
+ }
+ ApplicationIconsInfo icons;
+ // custom icons
+ for (auto& icon : icons_info->icons()) {
+ bf::path result;
+ if (FindFileWithinWidget(widget_path_, icon.path(), &result)
+ == FindResult::OK) {
+ if (!IsIconMimeTypeSupported(result)) {
+ LOG(WARNING) << "Unsupported icon: " << result;
+ continue;
+ }
+ std::string relative =
+ result.string().substr(widget_path_.string().size() + 1);
+ int width = -1;
+ int height = -1;
+ icon.GetWidth(&width);
+ icon.GetHeight(&height);
+ icons.AddIcon(ApplicationIcon(relative, height, width));
+ }
+ }
+ // default icons
+ for (auto& icon : kDefaultIconFiles) {
+ bf::path result;
+ if (FindFileWithinWidget(widget_path_, icon, &result)
+ == FindResult::OK) {
+ if (!IsIconMimeTypeSupported(result)) {
+ LOG(WARNING) << "Unsupported icon: " << result;
+ continue;
+ }
+ std::string relative =
+ result.string().substr(widget_path_.string().size() + 1);
+ icons.AddIcon(ApplicationIcon(relative));
+ }
+ }
+ for (auto& icon : icons.icons()) {
+ LOG(DEBUG) << "Valid icon: " << icon.path();
+ int value = 0;
+ if (icon.GetWidth(&value))
+ LOG(DEBUG) << " with width: " << value;
+ if (icon.GetHeight(&value))
+ LOG(DEBUG) << " with height: " << value;
+ }
+ *icons_info = icons;
+ return true;
+}
+
+bool WidgetConfigParser::ParseManifest(const boost::filesystem::path& path) {
+ widget_path_ = path.parent_path();
+ if (!parser_->ParseManifest(path))
+ return false;
+
+ if (!CheckWidgetIcons())
+ return false;
+
+ has_valid_start_file_ = CheckStartFile();
+ has_valid_services_start_files_ = CheckServicesStartFiles();
+
+ return true;
+}
+
+bool WidgetConfigParser::HasValidStartFile() const {
+ return has_valid_start_file_;
+}
+
+bool WidgetConfigParser::HasValidServicesStartFiles() const {
+ return has_valid_services_start_files_;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache 2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef WGT_MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
+#define WGT_MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
+
+#include <boost/filesystem/path.hpp>
+
+#include <memory>
+#include <string>
+
+#include "manifest_parser/manifest_parser.h"
+
+namespace wgt {
+namespace parse {
+
+/**
+ * @brief The WidgetConfigParser class
+ * Parser class of widget's config.xml configuration file.
+ *
+ * Instance of this class may be used to parse single configuration file.
+ * Depending on boolean result of @ref ParseManifest method, client code may
+ * call:
+ * - on success -> @ref GetManifestData(), passing the key of ManifestData
+ * instance that it is interested in.
+ * - on failure -> @ref GetErrorMessage(), to get value of error which was set
+ * during the processing of config.xml
+ *
+ * Additional check of presence of start files may be done via calling
+ * @ref HasValidStartFile(). This method is extracted separetly as missing start
+ * file will not cause the failure of parsing the config.xml file.
+ *
+ * To investigate which key do you need to get certain parsed piece of data,
+ * check the key reported by handler's @ref ManifestHandler::Key() method.
+ * Key returned by this method is the key to access data set by handler.
+ */
+class WidgetConfigParser {
+ public:
+ WidgetConfigParser();
+
+ std::shared_ptr<const parser::ManifestData> GetManifestData(
+ const std::string& key);
+ const std::string& GetErrorMessage() const;
+ bool ParseManifest(const boost::filesystem::path& path);
+ /**
+ * @brief HasValidStartFile
+ * @return true valid start file exists
+ */
+ bool HasValidStartFile() const;
+ /**
+ * @brief HasValidServicesStartFiles
+ * @return true if has valid service start files
+ */
+ bool HasValidServicesStartFiles() const;
+
+ private:
+ /**
+ * @brief CheckStartFile
+ * @return true if start file is correct
+ */
+ bool CheckStartFile();
+ /**
+ * @brief CheckServicesStartFiles
+ * @return true if services start files are correct
+ */
+ bool CheckServicesStartFiles();
+ // This function creates list of icons that are valid disregarding
+ // (in actual version) current system's locale as installer do not need to
+ // know about it.
+ // Edited/Created list is present as kIconsKey key in parser.
+ /**
+ * @brief CheckWidgetIcons
+ * @return true if widget icons are correct
+ */
+ bool CheckWidgetIcons();
+
+ std::unique_ptr<parser::ManifestParser> parser_;
+ boost::filesystem::path widget_path_;
+ std::string error_;
+ bool has_valid_start_file_;
+ bool has_valid_services_start_files_;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_WIDGET_CONFIG_PARSER_H_
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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.
+
+#include "wgt_manifest_handlers/widget_handler.h"
+
+#include <string.h>
+
+#include <algorithm>
+#include <cassert>
+#include <map>
+#include <utility>
+#include <set>
+
+#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/language_tag_validator.h"
+#include "manifest_parser/utils/logging.h"
+#include "manifest_parser/values.h"
+#include "wgt_manifest_handlers/application_manifest_constants.h"
+
+namespace wgt {
+namespace parse {
+
+namespace {
+const char kWidgetKey[] = "widget";
+
+const char kAuthorKey[] = "widget.author";
+const char kWidgetNamespacePrefix[] = "http://www.w3.org/ns/widgets";
+const char kWidgetNamespaceKey[] = "widget.@namespace";
+const char kAuthorHrefKey[] = "@href";
+const char kAuthorEmailKey[] = "@email";
+const char kVersionKey[] = "widget.@version";
+const char kNameKey[] = "widget.name";
+const char kPreferencesNameKey[] = "@name";
+const char kPreferencesValueKey[] = "@value";
+const char kPreferencesReadonlyKey[] = "@readonly";
+const char kXmlLangKey[] = "@lang";
+const char kXmlHrefKey[] = "@href";
+const char kLicenseKey[] = "widget.license";
+const char kShortKey[] = "@short";
+const char kWidgetLangKey[] = "widget.@lang";
+const char kIDKey[] = "widget.@id";
+const char kHeightKey[] = "widget.@height";
+const char kWidthKey[] = "widget.@width";
+const char kDefaultLocaleKey[] = "widget.@defaultlocale";
+const char kViewModesKey[] = "widget.@viewmodes";
+const char kPreferencesKey[] = "widget.preference";
+const char kXmlTextKey[] = "#text";
+const char kDescriptionKey[] = "widget.description";
+
+bool ParserPreferenceItem(const parser::Value* val, Preference** output,
+ std::string* error) {
+ const parser::DictionaryValue* pref_dict;
+ if (!val->GetAsDictionary(&pref_dict)) {
+ *error = "Parsing preference element failed";
+ return false;
+ }
+ std::string name;
+ std::string value;
+ std::string readonly = "false";
+ pref_dict->GetString(kPreferencesNameKey, &name);
+ pref_dict->GetString(kPreferencesValueKey, &value);
+ pref_dict->GetString(kPreferencesReadonlyKey, &readonly);
+ *output = new Preference(name, value, readonly == "true");
+ return true;
+}
+
+} // namespace
+
+void WidgetHandler::ParseSingleLocalizedLicenseElement(
+ const parser::DictionaryValue* item_dict, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ bool lang_overwriten = false;
+ std::string lang;
+ std::string text;
+ std::string href;
+
+ if (item_dict->HasKey(kXmlLangKey)) {
+ lang_overwriten = true;
+ item_dict->GetString(kXmlLangKey, &lang);
+ if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
+ LOG(ERROR) << "Tag " << lang << " is invalid";
+ return;
+ }
+ }
+ if (item_dict->HasKey(kXmlHrefKey)) {
+ item_dict->GetString(kXmlHrefKey, &href);
+ }
+ item_dict->GetString(kXmlTextKey, &text);
+ // TODO(w.kosowicz) check where href should be put...
+ if (lang_overwriten) {
+ info->license_set_.insert(std::make_pair(lang, text + href));
+ } else {
+ info->license_set_.insert(std::make_pair(parent_lang, text + href));
+ }
+}
+
+void WidgetHandler::ParseLocalizedLicenseElements(
+ const parser::Manifest& manifest, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ if (!manifest.HasPath(kLicenseKey)) return;
+
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (manifest.Get(kLicenseKey, &val)) {
+ if (val->GetAsDictionary(&dict)) {
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedLicenseElement(dict, parent_lang, info);
+ } else if (val->GetAsList(&list)) {
+ for_each(list->begin(), list->end(),
+ [list, &dict, parent_lang, info, this](parser::Value* item) {
+ if (item->GetAsDictionary(&dict))
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedLicenseElement(dict, parent_lang, info);
+ });
+ }
+ }
+}
+
+void WidgetHandler::ParseSingleLocalizedDescriptionElement(
+ const parser::DictionaryValue* item_dict, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ bool lang_overwriten = false;
+ std::string lang;
+ std::string text;
+
+ if (item_dict->HasKey(kXmlLangKey)) {
+ lang_overwriten = true;
+ item_dict->GetString(kXmlLangKey, &lang);
+ if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
+ LOG(ERROR) << "Tag " << lang << " is invalid";
+ return;
+ }
+ }
+ item_dict->GetString(kXmlTextKey, &text);
+ if (lang_overwriten) {
+ info->description_set_.insert(std::make_pair(lang, text));
+ } else {
+ info->description_set_.insert(std::make_pair(parent_lang, text));
+ }
+}
+
+void WidgetHandler::ParseLocalizedDescriptionElements(
+ const parser::Manifest& manifest, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ if (!manifest.HasPath(kDescriptionKey)) return;
+
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (manifest.Get(kDescriptionKey, &val)) {
+ if (val->GetAsDictionary(&dict)) {
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedDescriptionElement(dict, parent_lang, info);
+ } else if (val->GetAsList(&list)) {
+ for (auto& item : *list)
+ if (item->GetAsDictionary(&dict))
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedDescriptionElement(dict, parent_lang, info);
+ }
+ }
+}
+
+void WidgetHandler::ParseSingleLocalizedNameElement(
+ const parser::DictionaryValue* item_dict, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ bool lang_overwriten = false;
+ std::string lang;
+ std::string name;
+ std::string short_name;
+
+ if (item_dict->HasKey(kXmlLangKey)) {
+ lang_overwriten = true;
+ item_dict->GetString(kXmlLangKey, &lang);
+ if (!utils::w3c_languages::ValidateLanguageTag(lang)) {
+ LOG(ERROR) << "Tag " << lang << " is invalid";
+ return;
+ }
+ }
+ if (item_dict->HasKey(kShortKey)) {
+ item_dict->GetString(kShortKey, &short_name);
+ }
+ item_dict->GetString(kXmlTextKey, &name);
+
+ // ignore if given language already spotted
+ if (info->name_set_.find(lang) != info->name_set_.end()) return;
+
+ if (lang_overwriten) {
+ info->name_set_.insert(std::make_pair(lang, name));
+ if (!short_name.empty())
+ info->short_name_set_.insert(std::make_pair(lang, short_name));
+ } else {
+ info->name_set_.insert(std::make_pair(parent_lang, name));
+ if (!short_name.empty())
+ info->short_name_set_.insert(std::make_pair(parent_lang, short_name));
+ }
+}
+
+void WidgetHandler::ParseLocalizedNameElements(
+ const parser::Manifest& manifest, const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info) {
+ if (!manifest.HasPath(kNameKey)) return;
+
+ const parser::Value* val = nullptr;
+ const parser::DictionaryValue* dict = nullptr;
+ const parser::ListValue* list = nullptr;
+ if (manifest.Get(kNameKey, &val)) {
+ if (val->GetAsDictionary(&dict)) {
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedNameElement(dict, parent_lang, info);
+ } else if (val->GetAsList(&list)) {
+ for (auto& item : *list)
+ if (item->GetAsDictionary(&dict))
+ if (parser::VerifyElementNamespace(*dict, kWidgetNamespacePrefix))
+ ParseSingleLocalizedNameElement(dict, parent_lang, info);
+ }
+ }
+}
+
+void WidgetHandler::ParseSingleAuthorElement(
+ const parser::DictionaryValue* author_dict,
+ std::shared_ptr<WidgetInfo> info) {
+ author_dict->GetString(kXmlTextKey, &info->author_);
+ author_dict->GetString(kAuthorEmailKey, &info->author_email_);
+ std::string author_href;
+ author_dict->GetString(kAuthorHrefKey, &author_href);
+ if (!author_href.empty() && parser::utils::IsValidIRI(author_href))
+ info->author_href_ = author_href;
+}
+
+void WidgetHandler::ParseAuthorElements(const parser::Manifest& manifest,
+ std::shared_ptr<WidgetInfo> info) {
+ if (manifest.HasPath(kAuthorKey)) {
+ const parser::Value* author_value = nullptr;
+ manifest.Get(kAuthorKey, &author_value);
+
+ auto& authors = parser::GetOneOrMany(manifest.value(), kAuthorKey,
+ kWidgetNamespacePrefix);
+ if (!authors.empty())
+ ParseSingleAuthorElement(authors[0], info);
+ }
+}
+
+bool WidgetHandler::Parse(const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) {
+ std::shared_ptr<WidgetInfo> widget_info(new WidgetInfo());
+ widget_info->preferences_ = std::vector<Preference*>();
+
+ std::string parent_lang;
+
+ if (manifest.HasPath(kWidgetNamespaceKey)) {
+ manifest.GetString(kWidgetNamespaceKey, &widget_info->widget_namespace_);
+ manifest.GetString(kWidgetLangKey, &parent_lang);
+ }
+
+ if (widget_info->widget_namespace_ != kWidgetNamespacePrefix) {
+ *error = "Wrong namespace of <widget> element. Config.xml is invalid";
+ return false;
+ }
+
+ ParseAuthorElements(manifest, widget_info);
+
+ ParseLocalizedDescriptionElements(manifest, parent_lang, widget_info);
+ ParseLocalizedNameElements(manifest, parent_lang, widget_info);
+ ParseLocalizedLicenseElements(manifest, parent_lang, widget_info);
+
+ if (manifest.HasPath(kVersionKey))
+ manifest.GetString(kVersionKey, &widget_info->version_);
+ if (manifest.HasPath(kIDKey)) {
+ std::string id;
+ manifest.GetString(kIDKey, &id);
+ if (!id.empty() && parser::utils::IsValidIRI(id)) widget_info->id_ = id;
+ }
+ if (manifest.HasPath(kHeightKey)) {
+ int h;
+ manifest.GetInteger(kHeightKey, &h);
+ widget_info->height_ = static_cast<unsigned int>(h);
+ }
+ if (manifest.HasPath(kWidthKey)) {
+ int w;
+ manifest.GetInteger(kWidthKey, &w);
+ widget_info->width_ = static_cast<unsigned int>(w);
+ }
+ if (manifest.HasPath(kDefaultLocaleKey))
+ manifest.GetString(kDefaultLocaleKey, &widget_info->default_locale_);
+ if (manifest.HasPath(kViewModesKey))
+ manifest.GetString(kViewModesKey, &widget_info->viewmodes_);
+
+ for (auto& pref_dict : parser::GetOneOrMany(manifest.value(),
+ kPreferencesKey,
+ kWidgetNamespacePrefix)) {
+ Preference* preference = nullptr;
+ if (!ParserPreferenceItem(pref_dict, &preference, error))
+ return false;
+ widget_info->preferences_.push_back(preference);
+ }
+
+ *output = std::static_pointer_cast<parser::ManifestData>(widget_info);
+ return true;
+}
+
+bool WidgetHandler::Validate(const parser::ManifestData& data,
+ const parser::ManifestDataMap& /*handlers_output*/,
+ std::string* error) const {
+ const WidgetInfo& widget_info = static_cast<const WidgetInfo&>(data);
+ if (widget_info.widget_namespace() != kWidgetNamespacePrefix) {
+ *error = "The widget namespace is invalid.";
+ return false;
+ }
+ return true;
+}
+
+
+std::string WidgetHandler::Key() const {
+ return kWidgetKey;
+}
+
+std::string WidgetInfo::Key() {
+ return kWidgetKey;
+}
+
+} // namespace parse
+} // namespace wgt
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// 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 WGT_MANIFEST_HANDLERS_WIDGET_HANDLER_H_
+#define WGT_MANIFEST_HANDLERS_WIDGET_HANDLER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "manifest_parser/manifest_handler.h"
+#include "manifest_parser/values.h"
+
+namespace wgt {
+namespace parse {
+
+class Preference {
+ public:
+ Preference(const std::string& name, const std::string& value,
+ bool readonly)
+ : name_(name),
+ value_(value),
+ readonly_(readonly) {}
+
+ std::string Name() const { return name_; }
+ std::string Value() const { return value_; }
+ bool ReadOnly() const { return readonly_; }
+ private:
+ std::string name_;
+ std::string value_;
+ bool readonly_;
+};
+
+typedef std::map<std::string, std::string> LangValMap;
+
+class WidgetInfo : public parser::ManifestData {
+ public:
+ WidgetInfo() {}
+ WidgetInfo(const WidgetInfo&) = delete;
+ WidgetInfo& operator=(const WidgetInfo&) = delete;
+ virtual ~WidgetInfo() {
+ for (auto p : preferences_)
+ delete p;
+ }
+ static std::string Key();
+
+ const LangValMap& name_set() const { return name_set_; }
+ const LangValMap& short_name_set() const { return short_name_set_; }
+ const LangValMap& description_set() const { return description_set_; }
+ const LangValMap& license_set() const { return license_set_; }
+
+ const std::string& id() const { return id_; }
+ const std::string& version() const { return version_; }
+ const std::string& view_modes() const { return viewmodes_; }
+ const std::string& default_locale() const { return default_locale_; }
+ const std::string& author() const { return author_; }
+ const std::string& author_email() const { return author_email_; }
+ const std::string& author_href() const { return author_href_; }
+ const std::string& widget_namespace() const { return widget_namespace_; }
+ const std::vector<Preference*>& preferences() const { return preferences_; }
+ unsigned int height() const { return height_; }
+ unsigned int width() const { return width_; }
+
+ private:
+ std::vector<Preference*> preferences_;
+ std::string id_;
+ std::string version_;
+ std::string viewmodes_;
+ std::string default_locale_;
+ std::string author_;
+ LangValMap description_set_;
+ LangValMap name_set_;
+ LangValMap short_name_set_;
+ LangValMap license_set_;
+ std::string author_email_;
+ std::string author_href_;
+ std::string widget_namespace_;
+ unsigned int height_;
+ unsigned int width_;
+
+ friend class WidgetHandler;
+};
+
+/**
+ * @brief The WidgetHandler class
+ *
+ * Handler of config.xml for root xml element <w3c:widget>.
+ * Children parsed within this handlers:
+ * - <w3c:author>,
+ * - <w3c:description>,
+ * - <w3c:license>,
+ * - <w3c:name>,
+ * - <w3c:preference>.
+ *
+ * Code parsing rest of children is located in other handlers.
+ */
+class WidgetHandler : public parser::ManifestHandler {
+ public:
+ WidgetHandler() {}
+ virtual ~WidgetHandler() {}
+
+ bool Parse(
+ const parser::Manifest& manifest,
+ std::shared_ptr<parser::ManifestData>* output,
+ std::string* error) override;
+ bool AlwaysParseForKey() const override { return true; }
+ std::string Key() const override;
+ /**
+ * @brief ParseSingleLocalizedLicenseElement parses single license element
+ * @param item_dict
+ * @param parent_lang
+ * @param info
+ */
+ void ParseSingleLocalizedLicenseElement(
+ const parser::DictionaryValue* item_dict,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseLocalizedLicenseElements parser localized element
+ * @param manifest
+ * @param parent_lang
+ * @param info
+ */
+ void ParseLocalizedLicenseElements(
+ const parser::Manifest& manifest,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseSingleLocalizedDescriptionElement parses
+ * single localized description
+ * @param item_dict
+ * @param parent_lang
+ * @param info
+ */
+ void ParseSingleLocalizedDescriptionElement(
+ const parser::DictionaryValue* item_dict,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseLocalizedDescriptionElements parses localized description
+ * element
+ * @param manifest
+ * @param parent_lang
+ * @param info
+ */
+ void ParseLocalizedDescriptionElements(
+ const parser::Manifest& manifest,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseSingleLocalizedNameElement parses single localized name
+ * @param item_dict
+ * @param parent_lang
+ * @param info
+ */
+ void ParseSingleLocalizedNameElement(
+ const parser::DictionaryValue* item_dict,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseLocalizedNameElements parses localized name
+ * @param manifest
+ * @param parent_lang
+ * @param info
+ */
+ void ParseLocalizedNameElements(
+ const parser::Manifest& manifest,
+ const std::string& parent_lang,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseAuthorElements parses author element
+ * @param manifest
+ * @param info
+ */
+ void ParseAuthorElements(
+ const parser::Manifest& manifest,
+ std::shared_ptr<WidgetInfo> info);
+ /**
+ * @brief ParseSingleAuthorElement parses single author element
+ * @param author_dict
+ * @param info
+ */
+ void ParseSingleAuthorElement(
+ const parser::DictionaryValue* author_dict,
+ std::shared_ptr<WidgetInfo> info);
+
+ bool Validate(
+ const parser::ManifestData& data,
+ const parser::ManifestDataMap& handlers_output,
+ std::string* error) const override;
+};
+
+} // namespace parse
+} // namespace wgt
+
+#endif // WGT_MANIFEST_HANDLERS_WIDGET_HANDLER_H_