Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / password_manager / psl_matching_helper.cc
blob5d2ea69e9d1de8b3f8a1bf6a2fe5f3168e79206b
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/password_manager/psl_matching_helper.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "components/autofill/core/common/password_form.h"
12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
13 #include "url/gurl.h"
15 using autofill::PasswordForm;
17 bool PSLMatchingHelper::psl_enabled_override_ = false;
19 PSLMatchingHelper::PSLMatchingHelper() : psl_enabled_(DeterminePSLEnabled()) {}
21 PSLMatchingHelper::~PSLMatchingHelper() {}
23 bool PSLMatchingHelper::IsMatchingEnabled() const {
24 return psl_enabled_override_ || psl_enabled_;
27 bool PSLMatchingHelper::ShouldPSLDomainMatchingApply(
28 const std::string& registry_controlled_domain) const {
29 return IsMatchingEnabled() && registry_controlled_domain != "google.com";
32 // static
33 bool PSLMatchingHelper::IsPublicSuffixDomainMatch(const std::string& url1,
34 const std::string& url2) {
35 GURL gurl1(url1);
36 GURL gurl2(url2);
37 return gurl1.scheme() == gurl2.scheme() &&
38 GetRegistryControlledDomain(gurl1) ==
39 GetRegistryControlledDomain(gurl2) &&
40 gurl1.port() == gurl2.port();
43 // static
44 std::string PSLMatchingHelper::GetRegistryControlledDomain(
45 const GURL& signon_realm) {
46 return net::registry_controlled_domains::GetDomainAndRegistry(
47 signon_realm,
48 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
51 // static
52 void PSLMatchingHelper::EnablePublicSuffixDomainMatchingForTesting() {
53 psl_enabled_override_ = true;
56 // static
57 bool PSLMatchingHelper::DeterminePSLEnabled() {
58 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_LINUX)
59 // Default choice is "enabled", so we do not need to check for
60 // kEnablePasswordAutofillPublicSuffixDomainMatching.
61 bool enabled = true;
62 if (CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kDisablePasswordAutofillPublicSuffixDomainMatching)) {
64 enabled = false;
66 return enabled;
67 #else
68 return false;
69 #endif