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

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

Issue 2042033003: Displaying human-readable Android credentials on Android OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added unit test for SplitByDotAndReverse, addressed style issues. Created 4 years, 6 months 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
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "chrome/browser/password_manager/password_manager_util_win.h" 44 #include "chrome/browser/password_manager/password_manager_util_win.h"
45 #elif defined(OS_MACOSX) 45 #elif defined(OS_MACOSX)
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 int kAndroidAppSchemeAndDelimiterLength = 10; // Length of 'android://'.
55
56 const char kSortKeyPartsSeparator = ' '; 54 const char kSortKeyPartsSeparator = ' ';
57 55
58 // Reverse order of subdomains in hostname.
59 std::string SplitByDotAndReverse(StringPiece host) {
60 std::vector<std::string> parts =
61 base::SplitString(host, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
62 std::reverse(parts.begin(), parts.end());
63 return base::JoinString(parts, ".");
64 }
65
66 // 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,
67 // 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).
68 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) { 58 std::string GetEntryTypeCode(bool is_android_uri, bool is_clickable) {
69 if (!is_android_uri) 59 if (!is_android_uri)
70 return "0"; 60 return "0";
71 if (is_clickable) 61 if (is_clickable)
72 return "1"; 62 return "1";
73 return "2"; 63 return "2";
74 } 64 }
75 65
76 // Creates key for sorting password or password exception entries. 66 // Creates key for sorting password or password exception entries.
77 // The key is eTLD+1 followed by subdomains 67 // The key is eTLD+1 followed by subdomains
78 // (e.g. secure.accounts.example.com => example.com.accounts.secure). 68 // (e.g. secure.accounts.example.com => example.com.accounts.secure).
79 // If |entry_type == SAVED|, username, password and federation are appended to 69 // If |entry_type == SAVED|, username, password and federation are appended to
80 // the key. The entry type code (non-Android, Android w/ or w/o affiliated web 70 // the key. The entry type code (non-Android, Android w/ or w/o affiliated web
81 // realm) is also appended to the key. 71 // realm) is also appended to the key.
82 std::string CreateSortKey(const autofill::PasswordForm& form, 72 std::string CreateSortKey(const autofill::PasswordForm& form,
83 PasswordEntryType entry_type) { 73 PasswordEntryType entry_type) {
84 bool is_android_uri = false; 74 bool is_android_uri = false;
85 bool is_clickable = false; 75 bool is_clickable = false;
86 GURL link_url; 76 GURL link_url;
87 std::string origin = password_manager::GetShownOriginAndLinkUrl( 77 std::string origin = password_manager::GetShownOriginAndLinkUrl(
88 form, &is_android_uri, &link_url, &is_clickable); 78 form, &is_android_uri, &link_url, &is_clickable);
89 79
90 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.
91 origin = SplitByDotAndReverse( 81 origin = password_manager::SplitByDotAndReverse(
92 StringPiece(&origin[kAndroidAppSchemeAndDelimiterLength], 82 StringPiece(
93 origin.length() - kAndroidAppSchemeAndDelimiterLength)); 83 &origin[password_manager::kAndroidAppSchemeAndDelimiterLength],
84 origin.length() -
85 password_manager::kAndroidAppSchemeAndDelimiterLength));
94 } 86 }
95 87
96 std::string site_name = 88 std::string site_name =
97 net::registry_controlled_domains::GetDomainAndRegistry( 89 net::registry_controlled_domains::GetDomainAndRegistry(
98 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); 90 origin, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
99 if (site_name.empty()) // e.g. localhost. 91 if (site_name.empty()) // e.g. localhost.
100 site_name = origin; 92 site_name = origin;
101 std::string key = 93 std::string key =
102 site_name + SplitByDotAndReverse(StringPiece( 94 site_name + password_manager::SplitByDotAndReverse(StringPiece(
103 &origin[0], origin.length() - site_name.length())); 95 &origin[0], origin.length() - site_name.length()));
104 96
105 if (entry_type == PasswordEntryType::SAVED) { 97 if (entry_type == PasswordEntryType::SAVED) {
106 key = key + kSortKeyPartsSeparator + 98 key = key + kSortKeyPartsSeparator +
107 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator + 99 base::UTF16ToUTF8(form.username_value) + kSortKeyPartsSeparator +
108 base::UTF16ToUTF8(form.password_value); 100 base::UTF16ToUTF8(form.password_value);
109 if (!form.federation_origin.unique()) 101 if (!form.federation_origin.unique())
110 key = key + kSortKeyPartsSeparator + form.federation_origin.host(); 102 key = key + kSortKeyPartsSeparator + form.federation_origin.host();
111 } 103 }
112 104
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 390
399 void PasswordManagerPresenter::PasswordExceptionListPopulater:: 391 void PasswordManagerPresenter::PasswordExceptionListPopulater::
400 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) { 392 OnGetPasswordStoreResults(ScopedVector<autofill::PasswordForm> results) {
401 page_->password_exception_list_ = 393 page_->password_exception_list_ =
402 password_manager_util::ConvertScopedVector(std::move(results)); 394 password_manager_util::ConvertScopedVector(std::move(results));
403 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_, 395 page_->SortEntriesAndHideDuplicates(&page_->password_exception_list_,
404 &page_->password_exception_duplicates_, 396 &page_->password_exception_duplicates_,
405 PasswordEntryType::BLACKLISTED); 397 PasswordEntryType::BLACKLISTED);
406 page_->SetPasswordExceptionList(); 398 page_->SetPasswordExceptionList();
407 } 399 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698