public:
ScopedTestingManifestHandlerRegistry(
const std::vector<ManifestHandler*>& handlers)
- : registry_(
- new ManifestHandlerRegistry(handlers)),
- prev_registry_(
- ManifestHandlerRegistry::GetInstance(Manifest::TYPE_MANIFEST)) {
- ManifestHandlerRegistry::SetInstanceForTesting(
- registry_, Manifest::TYPE_MANIFEST);
+ : registry_(new ManifestHandlerRegistry(handlers)),
+ prev_registry_(ManifestHandlerRegistry::GetInstance()) {
+ ManifestHandlerRegistry::SetInstanceForTesting(registry_);
}
~ScopedTestingManifestHandlerRegistry() {
- ManifestHandlerRegistry::SetInstanceForTesting(
- prev_registry_, Manifest::TYPE_MANIFEST);
+ ManifestHandlerRegistry::SetInstanceForTesting(prev_registry_);
}
ManifestHandlerRegistry* registry_;
ParsingWatcher* watcher)
: TestManifestHandler(name, keys, prereqs, watcher) {
}
-
- bool AlwaysParseForType(Manifest::Type type) const override {
- return true;
- }
};
class TestManifestValidator : public ManifestHandler {
return return_value_;
}
- bool AlwaysValidateForType(Manifest::Type type) const override {
+ bool AlwaysValidateForType() const override {
return always_validate_;
}
install_dir /= "good_manifest.xml";
std::string error;
- std::unique_ptr<Manifest> manifest(LoadManifest(install_dir.string(),
- Manifest::Type::TYPE_WIDGET,
- &error));
+ std::unique_ptr<Manifest> manifest(
+ widget_manifest_parser::LoadManifest(install_dir.string(), &error));
ASSERT_TRUE(error.empty());
std::shared_ptr<common_installer::widget_manifest_parser::ApplicationData>
app_data =
install_dir /= "test_samples";
install_dir /= "bad_manifest.xml";
std::string error;
- std::unique_ptr<Manifest> manifest(LoadManifest(install_dir.string(),
- Manifest::Type::TYPE_WIDGET,
- &error));
+ std::unique_ptr<Manifest> manifest(
+ widget_manifest_parser::LoadManifest(install_dir.string(), &error));
ASSERT_TRUE(!error.empty());
ASSERT_FALSE(error.empty());
ASSERT_STREQ("Manifest file is missing or unreadable.", error.c_str());
return nullptr;
ManifestHandlerRegistry* registry =
- ManifestHandlerRegistry::GetInstance(app_data->manifest_type());
+ ManifestHandlerRegistry::GetInstance();
if (!registry->ValidateAppManifest(app_data, error_message))
return nullptr;
std::string* error) {
assert(error);
ManifestHandlerRegistry* registry =
- ManifestHandlerRegistry::GetInstance(manifest_type());
+ ManifestHandlerRegistry::GetInstance();
if (!registry->ParseAppManifest(shared_from_this(), error))
return false;
bool ApplicationData::LoadName(std::string* error) {
assert(error);
std::string localized_name;
- std::string name_key(GetNameKey(manifest_type()));
+ std::string name_key(GetNameKey());
- if (!manifest_->GetString(name_key, &localized_name) &&
- manifest_type() == Manifest::TYPE_MANIFEST) {
+ if (!manifest_->GetString(name_key, &localized_name)) {
*error = errors::kInvalidName;
return false;
}
const bf::path& path() const { return path_; }
const std::string& URL() const { return application_url_; }
SourceType source_type() const { return source_type_; }
- Manifest::Type manifest_type() const { return manifest_->type(); }
const std::string& ID() const { return application_id_; }
std::string GetPackageID() const;
const std::string Version() const { return version_; }
namespace widget_manifest_parser {
-const char* GetNameKey(Manifest::Type /*manifest_type*/) {
+const char* GetNameKey() {
return application_widget_keys::kNameKey;
}
-const char* GetVersionKey(Manifest::Type /*manifest_type*/) {
+const char* GetVersionKey() {
return application_widget_keys::kVersionKey;
}
-const char* GetCSPKey(Manifest::Type /*manifest_type*/) {
+const char* GetCSPKey() {
return application_widget_keys::kCSPKey;
}
-const char* GetTizenAppIdKey(Manifest::Type /*manifest_type*/) {
+const char* GetTizenAppIdKey() {
return application_widget_keys::kTizenAppIdKey;
}
-const char* GetIcon128Key(Manifest::Type /*manifest_type*/) {
+const char* GetIcon128Key() {
return application_widget_keys::kIcon128Key;
}
} // namespace application_manifest_errors
namespace widget_manifest_parser {
-const char* GetNameKey(Manifest::Type type);
-const char* GetCSPKey(Manifest::Type type);
-const char* GetTizenAppIdKey(Manifest::Type type);
-const char* GetIcon128Key(Manifest::Type type);
+const char* GetNameKey();
+const char* GetCSPKey();
+const char* GetTizenAppIdKey();
+const char* GetIcon128Key();
} // namespace widget_manifest_parser
} // namespace common_installer
} // namespace
-Manifest::Manifest(std::unique_ptr<utils::DictionaryValue> value, Type type)
+Manifest::Manifest(std::unique_ptr<utils::DictionaryValue> value)
: data_(std::move(value)),
- i18n_data_(new utils::DictionaryValue),
- type_(type) {
+ i18n_data_(new utils::DictionaryValue) {
if (data_->HasKey(widget_keys::kWidgetKey) &&
data_->Get(widget_keys::kWidgetKey, nullptr))
Manifest* Manifest::DeepCopy() const {
Manifest* manifest = new Manifest(
- std::unique_ptr<utils::DictionaryValue>(data_->DeepCopy()),
- type());
+ std::unique_ptr<utils::DictionaryValue>(data_->DeepCopy()));
return manifest;
}
// properties of the manifest using ManifestFeatureProvider.
class Manifest {
public:
- enum Type {
- TYPE_MANIFEST, // Corresponds to w3c.github.io/manifest
- TYPE_WIDGET // Corresponds to http://www.w3.org/TR/widgets
- };
-
explicit Manifest(
- std::unique_ptr<utils::DictionaryValue> value, Type type = TYPE_MANIFEST);
+ std::unique_ptr<utils::DictionaryValue> value);
~Manifest();
// Returns false and |error| will be non-empty if the manifest is malformed.
// be specified by the application type.
bool ValidateManifest(std::string* error) const;
- // Returns the manifest type.
- Type type() const { return type_; }
-
// These access the wrapped manifest value, returning false when the property
// does not exist or if the manifest type can't access it.
bool HasKey(const std::string& key) const;
std::string default_locale_;
std::unique_ptr<std::list<std::string> > user_agent_locales_;
- Type type_;
-
DISALLOW_COPY_AND_ASSIGN(Manifest);
};
return true;
}
-bool ManifestHandler::AlwaysParseForType(Manifest::Type /*type*/) const {
- return false;
-}
-
-bool ManifestHandler::AlwaysValidateForType(Manifest::Type /*type*/) const {
+bool ManifestHandler::AlwaysValidateForType() const {
return false;
}
}
ManifestHandlerRegistry*
-ManifestHandlerRegistry::GetInstance(Manifest::Type /*type*/) {
+ManifestHandlerRegistry::GetInstance() {
return GetInstanceForWGT();
}
for (ManifestHandlerMap::iterator iter = handlers_.begin();
iter != handlers_.end(); ++iter) {
ManifestHandler* handler = iter->second;
- if (application->GetManifest()->HasPath(iter->first) ||
- handler->AlwaysParseForType(application->manifest_type())) {
- handlers_by_order[order_map_[handler]] = handler;
- }
+ handlers_by_order[order_map_[handler]] = handler;
}
for (std::map<int, ManifestHandler*>::iterator iter =
handlers_by_order.begin();
iter != handlers_.end(); ++iter) {
ManifestHandler* handler = iter->second;
if ((application->GetManifest()->HasPath(iter->first) ||
- handler->AlwaysValidateForType(application->manifest_type())) &&
+ handler->AlwaysValidateForType()) &&
!handler->Validate(application, error))
return false;
}
// static
void ManifestHandlerRegistry::SetInstanceForTesting(
- ManifestHandlerRegistry* registry, Manifest::Type /*type*/) {
+ ManifestHandlerRegistry* registry) {
widget_registry_ = registry;
return;
}
virtual bool Validate(std::shared_ptr<const ApplicationData> application,
std::string* error) const;
- // If false (the default), only parse the manifest if a registered
- // key is present in the manifest. If true, always attempt to parse
- // the manifest for this application type, even if no registered keys
- // are present. This allows specifying a default parsed value for
- // application that don't declare our key in the manifest.
- virtual bool AlwaysParseForType(Manifest::Type type) const;
-
// Same as AlwaysParseForType, but for Validate instead of Parse.
- virtual bool AlwaysValidateForType(Manifest::Type type) const;
+ virtual bool AlwaysValidateForType() const;
// The list of keys that, if present, should be parsed before calling our
// Parse (typically, because our Parse needs to read those keys).
public:
~ManifestHandlerRegistry();
- static ManifestHandlerRegistry* GetInstance(Manifest::Type type);
+ static ManifestHandlerRegistry* GetInstance();
bool ParseAppManifest(
std::shared_ptr<ApplicationData> application, std::string* error);
void ReorderHandlersGivenDependencies();
// Sets a new global registry, for testing purposes.
- static void SetInstanceForTesting(ManifestHandlerRegistry* registry,
- Manifest::Type type);
+ static void SetInstanceForTesting(ManifestHandlerRegistry* registry);
static ManifestHandlerRegistry* GetInstanceForWGT();
- static ManifestHandlerRegistry* GetInstanceForXPK();
typedef std::map<std::string, ManifestHandler*> ManifestHandlerMap;
typedef std::map<ManifestHandler*, int> ManifestHandlerOrderMap;
// Handlers are executed in order; lowest order first.
ManifestHandlerOrderMap order_map_;
- static ManifestHandlerRegistry* xpk_registry_;
static ManifestHandlerRegistry* widget_registry_;
};
#include "widget-manifest-parser/manifest_handlers/category_handler.h"
+#include "utils/logging.h"
#include "utils/values.h"
#include "widget-manifest-parser/application_manifest_constants.h"
if (!ParseCategoryEntryAndStore(*dict, aplist.get()))
return false;
} else {
- *error = kErrMsgCategory;
- return false;
+ LOG(INFO) << "Category element is not defined.";
+ return true;
}
application->SetManifestData(keys::kTizenCategoryKey, aplist);
#include <memory>
#include <regex>
+#include "utils/logging.h"
#include "utils/values.h"
#include "widget-manifest-parser/application_manifest_constants.h"
const utils::DictionaryValue* dict;
value->GetAsDictionary(&dict);
result = ParseImeEntryAndStore(*dict, ime_info.get(), error);
- } else {
+ } else if (value->GetType() == utils::Value::TYPE_LIST) {
*error = kErrMsgParsingIme;
return false;
+ } else {
+ LOG(INFO) << "IME element is not defined.";
+ return true;
}
application->SetManifestData(keys::kTizenImeKey, ime_info);
#include <map>
#include <utility>
+#include "utils/logging.h"
#include "utils/values.h"
#include "widget-manifest-parser/application_manifest_constants.h"
utils::Value* metadata_value = NULL;
if (!manifest->Get(keys::kTizenMetaDataKey, &metadata_value)) {
- *error = "Failed to get value of tizen metaData";
+ LOG(INFO) << "Failed to get value of tizen metaData";
}
MetaDataPair metadata_item;
return true;
}
-bool PermissionsHandler::AlwaysParseForType(Manifest::Type type) const {
- return type == Manifest::TYPE_WIDGET;
-}
-
std::vector<std::string> PermissionsHandler::Keys() const {
return std::vector<std::string>(1, keys::kTizenPermissionsKey);
}
bool Parse(std::shared_ptr<ApplicationData> application,
std::string* error) override;
- bool AlwaysParseForType(Manifest::Type type) const override;
std::vector<std::string> Keys() const override;
private:
return std::vector<std::string>(1, keys::kTizenApplicationKey);
}
-bool TizenApplicationHandler::AlwaysParseForType(
- Manifest::Type /*type*/) const {
- return true;
-}
-
} // namespace widget_manifest_parser
} // namespace common_installer
std::string* error) override;
bool Validate(std::shared_ptr<const ApplicationData> application,
std::string* error) const override;
- bool AlwaysParseForType(Manifest::Type type) const override;
std::vector<std::string> Keys() const override;
private:
return true;
}
-bool WidgetHandler::AlwaysParseForType(Manifest::Type /*type*/) const {
- return true;
-}
-
std::vector<std::string> WidgetHandler::Keys() const {
return std::vector<std::string>(1, keys::kWidgetKey);
}
bool Parse(std::shared_ptr<ApplicationData> application,
std::string* error) override;
- bool AlwaysParseForType(Manifest::Type type) const override;
std::vector<std::string> Keys() const override;
bool Validate(std::shared_ptr<const ApplicationData> application,
} // namespace
std::unique_ptr<Manifest> LoadManifest(const std::string& manifest_path,
- Manifest::Type /*type*/, std::string* error) {
+ std::string* error) {
xmlDoc * doc = nullptr;
xmlNode* root_node = nullptr;
doc = xmlReadFile(manifest_path.c_str(), nullptr, 0);
if (dv)
result->Set(reinterpret_cast<const char*>(root_node->name), dv.release());
- return std::unique_ptr<Manifest>(
- new Manifest(std::move(result), Manifest::TYPE_WIDGET));
+ return std::unique_ptr<Manifest>(new Manifest(std::move(result)));
}
bf::path ApplicationURLToRelativeFilePath(const std::string& url) {
namespace common_installer {
namespace widget_manifest_parser {
-// Loads an application manifest from the specified directory. Returns NULL
+// Loads an application manifest from the specified directory. Returns nullptr
// on failure, with a description of the error in |error|.
std::unique_ptr<Manifest> LoadManifest(
- const std::string& file_path, Manifest::Type type, std::string* error);
+ const std::string& file_path, std::string* error);
} // namespace widget_manifest_parser
} // namespace common_installer
}
manifest_ = parser::LoadManifest(
- manifest_path.string(), parser::Manifest::TYPE_WIDGET, &error_);
+ manifest_path.string(), &error_);
if (!manifest_)
return false;
valid_ = error_.empty();