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"
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";
33 bool PSLMatchingHelper::IsPublicSuffixDomainMatch(const std::string
& url1
,
34 const std::string
& url2
) {
37 return gurl1
.scheme() == gurl2
.scheme() &&
38 GetRegistryControlledDomain(gurl1
) ==
39 GetRegistryControlledDomain(gurl2
) &&
40 gurl1
.port() == gurl2
.port();
44 std::string
PSLMatchingHelper::GetRegistryControlledDomain(
45 const GURL
& signon_realm
) {
46 return net::registry_controlled_domains::GetDomainAndRegistry(
48 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES
);
52 void PSLMatchingHelper::EnablePublicSuffixDomainMatchingForTesting() {
53 psl_enabled_override_
= true;
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.
62 if (CommandLine::ForCurrentProcess()->HasSwitch(
63 switches::kDisablePasswordAutofillPublicSuffixDomainMatching
)) {