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 namespace password_manager {
23 const char kPSLMatchingDesktopFieldTrialName[] = "PSLMatchingDesktop";
24 const char kPSLMatchingDesktopFieldTrialDisabledGroupName[] = "Disabled";
29 bool PSLMatchingHelper::psl_enabled_override_ = false;
31 PSLMatchingHelper::PSLMatchingHelper() : psl_enabled_(DeterminePSLEnabled()) {}
33 PSLMatchingHelper::~PSLMatchingHelper() {}
35 bool PSLMatchingHelper::IsMatchingEnabled() const {
36 return psl_enabled_override_ || psl_enabled_;
39 bool PSLMatchingHelper::ShouldPSLDomainMatchingApply(
40 const std::string& registry_controlled_domain) const {
41 return IsMatchingEnabled() && registry_controlled_domain != "google.com";
45 bool PSLMatchingHelper::IsPublicSuffixDomainMatch(const std::string& url1,
46 const std::string& url2) {
49 return gurl1.scheme() == gurl2.scheme() &&
50 GetRegistryControlledDomain(gurl1) ==
51 GetRegistryControlledDomain(gurl2) &&
52 gurl1.port() == gurl2.port();
56 std::string PSLMatchingHelper::GetRegistryControlledDomain(
57 const GURL& signon_realm) {
58 return net::registry_controlled_domains::GetDomainAndRegistry(
60 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
64 void PSLMatchingHelper::EnablePublicSuffixDomainMatchingForTesting() {
65 psl_enabled_override_ = true;
69 bool PSLMatchingHelper::DeterminePSLEnabled() {
72 if (base::FieldTrialList::FindFullName(kPSLMatchingDesktopFieldTrialName) ==
73 kPSLMatchingDesktopFieldTrialDisabledGroupName) {
80 } // namespace password_manager