"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 kErrMsgAppWidgetInfoNotFound[] =
"Cannot access app-widget info object.";
const char kErrMsgApplicationInfoNotFound[] =
const char kErrMsgInvalidAppWidgetIdFormat[] =
"Invalid format of an id attribute value in app-widget element."
" The value: ";
-const char kErrMsgNoPrimaryAppWidget[] =
- "No primary app-widget element (primary='true').";
-const char kErrMsgToManyPrimaryAppWidgets[] =
- "Too many primary app-widget elements (primary='true').";
const char kErrMsgUpdatePeriodOutOfDomain[] =
"Value of an update-period attribute in app-widget element out of domain."
" The value: ";
"Value of a height attribute in box-content element out of domain."
" The value: ";
+// 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;
}
+// If the error parameter is specified, it is filled with the given message
+// otherwise it does nothing.
+void SetError(const std::string& message,
+ base::string16* error) {
+ if (error)
+ *error = base::ASCIIToUTF16(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, base::string16* error) {
if (error)
*error = base::ASCIIToUTF16(message + arg);
}
+// Retrieves a mandatory dictionary from specified manifest and specified key.
+// Returns true, if the ditionary is found or false otherwise. If the error
+// parameter is specified, it is also filled with proper message.
+bool GetMandatoryDictionary(const Manifest& manifest, const std::string& key,
+ const base::DictionaryValue** dict, base::string16* error) {
+ if (!manifest.HasPath(key)) {
+ SetError(kErrMsgNoMandatoryKey, key, error);
+ return false;
+ }
+ if (!manifest.GetDictionary(key, dict) || !*dict) {
+ SetError(kErrMsgInvalidDictionary, key, error);
+ return false;
+ }
+ return true;
+}
+
// Converts given text value to a value of specific type. Returns true
// if convertion is successful or false otherwise.
template <typename ValueType>
}
// 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.
+// 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 base::DictionaryValue& dict,
const std::string& key, ValueType* value, base::string16* error) {
}
// 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
+// 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 base::DictionaryValue& dict,
return true;
}
+// 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 base::DictionaryValue& dict,
+ const std::string& key, const std::string& desired_namespace_value,
+ base::string16* error) {
+ std::string namespace_value;
+ if (!GetMandatoryValue(dict, keys::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 base::DictionaryValue& dict,
const std::string& key, TizenAppWidget* app_widget, base::string16* error) {
DCHECK(app_widget);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
std::string lang;
if (!GetOptionalValue(dict, keys::kTizenAppWidgetBoxLabelLangKey,
std::string(), &lang, error))
const std::string& key, TizenAppWidget* app_widget, base::string16* error) {
DCHECK(app_widget);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
if (!app_widget->icon_src.empty()) {
SetError(kErrMsgMultipleKeys, key, error);
return false;
const std::string& key, TizenAppWidget* app_widget, base::string16* error) {
DCHECK(app_widget);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
TizenAppWidgetSize size;
std::string str_type;
const std::string& key, TizenAppWidget* app_widget, base::string16* error) {
DCHECK(app_widget);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
if (!app_widget->content_drop_view.empty()) {
SetError(kErrMsgMultipleKeys, key, error);
return false;
const std::string& key, TizenAppWidget* app_widget, base::string16* error) {
DCHECK(app_widget);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
if (!app_widget->content_src.empty()) {
SetError(kErrMsgMultipleKeys, key, error);
return false;
base::string16* error) {
DCHECK(app_widgets);
+ if (!VerifyElementNamespace(dict, key, kTizenNamespacePrefix, error))
+ return false;
+
TizenAppWidget app_widget;
if (!GetMandatoryValue(dict, keys::kTizenAppWidgetIdKey,
return false;
if (!ParseEach(dict, keys::kTizenAppWidgetBoxIconKey,
- true, ParseIcon, &app_widget, error))
+ false, ParseIcon, &app_widget, error))
return false;
if (!ParseEach(dict, keys::kTizenAppWidgetBoxContentKey,
return true;
}
-// Validates all app-widget primary attributes
-bool ValidateEachPrimary(const TizenAppWidgetVector& app_widgets,
- std::string* error) {
- int primary_count = 0;
-
- for (const TizenAppWidget& app_widget : app_widgets)
- if (app_widget.primary)
- ++primary_count;
-
- if (!primary_count) {
- SetError(kErrMsgNoPrimaryAppWidget, "", error);
- return false;
- }
-
- if (primary_count > 1) {
- SetError(kErrMsgToManyPrimaryAppWidgets, "", error);
- return false;
- }
-
- return true;
-}
-
// Tests if specified string represents valid remote url
bool IsValidUrl(const std::string& value) {
// TODO(tweglarski): implement me (it's not crucial atm)
}
if (!mandatory_1x1_found) {
- SetError(kErrMsgNoMandatoryContentSize1x1, "", error);
+ SetError(kErrMsgNoMandatoryContentSize1x1, error);
return false;
}
const Manifest* manifest = application->GetManifest();
DCHECK(manifest);
- if (!manifest->HasPath(keys::kTizenWidgetKey)) {
- SetError(kErrMsgNoMandatoryKey, keys::kTizenWidgetKey, error);
- return false;
- }
-
const base::DictionaryValue* dict = nullptr;
- if (!manifest->GetDictionary(keys::kTizenWidgetKey, &dict) || !dict) {
- SetError(kErrMsgInvalidDictionary, keys::kTizenWidgetKey, error);
+ if (!GetMandatoryDictionary(*manifest, keys::kTizenWidgetKey, &dict, error))
return false;
- }
TizenAppWidgetVector app_widgets;
application->GetManifestData(keys::kTizenApplicationKey));
if (!app_widget_info) {
- SetError(kErrMsgAppWidgetInfoNotFound, "", error);
+ SetError(kErrMsgAppWidgetInfoNotFound, error);
return false;
}
if (!app_info) {
- SetError(kErrMsgApplicationInfoNotFound, "", error);
+ SetError(kErrMsgApplicationInfoNotFound, error);
return false;
}
if (!ValidateEachId(app_widgets, app_info->id(), error))
return false;
- if (!ValidateEachPrimary(app_widgets, error))
- return false;
-
for (const TizenAppWidget& app_widget : app_widgets) {
if (!app_widget.update_period.empty()
&& app_widget.update_period.front() < 1800) {
if (app_widget.label.default_value.empty()
&& app_widget.label.lang_value_map.empty()) {
- SetError(kErrMsgNoLabel, "", error);
+ SetError(kErrMsgNoLabel, error);
return false;
}