<commit_before>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/application/common/application_file_util.h"

#include <algorithm>
#include <map>
#include <vector>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/file_util.h"
#include "base/i18n/rtl.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "net/base/escape.h"
#include "net/base/file_stream.h"
#include "third_party/libxml/src/include/libxml/tree.h"
#include "ui/base/l10n/l10n_util.h"
#include "xwalk/application/common/application_data.h"
#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/constants.h"
#include "xwalk/application/common/manifest.h"
#include "xwalk/application/common/manifest_handler.h"

#if defined(OS_TIZEN)
#include "xwalk/application/common/id_util.h"
#endif

namespace errors = xwalk::application_manifest_errors;
namespace keys = xwalk::application_manifest_keys;
namespace widget_keys = xwalk::application_widget_keys;

namespace {
const char kAttributePrefix[] = "@";
const char kNamespaceKey[] = "@namespace";
const char kTextKey[] = "#text";

const char kContentKey[] = "content";

const xmlChar kWidgetNodeKey[] = "widget";
const xmlChar kNameNodeKey[] = "name";
const xmlChar kDescriptionNodeKey[] = "description";
const xmlChar kAuthorNodeKey[] = "author";
const xmlChar kLicenseNodeKey[] = "license";
const xmlChar kVersionAttributeKey[] = "version";
const xmlChar kShortAttributeKey[] = "short";
const xmlChar kDirAttributeKey[] = "dir";

const char kDirLTRKey[] = "ltr";
const char kDirRTLKey[] = "rtl";
const char kDirLROKey[] = "lro";
const char kDirRLOKey[] = "rlo";

const char* kSingletonElements[] = {
  "allow-navigation",
  "content-security-policy-report-only",
  "content-security-policy",
  "content"<commit_msg>[Tizen] Fix multiple occurrences of author in widget setting. According to widget spec(http://www.w3.org/TR/widgets/#the-author-element-and-its-attributes), the author element's occurrences should be zero or one. If there are more than single occurrences, just read the first one and ignore others.<commit_after>// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "xwalk/application/common/application_file_util.h"

#include <algorithm>
#include <map>
#include <vector>

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/file_util.h"
#include "base/i18n/rtl.h"
#include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "net/base/escape.h"
#include "net/base/file_stream.h"
#include "third_party/libxml/src/include/libxml/tree.h"
#include "ui/base/l10n/l10n_util.h"
#include "xwalk/application/common/application_data.h"
#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/constants.h"
#include "xwalk/application/common/manifest.h"
#include "xwalk/application/common/manifest_handler.h"

#if defined(OS_TIZEN)
#include "xwalk/application/common/id_util.h"
#endif

namespace errors = xwalk::application_manifest_errors;
namespace keys = xwalk::application_manifest_keys;
namespace widget_keys = xwalk::application_widget_keys;

namespace {
const char kAttributePrefix[] = "@";
const char kNamespaceKey[] = "@namespace";
const char kTextKey[] = "#text";

const char kContentKey[] = "content";

const xmlChar kWidgetNodeKey[] = "widget";
const xmlChar kNameNodeKey[] = "name";
const xmlChar kDescriptionNodeKey[] = "description";
const xmlChar kAuthorNodeKey[] = "author";
const xmlChar kLicenseNodeKey[] = "license";
const xmlChar kVersionAttributeKey[] = "version";
const xmlChar kShortAttributeKey[] = "short";
const xmlChar kDirAttributeKey[] = "dir";

const char kDirLTRKey[] = "ltr";
const char kDirRTLKey[] = "rtl";
const char kDirLROKey[] = "lro";
const char kDirRLOKey[] = "rlo";

const char* kSingletonElements[] = {
  "allow-navigation",
  "author",
  "content-security-policy-report-only",
  "content-security-policy",
  "content"
{'fraction_non_alphanumeric': 0.13620295279683925, 'fraction_numerical': 0.0051985859846121855, 'mean_word_length': 6.254901960784314, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5384901', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1581, 'n_words': 368}