| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/password_manager/core/browser/affiliation_utils.h" | 5 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| 11 #include "base/command_line.h" | |
| 12 #include "base/metrics/field_trial.h" | |
| 13 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
| 14 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 15 #include "components/autofill/core/common/password_form.h" | 13 #include "components/autofill/core/common/password_form.h" |
| 16 #include "components/password_manager/core/common/password_manager_switches.h" | |
| 17 #include "components/url_formatter/elide_url.h" | 14 #include "components/url_formatter/elide_url.h" |
| 18 #include "components/variations/variations_associated_data.h" | 15 #include "components/variations/variations_associated_data.h" |
| 19 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
| 20 #include "url/third_party/mozilla/url_parse.h" | 17 #include "url/third_party/mozilla/url_parse.h" |
| 21 #include "url/url_canon_stdstring.h" | 18 #include "url/url_canon_stdstring.h" |
| 22 | 19 |
| 23 namespace password_manager { | 20 namespace password_manager { |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // The scheme used for identifying Android applications. | 24 // The scheme used for identifying Android applications. |
| 28 const char kAndroidAppScheme[] = "android"; | 25 const char kAndroidAppScheme[] = "android"; |
| 29 | 26 |
| 30 // The name of the field trial controlling affiliation-based matching. | |
| 31 const char kFieldTrialName[] = "AffiliationBasedMatching"; | |
| 32 | |
| 33 // Returns a StringPiece corresponding to |component| in |uri|, or the empty | 27 // Returns a StringPiece corresponding to |component| in |uri|, or the empty |
| 34 // string in case there is no such component. | 28 // string in case there is no such component. |
| 35 base::StringPiece ComponentString(const std::string& uri, | 29 base::StringPiece ComponentString(const std::string& uri, |
| 36 const url::Component& component) { | 30 const url::Component& component) { |
| 37 if (!component.is_valid()) | 31 if (!component.is_valid()) |
| 38 return base::StringPiece(); | 32 return base::StringPiece(); |
| 39 return base::StringPiece(uri.c_str() + component.begin, component.len); | 33 return base::StringPiece(uri.c_str() + component.begin, component.len); |
| 40 } | 34 } |
| 41 | 35 |
| 42 // Returns true if the passed ASCII |input| string contains nothing else than | 36 // Returns true if the passed ASCII |input| string contains nothing else than |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (a.size() != b.size()) | 278 if (a.size() != b.size()) |
| 285 return false; | 279 return false; |
| 286 | 280 |
| 287 std::vector<FacetURI> a_sorted(a.begin(), a.end()); | 281 std::vector<FacetURI> a_sorted(a.begin(), a.end()); |
| 288 std::vector<FacetURI> b_sorted(b.begin(), b.end()); | 282 std::vector<FacetURI> b_sorted(b.begin(), b.end()); |
| 289 std::sort(a_sorted.begin(), a_sorted.end()); | 283 std::sort(a_sorted.begin(), a_sorted.end()); |
| 290 std::sort(b_sorted.begin(), b_sorted.end()); | 284 std::sort(b_sorted.begin(), b_sorted.end()); |
| 291 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); | 285 return std::equal(a_sorted.begin(), a_sorted.end(), b_sorted.begin()); |
| 292 } | 286 } |
| 293 | 287 |
| 294 bool IsAffiliationBasedMatchingEnabled(const base::CommandLine& command_line) { | |
| 295 // Note: It is important to always query the field trial state, to ensure that | |
| 296 // UMA reports the correct group. | |
| 297 const std::string group_name = | |
| 298 base::FieldTrialList::FindFullName(kFieldTrialName); | |
| 299 | |
| 300 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | |
| 301 return false; | |
| 302 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | |
| 303 return true; | |
| 304 return !base::StartsWith(group_name, "Disabled", | |
| 305 base::CompareCase::INSENSITIVE_ASCII); | |
| 306 } | |
| 307 | |
| 308 bool IsPropagatingPasswordChangesToWebCredentialsEnabled( | |
| 309 const base::CommandLine& command_line) { | |
| 310 // Note: It is important to always query the variation param first, which, in | |
| 311 // turn, queries the field trial state, which ensures that UMA reports the | |
| 312 // correct group if it is forced by a command line flag. | |
| 313 const std::string update_enabled = variations::GetVariationParamValue( | |
| 314 kFieldTrialName, "propagate_password_changes_to_web"); | |
| 315 | |
| 316 if (command_line.HasSwitch(switches::kDisableAffiliationBasedMatching)) | |
| 317 return false; | |
| 318 if (command_line.HasSwitch(switches::kEnableAffiliationBasedMatching)) | |
| 319 return true; | |
| 320 return !base::LowerCaseEqualsASCII(update_enabled, "disabled"); | |
| 321 } | |
| 322 | |
| 323 bool IsValidAndroidFacetURI(const std::string& url) { | 288 bool IsValidAndroidFacetURI(const std::string& url) { |
| 324 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); | 289 FacetURI facet = FacetURI::FromPotentiallyInvalidSpec(url); |
| 325 return facet.IsValidAndroidFacetURI(); | 290 return facet.IsValidAndroidFacetURI(); |
| 326 } | 291 } |
| 327 | 292 |
| 328 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, | 293 std::string GetHumanReadableOrigin(const autofill::PasswordForm& password_form, |
| 329 const std::string& languages) { | 294 const std::string& languages) { |
| 330 FacetURI facet_uri = | 295 FacetURI facet_uri = |
| 331 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); | 296 FacetURI::FromPotentiallyInvalidSpec(password_form.signon_realm); |
| 332 if (facet_uri.IsValidAndroidFacetURI()) | 297 if (facet_uri.IsValidAndroidFacetURI()) |
| 333 return GetHumanReadableOriginForAndroidUri(facet_uri); | 298 return GetHumanReadableOriginForAndroidUri(facet_uri); |
| 334 | 299 |
| 335 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( | 300 return base::UTF16ToUTF8(url_formatter::FormatUrlForSecurityDisplay( |
| 336 password_form.origin, languages)); | 301 password_form.origin, languages)); |
| 337 } | 302 } |
| 338 | 303 |
| 339 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { | 304 std::string GetHumanReadableOriginForAndroidUri(const FacetURI facet_uri) { |
| 340 DCHECK(facet_uri.IsValidAndroidFacetURI()); | 305 DCHECK(facet_uri.IsValidAndroidFacetURI()); |
| 341 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); | 306 return facet_uri.scheme() + "://" + facet_uri.android_package_name(); |
| 342 } | 307 } |
| 343 | 308 |
| 344 } // namespace password_manager | 309 } // namespace password_manager |
| OLD | NEW |