psl_matching_helper.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PSL_MATCHING_HELPER_H_ 6#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PSL_MATCHING_HELPER_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11 12class GURL; 13 14namespace autofill { 15struct PasswordForm; 16} // namespace autofill 17 18class PSLMatchingHelper { 19 public: 20 // Enum used for histogram tracking PSL Domain triggering. 21 // New entries should only be added to the end of the enum (before *_COUNT) so 22 // as to not disrupt existing data. 23 enum PSLDomainMatchMetric { 24 PSL_DOMAIN_MATCH_DISABLED = 0, 25 PSL_DOMAIN_MATCH_NONE, 26 PSL_DOMAIN_MATCH_FOUND, 27 PSL_DOMAIN_MATCH_COUNT 28 }; 29 30 PSLMatchingHelper(); 31 ~PSLMatchingHelper(); 32 33 bool IsMatchingEnabled() const; 34 35 // Using the public suffix list for matching the origin is only needed for 36 // websites that do not have a single hostname for entering credentials. It 37 // would be better for their users if they did, but until then we help them 38 // find 39 // credentials across different hostnames. We know that accounts.google.com is 40 // the only hostname we should be accepting credentials on for any domain 41 // under 42 // google.com, so we can apply a tighter policy for that domain. 43 // For owners of domains where a single hostname is always used when your 44 // users are entering their credentials, please contact palmer@chromium.org, 45 // nyquist@chromium.org or file a bug at http://crbug.com/ to be added here. 46 bool ShouldPSLDomainMatchingApply( 47 const std::string& registry_controlled_domain) const; 48 49 // Two URLs are considered a Public Suffix Domain match if they have the same 50 // scheme, ports, and their registry controlled domains are equal. 51 static bool IsPublicSuffixDomainMatch(const std::string& url1, 52 const std::string& url2); 53 54 // Two hosts are considered to belong to the same website when they share the 55 // registry-controlled domain part. 56 static std::string GetRegistryControlledDomain(const GURL& signon_realm); 57 58 // This overrides both the command line flags and platform restrictions. This 59 // function is not thread safe, and should be called before any other methods 60 // of |PSLMatchingHelper| are called. 61 static void EnablePublicSuffixDomainMatchingForTesting(); 62 63 private: 64 static bool DeterminePSLEnabled(); 65 66 const bool psl_enabled_; 67 68 // Default is false, once set to true, overrides |psl_enabled_|. 69 static bool psl_enabled_override_; 70 71 DISALLOW_COPY_AND_ASSIGN(PSLMatchingHelper); 72}; 73 74#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PSL_MATCHING_HELPER_H_ 75