#include <dpl/log/log.h>
#include <dpl/fast_delegate.h>
#include <dpl/foreach.h>
+#include <dpl/scoped_ptr.h>
#include <pcrecpp.h>
#include <algorithm>
#include <string>
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_t> 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:
&WidgetParser::
OnCspReportOnlyElement);
#endif
+ m_map[L"allow-navigation"] =
+ DPL::MakeDelegate(this, &WidgetParser::OnAllowNavigationElement);
m_map[L"account"] = DPL::MakeDelegate(this, &WidgetParser::OnAccountElement);
}
return ElementParserPtr(new CspReportOnlyParser(m_data));
}
+ElementParserPtr WidgetParser::OnAllowNavigationElement()
+{
+ return ElementParserPtr(new AllowNavigationParser(m_data));
+}
+
ElementParserPtr WidgetParser::OnAccountElement()
{
return ElementParserPtr(new AccountParser(m_data));