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. 4 5 #include "components/password_manager/core/browser/psl_matching_helper.h" 6 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" 14 #include "url/gurl.h" 15 16 using autofill::PasswordForm; 17 18 namespace password_manager { 19 20 #if !defined(OS_IOS) 21 namespace { 22 23 const char kPSLMatchingDesktopFieldTrialName[] = "PSLMatchingDesktop"; 24 const char kPSLMatchingDesktopFieldTrialDisabledGroupName[] = "Disabled"; 25 26 } // namespace 27 #endif 28 29 bool PSLMatchingHelper::psl_enabled_override_ = false; 30 PSLMatchingHelper()31PSLMatchingHelper::PSLMatchingHelper() : psl_enabled_(DeterminePSLEnabled()) {} 32 ~PSLMatchingHelper()33PSLMatchingHelper::~PSLMatchingHelper() {} 34 IsMatchingEnabled() const35bool PSLMatchingHelper::IsMatchingEnabled() const { 36 return psl_enabled_override_ || psl_enabled_; 37 } 38 ShouldPSLDomainMatchingApply(const std::string & registry_controlled_domain) const39bool PSLMatchingHelper::ShouldPSLDomainMatchingApply( 40 const std::string& registry_controlled_domain) const { 41 return IsMatchingEnabled() && registry_controlled_domain != "google.com"; 42 } 43 44 // static IsPublicSuffixDomainMatch(const std::string & url1,const std::string & url2)45bool PSLMatchingHelper::IsPublicSuffixDomainMatch(const std::string& url1, 46 const std::string& url2) { 47 GURL gurl1(url1); 48 GURL gurl2(url2); 49 return gurl1.scheme() == gurl2.scheme() && 50 GetRegistryControlledDomain(gurl1) == 51 GetRegistryControlledDomain(gurl2) && 52 gurl1.port() == gurl2.port(); 53 } 54 55 // static GetRegistryControlledDomain(const GURL & signon_realm)56std::string PSLMatchingHelper::GetRegistryControlledDomain( 57 const GURL& signon_realm) { 58 return net::registry_controlled_domains::GetDomainAndRegistry( 59 signon_realm, 60 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 61 } 62 63 // static EnablePublicSuffixDomainMatchingForTesting()64void PSLMatchingHelper::EnablePublicSuffixDomainMatchingForTesting() { 65 psl_enabled_override_ = true; 66 } 67 68 // static DeterminePSLEnabled()69bool PSLMatchingHelper::DeterminePSLEnabled() { 70 bool enabled = true; 71 #if !defined(OS_IOS) 72 if (base::FieldTrialList::FindFullName(kPSLMatchingDesktopFieldTrialName) == 73 kPSLMatchingDesktopFieldTrialDisabledGroupName) { 74 enabled = false; 75 } 76 #endif 77 return enabled; 78 } 79 80 } // namespace password_manager 81