-/*
- * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- * This file have been implemented in compliance with W3C WARP SPEC.
- * but there are some patent issue between W3C WARP SPEC and APPLE.
- * so if you want to use this file, refer to the README file in root directory
- */
-/**
- * @file widget_parser.cpp
- * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
- * @version 0.1
- * @brief
- */
-#include <widget_parser.h>
-
-#include <algorithm>
-#include <cerrno>
-#include <climits>
-#include <cmath>
-#include <cstdlib>
-#include <cstdio>
-#include <locale>
-#include <memory>
-#include <string>
-
-#include <iri.h>
-#include <pcrecpp.h>
-
-#include <ignoring_parser.h>
-#include <deny_all_parser.h>
-#include <dpl/wrt-dao-ro/config_parser_data.h>
-#include <libiriwrapper.h>
-#include <dpl/utils/warp_iri.h>
-#include <dpl/utils/mime_type_utils.h>
-#include <language_subtag_rst_tree.h>
-
-#include <dpl/fast_delegate.h>
-#include <dpl/foreach.h>
-
-#include <installer_log.h>
-
-using namespace WrtDB;
-
-namespace Unicode {
-static const DPL::String UTF_LRE = L"\x0202a";
-static const DPL::String UTF_LRO = L"\x0202d";
-static const DPL::String UTF_RLE = L"\x0202b";
-static const DPL::String UTF_RLO = L"\x0202e";
-static const DPL::String UTF_PDF = L"\x0202c";
-
-Direction ParseDirAttribute(const XmlAttribute& attribute)
-{
- Assert(L"dir" == attribute.name);
- if (L"ltr" == attribute.value) {
- return LRE;
- } else if (L"rtl" == attribute.value) {
- return RLE;
- } else if (L"lro" == attribute.value) {
- return LRO;
- } else if (L"rlo" == attribute.value) {
- return RLO;
- } else {
- _W("dir attribute has wrong value: %ls ", attribute.value.c_str());
- return EMPTY;
- }
-}
-
-void UpdateTextWithDirectionMark(Direction direction,
- DPL::String* text)
-{
- Assert(text);
- switch (direction) {
- case RLO:
- *text = UTF_RLO + *text + UTF_PDF;
- break;
- case RLE:
- *text = UTF_RLE + *text + UTF_PDF;
- break;
- case LRE:
- *text = UTF_LRE + *text + UTF_PDF;
- break;
- case LRO:
- *text = UTF_LRO + *text + UTF_PDF;
- break;
- case EMPTY:
- break;
- default:
- Assert(false);
- break;
- }
-}
-} // namespace Unicode
-
-class InnerElementsParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &InnerElementsParser::Other);
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const Text& text)
- {
- if (m_text.IsNull()) {
- m_text = text;
- } else {
- m_text->value += text.value;
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- }
- }
-
- virtual void Verify()
- {
- if (!m_text.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection,
- &m_text->value);
- m_parentParser->Accept(*m_text);
- }
- }
-
- InnerElementsParser(ElementParserPtr parent) :
- m_parentParser(parent),
- m_textDirection(Unicode::EMPTY)
- {}
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- std::static_pointer_cast<ElementParser>(
- shared_from_this())));
- }
-
- private:
- DPL::Optional<Text> m_text;
- ElementParserPtr m_parentParser;
- Unicode::Direction m_textDirection;
-};
-
-class NameParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &NameParser::Other);
- }
-
- virtual void Accept(const Element& element)
- {
- m_lang = element.lang;
- m_name = L"";
- }
-
- virtual void Accept(const Text& text)
- {
- if (m_name.IsNull()) {
- m_name = text.value;
- } else {
- *m_name += text.value;
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"short") {
- if (m_shortName.IsNull()) {
- m_shortName = attribute.value;
- }
- } else if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- }
- }
-
- virtual void Verify()
- {
- ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
- if (data.name.IsNull()) {
- NormalizeString(m_name);
- NormalizeString(m_shortName);
- if (!m_name.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_name);
- }
- data.name = m_name;
- if (!m_shortName.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection,
- &*m_shortName);
- }
- data.shortName = m_shortName;
- }
- }
-
- NameParser(Unicode::Direction direction,
- ConfigParserData& data) :
- m_data(data),
- m_textDirection(direction)
- {}
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- std::static_pointer_cast<ElementParser>(
- shared_from_this())));
- }
-
- private:
- ConfigParserData& m_data;
- DPL::OptionalString m_name;
- DPL::OptionalString m_shortName;
- DPL::OptionalString m_dir;
- DPL::String m_lang;
- Unicode::Direction m_textDirection;
-};
-
-class AccessParser : public ElementParser
-{
- public:
- enum StandardType
- {
- STANDARD_TYPE_NONE,
- STANDARD_TYPE_WARP
- };
-
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &AccessParser::Other);
- }
-
- virtual void Accept(const Element& element)
- {
- // for tizen web apps WARP should be used
- if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName ||
- element.ns == ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_standardType = STANDARD_TYPE_WARP;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- void AcceptWac(const XmlAttribute& attribute)
- {
- if (attribute.name == L"origin") {
- m_strIRIOrigin = attribute.value;
- NormalizeString(m_strIRIOrigin);
- } else if (attribute.name == L"subdomains") {
- DPL::String normalizedValue = attribute.value;
- NormalizeString(normalizedValue);
-
- if (normalizedValue == L"true") {
- m_bSubDomainAccess = true;
- } else if (normalizedValue == L"false") {
- m_bSubDomainAccess = false;
- }
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- switch (m_standardType) {
- case STANDARD_TYPE_WARP:
- AcceptWac(attribute);
- break;
- default:
- _E("Error in Access tag - unknown standard.");
- break;
- }
- }
-
- void VerifyWac()
- {
- WarpIRI iri;
- iri.set(m_strIRIOrigin, false);
-
- if (!iri.isAccessDefinition()) {
- _W("Access list element: %ls is not acceptable by WARP standard and will be ignored!",
- m_strIRIOrigin.c_str());
- return;
- }
-
- if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains
- {
- m_bSubDomainAccess = true;
- }
-
- ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin,
- m_bSubDomainAccess);
- //std::pair <ConfigParserData::AccessInfoSet::iterator, bool> ret =
- m_data.accessInfoSet.insert(accessInfo);
- }
-
- virtual void Verify()
- {
- switch (m_standardType) {
- case STANDARD_TYPE_WARP:
- VerifyWac();
- break;
- default:
- _E("Error in Access tag - unknown standard.");
- break;
- }
- }
-
- AccessParser(ConfigParserData& data) :
- ElementParser(),
- m_bSubDomainAccess(false),
- m_standardType(STANDARD_TYPE_NONE),
- m_network(false),
- m_data(data)
- {}
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- ElementParserPtr(shared_from_this())));
- }
-
- private:
- DPL::String m_strIRIOrigin;
- bool m_bSubDomainAccess;
- StandardType m_standardType;
- bool m_network;
- ConfigParserData& m_data;
-};
-
-class DescriptionParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &DescriptionParser::Other);
- }
-
- virtual void Accept(const Element& element)
- {
- m_lang = element.lang;
- m_description = L"";
- }
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- std::static_pointer_cast<ElementParser>(
- shared_from_this())));
- }
-
- virtual void Accept(const Text& text)
- {
- if (m_description.IsNull()) {
- m_description = text.value;
- } else {
- *m_description += text.value;
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- }
- }
-
- virtual void Verify()
- {
- ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
- if (data.description.IsNull()) {
- if (!m_description.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection,
- &*m_description);
- }
- data.description = m_description;
- }
- }
-
- DescriptionParser(Unicode::Direction direction,
- ConfigParserData& data) :
- m_data(data),
- m_lang(),
- m_description(),
- m_textDirection(direction)
- {}
-
- private:
- ConfigParserData& m_data;
- DPL::String m_lang;
- DPL::OptionalString m_description;
- Unicode::Direction m_textDirection;
-};
-
-class AuthorParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &AuthorParser::Other);
- }
-
- AuthorParser(Unicode::Direction direction,
- ConfigParserData& data) :
- m_data(data),
- m_textDirection(direction)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {
- m_authorName = L"";
- }
-
- virtual void Accept(const Text& text)
- {
- *(m_authorName) += text.value;
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"href") {
- //Validate href IRI and ignore it if invalid
- //See also test: ta-argMozRiC-an
- LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
- if (iri.Validate()) {
- m_authorHref = attribute.value;
- }
- } else if (attribute.name == L"email") {
- m_authorEmail = attribute.value;
- } else if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- }
- }
-
- virtual void Verify()
- {
- if (!m_data.authorName && !m_data.authorHref && !m_data.authorEmail) {
- NormalizeString(m_authorName);
- NormalizeString(m_authorHref);
- NormalizeString(m_authorEmail);
- if (!!m_authorName) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection,
- &*m_authorName);
- m_data.authorName = m_authorName;
- }
- if (!!m_authorHref) {
- m_data.authorHref = m_authorHref;
- }
- if (!!m_authorEmail) {
- m_data.authorEmail = m_authorEmail;
- }
- }
- }
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- std::static_pointer_cast<ElementParser>(
- shared_from_this())));
- }
-
- private:
- ConfigParserData& m_data;
- DPL::OptionalString m_authorEmail;
- DPL::OptionalString m_authorHref;
- DPL::OptionalString m_authorName;
- Unicode::Direction m_textDirection;
-};
-
-class LicenseParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return DPL::MakeDelegate(this, &LicenseParser::Other);
- }
-
- LicenseParser(Unicode::Direction direction,
- ConfigParserData& data) :
- m_data(data),
- m_ignore(true),
- m_textDirection(direction)
- {}
-
- virtual void Accept(const Element& element)
- {
- if (m_license.IsNull()) {
- m_lang = element.lang;
- m_license = L"";
- m_ignore = false;
- }
- }
-
- virtual void Accept(const Text& text)
- {
- if (!m_ignore) {
- *m_license += text.value;
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (!m_ignore) {
- if (attribute.name == L"href" && m_licenseHref.IsNull()) {
- m_licenseHref = attribute.value;
- } else if (attribute.name == L"file" && m_licenseFile.IsNull()) {
- m_licenseFile = attribute.value;
- } else if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- }
- }
- }
-
- virtual void Verify()
- {
- ConfigParserData::LocalizedData& data = m_data.localizedDataSet[m_lang];
- if (data.license.IsNull()) {
- if (!m_license.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection,
- &*m_license);
- }
- data.license = m_license;
- data.licenseHref = m_licenseHref;
- data.licenseFile = m_licenseFile;
- }
- }
-
- ElementParserPtr Other()
- {
- return ElementParserPtr(new InnerElementsParser(
- ElementParserPtr(shared_from_this())));
- }
-
- private:
- ConfigParserData& m_data;
- DPL::String m_lang;
- bool m_ignore;
-
- DPL::OptionalString m_license;
- DPL::OptionalString m_licenseFile;
- DPL::OptionalString m_licenseHref;
- Unicode::Direction m_textDirection;
-};
-
-class IconParser : public ElementParser
-{
- DECLARE_EXCEPTION_TYPE(ElementParser::Exception::ParseError, BadSrcError)
-
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- IconParser(ConfigParserData& data) : ElementParser(),
- m_data(data)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"src") {
- if (attribute.value.size() > 0) {
- m_src = attribute.value;
- }
- } else if (attribute.name == L"width") {
- m_width = ParseSizeAttributeValue(attribute.value);
- } else if (attribute.name == L"height") {
- m_height = ParseSizeAttributeValue(attribute.value);
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {
- ThrowMsg(Exception::ParseError, "Icon element must be empty");
- }
-
- virtual void Verify()
- {
- if (m_src.IsNull()) {
- _W("src attribute of icon element is mandatory - ignoring");
- return;
- }
-
- Try
- {
- ConfigParserData::Icon icon(delocalizeSrcPath(*m_src));
- icon.width = m_width;
- icon.height = m_height;
-
- ConfigParserData::IconsList::iterator it = std::find(
- m_data.iconsList.begin(), m_data.iconsList.end(), icon);
- if (it == m_data.iconsList.end()) {
- m_data.iconsList.push_front(icon);
- }
- }
- Catch(BadSrcError)
- {
- _W("src attribute is invalid: %ls", (*m_src).c_str());
- }
- }
-
- private:
- ConfigParserData& m_data;
- DPL::OptionalString m_src;
- DPL::OptionalInt m_width;
- DPL::OptionalInt m_height;
-
- static DPL::OptionalInt ParseSizeAttributeValue(const DPL::String& value)
- {
- DPL::OptionalString normalizedValue = value;
- NormalizeString(normalizedValue);
- if (!(*normalizedValue).empty()) {
- char* reterr = NULL;
- errno = 0;
- long int valueInt =
- strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10);
- if (errno != 0 ||
- std::string(reterr) == DPL::ToUTF8String(value) ||
- valueInt <= 0)
- {
- return DPL::OptionalInt::Null;
- } else {
- return valueInt;
- }
- }
- return DPL::OptionalInt::Null;
- }
-
- /**
- * @brief delocalizePath removes locales folder from relative path if
- * neccessary
- * @param source source string
- *
- * @throw BadSrcError if string is bad value of src attribute
- *
- * @return corrected string
- */
- static DPL::String delocalizeSrcPath(const DPL::String & source)
- {
- static const DPL::String localeFolder(L"locales/");
- static const int index = localeFolder.size();
-
- DPL::String result = source;
-
- if (source.substr(0, index) == localeFolder) {
- size_t pos = result.find_first_of('/', index);
- if (pos != std::string::npos && pos + 1 < source.size()) {
- result = result.substr(pos + 1, source.size());
- } else {
- Throw(BadSrcError);
- }
- }
- return result;
- }
-};
-
-class ContentParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- ContentParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data)
- {}
-
- virtual void Accept(const Element& element)
- {
- m_namespace = element.ns;
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- DPL::String value = attribute.value;
- NormalizeString(value);
-
- if (attribute.name == L"src") {
- m_src = value;
- } else if (attribute.name == L"type") {
- m_type = value;
- MimeTypeUtils::MimeAttributes mimeAttributes =
- MimeTypeUtils::getMimeAttributes(value);
- if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull())
- {
- m_encoding = mimeAttributes[L"charset"];
- }
- } else if (attribute.name == L"encoding") {
- if (!value.empty()) {
- m_encoding = value;
- }
- }
- }
-
- virtual void Verify()
- {
- if(!!m_data.startFileEncountered)
- {
- if(m_data.startFileNamespace == m_namespace
- || m_namespace != ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- return;
- }
- //else continue -> if previous item was not in tizen namespace
- }
-
- m_data.startFileEncountered = true;
- m_data.startFileNamespace = m_namespace;
-
- //we're consciously setting startFile even if m_src is null or invalid.
- //WidgetConfigurationManager will deal with this.
- m_data.startFile = m_src;
-
- if (!!m_src) {
- m_data.startFileContentType = m_type;
- if (!!m_encoding) {
- m_data.startFileEncoding = m_encoding;
- } else {
- m_data.startFileEncoding = L"UTF-8";
- }
- }
- }
-
- private:
- DPL::OptionalString m_src;
- DPL::OptionalString m_type;
- DPL::OptionalString m_encoding;
- ConfigParserData& m_data;
- DPL::String m_namespace;
-};
-
-class PreferenceParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- m_name = attribute.value;
- } else if (attribute.name == L"value") {
- m_value = attribute.value;
- } else if (attribute.name == L"readonly") {
- if (attribute.value == L"true") {
- m_required = true;
- } else {
- m_required = false;
- }
- }
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const Text& /*text*/)
- {
- ThrowMsg(Exception::ParseError, "param element must be empty");
- }
-
- virtual void Verify()
- {
- if (m_name.IsNull()) {
- _W("preference element must have name attribute");
- return;
- }
- NormalizeString(m_name);
- NormalizeString(m_value);
- ConfigParserData::Preference preference(*m_name, m_required);
- preference.value = m_value;
- if (m_data.preferencesList.find(preference) ==
- m_data.preferencesList.end())
- {
- m_data.preferencesList.insert(preference);
- }
- }
-
- PreferenceParser(ConfigParserData& data) :
- ElementParser(),
- m_required(false),
- m_data(data)
- {}
-
- private:
- DPL::OptionalString m_name;
- DPL::OptionalString m_value;
- bool m_required;
- ConfigParserData& m_data;
-};
-
-class SettingParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- m_setting.m_name = attribute.name;
- m_setting.m_value = attribute.value;
- m_data.settingsList.insert(m_setting);
- }
-
- virtual void Verify()
- {}
-
- SettingParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_setting(L"", L"")
- {}
-
- private:
- ConfigParserData& m_data;
- ConfigParserData::Setting m_setting;
-};
-
-class AppControlParser : public ElementParser
-{
- public:
- struct SourceParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_value = attribute.value;
- NormalizeString(m_value);
- }
- }
- }
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- m_data.m_src = *m_value;
- }
-
- SourceParser(ConfigParserData::AppControlInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AppControlInfo& m_data;
- };
-
- struct OperationParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_value = attribute.value;
- NormalizeString(m_value);
- }
- }
- }
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- m_data.m_operation = *m_value;
- }
-
- OperationParser(ConfigParserData::AppControlInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AppControlInfo& m_data;
- };
-
- struct UriParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_value = attribute.value;
- NormalizeString(m_value);
- }
- }
- }
-
- virtual void Verify()
- {
- // exception
- DPL::String ignoreUri(L"file");
-
- if (!m_value.IsNull() && *m_value == ignoreUri)
- {
- _D("exception : '%ls' scheme will be ignored.", (*m_value).c_str());
- m_value = DPL::OptionalString::Null;
- }
-
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- DPL::String wildString(L"*/*");
- if ((m_data.m_uriList.find(wildString) == m_data.m_uriList.end())
- && (m_data.m_uriList.find(*m_value) == m_data.m_uriList.end()))
- {
- m_data.m_uriList.insert(*m_value);
- } else {
- _D("Ignoring uri with name %ls", (*m_value).c_str());
- }
- }
-
- UriParser(ConfigParserData::AppControlInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AppControlInfo& m_data;
- };
-
- struct MimeParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_value = attribute.value;
- NormalizeString(m_value);
- }
- }
- }
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- DPL::String wildString(L"*/*");
- if ((m_data.m_mimeList.find(wildString) ==
- m_data.m_mimeList.end())
- && (m_data.m_mimeList.find(*m_value) ==
- m_data.m_mimeList.end()))
- {
- m_data.m_mimeList.insert(*m_value);
- } else {
- _D("Ignoring mime with name %ls", (*m_value).c_str());
- }
- }
-
- MimeParser(ConfigParserData::AppControlInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AppControlInfo& m_data;
- };
-
- struct DispositionParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create;
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_value = attribute.value;
- NormalizeString(m_value);
- }
- }
- }
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- DPL::String windowString(L"window");
- DPL::String inlineString(L"inline");
-
- if (*m_value == L"window") {
- m_data.m_disposition =
- ConfigParserData::AppControlInfo::Disposition::WINDOW;
- } else if (*m_value == L"inline") {
- m_data.m_disposition =
- ConfigParserData::AppControlInfo::Disposition::INLINE;
- } else {
- _D("Ignoring dispostion value %ls", (*m_value).c_str());
- }
- }
-
- DispositionParser(ConfigParserData::AppControlInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AppControlInfo& m_data;
- };
-
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& name)
- {
- if (name == L"src") {
- return DPL::MakeDelegate(this, &AppControlParser::OnSourceElement);
- } else if (name == L"operation") {
- return DPL::MakeDelegate(this,
- &AppControlParser::OnOperationElement);
- } else if (name == L"uri") {
- return DPL::MakeDelegate(this, &AppControlParser::OnUriElement);
- } else if (name == L"mime") {
- return DPL::MakeDelegate(this, &AppControlParser::OnMimeElement);
- } else if (name == L"disposition") {
- return DPL::MakeDelegate(this,
- &AppControlParser::OnDispositionElement);
- } else {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
- }
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {}
-
- virtual void Accept(const Element& element)
- {
- _W("namespace for app service = %ls", element.ns.c_str());
- if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) {
- ThrowMsg(Exception::ParseError,
- "Wrong xml namespace for widget element");
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {
- ThrowMsg(Exception::ParseError, "param element must be empty");
- }
-
- virtual void Verify()
- {
- if (m_appControl.m_src == L"") {
- ThrowMsg(Exception::ParseError, "service element must have src element");
- }
-
- if (m_appControl.m_operation == L"") {
- ThrowMsg(Exception::ParseError, "service element must have operation element");
- }
-
- auto res = std::find(m_data.appControlList.begin(), m_data.appControlList.end(), m_appControl);
- if(res != m_data.appControlList.end()) {
- ThrowMsg(Exception::ParseError, "service element must be unique");
- }
-
-#ifdef NFC_EXCEPTION_HANDLING_FOR_TIZEN_2_2_ONLY
- // XXX This feature should be retained to Tizen 2.2 only.
- // NFC exception handling which was requested from Tizen Device API team.
-
- const DPL::String exceptionNfcOperation =
- L"http://tizen.org/appcontrol/operation/nfc/transaction";
- const DPL::String exceptionNfcUri = L"nfc://secure/aid/";
- const DPL::String divertingNfcUri1 = L"nfc://secure/SIM1/aid/";
- const DPL::String divertingNfcUri2 = L"nfc://secure/eSE/aid/";
-
- if (m_appControl.m_operation == exceptionNfcOperation
- && m_appControl.m_mimeList.empty()
- && m_appControl.m_uriList.size() == 1
- && (m_appControl.m_uriList.begin())->compare(0, exceptionNfcUri.length(), exceptionNfcUri) == 0)
- {
- DPL::String originalUri = *m_appControl.m_uriList.begin();
- DPL::String newUri = originalUri;
-
- newUri.replace(0, exceptionNfcUri.length(), divertingNfcUri1);
- m_appControl.m_uriList.erase(m_appControl.m_uriList.begin());
- m_appControl.m_uriList.insert(newUri);
- m_data.appControlList.push_back(m_appControl);
- _D("NFC exception : %ls -> %ls", originalUri.c_str(), newUri.c_str());
-
- newUri = originalUri;
- newUri.replace(0, exceptionNfcUri.length(), divertingNfcUri2);
- m_appControl.m_uriList.erase(m_appControl.m_uriList.begin());
- m_appControl.m_uriList.insert(newUri);
- m_data.appControlList.push_back(m_appControl);
- _D("NFC exception : %ls -> %ls", originalUri.c_str(), newUri.c_str());
-
- return;
- }
-#endif // NFC_EXCEPTION_HANDLING_FOR_TIZEN_2_2_ONLY
-
- m_data.appControlList.push_back(m_appControl);
- }
-
- ElementParserPtr OnSourceElement()
- {
- return ElementParserPtr(new SourceParser(m_appControl));
- }
-
- ElementParserPtr OnOperationElement()
- {
- return ElementParserPtr(new OperationParser(m_appControl));
- }
-
- ElementParserPtr OnUriElement()
- {
- return ElementParserPtr(new UriParser(m_appControl));
- }
-
- ElementParserPtr OnMimeElement()
- {
- return ElementParserPtr(new MimeParser(m_appControl));
- }
-
- ElementParserPtr OnDispositionElement()
- {
- return ElementParserPtr(new DispositionParser(m_appControl));
- }
-
- AppControlParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_appControl(L"")
- {}
-
- private:
- ConfigParserData& m_data;
- ConfigParserData::AppControlInfo m_appControl;
-};
-
-class ApplicationParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {
- if (m_properNamespace) {
- ThrowMsg(Exception::ParseError, "application element must be empty");
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"id") {
- m_id = attribute.value;
- NormalizeAndTrimSpaceString(m_id);
- } else if (attribute.name == L"package") {
- m_package = attribute.value;
- } else if (attribute.name == L"required_version") {
- m_version = attribute.value;
- NormalizeString(m_version);
- } else {
- ThrowMsg(Exception::ParseError,
- "unknown attribute '" +
- DPL::ToUTF8String(attribute.name) +
- "' in application element");
- }
- }
- }
-
- virtual void Verify()
- {
- VerifyIdAndPackage();
- VerifyVersion();
- }
-
- ApplicationParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_id(DPL::OptionalString::Null),
- m_version(DPL::OptionalString::Null),
- m_properNamespace(false)
- {}
-
- static const char* const REGEXP_ID;
-
- private:
- void VerifyIdAndPackage()
- {
- if (!m_package)
- {
- ThrowMsg(Exception::ParseError,
- "application element must have package attribute");
- }
- else
- {
- pcrecpp::RE re(REGEXP_PACKAGE);
- if (!re.FullMatch(DPL::ToUTF8String(*m_package)))
- {
- ThrowMsg(Exception::ParseError,
- "invalid format of package attribute");
- }
- }
-
- if (!m_id) {
- ThrowMsg(Exception::ParseError,
- "application element must have id attribute");
- }
- else
- {
- std::string package;
- pcrecpp::RE re(REGEXP_ID);
- if (!re.FullMatch(DPL::ToUTF8String(*m_id), &package))
- {
- ThrowMsg(Exception::ParseError,
- "invalid format of id attribute");
- }
- if (package != DPL::ToUTF8String(*m_package))
- {
- ThrowMsg(Exception::ParseError,
- "invalid package prefix in id attribute");
- }
- }
-
- m_data.tizenAppId = m_id;
- m_data.tizenPkgId = m_package;
- }
-
- void VerifyVersion()
- {
- if (!m_version)
- {
- ThrowMsg(Exception::ParseError,
- "application element must have required_version attribute");
- }
- else
- {
- pcrecpp::RE re(REGEXP_VERSION);
- if (!re.FullMatch(DPL::ToUTF8String(*m_version)))
- {
- ThrowMsg(Exception::ParseError,
- "invalid format of version attribute");
- }
- }
-
- m_data.tizenMinVersionRequired = m_version;
- }
-
- static const char* const REGEXP_PACKAGE;
- static const char* const REGEXP_VERSION;
-
- ConfigParserData& m_data;
- DPL::OptionalString m_id;
- DPL::OptionalString m_package;
- DPL::OptionalString m_version;
- bool m_properNamespace;
-};
-
-const char* const ApplicationParser::REGEXP_PACKAGE = "[0-9A-Za-z]{10}";
-const char* const ApplicationParser::REGEXP_ID = "([0-9A-Za-z]{10})\\.[0-9A-Za-z]{1,52}";
-const char* const ApplicationParser::REGEXP_VERSION = "\\d+\\.\\d+(\\.\\d+)?";
-
-class SplashParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace)
- {
- if (attribute.name == L"src") {
- if (attribute.value.size() > 0) {
- m_src = attribute.value;
- }
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_src.IsNull())
- {
- _W("src attribute of splash element is mandatory - ignoring");
- return;
- }
-
- m_data.splashImgSrc = m_src;
- }
-
- SplashParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false)
- {}
-
- private:
- DPL::OptionalString m_src;
- ConfigParserData& m_data;
- bool m_properNamespace;
-};
-
-class BackgroundParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"src") {
- if (attribute.value.size() > 0) {
- m_src = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_src.IsNull()) {
- _W("src attribute of background element is mandatory - ignoring");
- return;
- }
-
- m_data.backgroundPage = m_src;
- }
-
- explicit BackgroundParser(ConfigParserData& data) :
- m_data(data)
- {}
-
- private:
- DPL::OptionalString m_src;
- ConfigParserData& m_data;
-};
-
-class PrivilegeParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- _D("element");
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"name") {
- m_feature.name = attribute.value;
- m_privilege.name = attribute.value;
- }
- }
- }
-
- virtual void Verify()
- {
- LibIri::Wrapper iri(DPL::ToUTF8String(m_feature.name).c_str());
-
- if (m_feature.name != L"") {
- if (iri.Validate()) {
- if (m_data.featuresList.find(m_feature) ==
- m_data.featuresList.end())
- {
- m_data.featuresList.insert(m_feature);
- } else {
- _D("Ignoring feature with name %ls", m_feature.name.c_str());
- }
- }
- }
-
- LibIri::Wrapper iriPrivilege(
- DPL::ToUTF8String(m_privilege.name).c_str());
-
- if (m_privilege.name != L"") {
- if (iriPrivilege.Validate()) {
- if (m_data.privilegeList.find(m_privilege) ==
- m_data.privilegeList.end())
- {
- m_data.privilegeList.insert(m_privilege);
- } else {
- _D("Ignoring privilege with name %ls", m_privilege.name.c_str());
- }
- }
- }
- }
-
- PrivilegeParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_feature(L""),
- m_privilege(L""),
- m_properNamespace(false)
- {}
-
- private:
- ConfigParserData& m_data;
- ConfigParserData::Feature m_feature;
- ConfigParserData::Privilege m_privilege;
- bool m_properNamespace;
-};
-
-class CategoryParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"name") {
- if (attribute.value.size() > 0) {
- m_name = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_name.IsNull()) {
- _W("name attribute of category element is mandatory - ignoring");
- return;
- }
-
- if (m_data.categoryList.find(*m_name) ==
- m_data.categoryList.end())
- {
- m_data.categoryList.insert(*m_name);
- }
- }
-
- explicit CategoryParser(ConfigParserData& data) :
- m_data(data)
- {}
-
- private:
- DPL::OptionalString m_name;
- ConfigParserData& m_data;
-};
-
-class AppWidgetParser : public ElementParser
-{
- public:
-
- struct BoxLabelParser : public ElementParser
- {
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- m_lang = attribute.lang;
- }
- }
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& text)
- {
- if (m_properNamespace) {
- m_label = text.value;
- }
- }
-
- virtual void Verify()
- {
- std::pair<DPL::String, DPL::String> boxLabel;
- if (m_label.empty()) {
- _W("box-label element is empty");
- boxLabel.first = DPL::FromUTF8String("");
- boxLabel.second = DPL::FromUTF8String("");
- m_data.m_label.push_back(boxLabel);
- }
- else {
- boxLabel.first = m_lang;
- boxLabel.second = m_label;
- m_data.m_label.push_back(boxLabel);
- }
- }
-
- BoxLabelParser(ConfigParserData::LiveboxInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- DPL::String m_lang;
- DPL::String m_label;
- bool m_properNamespace;
- ConfigParserData::LiveboxInfo& m_data;
- };
-
- struct BoxIconParser : public ElementParser
- {
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"src") {
- m_icon = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_icon.empty()) {
- ThrowMsg(Exception::ParseError,
- "src attribute of box-icon element is mandatory - ignoring");
- }
- if (!m_data.m_icon.empty()) {
- ThrowMsg(Exception::ParseError,
- "<tizen:box-icon /> element should occur as 0 or 1 time");
- }
- m_data.m_icon = m_icon;
- }
-
- explicit BoxIconParser(ConfigParserData::LiveboxInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- DPL::String m_icon;
- bool m_properNamespace;
- ConfigParserData::LiveboxInfo& m_data;
- };
-
- struct BoxContentParser : public ElementParser
- {
- struct BoxSizeParser : public ElementParser
- {
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"preview") {
- m_preview = attribute.value;
- }
- if (attribute.name == L"use-decoration") {
- m_useDecoration = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& text)
- {
- if (m_properNamespace) {
- m_size = text.value;
- }
- }
-
- virtual void Verify()
- {
- if(m_size.empty()) {
- ThrowMsg(Exception::ParseError,
- "size is mandatory - ignoring");
- }
-
- ConfigParserData::LiveboxInfo::BoxSizeInfo boxSizeInfo;
- boxSizeInfo.m_size = m_size;
- boxSizeInfo.m_preview = m_preview;
- boxSizeInfo.m_useDecoration = m_useDecoration;
- m_data.m_boxSize.push_back(boxSizeInfo);
- }
-
- explicit BoxSizeParser(
- ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- DPL::String m_size;
- DPL::String m_preview;
- DPL::String m_useDecoration;
- bool m_properNamespace;
- ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
- };
-
- struct PdParser : public ElementParser
- {
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"src") {
- m_src = attribute.value;
- } else if (attribute.name == L"width") {
- m_width = attribute.value;
- } else if (attribute.name == L"height") {
- m_height = attribute.value;
- } else if (attribute.name == L"fast-open") {
- m_fastOpen= attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_src.empty()) {
- ThrowMsg(Exception::ParseError,
- "src attribute of pd element is mandatory - ignoring");
- }
-
- if (m_width.empty()) {
- ThrowMsg(Exception::ParseError,
- "width attribute of pd element is mandatory - ignoring");
- }
-
- if (m_height.empty()) {
- ThrowMsg(Exception::ParseError,
- "height attribute of pd element is mandatory - ignoring");
- }
-
- if (ConvertToInt(m_width).IsNull()) {
- ThrowMsg(Exception::ParseError,
- "width attribute of pd element cannot be converted to int - ignoring. value: " << m_width);
- }
-
-
- DPL::OptionalInt height = ConvertToInt(m_height);
-
- if (height.IsNull()) {
- ThrowMsg(Exception::ParseError,
- "height attribute of pd element cannot be converted to int - ignoring. value: " << m_height);
- }
-
- if (*height < 1) {
- m_height = L"1";
- _D("height attribute of pd element shouldn't be less than 1. Changed to 1 from %d", *height);
- } else if (*height > 380){
- m_height = L"380";
- _D("height attribute of pd element shouldn't be greater than 380. Changed to 380 from %d", *height);
- }
-
- m_data.m_pdSrc = m_src;
- m_data.m_pdWidth = m_width;
- m_data.m_pdHeight = m_height;
- m_data.m_pdFastOpen = m_fastOpen;
- }
-
- explicit PdParser(
- ConfigParserData::LiveboxInfo::BoxContentInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- DPL::OptionalInt ConvertToInt(const DPL::String& intAsString)
- {
- char * endptr;
- std::string tempStr = DPL::ToUTF8String(intAsString);
- const char * intAsString_c = tempStr.c_str();
- errno = 0;
- long int intAsString_i = strtol(intAsString_c, &endptr, 10);
-
- if ((errno == ERANGE && (intAsString_i == LONG_MAX || intAsString_i == LONG_MIN))
- || intAsString_i > INT_MAX || intAsString_i < INT_MIN
- || *endptr != '\0') {
- return DPL::OptionalInt::Null;
- }
-
- return static_cast<int>(intAsString_i);
- }
-
- DPL::String m_src;
- DPL::String m_width;
- DPL::String m_height;
- DPL::String m_fastOpen;
-
- bool m_properNamespace;
- ConfigParserData::LiveboxInfo::BoxContentInfo& m_data;
- };
-
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& name)
- {
- if (name == L"box-size") {
- return DPL::MakeDelegate(
- this,
- &AppWidgetParser::BoxContentParser::
- OnBoxSizeElement);
- } else if (name == L"pd") {
- return DPL::MakeDelegate(
- this,
- &AppWidgetParser::BoxContentParser::
- OnPdElement);
- } else {
- ThrowMsg(Exception::ParseError,
- "No element parser for name: " << name);
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"src") {
- m_box.m_boxSrc = attribute.value;
- }
- if (attribute.name == L"mouse-event") {
- m_box.m_boxMouseEvent = attribute.value;
- }
- if (attribute.name == L"touch-effect") {
- m_box.m_boxTouchEffect = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_box.m_boxSrc.empty()) {
- ThrowMsg(Exception::ParseError,
- "src attribute of box-content element is mandatory - ignoring");
- }
-
- if (!m_box.m_boxMouseEvent.empty() &&
- CheckIfNotTrueNorFalse(m_box.m_boxMouseEvent))
- {
- ThrowMsg(Exception::ParseError,
- "mouse-event attribute of box-content element should be true or false - ignoring");
- }
-
- if (!m_box.m_boxTouchEffect.empty() &&
- CheckIfNotTrueNorFalse(m_box.m_boxTouchEffect))
- {
- ThrowMsg(Exception::ParseError,
- "touch-effect attribute of box-content element should be true or false - ignoring");
- }
-
- if (m_box.m_boxMouseEvent.empty()) {
- m_box.m_boxMouseEvent = L"false";
- }
-
- if (m_box.m_boxTouchEffect.empty()) {
- m_box.m_boxTouchEffect = L"true";
- }
-
- if (m_box.m_boxSize.empty()) {
- ThrowMsg(Exception::ParseError,
- "box-size element of box-content element not found - ignoring");
- }
-
- m_data.m_boxInfo = m_box;
- }
-
- explicit BoxContentParser(ConfigParserData::LiveboxInfo& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- ElementParserPtr OnBoxSizeElement()
- {
- return ElementParserPtr(new BoxSizeParser(m_box));
- }
-
- ElementParserPtr OnPdElement()
- {
- return ElementParserPtr(new PdParser(m_box));
- }
-
- private:
- bool m_properNamespace;
- ConfigParserData::LiveboxInfo& m_data;
- ConfigParserData::LiveboxInfo::BoxContentInfo m_box;
- };
-
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& name)
- {
- if (name == L"box-label") {
- return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxLabelElement);
- } else if (name == L"box-icon") {
- return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxIconElement);
- } else if (name == L"box-content") {
- return DPL::MakeDelegate(this, &AppWidgetParser::OnBoxContentElement);
- } else {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"id") {
- m_liveboxId = attribute.value;
- } else if (attribute.name == L"primary") {
- m_primary = attribute.value;
- } else if (attribute.name == L"auto-launch") {
- m_autoLaunch = attribute.value;
- } else if (attribute.name == L"update-period") {
- m_updatePeriod = attribute.value;
- } else if (attribute.name == L"type") {
- m_type = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns ==
- ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Verify()
- {
- if (m_liveboxId.empty()) {
- ThrowMsg(Exception::ParseError,
- "app-widget element must have id attribute");
- }
- else
- {
- pcrecpp::RE re(REGEXP_ID_STRING.c_str());
- if (!re.FullMatch(DPL::ToUTF8String(m_liveboxId)))
- {
- ThrowMsg(Exception::ParseError,
- "invalid format of app-widget id attribute");
- }
- }
-
- if (m_primary.empty())
- {
- ThrowMsg(Exception::ParseError,
- "app-widget element must have primary attribute");
- } else if (CheckIfNotTrueNorFalse(m_primary))
- {
- ThrowMsg(Exception::ParseError,
- "auto-launch attribute of app-widget element should be true or false - ignoring");
- }
-
- if (!m_autoLaunch.empty() &&
- CheckIfNotTrueNorFalse(m_autoLaunch))
- {
- ThrowMsg(Exception::ParseError,
- "auto-launch attribute of app-widget element should be true or false - ignoring");
- }
-
- if (!m_updatePeriod.empty())
- {
- char * endptr;
- errno = 0;
- std::string tempStr = DPL::ToUTF8String(m_updatePeriod);
-
- //set standard locale to fix decimal point mark - '.'
- std::string currentLocale = setlocale(LC_NUMERIC, NULL);
- if (NULL == setlocale(LC_NUMERIC, "C"))
- _W("Failed to change locale to \"C\"");
- double updatePeriod = strtod(tempStr.c_str(), &endptr);
-
- //go back to previous locale
- if (NULL == setlocale(LC_NUMERIC, currentLocale.c_str()))
- _W("Failed to set previous locale");
-
- if ((errno == ERANGE && (updatePeriod == -HUGE_VAL || updatePeriod == HUGE_VAL))
- || *endptr != '\0') {
- ThrowMsg(Exception::ParseError,
- "update-period attribute of app-widget element should be a number - ignoring. current value: " << m_updatePeriod);
- } else if (updatePeriod < 1800.0) {
- _D("update-period attribute of app-widget element shouldn't be less than 1800.0 - changed to 1800 from value: %ls", m_updatePeriod.c_str());
- m_updatePeriod = L"1800.0";
- }
- }
-
- if (m_autoLaunch.empty()) {
- m_autoLaunch = L"false";
- }
-
- if(m_livebox.m_label.empty()) {
- ThrowMsg(Exception::ParseError,
- "box-label element of app-widget element not found - ignoring");
- }
-
- if(!m_boxContentFound) {
- ThrowMsg(Exception::ParseError,
- "box-content element of app-widget element not found - ignoring");
- }
-
- m_livebox.m_liveboxId = m_liveboxId;
- m_livebox.m_primary = m_primary;
- m_livebox.m_autoLaunch = m_autoLaunch;
- m_livebox.m_updatePeriod = m_updatePeriod;
- m_livebox.m_type = m_type;
-
- m_data.m_livebox.push_back(m_livebox);
- }
-
- explicit AppWidgetParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false),
- m_boxContentFound(false)
- {
- m_livebox = ConfigParserData::LiveboxInfo();
- }
-
- ElementParserPtr OnBoxLabelElement()
- {
-
- return ElementParserPtr(new BoxLabelParser(m_livebox));
- }
-
- ElementParserPtr OnBoxIconElement()
- {
- return ElementParserPtr(new BoxIconParser(m_livebox));
- }
-
- ElementParserPtr OnBoxContentElement()
- {
- m_boxContentFound = true;
- return ElementParserPtr(new BoxContentParser(m_livebox));
- }
-
- private:
- static std::string REGEXP_ID_STRING;
- ConfigParserData& m_data;
- ConfigParserData::LiveboxInfo m_livebox;
- DPL::String m_liveboxId;
- DPL::String m_primary;
- DPL::String m_autoLaunch;
- DPL::String m_updatePeriod;
- DPL::String m_type;
- bool m_properNamespace;
- bool m_boxContentFound;
-
- static bool CheckIfNotTrueNorFalse(const DPL::String &stringToCheck)
- {
- return stringToCheck.compare(L"true") != 0 && stringToCheck.compare(L"false") != 0;
- }
-};
-
-std::string AppWidgetParser::REGEXP_ID_STRING = std::string(ApplicationParser::REGEXP_ID) + "\\.[0-9A-Za-z]+";
-
-class AllowNavigationParser : public ElementParser
-{
- public:
- AllowNavigationParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false)
- {}
-
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& text)
- {
- if (m_properNamespace)
- {
- m_origin = text.value;
- }
- }
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {
- }
-
- virtual void Verify()
- {
- if (m_data.allowNavigationEncountered || !m_properNamespace)
- {
- return;
- }
- m_data.allowNavigationEncountered = true;
-
- if (m_origin.IsNull()) {
- _W("data is empty");
- return;
- }
-
- char* data = strdup(DPL::ToUTF8String(*m_origin).c_str());
- char* ptr = strtok(data," ");
- while (ptr != NULL) {
- std::string origin = ptr;
- ptr = strtok(NULL," ");
- if(origin == "*") {
- ConfigParserData::AllowNavigationInfo info(L"*", L"*");
- m_data.allowNavigationInfoList.push_back(info);
- continue;
- }
-
- std::unique_ptr<iri_t, decltype(&iri_destroy)> iri(iri_parse(origin.c_str()), iri_destroy);
- if (!iri->host || strlen(iri->host) == 0) {
- // input origin should has schem and host
- // in case of file scheme path is filled
- // "http://"
- _W("input origin isn't verified");
- continue;
- }
- DPL::String scheme = L"*";
- if (iri->scheme && strlen(iri->scheme) != 0) {
- scheme = DPL::FromUTF8String(iri->scheme);
- }
- ConfigParserData::AllowNavigationInfo info(
- scheme,
- DPL::FromUTF8String(iri->host));
- m_data.allowNavigationInfoList.push_back(info);
- }
- free(data);
- }
-
- private:
- DPL::OptionalString m_origin;
- ConfigParserData& m_data;
- bool m_properNamespace;
-};
-
-class CspParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- CspParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false)
- {}
-
- virtual void Accept(const Element& element)
- {
- if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {}
-
- virtual void Accept(const Text& text)
- {
- if (m_properNamespace) {
- m_policy = text.value;
- }
- }
-
- virtual void Verify()
- {
- if (!m_policy.IsNull()) {
- m_data.cspPolicy = *m_policy;
- }
- }
-
- private:
- ConfigParserData& m_data;
- bool m_properNamespace;
- DPL::OptionalString m_policy;
-};
-
-class CspReportOnlyParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- CspReportOnlyParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false)
- {}
-
- virtual void Accept(const Element& element)
- {
- if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {}
-
- virtual void Accept(const Text& text)
- {
- if (m_properNamespace) {
- m_policy = text.value;
- }
- }
-
- virtual void Verify()
- {
- if (!m_policy.IsNull()) {
- m_data.cspPolicyReportOnly = *m_policy;
- }
- }
-
- private:
- ConfigParserData& m_data;
- bool m_properNamespace;
- DPL::OptionalString m_policy;
-};
-
-class AccountParser : public ElementParser
-{
- public:
- struct IconParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& text)
- {
- if (text.value == L"") {
- return;
- }
- m_value = text.value;
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"section") {
- if (attribute.value == L"Account") {
- m_type = ConfigParserData::IconSectionType::DefaultIcon;
- } else if (attribute.value == L"AccountSmall") {
- m_type = ConfigParserData::IconSectionType::SmallIcon;
- }
- }
- }
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- std::pair<ConfigParserData::IconSectionType, DPL::String> icon;
- icon.first = m_type;
- icon.second = *m_value;
-
- m_data.m_iconSet.insert(icon);
- }
-
- IconParser(ConfigParserData::AccountProvider& data) :
- ElementParser(),
- m_properNamespace(false),
- m_type(ConfigParserData::DefaultIcon),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- ConfigParserData::IconSectionType m_type;
- ConfigParserData::AccountProvider& m_data;
- DPL::OptionalString m_value;
- };
-
- struct DisplayNameParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& text)
- {
- if (text.value == L"") {
- return;
- }
- m_value = text.value;
- }
-
- virtual void Accept(const Element& element)
- {
- m_lang = element.lang;
- m_value= L"";
- }
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {}
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
-
- std::pair<DPL::String, DPL::String> name;
- name.first = *m_lang;
- name.second = *m_value;
-
- m_data.m_displayNameSet.insert(name);
- }
-
- DisplayNameParser(ConfigParserData::AccountProvider& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_lang;
- DPL::OptionalString m_value;
- ConfigParserData::AccountProvider& m_data;
- };
-
- struct CapabilityParser : public ElementParser
- {
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const Text& text)
- {
- if (text.value == L"") {
- return;
- }
- m_value = text.value;
- }
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& /*attribute*/)
- {}
-
- virtual void Verify()
- {
- if (m_value.IsNull() || *m_value == L"") {
- return;
- }
- m_data.m_capabilityList.push_back(*m_value);
- }
-
- CapabilityParser(ConfigParserData::AccountProvider& data) :
- ElementParser(),
- m_properNamespace(false),
- m_data(data)
- {}
-
- private:
- bool m_properNamespace;
- DPL::OptionalString m_value;
- ConfigParserData::AccountProvider& m_data;
- };
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& name)
- {
- if (name == L"icon") {
- return DPL::MakeDelegate(this, &AccountParser::OnIconElement);
- } else if (name == L"display-name") {
- return DPL::MakeDelegate(this,
- &AccountParser::OnDisplayNameElement);
- } else if (name == L"capability") {
- return DPL::MakeDelegate(this, &AccountParser::OnCapabilityElement);
- } else {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {}
-
- virtual void Accept(const Element& /*element*/)
- {}
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (attribute.name == L"multiple-account-support") {
- if (attribute.value == L"true") {
- m_account.m_multiAccountSupport = true;
- }
- }
- }
-
- virtual void Verify()
- {
- }
-
- ElementParserPtr OnIconElement()
- {
- return ElementParserPtr(new IconParser(m_account));
- }
-
- ElementParserPtr OnDisplayNameElement()
- {
- return ElementParserPtr(new DisplayNameParser(m_account));
- }
-
- ElementParserPtr OnCapabilityElement()
- {
- return ElementParserPtr(new CapabilityParser(m_account));
- }
-
- AccountParser(ConfigParserData& data) :
- ElementParser(),
- m_properNamespace(false),
- m_multiSupport(false),
- m_data(data),
- m_account(data.accountProvider)
- {
- }
-
- private:
- bool m_properNamespace;
- bool m_multiSupport;
- ConfigParserData& m_data;
- ConfigParserData::AccountProvider& m_account;
-};
-
-class MetadataParser : public ElementParser
-{
- public:
- virtual ActionFunc GetElementParser(const DPL::String& /*ns*/,
- const DPL::String& /*name*/)
- {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-
- virtual void Accept(const XmlAttribute& attribute)
- {
- if (m_properNamespace) {
- if (attribute.name == L"key") {
- m_key = attribute.value;
- } else if (attribute.name == L"value") {
- m_value = attribute.value;
- }
- }
- }
-
- virtual void Accept(const Element& element)
- {
- if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) {
- m_properNamespace = true;
- }
- }
-
- virtual void Accept(const Text& /*text*/)
- {
- ThrowMsg(Exception::ParseError, "param element must be empty");
- }
-
- virtual void Verify()
- {
- if (m_key.IsNull()) {
- _W("metadata element must have key attribute");
- return;
- }
- NormalizeString(m_key);
- NormalizeString(m_value);
- ConfigParserData::Metadata metaData(m_key, m_value);
- FOREACH(it, m_data.metadataList) {
- if (!DPL::StringCompare(*it->key, *m_key)) {
- _E("Key isn't unique");
- return;
- }
- }
- m_data.metadataList.push_back(metaData);
- }
-
- MetadataParser(ConfigParserData& data) :
- ElementParser(),
- m_data(data),
- m_properNamespace(false)
- {}
-
- private:
- DPL::OptionalString m_key;
- DPL::OptionalString m_value;
- ConfigParserData& m_data;
- bool m_properNamespace;
-};
-
-ElementParser::ActionFunc WidgetParser::GetElementParser(
- const DPL::String& /*ns*/,
- const DPL::String& name)
-{
- FuncMap::const_iterator it = m_map.find(name);
- if (it != m_map.end()) {
- return it->second;
- } else {
- return &IgnoringParser::Create; //ignore unknown according to w3c
- }
-}
-
-WidgetParser::WidgetParser(ConfigParserData& data) :
- m_data(data),
- m_textDirection(Unicode::EMPTY)
-{
- m_map[L"name"] = DPL::MakeDelegate(this, &WidgetParser::OnNameElement);
- m_map[L"access"] = DPL::MakeDelegate(this, &WidgetParser::OnAccessElement);
- m_map[L"description"] =
- DPL::MakeDelegate(this, &WidgetParser::OnDescriptionElement);
- m_map[L"author"] = DPL::MakeDelegate(this, &WidgetParser::OnAuthorElement);
- m_map[L"license"] =
- DPL::MakeDelegate(this, &WidgetParser::OnLicenseElement);
- m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement);
- m_map[L"content"] =
- DPL::MakeDelegate(this, &WidgetParser::OnContentElement);
- m_map[L"preference"] =
- DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement);
- m_map[L"setting"] =
- DPL::MakeDelegate(this, &WidgetParser::OnSettingElement);
- m_map[L"application"] = DPL::MakeDelegate(
- this,
- &WidgetParser::
- OnApplicationElement);
- m_map[L"splash"] = DPL::MakeDelegate(this, &WidgetParser::OnSplashElement);
- m_map[L"background"] = DPL::MakeDelegate(this,
- &WidgetParser::OnBackgroundElement);
- m_map[L"privilege"] = DPL::MakeDelegate(this,
- &WidgetParser::OnPrivilegeElement);
- m_map[L"app-control"] = DPL::MakeDelegate(
- this,
- &WidgetParser::
- OnAppControlElement);
- m_map[L"category"] = DPL::MakeDelegate(this,
- &WidgetParser::OnCategoryElement);
- m_map[L"app-widget"] = DPL::MakeDelegate(this, &WidgetParser::OnAppWidgetElement);
-#ifdef CSP_ENABLED
- m_map[L"content-security-policy"] = DPL::MakeDelegate(
- this,
- &WidgetParser::
- OnCspElement);
- m_map[L"content-security-policy-report-only"] = DPL::MakeDelegate(
- this,
- &WidgetParser::
- OnCspReportOnlyElement);
-#endif
-#ifdef ALLOW_NAVIGATION_ENABLED
- m_map[L"allow-navigation"] =
- DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
-#endif
- m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
- m_map[L"metadata"] = DPL::MakeDelegate(this, &WidgetParser::OnMetadataElement);
-}
-
-ElementParserPtr WidgetParser::OnNameElement()
-{
- return ElementParserPtr(new NameParser(m_textDirection, m_data));
-}
-
-ElementParserPtr WidgetParser::OnAccessElement()
-{
- return ElementParserPtr(new AccessParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnDescriptionElement()
-{
- return ElementParserPtr(new DescriptionParser(m_textDirection, m_data));
-}
-
-ElementParserPtr WidgetParser::OnAuthorElement()
-{
- return ElementParserPtr(new AuthorParser(m_textDirection, m_data));
-}
-
-ElementParserPtr WidgetParser::OnLicenseElement()
-{
- return ElementParserPtr(new LicenseParser(m_textDirection, m_data));
-}
-
-ElementParserPtr WidgetParser::OnIconElement()
-{
- return ElementParserPtr(new IconParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnContentElement()
-{
- return ElementParserPtr(new ContentParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnPreferenceElement()
-{
- return ElementParserPtr(new PreferenceParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnSettingElement()
-{
- return ElementParserPtr(new SettingParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnApplicationElement()
-{
- return ElementParserPtr(new ApplicationParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnSplashElement()
-{
- return ElementParserPtr(new SplashParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnBackgroundElement()
-{
- return ElementParserPtr(new BackgroundParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnPrivilegeElement()
-{
- return ElementParserPtr(new PrivilegeParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnAppControlElement()
-{
- return ElementParserPtr(new AppControlParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnCategoryElement()
-{
- return ElementParserPtr(new CategoryParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnAppWidgetElement()
-{
- return ElementParserPtr(new AppWidgetParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnCspElement()
-{
- return ElementParserPtr(new CspParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnCspReportOnlyElement()
-{
- return ElementParserPtr(new CspReportOnlyParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnAllowNavigationElement()
-{
- return ElementParserPtr(new AllowNavigationParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnAccountElement()
-{
- return ElementParserPtr(new AccountParser(m_data));
-}
-
-ElementParserPtr WidgetParser::OnMetadataElement()
-{
- return ElementParserPtr(new MetadataParser(m_data));
-}
-
-void WidgetParser::Accept(const Element& element)
-{
- if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName &&
- element.ns != ConfigurationNamespace::TizenWebAppNamespaceName)
- {
- ThrowMsg(Exception::ParseError,
- "Wrong xml namespace for widget element");
- }
-}
-
-void WidgetParser::Accept(const Text& /*text*/)
-{
- ThrowMsg(Exception::ParseError, "widged element must be empty");
-}
-
-void WidgetParser::Accept(const XmlAttribute& attribute)
-{
- if (attribute.name == L"id") {
- LibIri::Wrapper iri(DPL::ToUTF8String(attribute.value).c_str());
- //If may important tests starts to fail this test we will have
- //to consider commenting this test out again.
- if (iri.Validate()) {
- m_data.widget_id = attribute.value;
- NormalizeString(m_data.widget_id);
- } else {
- _W("Widget id validation failed: %ls", attribute.value.c_str());
- }
- } else if (attribute.name == L"version") {
- m_version = attribute.value;
- NormalizeString(m_version);
- } else if (attribute.name == L"min-version") {
- _D("min-version attribute was found. Value: %ls", attribute.value.c_str());
- m_minVersion = attribute.value;
- NormalizeString(m_minVersion);
- m_data.minVersionRequired = m_minVersion;
- } else if (attribute.name == L"height") {
- DPL::OptionalString value = attribute.value;
- NormalizeString(value);
- std::string v = DPL::ToUTF8String(*value);
-
- if (!v.empty()) {
- unsigned char c = v.c_str()[0];
- if (isdigit(c)) {
- int val = 0;
- for (size_t i = 0; i < v.size(); ++i) {
- c = v.c_str()[i];
- if (isdigit(c)) {
- val *= 10;
- val += (c - '0');
- } else {
- break;
- }
- }
- m_data.height = val;
- }
- }
- } else if (attribute.name == L"width") {
- DPL::OptionalString value = attribute.value;
- NormalizeString(value);
- std::string v = DPL::ToUTF8String(*value);
-
- if (!v.empty()) {
- unsigned char c = v.c_str()[0];
- if (c >= '0' && c <= '9') {
- int val = 0;
- for (size_t i = 0; i < v.size(); ++i) {
- c = v.c_str()[i];
- if (c >= '0' && c <= '9') {
- val *= 10;
- val += (c - '0');
- } else {
- break;
- }
- }
- m_data.width = val;
- }
- }
- } else if (attribute.name == L"viewmodes") {
- DPL::Tokenize(attribute.value,
- L" ",
- std::inserter(m_windowModes,
- m_windowModes.end()),
- true);
- } else if (attribute.name == L"dir") {
- m_textDirection = Unicode::ParseDirAttribute(attribute);
- } else if (L"defaultlocale" == attribute.name) {
- if (!m_defaultlocale) {
- m_defaultlocale = attribute.value;
- NormalizeString(m_defaultlocale);
- std::string dl = DPL::ToUTF8String(*m_defaultlocale);
-
- if (!LanguageSubtagRstTreeSingleton::Instance().
- ValidateLanguageTag(dl)) {
- _W("Language tag: %s is not valid", dl.c_str());
- m_defaultlocale = DPL::OptionalString::Null;
- } else {
- _D("Default locale found %s", dl.c_str());
- }
- } else {
- _W("Ignoring subsequent default locale");
- }
- //Any other value consider as a namespace definition
- } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") {
- _D("Namespace domain: %ls", attribute.name.c_str());
- _D("Namespace value: %ls", attribute.value.c_str());
- m_nameSpaces[attribute.name] = attribute.value;
- } else {
- _E("Unknown attirbute: namespace=%ls, name=%ls, value=%ls",
- attribute.ns.c_str(), attribute.name.c_str(), attribute.value.c_str());
- }
-}
-
-void WidgetParser::Verify()
-{
- FOREACH(mode, m_windowModes) {
- if (L"windowed" == *mode || L"floating" == *mode ||
- L"fullscreen" == *mode || L"maximized" == *mode ||
- L"minimized" == *mode)
- {
- m_data.windowModes.insert(*mode);
- }
- }
- if (!m_version.IsNull()) {
- Unicode::UpdateTextWithDirectionMark(m_textDirection, &*m_version);
- m_data.version = m_version;
- }
- m_data.defaultlocale = m_defaultlocale;
- FOREACH(ns, m_nameSpaces) {
- m_data.nameSpaces.insert(ns->second);
- }
-}
-