From c897c19c39138c222df34bd53b2b026841285fd3 Mon Sep 17 00:00:00 2001 From: Andrzej Surdej Date: Wed, 27 Feb 2013 14:35:25 +0100 Subject: [PATCH] Content-Security-Policy-Report-Only xml tag support [Issue#] N/A [Problem] Report only csp policy was not supported. [Cause] N/A [Solution] Provided parsing and storing of csp-report-only [Verification] Build repo and run any widget. This commit requires: https://tizendev.org/gerrit/#/c/48887/ Change-Id: I21bbecd69775029ea205076aec0dc231879df00f --- src/configuration_parser/widget_parser.cpp | 54 ++++++++++++++++++++++++++++++ src/configuration_parser/widget_parser.h | 1 + 2 files changed, 55 insertions(+) diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index 7703f4b..7dc58aa 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -2161,6 +2161,51 @@ class CspParser : public ElementParser DPL::OptionalString m_policy; }; +class CspReportOnlyParser : public ElementParser +{ + public: + virtual ActionFunc GetElementParser(const DPL::String& /*ns*/, + const DPL::String& /*name*/) + { + return &IgnoringParser::Create; + } + + 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& @@ -2219,6 +2264,10 @@ WidgetParser::WidgetParser(ConfigParserData& data) : this, &WidgetParser:: OnCspElement); + m_map[L"Content-Security-Policy-Report-Only"] = DPL::MakeDelegate( + this, + &WidgetParser:: + OnCspReportOnlyElement); #endif } @@ -2322,6 +2371,11 @@ 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 && diff --git a/src/configuration_parser/widget_parser.h b/src/configuration_parser/widget_parser.h index af39afd..c8c1a2b 100644 --- a/src/configuration_parser/widget_parser.h +++ b/src/configuration_parser/widget_parser.h @@ -84,6 +84,7 @@ class WidgetParser : public ElementParser ElementParserPtr OnCategoryElement(); ElementParserPtr OnLiveboxElement(); ElementParserPtr OnCspElement(); + ElementParserPtr OnCspReportOnlyElement(); virtual ActionFunc GetElementParser(const DPL::String& ns, const DPL::String& name); -- 2.7.4