From 9d41b3a500d534a96c851ffddb9d3265a58433ee Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Tue, 23 Apr 2013 14:10:39 +0900 Subject: [PATCH] Implement allow-navigation [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Support allow-navigation This commit parsing Also store data which is separate scheme and host by irid to WidgetDAO [SCMRequest] must be imported with wrt-commons Change-Id: I7bd449861958543070527ecf3b759ed7976c5c5b --- src/configuration_parser/widget_parser.cpp | 80 ++++++++++++++++++++++++++++++ src/configuration_parser/widget_parser.h | 1 + 2 files changed, 81 insertions(+) diff --git a/src/configuration_parser/widget_parser.cpp b/src/configuration_parser/widget_parser.cpp index da4e1b9..0c054e2 100644 --- a/src/configuration_parser/widget_parser.cpp +++ b/src/configuration_parser/widget_parser.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1941,6 +1942,78 @@ class AppWidgetParser : public ElementParser bool m_properNamespace; }; +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 Element& element) + { + if (element.ns == ConfigurationNamespace::TizenWebAppNamespaceName) { + m_properNamespace = true; + } + } + + virtual void Accept(const Text& text) + { + if (m_properNamespace) { + m_origin = text.value; + } + } + + virtual void Accept(const XmlAttribute& /*attribute*/) + { + } + + virtual void Verify() + { + if (m_origin.IsNull()) { + LogWarning("data is empty"); + return; + } + + char* data = strdup(DPL::ToUTF8String(*m_origin).c_str()); + char* ptr = strtok(data," "); + while (ptr != NULL) { + std::string origin = ptr; + ptr = strtok(NULL," "); + if(origin == "*") { + ConfigParserData::AllowNavigationInfo info(L"*", L"*"); + m_data.allowNavigationInfoList.push_back(info); + continue; + } + + DPL::ScopedPtr iri(iri_parse(origin.c_str())); + if (!iri->scheme || !iri->host || strlen(iri->host) == 0) { + // input origin should has schem and host + // in case of file scheme path is filled + // "http://", "www.samsung.com" + LogWarning("input origin isn't verified"); + continue; + } + ConfigParserData::AllowNavigationInfo info( + DPL::FromUTF8String(iri->scheme), + DPL::FromUTF8String(iri->host)); + m_data.allowNavigationInfoList.push_back(info); + } + } + + private: + DPL::OptionalString m_origin; + ConfigParserData& m_data; + bool m_properNamespace; +}; + class CspParser : public ElementParser { public: @@ -2361,6 +2434,8 @@ WidgetParser::WidgetParser(ConfigParserData& data) : &WidgetParser:: OnCspReportOnlyElement); #endif + m_map[L"allow-navigation"] = + DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement); m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement); } @@ -2459,6 +2534,11 @@ 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)); diff --git a/src/configuration_parser/widget_parser.h b/src/configuration_parser/widget_parser.h index 883a5fc..c1147c9 100644 --- a/src/configuration_parser/widget_parser.h +++ b/src/configuration_parser/widget_parser.h @@ -83,6 +83,7 @@ class WidgetParser : public ElementParser ElementParserPtr OnAppWidgetElement(); ElementParserPtr OnCspElement(); ElementParserPtr OnCspReportOnlyElement(); + ElementParserPtr OnAllowNavigationElement(); ElementParserPtr OnAccountElement(); virtual ActionFunc GetElementParser(const DPL::String& ns, -- 2.7.4