<commit_before>// Copyright (c) 2011 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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"

#include <set>

#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/view_blob_internals_job_factory.h"
#include "chrome/browser/net/view_http_cache_job_factory.h"
#include "chrome/browser/ui/webui/shared_resources_data_source.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/browser_thread.h"
#include "googleurl/src/url_util.h"
#include "grit/platform_locale_settings.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "webkit/appcache/view_appcache_internals_job.h"

namespace {

// X-WebKit-CSP is our development name for Content-Security-Policy.
// TODO(tsepez) rename when Content-security-policy is done.
// TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed.
// TODO(tsepez) chrome-extension: permits the ChromeVox screen reader
//     extension to function on these pages.  Remove it when the extension
//     is updated to stop injecting script into the pages.
const char kChromeURLContentSecurityPolicyHeader[] =
    "X-WebKit-CSP: object-src 'self'; script-src chrome://resources "
    "chrome-extension://mndnfokpggljbaajbnioimlmbfngpief "
    "'self' 'unsafe-eval'";

class ChromeURLContentSecurityPolicyExceptionSet
    : public std::set<std::string> {
 public:
  ChromeURLContentSecurityPolicyExceptionSet() : std::set<std::string>() {
    insert(chrome::kChromeUICloudPrintResourcesHost);
    insert(chrome::kChromeUICloudPrintSetupHost);
    insert(chrome::kChromeUICreditsHost);
    insert(chrome::kChromeUIDevToolsHost);
    insert(chrome::kChromeUIDialogHost);
    insert(chrome::kChromeUINewTabHost);
#if defined(OS_CHROMEOS)
    insert(chrome::kChromeUIEnterpriseEnrollmentHost);
    insert(chrome::kChromeUIOobeHost);
    insert(chrome::kChromeUIMobileSetupHost);
    insert(chrome::kChromeUIProxySettingsHost);
    insert(chrome::kChromeUIRegisterPageHost);
    insert(chrome::kChromeUISimUnlockHost);
    insert(chrome::kChromeUISystemInfoHost);
#else
    insert(chrome::kChromeUISyncPromoHost);
#endif
#if defined(TOUCH_UI)
    insert(chrome::kChromeUIKeyboardHost);
#endif
#if defined(OS_CHROMEOS) || defined(TOUCH_UI)
    insert(chrome::kChromeUICollectedCookiesHost);
    insert(chrome::kChromeUIHttpAuthHost);
    insert(chrome::kChromeUIRepostFormWarningHost);
#endif
  }
};

base::LazyInstance<ChromeURLContentSecurityPolicyExceptionSet>
    g_chrome_url_content_security_policy_exceptions(base::LINKER_INITIALIZED);

// Parse a URL into the components used to resolve its request. |source_name|
// is the hostname and |path| is the remaining portion of the URL.
void URLToRequest(const GURL& url, std::string* source_name,
                  std::string* path) {
  DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) ||
         url.SchemeIs(chrome::kChromeUIScheme));<commit_msg>Fix the repost_form_warning.html issue with aura linux build caused by Content Security Policy.<commit_after>// Copyright (c) 2011 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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"

#include <set>

#include "base/basictypes.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/lazy_instance.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/view_blob_internals_job_factory.h"
#include "chrome/browser/net/view_http_cache_job_factory.h"
#include "chrome/browser/ui/webui/shared_resources_data_source.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/browser_thread.h"
#include "googleurl/src/url_util.h"
#include "grit/platform_locale_settings.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job.h"
#include "net/url_request/url_request_job_factory.h"
#include "webkit/appcache/view_appcache_internals_job.h"

namespace {

// X-WebKit-CSP is our development name for Content-Security-Policy.
// TODO(tsepez) rename when Content-security-policy is done.
// TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed.
// TODO(tsepez) chrome-extension: permits the ChromeVox screen reader
//     extension to function on these pages.  Remove it when the extension
//     is updated to stop injecting script into the pages.
const char kChromeURLContentSecurityPolicyHeader[] =
    "X-WebKit-CSP: object-src 'self'; script-src chrome://resources "
    "chrome-extension://mndnfokpggljbaajbnioimlmbfngpief "
    "'self' 'unsafe-eval'";

class ChromeURLContentSecurityPolicyExceptionSet
    : public std::set<std::string> {
 public:
  ChromeURLContentSecurityPolicyExceptionSet() : std::set<std::string>() {
    insert(chrome::kChromeUICloudPrintResourcesHost);
    insert(chrome::kChromeUICloudPrintSetupHost);
    insert(chrome::kChromeUICreditsHost);
    insert(chrome::kChromeUIDevToolsHost);
    insert(chrome::kChromeUIDialogHost);
    insert(chrome::kChromeUINewTabHost);
#if defined(OS_CHROMEOS)
    insert(chrome::kChromeUIEnterpriseEnrollmentHost);
    insert(chrome::kChromeUIOobeHost);
    insert(chrome::kChromeUIMobileSetupHost);
    insert(chrome::kChromeUIProxySettingsHost);
    insert(chrome::kChromeUIRegisterPageHost);
    insert(chrome::kChromeUISimUnlockHost);
    insert(chrome::kChromeUISystemInfoHost);
#else
    insert(chrome::kChromeUISyncPromoHost);
#endif
#if defined(TOUCH_UI)
    insert(chrome::kChromeUIKeyboardHost);
#endif
#if defined(OS_CHROMEOS) || defined(TOUCH_UI) || defined(USE_AURA)
    insert(chrome::kChromeUICollectedCookiesHost);
    insert(chrome::kChromeUIHttpAuthHost);
    insert(chrome::kChromeUIRepostFormWarningHost);
#endif
  }
};

base::LazyInstance<ChromeURLContentSecurityPolicyExceptionSet>
    g_chrome_url_content_security_policy_exceptions(base::LINKER_INITIALIZED);

// Parse a URL into the components used to resolve its request. |source_name|
// is the hostname and |path| is the remaining portion of the URL.
void URLToRequest(const GURL& url, std::string* source_name,
                  std::string* path) {
  DCHECK(url.SchemeIs(chrome::kChromeDevToolsScheme) ||
         url.SchemeIs(chrome::kChromeUIScheme));
{'fraction_non_alphanumeric': 0.1160098842502276, 'fraction_numerical': 0.001040447392378723, 'mean_word_length': 6.100646352723915, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4041272', 'n_tokens_mistral': 2587, 'n_tokens_neox': 2568, 'n_words': 458}