Chromium Code Reviews| Index: components/password_manager/core/browser/affiliation_utils.cc |
| diff --git a/components/password_manager/core/browser/affiliation_utils.cc b/components/password_manager/core/browser/affiliation_utils.cc |
| index 8018ec4e879e367a83f5a946063072eaebc33565..699c6c49c5d4918612e11e12aff755a6f4d93b64 100644 |
| --- a/components/password_manager/core/browser/affiliation_utils.cc |
| +++ b/components/password_manager/core/browser/affiliation_utils.cc |
| @@ -30,6 +30,9 @@ const char kAndroidAppScheme[] = "android"; |
| // The name of the field trial controlling affiliation-based matching. |
| const char kFieldTrialName[] = "AffiliationBasedMatching"; |
| +// The URL prefixes that are removed from shown origin. |
| +const std::string kRemovedPrefixes[] = {"m.", "mobile.", "www."}; |
| + |
| // Returns a StringPiece corresponding to |component| in |uri|, or the empty |
| // string in case there is no such component. |
| base::StringPiece ComponentString(const std::string& uri, |
| @@ -347,4 +350,23 @@ std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, |
| password_form.origin, languages)); |
| } |
| +std::string GetShownOrigin(const GURL& url, const std::string& languages) { |
| + std::string original = base::UTF16ToUTF8( |
| + url_formatter::FormatUrlForSecurityDisplayOmitScheme(url, languages)); |
| + std::string result = original; |
| + for (std::string prefix : kRemovedPrefixes) { |
| + if (base::StartsWith(result, prefix, |
| + base::CompareCase::INSENSITIVE_ASCII)) { |
| + result = result.substr(prefix.length()); |
| + break; // remove only one prefix (e.g. www.mobile.de) |
|
Evan Stade
2015/10/05 18:59:41
nit: comments should be formatted like sentences (
kolos1
2015/10/06 18:52:33
Done.
|
| + } |
| + } |
| + |
| + if (result.find('.') != std::string::npos) { |
| + return result; |
| + } else { |
|
Evan Stade
2015/10/05 18:59:41
nit: ternary operator
kolos1
2015/10/06 18:52:33
Done.
|
| + return original; |
| + } |
| +} |
| + |
| } // namespace password_manager |