X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fconfiguration_parser%2Fwidget_parser.cpp;h=3b0a0ec3dd1778d5037d9d8fe062b44d0ab9502e;hb=f56543848daf0a8585b6023c11cb1738b42b5e1e;hp=d740ac3f645a6b7477f44aae888920be7f6cf0f7;hpb=da52eb3014c6a6bafb16315c99f2ac6e45e854d5;p=framework%2Fweb%2Fwrt-installer.git diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp old mode 100755 new mode 100644 index d740ac3..3b0a0ec --- 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 @@ -68,7 +68,7 @@ Direction ParseDirAttribute(const XmlAttribute& attribute) } void UpdateTextWithDirectionMark(Direction direction, - DPL::String* text) + DPL::String* text) { Assert(text); switch (direction) { @@ -88,6 +88,7 @@ void UpdateTextWithDirectionMark(Direction direction, break; default: Assert(false); + break; } } } // namespace Unicode @@ -96,14 +97,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 +133,7 @@ class InnerElementsParser : public ElementParser InnerElementsParser(ElementParserPtr parent) : m_parentParser(parent), m_textDirection(Unicode::EMPTY) - { - } + {} ElementParserPtr Other() { @@ -153,7 +152,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 +202,10 @@ class NameParser : public ElementParser } NameParser(Unicode::Direction direction, - ConfigParserData& data) : + ConfigParserData& data) : m_data(data), m_textDirection(direction) - { - } + {} ElementParserPtr Other() { @@ -235,7 +233,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 +249,7 @@ class AccessParser : public ElementParser } virtual void Accept(const Text& /*text*/) - { - } + {} void AcceptWac(const XmlAttribute& attribute) { @@ -279,6 +276,7 @@ class AccessParser : public ElementParser break; default: LogError("Error in Access tag - unknown standard."); + break; } } @@ -297,7 +295,7 @@ class AccessParser : public ElementParser ConfigParserData::AccessInfo accessInfo(m_strIRIOrigin, m_bSubDomainAccess); - std::pair ret = + //std::pair ret = m_data.accessInfoSet.insert(accessInfo); } @@ -309,6 +307,7 @@ class AccessParser : public ElementParser break; default: LogError("Error in Access tag - unknown standard."); + break; } } @@ -318,8 +317,7 @@ class AccessParser : public ElementParser m_standardType(STANDARD_TYPE_NONE), m_network(false), m_data(data) - { - } + {} ElementParserPtr Other() { @@ -339,7 +337,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 +384,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 +402,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 +478,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 +556,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 +628,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 +639,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 +654,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 +670,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 +678,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) { @@ -756,7 +744,7 @@ class FeatureParser : public ElementParser struct ParamParser : public ElementParser { virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } @@ -773,8 +761,7 @@ class FeatureParser : public ElementParser } virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const Text& /*text*/) { @@ -801,8 +788,7 @@ class FeatureParser : public ElementParser ParamParser(ConfigParserData::Feature& data) : ElementParser(), m_data(data) - { - } + {} private: DPL::OptionalString m_name; @@ -811,7 +797,7 @@ class FeatureParser : public ElementParser }; virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + const DPL::String& name) { if (name == L"param") { return DPL::MakeDelegate(this, &FeatureParser::OnParamElement); @@ -821,12 +807,10 @@ class FeatureParser : public ElementParser } virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const XmlAttribute& attribute) { @@ -848,7 +832,8 @@ class FeatureParser : public ElementParser if (m_feature.name != L"") { if (iri.Validate()) { if (m_data.featuresList.find(m_feature) == - m_data.featuresList.end()) { + m_data.featuresList.end()) + { m_data.featuresList.insert(m_feature); } else { LogDebug("Ignoring feature with name" << @@ -872,8 +857,7 @@ class FeatureParser : public ElementParser ElementParser(), m_data(data), m_feature(L"") - { - } + {} private: ConfigParserData& m_data; @@ -884,7 +868,7 @@ 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 +889,7 @@ class PreferenceParser : public ElementParser } virtual void Accept(const Element& /*element*/) - { - } + {} virtual void Accept(const Text& /*text*/) { @@ -924,7 +907,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 +917,7 @@ class PreferenceParser : public ElementParser ElementParser(), m_required(false), m_data(data) - { - } + {} private: DPL::OptionalString m_name; @@ -947,7 +930,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 +944,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 +995,7 @@ class LinkParser : public ElementParser m_properNamespace(false), m_data(data), m_href(DPL::OptionalString::Null) - { - } + {} private: bool m_properNamespace; @@ -1024,18 +1007,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 +1026,13 @@ class SettingParser : public ElementParser } virtual void Verify() - { - } + {} SettingParser(ConfigParserData& data) : ElementParser(), m_data(data), m_setting(L"", L"") - { - } + {} private: ConfigParserData& m_data; @@ -1079,6 +1058,10 @@ class AppServiceParser : public ElementParser m_scheme = attribute.value; } else if (attribute.name == L"mime") { m_mime = attribute.value; + } else if (attribute.name == L"disposition") { + if (attribute.value == L"inline") + m_disposition = + ConfigParserData::ServiceInfo::Disposition::INLINE; } } @@ -1087,7 +1070,7 @@ class AppServiceParser : public ElementParser LogWarning("namespace for app service = " << element.ns); if (element.ns == ConfigurationNamespace::W3CWidgetNamespaceName) { ThrowMsg(Exception::ParseError, - "Wrong xml namespace for widget element"); + "Wrong xml namespace for widget element"); } } @@ -1110,37 +1093,47 @@ class AppServiceParser : public ElementParser NormalizeString(m_scheme); NormalizeString(m_mime); + // exception + DPL::String ignoreUri(L"file"); + + if (!m_scheme.IsNull() && *m_scheme == ignoreUri) + { + LogInfo("exception : '" << *m_scheme << "' scheme will be ignored."); + m_scheme = DPL::OptionalString::Null; + } + // 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); + m_src.IsNull() ? nullString : *m_src, + m_operation.IsNull() ? nullString : *m_operation, + m_scheme.IsNull() ? nullString : *m_scheme, + m_mime.IsNull() ? nullString : *m_mime, + m_disposition); 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)) && + // 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))) + // 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)); + "service operation is duplicated " + + DPL::ToUTF8String(*m_operation)); } } m_data.appServiceList.push_back(serviceInfo); @@ -1152,262 +1145,259 @@ class AppServiceParser : public ElementParser m_operation(DPL::OptionalString::Null), m_scheme(DPL::OptionalString::Null), m_mime(DPL::OptionalString::Null), + m_disposition(ConfigParserData::ServiceInfo::Disposition::WINDOW), m_data(data) - { - } + {} private: DPL::OptionalString m_src; DPL::OptionalString m_operation; DPL::OptionalString m_scheme; DPL::OptionalString m_mime; + ConfigParserData::ServiceInfo::Disposition m_disposition; ConfigParserData& m_data; }; class AppControlParser : public ElementParser { public: - struct SourceParser : 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; - } - - 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; - } - - 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; - } - - 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_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; - }; - + struct SourceParser : 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; + } + + 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; + } + + 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; + } + + 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) + 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); + return DPL::MakeDelegate(this, + &AppControlParser::OnOperationElement); } else if (name == L"uri") { return DPL::MakeDelegate(this, &AppControlParser::OnUriElement); - } else if (name == L"mime") { + } 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 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"); + "Wrong xml namespace for widget element"); } } @@ -1418,26 +1408,16 @@ class AppControlParser : public ElementParser virtual void Verify() { - if (m_appControl.m_src == L""){ + if (m_appControl.m_src == L"") { LogWarning("service element must have src element"); return; } - if (m_appControl.m_operation == L""){ + if (m_appControl.m_operation == L"") { LogWarning("service element must have operation element"); return; } - FOREACH(iterator, m_data.appControlList) { - if (iterator->m_src == m_appControl.m_src && - iterator->m_operation == m_appControl.m_operation ) - { - ThrowMsg(Exception::ParseError, - "app control element is duplicated " + - DPL::ToUTF8String(m_appControl.m_src) + ", " + - DPL::ToUTF8String(m_appControl.m_operation)); - } - } m_data.appControlList.push_back(m_appControl); } @@ -1460,13 +1440,12 @@ class AppControlParser : public ElementParser { return ElementParserPtr(new MimeParser(m_appControl)); } - + AppControlParser(ConfigParserData& data) : ElementParser(), m_data(data), m_appControl(L"") - { - } + {} private: ConfigParserData& m_data; @@ -1477,12 +1456,12 @@ class ApplicationParser : 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 Text& /*text*/) { if (m_properNamespace) { LogDebug("text"); @@ -1506,6 +1485,9 @@ class ApplicationParser : public ElementParser 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); @@ -1520,18 +1502,22 @@ class ApplicationParser : public ElementParser virtual void Verify() { - if(!m_id) { + if (!m_id) { ThrowMsg(Exception::ParseError, "application element must have id attribute"); } - if(!m_version) { + if (!!m_package) { + m_data.tizenPkgId = m_package; + } + + if (!m_version) { ThrowMsg(Exception::ParseError, "application element must have required_version attribute"); } //TODO check if id and version format is right - m_data.tizenId = m_id; + m_data.tizenAppId = m_id; m_data.tizenMinVersionRequired = m_version; } @@ -1541,12 +1527,12 @@ class ApplicationParser : public ElementParser m_id(DPL::OptionalString::Null), m_version(DPL::OptionalString::Null), m_properNamespace(false) - { - } + {} private: ConfigParserData& m_data; DPL::OptionalString m_id; + DPL::OptionalString m_package; DPL::OptionalString m_version; bool m_properNamespace; }; @@ -1569,18 +1555,17 @@ class SplashParser : public ElementParser } } - virtual void Accept(const Element& element) - { - } + 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"); + LogWarning( + "src attribute of splash element is mandatory - ignoring"); return; } @@ -1590,8 +1575,7 @@ class SplashParser : public ElementParser SplashParser(ConfigParserData& data) : ElementParser(), m_data(data) - { - } + {} private: DPL::OptionalString m_src; @@ -1617,17 +1601,16 @@ class BackgroundParser : public ElementParser } 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"); + LogWarning( + "src attribute of background element is mandatory - ignoring"); return; } @@ -1636,8 +1619,7 @@ class BackgroundParser : public ElementParser explicit BackgroundParser(ConfigParserData& data) : m_data(data) - { - } + {} private: DPL::OptionalString m_src; @@ -1648,14 +1630,13 @@ class PrivilegeParser : 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) { @@ -1685,7 +1666,8 @@ class PrivilegeParser : public ElementParser if (m_feature.name != L"") { if (iri.Validate()) { if (m_data.featuresList.find(m_feature) == - m_data.featuresList.end()) { + m_data.featuresList.end()) + { m_data.featuresList.insert(m_feature); } else { LogDebug("Ignoring feature with name" << @@ -1700,7 +1682,8 @@ class PrivilegeParser : public ElementParser if (m_privilege.name != L"") { if (iriPrivilege.Validate()) { if (m_data.privilegeList.find(m_privilege) == - m_data.privilegeList.end()) { + m_data.privilegeList.end()) + { m_data.privilegeList.insert(m_privilege); } else { LogDebug("Ignoring privilege with name" << @@ -1716,8 +1699,7 @@ class PrivilegeParser : public ElementParser m_feature(L""), m_privilege(L""), m_properNamespace(false) - { - } + {} private: ConfigParserData& m_data; @@ -1745,30 +1727,29 @@ class CategoryParser : public ElementParser } 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"); + LogWarning( + "name attribute of category element is mandatory - ignoring"); return; } if (m_data.categoryList.find(*m_name) == - m_data.categoryList.end()) { + m_data.categoryList.end()) + { m_data.categoryList.insert(*m_name); } } explicit CategoryParser(ConfigParserData& data) : m_data(data) - { - } + {} private: DPL::OptionalString m_name; @@ -1777,24 +1758,23 @@ class CategoryParser : public ElementParser class LiveboxParser : public ElementParser { - public: + public: struct BoxLabelParser : public ElementParser { virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } - virtual void Accept(const XmlAttribute& attribute) - { - } + virtual void Accept(const XmlAttribute& /*attribute*/) + {} virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } @@ -1802,8 +1782,9 @@ class LiveboxParser : public ElementParser virtual void Accept(const Text& text) { - if(m_properNamespace) + if (m_properNamespace) { m_label = text.value; + } } virtual void Verify() @@ -1815,10 +1796,9 @@ class LiveboxParser : public ElementParser ElementParser(), m_properNamespace(false), m_data(data) - { - } + {} - private: + private: DPL::String m_label; bool m_properNamespace; ConfigParserData::LiveboxInfo& m_data; @@ -1827,14 +1807,14 @@ class LiveboxParser : public ElementParser struct BoxIconParser : public ElementParser { virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } virtual void Accept(const XmlAttribute& attribute) { - if(m_properNamespace) { + if (m_properNamespace) { if (attribute.name == L"src") { m_icon = attribute.value; } @@ -1844,15 +1824,14 @@ class LiveboxParser : public ElementParser virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } } virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Verify() { @@ -1863,10 +1842,9 @@ class LiveboxParser : public ElementParser ElementParser(), m_properNamespace(false), m_data(data) - { - } + {} - private: + private: DPL::String m_icon; bool m_properNamespace; ConfigParserData::LiveboxInfo& m_data; @@ -1877,14 +1855,14 @@ class LiveboxParser : public ElementParser struct BoxSizeParser : public ElementParser { virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& /*name*/) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } virtual void Accept(const XmlAttribute& attribute) { - if(m_properNamespace) { + if (m_properNamespace) { if (attribute.name == L"preview") { m_preview = attribute.value; } @@ -1894,7 +1872,7 @@ class LiveboxParser : public ElementParser virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } @@ -1902,8 +1880,9 @@ class LiveboxParser : public ElementParser virtual void Accept(const Text& text) { - if(m_properNamespace) + if (m_properNamespace) { m_size = text.value; + } } virtual void Verify() @@ -1914,13 +1893,14 @@ class LiveboxParser : public ElementParser m_data.m_boxSize.push_back(boxSize); } - explicit BoxSizeParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) : + explicit BoxSizeParser( + ConfigParserData::LiveboxInfo::BoxContentInfo& data) : ElementParser(), + m_properNamespace(false), m_data(data) - { - } + {} - private: + private: DPL::String m_size; DPL::String m_preview; bool m_properNamespace; @@ -1930,14 +1910,14 @@ class LiveboxParser : public ElementParser struct PdParser : public ElementParser { virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + const DPL::String& /*name*/) { return &IgnoringParser::Create; } virtual void Accept(const XmlAttribute& attribute) { - if(m_properNamespace) { + if (m_properNamespace) { if (attribute.name == L"src") { m_src = attribute.value; } else if (attribute.name == L"width") { @@ -1951,15 +1931,14 @@ class LiveboxParser : public ElementParser virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } } virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Verify() { @@ -1968,14 +1947,14 @@ class LiveboxParser : public ElementParser m_data.m_pdHeight = m_height; } - explicit PdParser(ConfigParserData::LiveboxInfo::BoxContentInfo& data) : + explicit PdParser( + ConfigParserData::LiveboxInfo::BoxContentInfo& data) : ElementParser(), m_properNamespace(false), m_data(data) - { - } + {} - private: + private: DPL::String m_src; DPL::String m_width; DPL::String m_height; @@ -1985,37 +1964,47 @@ class LiveboxParser : public ElementParser }; virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + const DPL::String& name) { if (name == L"box-size") { - return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnBoxSizeElement); + return DPL::MakeDelegate( + this, + &LiveboxParser::BoxContentParser:: + OnBoxSizeElement); } else if (name == L"pd") { - return DPL::MakeDelegate(this, &LiveboxParser::BoxContentParser::OnPdElement); - } else{ - ThrowMsg(Exception::ParseError, "No element parser for name: " << name); + return DPL::MakeDelegate( + this, + &LiveboxParser::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") + if (attribute.name == L"src") { m_box.m_boxSrc = attribute.value; + } + if (attribute.name == L"mouse-event") { + m_box.m_boxMouseEvent = attribute.value; + } } } virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } } virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Verify() { @@ -2026,8 +2015,7 @@ class LiveboxParser : public ElementParser ElementParser(), m_properNamespace(false), m_data(data) - { - } + {} ElementParserPtr OnBoxSizeElement() { @@ -2039,7 +2027,7 @@ class LiveboxParser : public ElementParser return ElementParserPtr(new PdParser(m_box)); } - private: + private: DPL::String m_src; bool m_properNamespace; ConfigParserData::LiveboxInfo& m_data; @@ -2047,13 +2035,13 @@ class LiveboxParser : public ElementParser }; virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + const DPL::String& name) { if (name == L"box-label") { return DPL::MakeDelegate(this, &LiveboxParser::OnBoxLabelElement); } else if (name == L"box-icon") { return DPL::MakeDelegate(this, &LiveboxParser::OnBoxIconElement); - } else if (name == L"box-content") { + } else if (name == L"box-content") { return DPL::MakeDelegate(this, &LiveboxParser::OnBoxContentElement); } else { return &IgnoringParser::Create; @@ -2071,6 +2059,8 @@ class LiveboxParser : public ElementParser 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; } } } @@ -2078,15 +2068,14 @@ class LiveboxParser : public ElementParser virtual void Accept(const Element& element) { if (element.ns == - ConfigurationNamespace::TizenWebAppNamespaceName) + ConfigurationNamespace::TizenWebAppNamespaceName) { m_properNamespace = true; } } virtual void Accept(const Text& /*text*/) - { - } + {} virtual void Verify() { @@ -2094,6 +2083,7 @@ class LiveboxParser : public ElementParser 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); } @@ -2128,13 +2118,104 @@ class LiveboxParser : public ElementParser DPL::String m_primary; DPL::String m_autoLaunch; DPL::String m_updatePeriod; + DPL::String m_type; bool m_properNamespace; +}; + +class CspParser : public ElementParser +{ + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + 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; + } -ElementParser::ActionFunc WidgetParser::GetElementParser(const DPL::String& /*ns*/, - const DPL::String& name) + 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; +}; + +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()) { @@ -2166,17 +2247,34 @@ WidgetParser::WidgetParser(ConfigParserData& data) : m_map[L"setting"] = DPL::MakeDelegate(this, &WidgetParser::OnSettingElement); // TODO: appservice will be removed - m_map[L"appservice"] = DPL::MakeDelegate(this, &WidgetParser::OnAppServiceElement); - m_map[L"application"] = DPL::MakeDelegate(this, &WidgetParser::OnApplicationElement); + m_map[L"appservice"] = DPL::MakeDelegate(this, + &WidgetParser::OnAppServiceElement); + 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"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"livebox"] = DPL::MakeDelegate(this, &WidgetParser::OnLiveboxElement); - +#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 } ElementParserPtr WidgetParser::OnNameElement() @@ -2274,6 +2372,16 @@ ElementParserPtr WidgetParser::OnLiveboxElement() return ElementParserPtr(new LiveboxParser(m_data)); } +ElementParserPtr WidgetParser::OnCspElement() +{ + return ElementParserPtr(new CspParser(m_data)); +} + +ElementParserPtr WidgetParser::OnCspReportOnlyElement() +{ + return ElementParserPtr(new CspReportOnlyParser(m_data)); +} + void WidgetParser::Accept(const Element& element) { if (element.ns != ConfigurationNamespace::W3CWidgetNamespaceName && @@ -2364,26 +2472,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); } } @@ -2392,7 +2501,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); } }