OLD | NEW |
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // Helper function that returns the type of the entry (non-Android credentials, | 56 // 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). | 57 // Android w/ affiliated web realm (i.e. clickable) or w/o web realm). |
58 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { | 58 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { |
59 if (!is_android_uri) | 59 if (!is_android_uri) |
60 return "0"; | 60 return "0"; |
61 if (is_clickable) | 61 if (is_clickable) |
62 return "1"; | 62 return "1"; |
63 return "2"; | 63 return "2"; |
64 } | 64 } |
65 | 65 |
66 // Creates key for sorting password or password exception entries. | 66 // Creates key for sorting password or password exception entries. The key is |
67 // The key is eTLD+1 followed by subdomains | 67 // eTLD+1 followed by the reversed list of domains (e.g. |
68 // (e.g. secure.accounts.example.com => example.com.accounts.secure). | 68 // secure.accounts.example.com => example.com.com.example.accounts.secure). If |
69 // If |entry_type == SAVED|, username, password and federation are appended to | 69 // |entry_type == SAVED|, username, password and federation are appended to the |
70 // the key. The entry type code (non-Android, Android w/ or w/o affiliated web | 70 // key. The entry type code (non-Android, Android w/ or w/o affiliated web |
71 // realm) is also appended to the key. | 71 // realm) is also appended to the key. |
72 std::string CreateSortKey(const autofill::PasswordForm& form, | 72 std::string CreateSortKey(const autofill::PasswordForm& form, |
73 PasswordEntryType entry_type) { | 73 PasswordEntryType entry_type) { |
74 bool is_android_uri = false; | 74 bool is_android_uri = false; |
75 bool is_clickable = false; | 75 bool is_clickable = false; |
76 GURL link_url; | 76 GURL link_url; |
77 std::string origin = password_manager::GetShownOriginAndLinkUrl( | 77 std::string origin = password_manager::GetShownOriginAndLinkUrl( |
78 form, &is_android_uri, &link_url, &is_clickable); | 78 form, &is_android_uri, &link_url, &is_clickable); |
79 | 79 |
80 if (!is_clickable) { // e.g. android://com.example.r => r.example.com. | 80 if (!is_clickable) // e.g. android://com.example.r => r.example.com. |
81 origin = password_manager::StripAndroidAndReverse(origin); | 81 origin = password_manager::StripAndroidAndReverse(origin); |
82 } | |
83 | 82 |
84 std::string site_name = | 83 std::string site_name = |
85 net::registry_controlled_domains::GetDomainAndRegistry( | 84 net::registry_controlled_domains::GetDomainAndRegistry( |
86 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 85 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
87 if (site_name.empty()) // e.g. localhost. | 86 if (site_name.empty()) // e.g. localhost. |
88 site_name = origin; | 87 site_name = origin; |
89 std::string key = | 88 std::string key = site_name + password_manager::SplitByDotAndReverse(origin); |
90 site_name + password_manager::SplitByDotAndReverse(StringPiece( | |
91 &origin[0], origin.length() - site_name.length())); | |
92 | 89 |
93 if (entry_type == PasswordEntryType::SAVED) { | 90 if (entry_type == PasswordEntryType::SAVED) { |
94 key = key + kSortKeyPartsSeparator + | 91 key = key + kSortKeyPartsSeparator + |
95 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + | 92 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + |
96 base::UTF16ToUTF8(form.password_value); | 93 base::UTF16ToUTF8(form.password_value); |
97 if (!form.federation_origin.unique()) | 94 if (!form.federation_origin.unique()) |
98 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); | 95 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); |
99 } | 96 } |
100 | 97 |
101 // Since Android and non-Android entries shouldn't be merged into one entry, | 98 // Since Android and non-Android entries shouldn't be merged into one entry, |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 382 |
386 void PasswordManagerPresenter::PasswordExceptionListPopulater:: | 383 void PasswordManagerPresenter::PasswordExceptionListPopulater:: |
387 OnGetPasswordStoreResults( | 384 OnGetPasswordStoreResults( |
388 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { | 385 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { |
389 page_->password_exception_list_ = std::move(results); | 386 page_->password_exception_list_ = std::move(results); |
390 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, | 387 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, |
391 &page_->password_exception_duplicates_, | 388 &page_->password_exception_duplicates_, |
392 PasswordEntryType::BLACKLISTED); | 389 PasswordEntryType::BLACKLISTED); |
393 page_->SetPasswordExceptionList(); | 390 page_->SetPasswordExceptionList(); |
394 } | 391 } |
OLD | NEW |