X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fconfiguration_parser%2Fwidget_parser.cpp;h=282c12458641ca2143783d028d2a09fd53381c0b;hb=c19ea14dd1a30364ab4357718647d98961743a96;hp=20ec69e49473326b0dc1299edd3fbc0293348de4;hpb=b94ee32391b6740cc930c9e091978c0a02114367;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index 20ec69e..282c124 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -13,7 +13,7 @@ * 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 @@ -37,7 +37,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -68,7 +71,7 @@ Direction ParseDirAttribute(const XmlAttribute& attribute) } void UpdateTextWithDirectionMark(Direction direction, - DPL::String* text) + DPL::String* text) { Assert(text); switch (direction) { @@ -88,6 +91,7 @@ void UpdateTextWithDirectionMark(Direction direction, break; default: Assert(false); + break; } } } // namespace Unicode @@ -96,14 +100,13 @@ class InnerElementsParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &InnerElementsParser::Other); } virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const Text& text) { @@ -133,8 +136,7 @@ class InnerElementsParser : public ElementParser InnerElementsParser(ElementParserPtr parent) : m_parentParser(parent), m_textDirection(Unicode::EMPTY) - { - } + {} ElementParserPtr Other() { @@ -153,7 +155,7 @@ class NameParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &NameParser::Other); } @@ -203,11 +205,10 @@ class NameParser : public ElementParser } NameParser(Unicode::Direction direction, - ConfigParserData& data) : + ConfigParserData& data) : m_data(data), m_textDirection(direction) - { - } + {} ElementParserPtr Other() { @@ -235,7 +236,7 @@ class AccessParser : public ElementParser }; virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &AccessParser::Other); } @@ -251,8 +252,7 @@ class AccessParser : public ElementParser } virtual void Accept(const Text& /*text*/) - { - } + {} void AcceptWac(const XmlAttribute& attribute) { @@ -279,6 +279,7 @@ class AccessParser : public ElementParser break; default: LogError("Error in Access tag - unknown standard."); + break; } } @@ -295,10 +296,15 @@ class AccessParser : public ElementParser return; } + if(m_strIRIOrigin == L"*") //wildcard match means yes for subdomains + { + m_bSubDomainAccess = true; + } + ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin, m_bSubDomainAccess); - std::pair ret = - m_data.accessInfoSet.insert(accessInfo); + //std::pair ret = + m_data.accessInfoSet.insert(accessInfo); } virtual void Verify() @@ -309,6 +315,7 @@ class AccessParser : public ElementParser break; default: LogError("Error in Access tag - unknown standard."); + break; } } @@ -318,8 +325,7 @@ class AccessParser : public ElementParser m_standardType(STANDARD_TYPE_NONE), m_network(false), m_data(data) - { - } + {} ElementParserPtr Other() { @@ -339,7 +345,7 @@ class DescriptionParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &DescriptionParser::Other); } @@ -386,13 +392,12 @@ class DescriptionParser : public ElementParser } DescriptionParser(Unicode::Direction direction, - ConfigParserData& data) : + ConfigParserData& data) : m_data(data), m_lang(), m_description(), m_textDirection(direction) - { - } + {} private: ConfigParserData& m_data; @@ -405,17 +410,16 @@ class AuthorParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &AuthorParser::Other); } AuthorParser(Unicode::Direction direction, - ConfigParserData& data) : + ConfigParserData& data) : m_data(data), m_textDirection(direction) - { - } + {} virtual void Accept(const Element& /*element*/) { @@ -482,18 +486,17 @@ class LicenseParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return DPL::MakeDelegate(this, &LicenseParser::Other); } LicenseParser(Unicode::Direction direction, - ConfigParserData& data) : + ConfigParserData& data) : m_data(data), m_ignore(true), m_textDirection(direction) - { - } + {} virtual void Accept(const Element& element) { @@ -561,19 +564,17 @@ class IconParser : public ElementParser public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } IconParser(ConfigParserData& data) : ElementParser(), m_data(data) - { - } + {} virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const XmlAttribute& attribute) { @@ -635,7 +636,8 @@ class IconParser : public ElementParser strtol(DPL::ToUTF8String(value).c_str(), &reterr, 10); if (errno != 0 || std::string(reterr) == DPL::ToUTF8String(value) || - valueInt <= 0) { + valueInt <= 0) + { return DPL::OptionalInt::Null; } else { return valueInt; @@ -645,7 +647,8 @@ class IconParser : public ElementParser } /** - * @brief delocalizePath removes locales folder from relative path if neccessary + * @brief delocalizePath removes locales folder from relative path if + * neccessary * @param source source string * * @throw BadSrcError if string is bad value of src attribute @@ -659,15 +662,11 @@ class IconParser : public ElementParser 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 - { + 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); } } @@ -679,7 +678,7 @@ class ContentParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } @@ -687,16 +686,13 @@ class ContentParser : public ElementParser ContentParser(ConfigParserData& data) : ElementParser(), m_data(data) - { - } + {} virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Accept(const XmlAttribute& attribute) { @@ -709,7 +705,8 @@ class ContentParser : public ElementParser m_type = value; MimeTypeUtils::MimeAttributes mimeAttributes = MimeTypeUtils::getMimeAttributes(value); - if (mimeAttributes.count(L"charset") > 0) { + if ((mimeAttributes.count(L"charset") > 0) && m_encoding.IsNull()) + { m_encoding = mimeAttributes[L"charset"]; } } else if (attribute.name == L"encoding") { @@ -750,141 +747,11 @@ class ContentParser : public ElementParser ConfigParserData& m_data; }; -class FeatureParser : public ElementParser -{ - public: - struct ParamParser : public ElementParser - { - virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) - { - return &IgnoringParser::Create; - } - - virtual void Accept(const XmlAttribute& attribute) - { - if (attribute.name == L"name") { - m_name = attribute.value; - NormalizeString(m_name); - } else if (attribute.name == L"value") { - m_value = attribute.value; - NormalizeString(m_value); - } - } - - 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() || *m_name == L"") { - return; - } - if (m_value.IsNull() || *m_value == L"") { - return; - } - - ConfigParserData::Param param(*m_name); - param.value = *m_value; - - if (m_data.paramsList.find(param) == m_data.paramsList.end()) { - m_data.paramsList.insert(param); - } - } - - ParamParser(ConfigParserData::Feature& data) : - ElementParser(), - m_data(data) - { - } - - private: - DPL::OptionalString m_name; - DPL::OptionalString m_value; - ConfigParserData::Feature& m_data; - }; - - virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) - { - if (name == L"param") { - return DPL::MakeDelegate(this, &FeatureParser::OnParamElement); - } else { - 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") { - m_feature.name = attribute.value; - } else if (attribute.name == L"required") { - if (attribute.value == L"false") { - m_feature.required = false; - } else { - m_feature.required = true; - } - } - } - - 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 { - LogDebug("Ignoring feature with name" << - DPL::ToUTF8String(m_feature.name)); - } - } else { - if (m_feature.required) { - //Throw only if required - ThrowMsg(Exception::ParseError, "invalid feature IRI"); - } - } - } - } - - ElementParserPtr OnParamElement() - { - return ElementParserPtr(new ParamParser(m_feature)); - } - - FeatureParser(ConfigParserData& data) : - ElementParser(), - m_data(data), - m_feature(L"") - { - } - - private: - ConfigParserData& m_data; - ConfigParserData::Feature m_feature; -}; - class PreferenceParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } @@ -905,8 +772,7 @@ class PreferenceParser : public ElementParser } virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const Text& /*text*/) { @@ -924,7 +790,8 @@ class PreferenceParser : public ElementParser ConfigParserData::Preference preference(*m_name, m_required); preference.value = m_value; if (m_data.preferencesList.find(preference) == - m_data.preferencesList.end()) { + m_data.preferencesList.end()) + { m_data.preferencesList.insert(preference); } } @@ -933,8 +800,7 @@ class PreferenceParser : public ElementParser ElementParser(), m_required(false), m_data(data) - { - } + {} private: DPL::OptionalString m_name; @@ -947,7 +813,7 @@ class LinkParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &DenyAllParser::Create; } @@ -961,8 +827,9 @@ class LinkParser : public ElementParser ThrowMsg(Exception::ParseError, "rel attribute must have describedby value"); } - } else if (attribute.name == L"type") { - } else if (attribute.name == L"href") { + } else if (attribute.name == L"type") {} else if (attribute.name == + L"href") + { LogDebug("here is href"); m_href = attribute.value; } else { @@ -1011,8 +878,7 @@ class LinkParser : public ElementParser m_properNamespace(false), m_data(data), m_href(DPL::OptionalString::Null) - { - } + {} private: bool m_properNamespace; @@ -1024,18 +890,16 @@ class SettingParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + 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) { @@ -1045,15 +909,13 @@ class SettingParser : public ElementParser } virtual void Verify() - { - } + {} SettingParser(ConfigParserData& data) : ElementParser(), m_data(data), m_setting(L"", L"") - { - } + {} private: ConfigParserData& m_data; @@ -1063,140 +925,333 @@ class SettingParser : public ElementParser class AppControlParser : public ElementParser { public: - virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + struct SourceParser : public ElementParser { - return &IgnoringParser::Create; - } - - virtual void Accept(const XmlAttribute& attribute) - { - if (attribute.name == L"src") { - m_src = attribute.value; - } else if (attribute.name == L"operation") { - m_operation = attribute.value; - } else if (attribute.name == L"scheme") { - m_scheme = attribute.value; - } else if (attribute.name == L"mime") { - m_mime = attribute.value; + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; } - } - virtual void Accept(const Element& element) - { - LogWarning("namespace for app service = " << element.ns); - if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) { - ThrowMsg(Exception::ParseError, - "Wrong xml namespace for widget element"); - } - } + virtual void Accept(const Text& /*text*/) + {} - virtual void Accept(const Text& /*text*/) - { - ThrowMsg(Exception::ParseError, "param element must be empty"); - } + virtual void Accept(const Element& /*element*/) + {} - virtual void Verify() - { - if (m_src.IsNull()) { - LogWarning("service element must have target attribute"); - return; - } else if (m_operation.IsNull()) { - LogWarning("service element must have operation attribute"); - return; - } - NormalizeString(m_src); - NormalizeString(m_operation); - NormalizeString(m_scheme); - NormalizeString(m_mime); - - // verify duplicate element - DPL::String wildString(L"*/*"); - DPL::String nullString(L""); - ConfigParserData::ServiceInfo serviceInfo( - m_src.IsNull() ? nullString:*m_src, - m_operation.IsNull() ? nullString:*m_operation, - m_scheme.IsNull() ? nullString:*m_scheme, - m_mime.IsNull() ? nullString:*m_mime); - - FOREACH(iterator, m_data.appServiceList) { - if (iterator->m_operation == serviceInfo.m_operation && - // check scheme - (iterator->m_scheme == serviceInfo.m_scheme || - // check input scheme is "*/*" case - (iterator->m_scheme == wildString && - serviceInfo.m_scheme != nullString) || - // check iterator scheme is "*/*" case - (serviceInfo.m_scheme == wildString && - iterator->m_scheme != nullString)) && - - (iterator->m_mime == serviceInfo.m_mime || - // check input mime is "*/*" case - (iterator->m_mime == wildString && - serviceInfo.m_mime != nullString) || - // check iterator mime is "*/*" case - (serviceInfo.m_mime == wildString && - iterator->m_mime != nullString))) - { - ThrowMsg(Exception::ParseError, - "service operation is duplicated " + - DPL::ToUTF8String(*m_operation)); + virtual void Accept(const XmlAttribute& attribute) + { + if (attribute.name == L"name") { + if (attribute.value.size() > 0) { + m_value = attribute.value; + NormalizeString(m_value); + } } } - m_data.appServiceList.push_back(serviceInfo); - } - AppControlParser(ConfigParserData& data) : - ElementParser(), - m_src(DPL::OptionalString::Null), - m_operation(DPL::OptionalString::Null), - m_scheme(DPL::OptionalString::Null), - m_mime(DPL::OptionalString::Null), - m_data(data) - { - } + virtual void Verify() + { + if (m_value.IsNull() || *m_value == L"") { + return; + } - private: - DPL::OptionalString m_src; - DPL::OptionalString m_operation; - DPL::OptionalString m_scheme; - DPL::OptionalString m_mime; - ConfigParserData& m_data; -}; + m_data.m_src = *m_value; + } -class ApplicationParser : public ElementParser -{ - public: - virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) - { - return &IgnoringParser::Create; - } + SourceParser(ConfigParserData::AppControlInfo& data) : + ElementParser(), + m_properNamespace(false), + m_data(data) + {} - virtual void Accept(const Text& text) + private: + bool m_properNamespace; + DPL::OptionalString m_value; + ConfigParserData::AppControlInfo& m_data; + }; + + struct OperationParser : public ElementParser { - if (m_properNamespace) { - LogDebug("text"); - ThrowMsg(Exception::ParseError, "application element must be empty"); + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; } - } - virtual void Accept(const Element& element) - { - if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + virtual void Accept(const Text& /*text*/) + {} + + virtual void Accept(const Element& /*element*/) + {} + + virtual void Accept(const XmlAttribute& attribute) { - m_properNamespace = true; + if (attribute.name == L"name") { + if (attribute.value.size() > 0) { + m_value = attribute.value; + NormalizeString(m_value); + } + } } - LogDebug("element"); - } - virtual void Accept(const XmlAttribute& attribute) + 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; + } + + 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) + { + LogInfo("exception : '" << *m_value << "' scheme will be ignored."); + 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 { + LogDebug("Ignoring uri with name" << + DPL::ToUTF8String(*m_value)); + } + } + + 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; + } + + 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 { + LogDebug("Ignoring mime with name" << + DPL::ToUTF8String(*m_value)); + } + } + + MimeParser(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 { + return &IgnoringParser::Create; + } + } + + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + virtual void Accept(const Element& element) + { + LogWarning("namespace for app service = " << element.ns); + 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"") { + LogWarning("service element must have src element"); + return; + } + + if (m_appControl.m_operation == L"") { + LogWarning("service element must have operation element"); + return; + } + + 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)); + } + + 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; + } + + virtual void Accept(const Text& /*text*/) + { + if (m_properNamespace) { + LogDebug("text"); + ThrowMsg(Exception::ParseError, "application element must be empty"); + } + } + + virtual void Accept(const Element& element) + { + if (element.ns == + ConfigurationNamespace::TizenWebAppNamespaceName) + { + m_properNamespace = true; + } + LogDebug("element"); + } + + virtual void Accept(const XmlAttribute& attribute) { if (m_properNamespace) { LogDebug("attribute"); 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); @@ -1209,87 +1264,765 @@ class ApplicationParser : public ElementParser } } - virtual void Verify() + 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) + {} + + 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_ID; + 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; + } + + 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()) { + LogWarning( + "src attribute of splash element is mandatory - ignoring"); + return; + } + + m_data.splashImgSrc = m_src; + } + + SplashParser(ConfigParserData& data) : + ElementParser(), + m_data(data) + {} + + private: + DPL::OptionalString m_src; + ConfigParserData& m_data; +}; + +class BackgroundParser : public ElementParser +{ + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + 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()) { + LogWarning( + "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; + } + + virtual void Accept(const Text& /*text*/) + {} + + virtual void Accept(const Element& element) + { + if (element.ns == + ConfigurationNamespace::TizenWebAppNamespaceName) + { + m_properNamespace = true; + } + LogDebug("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 { + LogDebug("Ignoring feature with name" << + DPL::ToUTF8String(m_feature.name)); + } + } + } + + 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 { + LogDebug("Ignoring privilege with name" << + DPL::ToUTF8String(m_privilege.name)); + } + } + } + } + + 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; + } + + 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()) { + LogWarning( + "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; + } + + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + 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() + { + m_data.m_label = m_label; + } + + BoxLabelParser(ConfigParserData::LiveboxInfo& data) : + ElementParser(), + m_properNamespace(false), + m_data(data) + {} + + private: + 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; + } + + 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() + { + 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; + } + + virtual void Accept(const XmlAttribute& attribute) + { + if (m_properNamespace) { + if (attribute.name == L"preview") { + m_preview = 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() + { + std::pair boxSize; + boxSize.first = m_size; + boxSize.second = m_preview; + m_data.m_boxSize.push_back(boxSize); + } + + explicit BoxSizeParser( + ConfigParserData::LiveboxInfo::BoxContentInfo& data) : + ElementParser(), + m_properNamespace(false), + m_data(data) + {} + + private: + DPL::String m_size; + DPL::String m_preview; + 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; + } + + 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() + { + 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::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() + { + 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: + DPL::String m_src; + 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; + } + } + + virtual void Accept(const XmlAttribute& attribute) { - if(!m_id) { - ThrowMsg(Exception::ParseError, - "application element must have id 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; + } } + } - if(!m_version) { - ThrowMsg(Exception::ParseError, - "application element must have required_version attribute"); + virtual void Accept(const Element& element) + { + if (element.ns == + ConfigurationNamespace::TizenWebAppNamespaceName) + { + m_properNamespace = true; } + } - //TODO check if id and version format is right - m_data.tizenId = m_id; - m_data.tizenMinVersionRequired = m_version; + virtual void Accept(const Text& /*text*/) + {} + + virtual void Verify() + { + 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); } - ApplicationParser(ConfigParserData& data) : + explicit AppWidgetParser(ConfigParserData& data) : ElementParser(), m_data(data), - m_id(DPL::OptionalString::Null), - m_version(DPL::OptionalString::Null), m_properNamespace(false) { + m_livebox = ConfigParserData::LiveboxInfo(); + } + + ElementParserPtr OnBoxLabelElement() + { + return ElementParserPtr(new BoxLabelParser(m_livebox)); + } + + ElementParserPtr OnBoxIconElement() + { + return ElementParserPtr(new BoxIconParser(m_livebox)); + } + + ElementParserPtr OnBoxContentElement() + { + return ElementParserPtr(new BoxContentParser(m_livebox)); } private: ConfigParserData& m_data; - DPL::OptionalString m_id; - DPL::OptionalString m_version; + 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; }; -class SplashParser : public ElementParser +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; } - virtual void Accept(const XmlAttribute& attribute) + virtual void Accept(const Element& element) { - if (attribute.name == L"src") { - if (attribute.value.size() > 0) { - m_src = attribute.value; - } + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) { + m_properNamespace = true; } } - virtual void Accept(const Element& element) + virtual void Accept(const Text& text) { + if (m_properNamespace) { + m_origin = text.value; + } } - virtual void Accept(const Text& /*text*/) + virtual void Accept(const XmlAttribute& /*attribute*/) { } virtual void Verify() { - if (m_src.IsNull()) { - LogWarning("src attribute of splash element is mandatory - ignoring"); + if (m_origin.IsNull()) { + LogWarning("data is empty"); return; } - m_data.splashImgSrc = m_src; - } + 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; + } - SplashParser(ConfigParserData& data) : - ElementParser(), - m_data(data) - { + DPL::ScopedPtr iri(iri_parse(origin.c_str())); + if (!iri->host || strlen(iri->host) == 0) { + // input origin should has schem and host + // in case of file scheme path is filled + // "http://" + LogWarning("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); + } } private: - DPL::OptionalString m_src; + DPL::OptionalString m_origin; ConfigParserData& m_data; + bool m_properNamespace; }; -class BackgroundParser : public ElementParser +class CspParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, @@ -1298,176 +2031,363 @@ class BackgroundParser : public ElementParser return &IgnoringParser::Create; } - virtual void Accept(const XmlAttribute& attribute) + CspParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_properNamespace(false) + {} + + virtual void Accept(const Element& element) { - if (attribute.name == L"src") { - if (attribute.value.size() > 0) { - m_src = attribute.value; - } + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) { + m_properNamespace = true; } } - virtual void Accept(const Element& /*element*/) - { - } + virtual void Accept(const XmlAttribute& /*attribute*/) + {} - virtual void Accept(const Text& /*text*/) + virtual void Accept(const Text& text) { + if (m_properNamespace) { + m_policy = text.value; + } } virtual void Verify() { - if (m_src.IsNull()) { - LogWarning("src attribute of background element is mandatory - ignoring"); - return; + if (!m_policy.IsNull()) { + m_data.cspPolicy = *m_policy; } - - m_data.backgroundPage = m_src; - } - - explicit BackgroundParser(ConfigParserData& data) : - m_data(data) - { } private: - DPL::OptionalString m_src; ConfigParserData& m_data; + bool m_properNamespace; + DPL::OptionalString m_policy; }; -class PrivilegeParser : public ElementParser +class CspReportOnlyParser : public ElementParser { public: virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } - virtual void Accept(const Text& /*text*/) - { - } + CspReportOnlyParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_properNamespace(false) + {} virtual void Accept(const Element& element) { - if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) - { + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } - LogDebug("element"); } - virtual void Accept(const XmlAttribute& attribute) + virtual void Accept(const XmlAttribute& /*attribute*/) + {} + + virtual void Accept(const Text& text) { if (m_properNamespace) { - if (attribute.name == L"name") { - m_feature.name = attribute.value; - m_privilege.name = attribute.value; - } + m_policy = text.value; } - m_feature.required = true; } 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 { - LogDebug("Ignoring feature with name" << - DPL::ToUTF8String(m_feature.name)); - } - } - } - - 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 { - LogDebug("Ignoring privilege with name" << - DPL::ToUTF8String(m_privilege.name)); - } - } + if (!m_policy.IsNull()) { + m_data.cspPolicyReportOnly = *m_policy; } } - 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; + DPL::OptionalString m_policy; }; -class CategoryParser : public ElementParser +class AccountParser : public ElementParser { public: - virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + struct AccountProviderParser : public ElementParser { - return &IgnoringParser::Create; - } + public: - virtual void Accept(const XmlAttribute& attribute) + struct IconParser : public ElementParser + { + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + 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"account-small") { + m_type = ConfigParserData::IconSectionType::SmallIcon; + } + } + } + + virtual void Verify() + { + if (m_value.IsNull() || *m_value == L"") { + return; + } + + std::pair 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; + } + + 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 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; + } + + 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, &AccountProviderParser::OnIconElement); + } else if (name == L"display-name") { + return DPL::MakeDelegate(this, + &AccountProviderParser::OnDisplayNameElement); + } else if (name == L"capability") { + return DPL::MakeDelegate(this, &AccountProviderParser::OnCapabilityElement); + } else { + 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"multiple-accounts-support") { + if (attribute.value == L"") { + return; + } + + if (attribute.value == L"ture") { + m_multiSupport = true; + } + } + } + + virtual void Verify() + { + m_data.m_multiAccountSupport = m_multiSupport; + } + + ElementParserPtr OnIconElement() + { + return ElementParserPtr(new IconParser(m_data)); + } + + ElementParserPtr OnDisplayNameElement() + { + return ElementParserPtr(new DisplayNameParser(m_data)); + } + + ElementParserPtr OnCapabilityElement() + { + return ElementParserPtr(new CapabilityParser(m_data)); + } + + AccountProviderParser(ConfigParserData::AccountProvider& data) : + ElementParser(), + m_properNamespace(false), + m_multiSupport(false), + m_data(data) + {} + + private: + bool m_properNamespace; + bool m_multiSupport; + ConfigParserData::AccountProvider& m_data; + }; + + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& name) { - if (attribute.name == L"name") { - if (attribute.value.size() > 0) { - m_name = attribute.value; - } + if (name == L"account-provider") { + return DPL::MakeDelegate(this, &AccountParser::OnProviderElement); + } else { + return &IgnoringParser::Create; } } - virtual void Accept(const Element& /*element*/) + 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*/) - { - } + {} virtual void Verify() - { - if (m_name.IsNull()) { - LogWarning("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) + ElementParserPtr OnProviderElement() { + return ElementParserPtr(new AccountProviderParser(m_account)); } + AccountParser(ConfigParserData& data) : + ElementParser(), + m_data(data), + m_account(data.accountProvider), + m_properNamespace(false), + m_multiSupport(false) + {} + private: - DPL::OptionalString m_name; ConfigParserData& m_data; + ConfigParserData::AccountProvider& m_account; + bool m_properNamespace; + bool m_multiSupport; }; -ElementParser::ActionFunc WidgetParser::GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) +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()) { @@ -1491,23 +2411,42 @@ WidgetParser::WidgetParser(ConfigParserData& data) : m_map[L"icon"] = DPL::MakeDelegate(this, &WidgetParser::OnIconElement); m_map[L"content"] = DPL::MakeDelegate(this, &WidgetParser::OnContentElement); - m_map[L"feature"] = - DPL::MakeDelegate(this, &WidgetParser::OnFeatureElement); m_map[L"preference"] = DPL::MakeDelegate(this, &WidgetParser::OnPreferenceElement); m_map[L"link"] = DPL::MakeDelegate(this, &WidgetParser::OnLinkElement); m_map[L"setting"] = DPL::MakeDelegate(this, &WidgetParser::OnSettingElement); - // TODO: appservice will be removed - m_map[L"appservice"] = DPL::MakeDelegate(this, &WidgetParser::OnAppControlElement); - m_map[L"application"] = DPL::MakeDelegate(this, &WidgetParser::OnApplicationElement); + 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"appcontrol"] = DPL::MakeDelegate(this, - &WidgetParser::OnAppControlElement); + 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); + &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); } ElementParserPtr WidgetParser::OnNameElement() @@ -1545,11 +2484,6 @@ ElementParserPtr WidgetParser::OnContentElement() return ElementParserPtr(new ContentParser(m_data)); } -ElementParserPtr WidgetParser::OnFeatureElement() -{ - return ElementParserPtr(new FeatureParser(m_data)); -} - ElementParserPtr WidgetParser::OnPreferenceElement() { return ElementParserPtr(new PreferenceParser(m_data)); @@ -1595,6 +2529,31 @@ 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)); +} + void WidgetParser::Accept(const Element& element) { if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName && @@ -1685,26 +2644,27 @@ void WidgetParser::Accept(const XmlAttribute& attribute) m_defaultlocale = attribute.value; NormalizeString(m_defaultlocale); if (!LanguageSubtagRstTreeSingleton::Instance().ValidateLanguageTag( - DPL::ToUTF8String(*m_defaultlocale))) { + DPL::ToUTF8String(*m_defaultlocale))) + { LogWarning("Language tag: " << m_defaultlocale << " is not valid"); m_defaultlocale = DPL::OptionalString::Null; - } - else + } else { LogDebug("Default Locale Found " << m_defaultlocale); + } } else { LogWarning("Ignoring subsequent default locale"); } - //Any other value consider as a namespace definition + //Any other value consider as a namespace definition } else if (attribute.name == L"xmlns" || attribute.prefix == L"xmlns") { LogInfo("Namespace domain: " << attribute.name); LogInfo("Namespace value: " << attribute.value); m_nameSpaces[attribute.name] = attribute.value; } else { LogError("Unknown attirbute: namespace=" << attribute.ns << - ", name=" << attribute.name << - ", value=" << attribute.value); + ", name=" << attribute.name << + ", value=" << attribute.value); } } @@ -1713,7 +2673,8 @@ void WidgetParser::Verify() FOREACH(mode, m_windowModes) { if (L"windowed" == *mode || L"floating" == *mode || L"fullscreen" == *mode || L"maximized" == *mode || - L"minimized" == *mode) { + L"minimized" == *mode) + { m_data.windowModes.insert(*mode); } }