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 "components/password_manager/core/browser/psl_matching_helper.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/metrics/field_trial.h"
11 #include "components/autofill/core/common/password_form.h"
12 #include "components/password_manager/core/common/password_manager_switches.h"
13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
16 using autofill::PasswordForm;
18 #if !defined(OS_ANDROID) && !defined(OS_IOS)
21 const char kPSLMatchingDesktopFieldTrialName[] = "PSLMatchingDesktop";
22 const char kPSLMatchingDesktopFieldTrialDisabledGroupName[] = "Disabled";
27 bool PSLMatchingHelper::psl_enabled_override_ = false;
29 PSLMatchingHelper::PSLMatchingHelper() : psl_enabled_(DeterminePSLEnabled()) {}
31 PSLMatchingHelper::~PSLMatchingHelper() {}
33 bool PSLMatchingHelper::IsMatchingEnabled() const {
34 return psl_enabled_override_ || psl_enabled_;
37 bool PSLMatchingHelper::ShouldPSLDomainMatchingApply(
38 const std::string& registry_controlled_domain) const {
39 return IsMatchingEnabled() && registry_controlled_domain != "google.com";
43 bool PSLMatchingHelper::IsPublicSuffixDomainMatch(const std::string& url1,
44 const std::string& url2) {
47 return gurl1.scheme() == gurl2.scheme() &&
48 GetRegistryControlledDomain(gurl1) ==
49 GetRegistryControlledDomain(gurl2) &&
50 gurl1.port() == gurl2.port();
54 std::string PSLMatchingHelper::GetRegistryControlledDomain(
55 const GURL& signon_realm) {
56 return net::registry_controlled_domains::GetDomainAndRegistry(
58 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
62 void PSLMatchingHelper::EnablePublicSuffixDomainMatchingForTesting() {
63 psl_enabled_override_ = true;
67 bool PSLMatchingHelper::DeterminePSLEnabled() {
68 // Default choice is "enabled", so we do not need to check for
69 // kEnablePasswordAutofillPublicSuffixDomainMatching.
71 #if !defined(OS_ANDROID) && !defined(OS_IOS)
72 if (base::FieldTrialList::FindFullName(kPSLMatchingDesktopFieldTrialName) ==
73 kPSLMatchingDesktopFieldTrialDisabledGroupName) {
77 if (CommandLine::ForCurrentProcess()->HasSwitch(
78 switches::kDisablePasswordAutofillPublicSuffixDomainMatching)) {