Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1349)

Side by Side Diff: chrome/browser/ui/passwords/password_manager_presenter.cc

Issue 2500393002: [Password Manager] Add the scheme to sort keys for chrome://settings/passwords (Closed)
Patch Set: Changes addressed to reviewer comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/passwords/password_manager_presenter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/passwords/password_manager_presenter.h" 5 #include "chrome/browser/ui/passwords/password_manager_presenter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "chrome/browser/password_manager/password_manager_util_mac.h" 46 #include "chrome/browser/password_manager/password_manager_util_mac.h"
47 #endif 47 #endif
48 48
49 using base::StringPiece; 49 using base::StringPiece;
50 using password_manager::PasswordStore; 50 using password_manager::PasswordStore;
51 51
52 namespace { 52 namespace {
53 53
54 const char kSortKeyPartsSeparator = ' '; 54 const char kSortKeyPartsSeparator = ' ';
55 55
56 // The character that is added to a sort key if there is no federation.
57 // Note: to separate the entries w/ federation and the entries w/o federation,
58 // this character should be alphabetically smaller than real federations.
59 const char kSortKeyNoFederationSymbol = '-';
60
56 // Helper function that returns the type of the entry (non-Android credentials, 61 // Helper function that returns the type of the entry (non-Android credentials,
57 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm). 62 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm).
58 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { 63 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) {
59 if (!is_android_uri) 64 if (!is_android_uri)
60 return "0"; 65 return "0";
61 if (is_clickable) 66 if (is_clickable)
62 return "1"; 67 return "1";
63 return "2"; 68 return "2";
64 } 69 }
65 70
66 // Creates key for sorting password or password exception entries. The key is 71 // Creates key for sorting password or password exception entries. The key is
67 // eTLD+1 followed by the reversed list of domains (e.g. 72 // eTLD+1 followed by the reversed list of domains (e.g.
68 // secure.accounts.example.com => example.com.com.example.accounts.secure). If 73 // secure.accounts.example.com => example.com.com.example.accounts.secure) and
69 // |entry_type == SAVED|, username, password and federation are appended to the 74 // the scheme. If |entry_type == SAVED|, username, password and federation are
70 // key. The entry type code (non-Android, Android w/ or w/o affiliated web 75 // appended to the key. The entry type code (non-Android, Android w/ or w/o
71 // realm) is also appended to the key. 76 // affiliated web realm) is also appended to the key.
72 std::string CreateSortKey(const autofill::PasswordForm& form, 77 std::string CreateSortKey(const autofill::PasswordForm& form,
73 PasswordEntryType entry_type) { 78 PasswordEntryType entry_type) {
74 bool is_android_uri = false; 79 bool is_android_uri = false;
75 bool is_clickable = false; 80 bool is_clickable = false;
76 GURL link_url; 81 GURL link_url;
77 std::string origin = password_manager::GetShownOriginAndLinkUrl( 82 std::string origin = password_manager::GetShownOriginAndLinkUrl(
78 form, &is_android_uri, &link_url, &is_clickable); 83 form, &is_android_uri, &link_url, &is_clickable);
79 84
80 if (!is_clickable) // e.g. android://com.example.r => r.example.com. 85 if (!is_clickable) // e.g. android://com.example.r => r.example.com.
81 origin = password_manager::StripAndroidAndReverse(origin); 86 origin = password_manager::StripAndroidAndReverse(origin);
82 87
83 std::string site_name = 88 std::string site_name =
84 net::registry_controlled_domains::GetDomainAndRegistry( 89 net::registry_controlled_domains::GetDomainAndRegistry(
85 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 90 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
86 if (site_name.empty()) // e.g. localhost. 91 if (site_name.empty()) // e.g. localhost.
87 site_name = origin; 92 site_name = origin;
88 std::string key = site_name + password_manager::SplitByDotAndReverse(origin); 93 std::string key = site_name + password_manager::SplitByDotAndReverse(origin);
89 94
90 if (entry_type == PasswordEntryType::SAVED) { 95 if (entry_type == PasswordEntryType::SAVED) {
91 key = key + kSortKeyPartsSeparator + 96 key += kSortKeyPartsSeparator + base::UTF16ToUTF8(form.username_value) +
92 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + 97 kSortKeyPartsSeparator + base::UTF16ToUTF8(form.password_value);
93 base::UTF16ToUTF8(form.password_value); 98
99 key += kSortKeyPartsSeparator;
94 if (!form.federation_origin.unique()) 100 if (!form.federation_origin.unique())
95 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); 101 key += form.federation_origin.host();
102 else
103 key += kSortKeyNoFederationSymbol;
96 } 104 }
97 105
106 // To separate HTTP/HTTPS credentials, add the scheme to the key.
107 key += kSortKeyPartsSeparator + link_url.scheme();
108
98 // Since Android and non-Android entries shouldn't be merged into one entry, 109 // Since Android and non-Android entries shouldn't be merged into one entry,
99 // add the entry type code to the sort key. 110 // add the entry type code to the sort key.
100 key += 111 key +=
101 kSortKeyPartsSeparator + GetEntryTypeCode(is_android_uri, is_clickable); 112 kSortKeyPartsSeparator + GetEntryTypeCode(is_android_uri, is_clickable);
102 return key; 113 return key;
103 } 114 }
104 115
105 // Finds duplicates of |form| in |duplicates|, removes them from |store| and 116 // Finds duplicates of |form| in |duplicates|, removes them from |store| and
106 // from |duplicates|. 117 // from |duplicates|.
107 void RemoveDuplicates(const autofill::PasswordForm& form, 118 void RemoveDuplicates(const autofill::PasswordForm& form,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 393
383 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 394 void PasswordManagerPresenter::PasswordExceptionListPopulater::
384 OnGetPasswordStoreResults( 395 OnGetPasswordStoreResults(
385 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { 396 std::vector<std::unique_ptr<autofill::PasswordForm>> results) {
386 page_->password_exception_list_ = std::move(results); 397 page_->password_exception_list_ = std::move(results);
387 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, 398 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_,
388 &page_->password_exception_duplicates_, 399 &page_->password_exception_duplicates_,
389 PasswordEntryType::BLACKLISTED); 400 PasswordEntryType::BLACKLISTED);
390 page_->SetPasswordExceptionList(); 401 page_->SetPasswordExceptionList();
391 } 402 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/passwords/password_manager_presenter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698